How to mock multiple examples with swaggerhub API Mocking tool - OpenAPI 3
As per OpenAPI 3 we can have multiple examples. Swaggerhub provides auto-mocking which by default returns the first example (Jessica). I can't find a way to return the second example so in the below I'd like Ron to be returned.
Can anyone suggest how to achieve that with Swaggerhub?
openapi: 3.0.0 servers: - url: https://localhost/account info: description: This is a simple API version: "1.0.0" title: Simple Inventory API contact: email: firstname.lastname@example.org paths: /users: post: summary: Adds a new user requestBody: content: application/json: # Media type schema: # Request body contents $ref: '#/components/schemas/User' # Reference to an object examples: # Child of media type Jessica: # Example 1 value: id: 10 name: Jessica Smith Ron: # Example 2 value: id: 11 name: Ron Stewart responses: 200: description: A user object. content: application/json: schema: $ref: '#/components/schemas/User' # Reference to an object examples: Jessica: value: id: 10 name: Jessica Smith Ron: value: id: 20 name: Ron Stewart components: schemas: User: # Schema name type: object properties: id: type: integer format: int64
Mocked api example in swaggerhub as per above example.
In prism/stoplight which implements OpenAPI v 3 you can do this by adding Prefer key to the header. It would be strange for SwaggerHub to no leverage this functionality so I'm assuming I missed something.
Solved! Go to Solution.
As you've correctly noted, SwaggerHub always returns the first example if multiple examples are provided. SwaggerHub mock server does not support looping through responses or examples, but this is supported in our service virtualization product ServiceV.
SmartBear Documentation Team Lead
Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
That's great to know, I finally realised that this is the same as the Swagger tool here https://swagger.io/solutions/mocking-and-virtualization/ thanks for clarifying.