Skip to content
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
merged 4 commits into from
Nov 6, 2020
Merged

Conversation

erunion
Copy link
Member

@erunion erunion commented Nov 5, 2020

🧰 What's being changed?

This expands upon our support for response examples by supporting the following new methods of example pulling:

  • Examples in response model $ref schemas are now discovered and hoisted up into a visible example that can be rendered in the response example component.
  • For responses that don't have any examples present, but have schemas, we now generate an example schema that's relevant to the types that the schema has (strings get marked a string depending on the attached format, 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.
    • This work also paves the way for us to begin to surface 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 or examples at the media type level for the response, but the Pet schema it references has an example set on name to doggie. Previously since this example wasn't at the media type level we wouldn't be able to surface it, as shown here:

Screen Shot 2020-11-05 at 11 20 25 AM

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:

Screen Shot 2020-11-05 at 11 24 08 AM

@erunion erunion added the type:enhancement A potential new feature to be added, or an improvement we could make label Nov 5, 2020
@erunion erunion force-pushed the feat/improved-examples branch from 57d91fd to 84e9f46 Compare November 5, 2020 18:45
@erunion erunion marked this pull request as ready for review November 5, 2020 19:26
@darrenyong
Copy link
Contributor

so /pets POST and PUT methods don't show the examples since it isn't set in the response section, right?

@erunion
Copy link
Member Author

erunion commented Nov 5, 2020

@darrenyong Yeah no examples on those operations because there's no schema defined in the responses, just a description.

Copy link
Contributor

@darrenyong darrenyong left a comment

Choose a reason for hiding this comment

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

Looks good! This is awesome, a lot of customers are going to love this :pandaparty:

@erunion erunion merged commit d22a5cf into next Nov 6, 2020
@erunion erunion deleted the feat/improved-examples branch November 6, 2020 00:49
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type:enhancement A potential new feature to be added, or an improvement we could make
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants