1

I'm making APIs documentation by swagger In my swagger editor, I'm returning this response

 {
  "id": "70020ed1-50fe-4c7e-afed",
  "email": "test123@gmail.com",
  "authentication_token": "xzmsjvvkvgf448449"
}

by the code below from swagger editor

responses:
        200:
          description: User credentials.
          schema:
          # $ref: '#/definitions/User'
            properties:
              id:
                type: string
                example: 70020ed1-50fe-4c7e-afed
              email:
                type: string
                example: test123@gmail.com
              authentication_token:
                type: string
                example: xzmsjvvkvgf448449

I want to show it in a way as I'm getting it in an actual way. like this

    {
    "message": "User Information & already exist",
    "user": {
        "id": "2386d9c5-5530-4950-b8fe-",
        "email": "saad.arshad@yahoo.com",
        "authentication_token": "kagHmoRSmPiu2R"}}

probably in a user object.

Humayun Naseer
  • 440
  • 7
  • 18
  • Does this answer your question -- [Swagger: How to have a property reference a model in OpenAPI 2.0 (i.e. nest the models)?](https://stackoverflow.com/q/26287962/113116) – Helen Dec 21 '20 at 08:52
  • @Helen thankyou but the answer below is the correct answer for my case – Humayun Naseer Dec 21 '20 at 10:44

1 Answers1

3

You would need to nest your user in an object:

responses:
  200:
    description: User credentials.
    content:
      application/json:
        schema:
          properties:
            message:
              type: string
              example: "User Information already exists"
            user:
              type: object
              properties:
                id:
                  type: string
                  example: 70020ed1-50fe-4c7e-afed
                email:
                  type: string
                  example: test123@gmail.com
                authentication_token:
                  type: string
                  example: xzmsjvvkvgf448449

See https://swagger.io/docs/specification/data-models/data-types/#nested for more information, as well as a note on how to use references.

martyn
  • 676
  • 7
  • 17