Skip to content
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

Closed
wants to merge 10 commits into from

Conversation

thiyagu06
Copy link

@thiyagu06 thiyagu06 commented Aug 15, 2022

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.

  • port all existing rules into new design
  • make CLI, maven and gradle plugin to use the new rule structure with backward compatible way
  • update README.md to inculde info on how to add custom rules

@thiyagu06 thiyagu06 changed the title Basic skeleton idea for plugging custom rules in the validation chain. Basic skeleton for plugging custom rules in the validation chain. Aug 15, 2022
@JFCote
Copy link
Member

JFCote commented Aug 15, 2022

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.

@JFCote
Copy link
Member

JFCote commented Aug 21, 2022

Hi @thiyagu06, please update with latest master. I have removed the sonarqube scan (too much bugs/missing features). It should build without issues now.

Copy link
Member

@JFCote JFCote left a 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 {
Copy link
Member

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!

Copy link
Author

@thiyagu06 thiyagu06 Aug 24, 2022

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.

cli/src/main/java/rules/CheckTagsAreDefinedRule.java Outdated Show resolved Hide resolved
cli/src/main/java/rules/CheckTagsAreDefinedRule.java Outdated Show resolved Hide resolved
@thiyagu06
Copy link
Author

thiyagu06 commented Aug 24, 2022

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.

@thiyagu06 thiyagu06 marked this pull request as ready for review August 27, 2022 16:35

private final String designation;

NamingConvention(String appelation) {
private final Predicate<String> predicate;
Copy link
Contributor

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;
Copy link
Contributor

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]+)*");
Copy link
Contributor

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 ]

@thiyagu06
Copy link
Author

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.

@JFCote
Copy link
Member

JFCote commented Aug 31, 2022

Hey @thiyagu06 , I'm back from vacation and will try to look at this in the upcoming days.
Thanks

@JFCote
Copy link
Member

JFCote commented Sep 6, 2022

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?

@thiyagu06
Copy link
Author

@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 😄 .

@thiyagu06 thiyagu06 closed this Sep 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants