-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
[all] Adds strict spec option #2783
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
Conversation
Introduces an option to allow user customization of strict specification behaviors. For instance, OpenAPI 3.x requires a path object name to be prefixed with '/' so we append any missing '/', but this may not be desirable to some users or generators. In this commit, this fix specifically is the only modification affected.
@@ -214,6 +214,12 @@ | |||
description = "Skips the default behavior of validating an input specification.") | |||
private Boolean skipValidateSpec; | |||
|
|||
@Option(name = {"--strict-spec"}, | |||
title = "true/false strict behavior", | |||
description = "'MUST' and 'SHALL' wording in OpenAPI spec is strictly adhered to, e.g. no fixes will be applied to documents which pass validation but don't follow the spec.", |
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.
s/, e.g. no/. When false, no/
@@ -57,6 +57,7 @@ mvn clean compile | |||
- `logToStderr` - write all log messages (not just errors) to STDOUT | |||
- `enablePostProcessFile` - enable file post-processing hook | |||
- `skipValidateSpec` - Whether or not to skip validating the input spec prior to generation. By default, invalid specifications will result in an error. | |||
- `strictSpec` - Whether or not to treat an input document strictly against the spec. 'MUST' and 'SHALL' wording in OpenAPI spec is strictly adhered to, e.g. no fixes will be applied to documents which pass validation but don't follow the spec. |
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.
s/, e.g. no/. When false, no/
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 left a couple of comments about the docs, but the rest of this looks right to me. Thanks for putting this together!
Thanks for the review, it made me realize I had missed documenting the CLI option in a couple places. |
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.
LGTM
Forgot to assign from |
Introduces an option to allow user customization of strict specification
behaviors. For instance, OpenAPI 3.x requires a path object name to be
prefixed with '/' so we append any missing '/', but this may not be
desirable to some users or generators. In this commit, this fix specifically is
the only modification affected.
PR checklist
./bin/
to update Petstore sample so that CIs can verify the change. (For instance, only need to run./bin/{LANG}-petstore.sh
,./bin/openapi3/{LANG}-petstore.sh
if updating the {LANG} (e.g. php, ruby, python, etc) code generator or {LANG} client's mustache templates). Windows batch files can be found in.\bin\windows\
.master
,. Default:3.4.x
,4.0.x
master
.Description of the PR
Adds an option which allows users to disable any strict specification behaviors applied during generation. For example, #1034 introduces a modification which prefixes all paths missing a beginning slash to better fit "MUST" definitions in the OpenAPI Specification 3.x. Ideally, this behavior would be rolled up into the parser (i.e. if we've validated via the parser, we shouldn't need to fix the spec document).
Such a switch is necessary because, as discussed in #2702, users may not want the input document to be modified to match strict behaviors against the specification.
Use of this option to disable strict behaviors, however, does mean that one or more generators may not work as expected. For example, if the url part of a document is:
http://localhost/api
and the path isresource/{id}
, this may result in a generated URL such ashttp://localhost/apiresource/{id}
.Note that there seems to be a discrepancy or error in the OpenAPI 3.0.x specification. A server url object default is a server with relative url
/
. The url requirement is defined as:But, URLs with and without trailing
/
are both valid.The field name for a paths object is defined as:
So, strictly following the spec here, it seems that when
server.url = /
andpaths["/api"]
exist, the desired outcome (no relative URL resolution, appending path to URL) is//api
, which obviously isn't correct as this means the protocol-relative hostnameapi
.This PR does not attempt to resolve any concerns with the above scenario; it is only provided as an example of why we follow strict behaviors by default and need to sometimes modify what a user provides (even when it successfully validates against the spec).
/cc @OpenAPITools/generator-core-team
TODO
Once merged, the option will need to be applied to the gradle plugin. It seems to always resolve against maven with greater precedence over mavenLocal, and I'm hesitant to shift repository settings around and introduce any issues with the build pipeline.