-
-
Notifications
You must be signed in to change notification settings - Fork 45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Basic skeleton for plugging custom rules in the validation chain. #388
Conversation
Hi @thiyagu06 ! Thanks for this PR. Looks very interesting. I'm currently on vacation and will look closely when I get back. Thanks. In the meantime, you can check for the Lift recommandation. Also, don't worry about the build failing. It's because of Sonarqube. |
Hi @thiyagu06, please update with latest master. I have removed the sonarqube scan (too much bugs/missing features). It should build without issues now. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have put a lot of comments, hope that makes sense. Very good start, just need some adjustment I think. And this could lead to something very nice!
/** | ||
* This rule will check whether tags are defined in the rule section | ||
*/ | ||
public class CheckTagsAreDefinedRule extends OpenAPIRule { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I love the idea of custom rules! Why did you put them in the CLI modules? I think they should go in the lib
module so anyone could use them (cli, java, maven, gradle, etc...). But maybe there was a reason. Let me know!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes.. you're right. it should not be there in the cli module. I just put it there to validate my design such that loadAndExecuteRules()
method is able to find all the rules available in the class path.
lib/src/main/java/org/openapitools/openapistylevalidator/ErrorAggregator.java
Show resolved
Hide resolved
lib/src/main/java/org/openapitools/openapistylevalidator/ErrorAggregator.java
Outdated
Show resolved
Hide resolved
lib/src/main/java/org/openapitools/openapistylevalidator/UserDefinedRuleExecutor.java
Outdated
Show resolved
Hide resolved
...ain/java/org/openapitools/openapistylevalidator/custom/CheckOperationTagsAreDefinedRule.java
Outdated
Show resolved
Hide resolved
lib/src/main/java/org/openapitools/openapistylevalidator/custom/OpenAPIRule.java
Outdated
Show resolved
Hide resolved
Hi @JFCote ,I hope I answered most of your queries. I will try to find sometime during this week to refine more on this approach. |
b09f682
to
712e863
Compare
lib/src/main/java/org/openapitools/openapistylevalidator/rules/ContactInfoRule.java
Outdated
Show resolved
Hide resolved
lib/src/main/java/org/openapitools/openapistylevalidator/RulesManager.java
Outdated
Show resolved
Hide resolved
…es into new design. I
…iple style errors from the specific rule. see HeaderNamingRule
…iple style errors from the specific rule. see HeaderNamingRule
fae0b8a
to
87503a8
Compare
|
||
private final String designation; | ||
|
||
NamingConvention(String appelation) { | ||
private final Predicate<String> predicate; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ImmutableEnumChecker: enums should be immutable: 'NamingConvention' has field 'predicate' of type 'java.util.function.Predicate<java.lang.String>', the declaration of type 'java.util.function.Predicate<java.lang.String>' is not annotated with @com.google.errorprone.annotations.Immutable
Reply with "@sonatype-lift help" for info about LiftBot commands.
Reply with "@sonatype-lift ignore" to tell LiftBot to leave out the above finding from this PR.
Reply with "@sonatype-lift ignoreall" to tell LiftBot to leave out all the findings from this PR and from the status bar in Github.
When talking to LiftBot, you need to refresh the page to see its response. Click here to get to know more about LiftBot commands.
Was this a good recommendation?
[ 🙁 Not relevant ] - [ 😕 Won't fix ] - [ 😑 Not critical, will fix ] - [ 🙂 Critical, will fix ] - [ 😊 Critical, fixing now ]
public class ParameterNamingRule implements Rule { | ||
|
||
public static final String PARAMETER_NAMING = "parameter naming"; | ||
private final RuleParameterProvider ruleParameterProvider; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💬 2 similar findings have been found in this PR
UnusedVariable: The field 'ruleParameterProvider' is never read.
Expand here to view all instances of this finding
File Path | Line Number |
---|---|
lib/src/main/java/org/openapitools/openapistylevalidator/rules/PathNamingRule.java | 13 |
lib/src/main/java/org/openapitools/openapistylevalidator/rules/PropertyNamingRule.java | 13 |
Visit the Lift Web Console to find more details in your report.
Reply with "@sonatype-lift help" for info about LiftBot commands.
Reply with "@sonatype-lift ignore" to tell LiftBot to leave out the above finding from this PR.
Reply with "@sonatype-lift ignoreall" to tell LiftBot to leave out all the findings from this PR and from the status bar in Github.
When talking to LiftBot, you need to refresh the page to see its response. Click here to get to know more about LiftBot commands.
Was this a good recommendation?
[ 🙁 Not relevant ] - [ 😕 Won't fix ] - [ 😑 Not critical, will fix ] - [ 🙂 Critical, will fix ] - [ 😊 Critical, fixing now ]
Predicate<String> camelCaseMatcher = | ||
(input) -> notEmpty.test(input) && input.matches("[a-z][a-z\\d]*(?:[A-Z\\d]+[a-z\\d]*)*"); | ||
Predicate<String> hyphenCaseMatcher = | ||
(input) -> notEmpty.test(input) && input.matches("[a-z][a-z\\d]*(?:-[a-z\\d]+)*"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💬 4 similar findings have been found in this PR
REDOS: The regular expression "[a-z][a-z\d](?:-[a-z\d]+)" is vulnerable to a denial of service attack (ReDOS)
Expand here to view all instances of this finding
File Path | Line Number |
---|---|
lib/src/main/java/org/openapitools/openapistylevalidator/naming/PatternPredicates.java | 10 |
lib/src/main/java/org/openapitools/openapistylevalidator/naming/PatternPredicates.java | 12 |
lib/src/main/java/org/openapitools/openapistylevalidator/naming/PatternPredicates.java | 14 |
lib/src/main/java/org/openapitools/openapistylevalidator/naming/PatternPredicates.java | 18 |
Visit the Lift Web Console to find more details in your report.
Reply with "@sonatype-lift help" for info about LiftBot commands.
Reply with "@sonatype-lift ignore" to tell LiftBot to leave out the above finding from this PR.
Reply with "@sonatype-lift ignoreall" to tell LiftBot to leave out all the findings from this PR and from the status bar in Github.
When talking to LiftBot, you need to refresh the page to see its response. Click here to get to know more about LiftBot commands.
Was this a good recommendation?
[ 🙁 Not relevant ] - [ 😕 Won't fix ] - [ 😑 Not critical, will fix ] - [ 🙂 Critical, will fix ] - [ 😊 Critical, fixing now ]
Hi @JFCote , If you feel the PR is huge and trying to do too much in a single PR. I can split into multiple logical unit and raise another PR once we agreed upon the new design. You can take a look at an sample here custom rules to see my thoughts in actions. |
Hey @thiyagu06 , I'm back from vacation and will try to look at this in the upcoming days. |
Hi @thiyagu06 ! Sorry for the delay! I really like the design and would like that we start working towards that. I'm thinking this could take a lot of PRs and love the idea that we go step by step, assuring that nothing is broken along the way. So I guess this PR will be closed and you will start fresh? |
@JFCote , Thanks for the comments. I will think about more on how to split up the work without breaking the existing flow in coming weeks and create small logical PRs 😄 . |
This is the first to attempt improve this validation tool to be more extensible and customisable as discussed in #347. I just created basic skeleton on how we can implement a custom rule in the existing feature. The design is inspired from the custom generator approach. The idea is at very nascent stage, we can discuss further to improve this validator to be more extensible and customisable.