Skip to content

Conversation

jgabriels
Copy link

added support for examples if no default. Also added support for properties when type is not an object


if (val.example) {
return val.example
}
Copy link
Contributor

@michaelgwelch michaelgwelch Jul 26, 2022

Choose a reason for hiding this comment

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

I'd recommend checking example before default.

See "Common Mistakes" at https://swagger.io/docs/specification/describing-parameters/

There are two common mistakes ...

  • Using default to specify a sample value. This is not intended use of default and can lead to unexpected behavior in some Swagger tools. Use the example or examples keyword for this purpose instead. See Adding Examples.

So while default might be a fine example if nothing else is available, I'd default to example first and then the first entry in examples and then finally default. That's what I did in #86 for parameter parsing.

michaelgwelch added a commit to michaelgwelch/openapi-snippet that referenced this pull request Sep 30, 2025
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