6

I want to add examples of my response schema in openapi 3.0 YAML. I have went through the idea on link https://swagger.io/docs/specification/adding-examples/ but my issue is that my response schema object contains nested objects inside it. Can anyone help and guide me about how to add example while having nested objects?

1 Answer 1

12

You can define a response example in two ways. Let this is your nested json object response :

{
  "status": true,
  "data": {
    "storeId": "string",
    "message": "string"
  }
}

Method 1: Here in parameter definition itself you can add the example

myschema:
  type: object
  properties:
    status:
      type: boolean
      required: true
      example: true
    data:
      type: object
      properties:
        "message":
          type: string
          example: Success
        "Id":
          type: string
          example: 1234

Method 2: Here after the property definition you can define an example: tag like this:

myschema:
  type: object
  properties:
    status:
      type: boolean
      required: true
    data:
      type: object
      properties:
        message:
          type: string
        Id:
          type: string
  example: 
    status: true
    data:
      Id: '1234'
      message: success
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.