-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
[core] Extracting recommendations to validation framework #4979
[core] Extracting recommendations to validation framework #4979
Conversation
👍 Thanks for opening this issue! The team will review the labels and make any necessary changes. |
Looking for feedback before I write out all docs and tests. |
@jimschubert Thanks for personal invite! 😉 What about #4413? I know that Something like |
@ybelenko good call, added it via 2e3b927 (included GET and HEAD operations). |
A possible future option would be to reformat how we present recommendations from the The evaluated rules are captured as Valid or Invalid instances. An Invalid result holds a reference to the rule with generic failure message and (if supported by the rule being evaluated), a more detailed failure message. For now I've kept the CLI output as the generic failure message because larger specs may become very verbose if we output recommendations at the very detailed level. Plus, I'd like to look further into how we might present the "path" or context within a spec for the suggestion, and I think this will be difficult using a third-party parser. This is lower priority for me, though (focusing on quick win usability type work for both users and contributors). |
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.
...openapi-generator-core/src/main/java/org/openapitools/codegen/validation/ValidationRule.java
Show resolved
Hide resolved
2e3b927
to
557e4be
Compare
I've rebased and retargeted to 4.3.x because of my concern about the signature change being a breaking change. Although I don't anticipate people are using the type, it's better to be safe. If CI passes and there are no other reviews, I'll merge it up to 4.3.x. |
This is work to extract recommendation logic out of the CLI validate command into a shared evaluation instance which can be used elsewhere (such as Gradle, or the Online tool). For now, these validations are in addition to those provided by swagger-parser and are only the following recommendations: * Apache/Nginx warning that header values with underscore are dropped by default * Unused models/schemas * Use of properties with oneOf, which is ambiguous in OpenAPI Specification I've allowed for disabling recommendations via System properties, since this is something that has been requested a few times by users. System properties in this commit include: * openapi.generator.rule.recommendations=false - Allows for disabling recommendations completely. This wouldn't include all warnings and errors, only those we deem to be suggestions * openapi.generator.rule.apache-nginx-underscore=false - Allows for disabling the Apache/Nginx warning when header names have underscore - This is a legacy CGI configuration, and doesn't affect all web servers * openapi.generator.rule.oneof-properties-ambiguity=false - We support this functionality, but the specification may not intend for it - This is more to reduce noise * openapi.generator.rule.unused-schemas=false - We will warn when a schema is not referenced outside of Components, which users have requested to be able to turn off
Recommendation can be disabled via system property: -Dopenapi.generator.rule.anti-patterns.uri-unexpected-body=false
722a1a3
to
129d0e1
Compare
I've marked this as breaking change without fallback, however I doubt anyone was using the validation framework outside of the codebase and nobody should be affected by the signature changes in this PR. |
This is work to extract recommendation logic out of the CLI validate command into a shared evaluation instance which can be used elsewhere (such as Gradle, or the Online tool).
For now, these validations are in addition to those provided by swagger-parser and are only the following recommendations:
I've allowed for disabling recommendations via System properties, since this is something that has been requested a few times by users. System properties in this commit include:
This moves validations as suggested in #4412, and prepares for sharing it with other tools in our project.
Example output:
PR checklist
./bin/
(or Windows batch scripts under.\bin\windows
) to update Petstore samples related to your fix. This is important, as CI jobs will verify all generator outputs of your HEAD commit, and these must match the expectations made by your contribution. You only need to run./bin/{LANG}-petstore.sh
,./bin/openapi3/{LANG}-petstore.sh
if updating the code or mustache templates for a language ({LANG}
) (e.g. php, ruby, python, etc).master
,4.3.x
,5.0.x
. Default:master
.cc @ybelenko @OpenAPITools/generator-core-team