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

Merged
merged 2 commits into from
Jun 2, 2025

Conversation

olivier-thatch
Copy link
Contributor

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 2 times, most recently from bc32c7e to 647b5e1 Compare May 7, 2025 01:40
@olivier-thatch
Copy link
Contributor 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
Contributor Author

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

@olivier-thatch olivier-thatch force-pushed the handle-param-examples branch from 647b5e1 to 72a9e69 Compare May 12, 2025 16:38
@olivier-thatch
Copy link
Contributor Author

@numbata Tests are passing now!

@numbata
Copy link
Contributor

numbata commented May 12, 2025

Cool! It looks like this should also solve #884 and supersede #885.

@olivier-thatch olivier-thatch force-pushed the handle-param-examples branch 2 times, most recently from c943989 to ea10462 Compare May 19, 2025 17:09
@olivier-thatch
Copy link
Contributor Author

Hm. I'm not sure why this PR is now causing segfaults with Ruby 3.5-dev 🤔

@dblock
Copy link
Member

dblock commented May 24, 2025

I fixed CI on master, rebase please?

@olivier-thatch olivier-thatch force-pushed the handle-param-examples branch from ea10462 to 1877046 Compare May 28, 2025 16:31
@numbata
Copy link
Contributor

numbata commented May 28, 2025

Thanks for the rebase, @olivier-thatch! Could you add a CHANGELOG entry? Once that's in, we'll squash and merge this PR into master.

@olivier-thatch olivier-thatch changed the title Use x-example for non-body parameters Use x-example for non-body parameters May 28, 2025
@olivier-thatch olivier-thatch force-pushed the handle-param-examples branch from c5035e4 to af6eea5 Compare May 28, 2025 18:26
@numbata
Copy link
Contributor

numbata commented May 28, 2025

#951 (comment)
it wants a period in the end of the line.

@olivier-thatch olivier-thatch force-pushed the handle-param-examples branch from af6eea5 to 5e2504a Compare May 28, 2025 21:12
@numbata
Copy link
Contributor

numbata commented May 31, 2025

@olivier-thatch Fantastic work on this PR! 👍
@dblock It looks ready to merge when you have a moment.

@dblock
Copy link
Member

dblock commented May 31, 2025

LGTM, @LeFnord is usual maintainer here, tagging him but will merge if we don't hear back in a bit

@dblock dblock requested a review from LeFnord May 31, 2025 14:42
@LeFnord
Copy link
Member

LeFnord commented May 31, 2025

@dblock … will do it on sunday, but feel free to to merge it, if you think it is urgent

Copy link
Member

@LeFnord LeFnord left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @olivier-thatch
Do we want an documentation entry, so this feture is known?
no, don't think so … will merge it

@LeFnord LeFnord merged commit cb6962a into ruby-grape:master Jun 2, 2025
19 checks passed
@olivier-thatch olivier-thatch deleted the handle-param-examples branch June 2, 2025 18:29
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.

4 participants