This repository has been archived by the owner on Nov 28, 2022. It is now read-only.
feat: improved support for response examples #1027
Merged
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.
🧰 What's being changed?
This expands upon our support for response examples by supporting the following new methods of example pulling:
$ref
schemas are now discovered and hoisted up into a visible example that can be rendered in the response example component.string
depending on the attachedformat
, numbers get a fake numbers, booleans a boolean, etc.). Check out feat: ability to generate sample schemas for a request and response oas#295 for some more indepth details on how this all works.requestBody
examples as well, but that isn't included in this batch of work.Should note that we only support this automatic example creation on non-XML media types as the objects we're composing are JSON.
🧪 Testing
To see this new example support in action, load up the "Finds Pets by status" petstore example on https://preview.readme.io/
In the definition for that operation, it has no
example
orexamples
at the media type level for the response, but thePet
schema it references has an example set onname
todoggie
. Previously since this example wasn't at the media type level we wouldn't be able to surface it, as shown here:However with these improvements we're now able to surface
doggie
as well as flesh out the rest of the documented response with some example values: