Use x-example for non-body parameters #951
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
OpenAPI 2.0 does not support setting
example
for non-body parameters. Thex-example
extension is commonly used instead and is understood by most OpenAPI tooling including Swagger UI and Swagger Converter (which will convertx-example
toexample
, since that works in OpenAPI 3.0).Today one can work around this by setting
documentation: { x: { example: "foo" } }
for non-body parameters, however the inconsistency betweendocumentation: { example: "foo" }
anddocumentation: { x: { example: "foo" } }
is annoying, and it's also problematic if you want to share params between e.g. a GET endpoint (which will use query parameters by default) and a POST endpoint (which will use body parameters by default).This PR makes is so that
documentation: { example: "foo" }
can be used in all places, and grape-swagger will automatically convert the examples for non-body parameters to be rendered asx-example
in the generated schema.References: