Skip to content

[openapi3] add support for parameter examples via @opExample #7403

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 15 commits into from
Jun 6, 2025

Conversation

chrisradek
Copy link
Member

@chrisradek chrisradek commented May 20, 2025

Fixes #3873

This PR adds support for generating parameter examples in openapi3.

Notes:
From the OpenAPI spec (https://spec.openapis.org/oas/v3.0.4.html#fixed-fields-for-use-with-schema):

When example or examples are provided in conjunction with the schema field, the example SHOULD match the specified schema and follow the prescribed serialization strategy for the parameter.

The parameter-level examples are meant to be serialized as they would appear over the wire. This means in some cases, they conflict with the parameter schema. For example, when a header parameter is an array.

The OpenAPI spec provides a table that shows what an example should look like for any given parameter style:
https://spec.openapis.org/oas/v3.0.4.html#style-examples

Link to inconclusive discussion on the correct way to represent example in OpenAPI 3 OAI/OpenAPI-Specification#4622

Copy link
Contributor

github-actions bot commented May 20, 2025

All changed packages have been documented.

  • @typespec/openapi3
Show changes

@typespec/openapi3 - feature ✏️

Adds support for parameter examples via @opExample via the experimental-parameter-examples option.

@azure-sdk
Copy link
Collaborator

azure-sdk commented May 20, 2025

You can try these changes here

🛝 Playground 🌐 Website 🛝 VSCode Extension

@timotheeguerin
Copy link
Member

For reference link to inconclusive discussion on what is the correct way OAI/OpenAPI-Specification#4622

Copy link
Member

@timotheeguerin timotheeguerin left a comment

Choose a reason for hiding this comment

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

This looks good, lets maybe make sure everyone is onboard with having it has this experimental flag vs just naming it parameter-examples

Copy link
Member

@timotheeguerin timotheeguerin left a comment

Choose a reason for hiding this comment

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

Lets just do that and we can change the property later when we have more info

@chrisradek chrisradek enabled auto-merge June 6, 2025 23:23
@chrisradek chrisradek added this pull request to the merge queue Jun 6, 2025
Merged via the queue into microsoft:main with commit ccc0a22 Jun 6, 2025
25 checks passed
@chrisradek chrisradek deleted the oa3-examples-on-params branch June 6, 2025 23:49
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.

Extend the @opExample decorator to support example values for path / query string parameters
3 participants