Skip to content

Use x-example for non-body parameters #951

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

olivier-thatch
Copy link

OpenAPI 2.0 does not support setting example for non-body parameters. The x-example extension is commonly used instead and is understood by most OpenAPI tooling including Swagger UI and Swagger Converter (which will convert x-example to example, 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 between documentation: { example: "foo" } and documentation: { 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 as x-example in the generated schema.

References:

@olivier-thatch olivier-thatch force-pushed the handle-param-examples branch from f77c8bc to bc32c7e Compare May 7, 2025 01:35
@olivier-thatch olivier-thatch force-pushed the handle-param-examples branch from bc32c7e to 647b5e1 Compare May 7, 2025 01:40
@olivier-thatch
Copy link
Author

I don't know why tests are failing. The failures do not look related to the code changed in this PR, and I cannot reproduce the failures locally.

@numbata
Copy link
Contributor

numbata commented May 7, 2025

Hi @olivier-thatch,
I've been able to reproduce the failed test with the following commands:

MODEL_PARSER=grape-swagger-entity bundle install
MODEL_PARSER=grape-swagger-entity bundle exec rspec spec/swagger_v2/api_swagger_v2_type-format_spec.rb:87

For now, I can confirm that these failures do not seem to be related to the code changed in this PR. I will be looking closely into the issue. If you'd like to investigate these unrelated failures as well, please let me know.

@numbata
Copy link
Contributor

numbata commented May 7, 2025

Just a heads-up, I've identified the cause of the failing test and have opened a PR (ruby-grape/grape-swagger-entity#82) to address it. The issue with red specs absolutely is not related to the changes in this PR.

@olivier-thatch
Copy link
Author

@numbata Thanks! I will rebase once your PR is merged.

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