0

The API response format is like this (there are more attributes under couponReportData but not showing here)-

{
    "status": "success",
    "success_id": "S-001",
    "message": "Request processed successfully",
    "couponReportData": [
        {
            "uuid": "8432732587408386841",

        },
        {
            "uuid": "7916954142184535581",

        }
    ]
}

I am trying to write the swagger documentation for the same by editing the json file (which is specified in the redoc spec-url attribute of the swagger html file).

Following is what I have written so far within the paths attribute of json -

"paths": {
        "/endPoint": {
            "get": {
                "tags": ["Fetch Data Apis"],
                "summary": "summary",
                "operationId": "fetchcouponGET",
                "consumes": ["application/json"],
                "produces": ["application/json"],
                "parameters": [],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "$ref": "#/definitions/ResultDTO1_endpoint"
                        }
                    },
                    "400": {
                        "description": "Bad Request"
                    },
                    "500": {
                        "description": "Internal Server Error"
                    },
                    "404": {
                        "description": "Not Found"
                    }
                }
            }
        },
        "definitions": {
            "ResultDTO1_endpoint": {
                "type": "object",
                "properties": {
                    "status": {
                        "type": "string",
                        "description": "Api status success or error",
                        "example": "success"
                    },
                    "success_id": {
                        "type": "string",
                        "description": "When success Response",
                        "example": "S-001"
                    },
                    "message": {
                        "type": "string",
                        "description": "Api message response",
                        "example": "Request processed successfully"
                    },
                    "couponReportData": {
                        "type": "object",
                        "properties": {
                            "uuid": {
                                "type": "integer",
                                "description": "Some description",
                                "example": "2"
                            }
                        }
                    }
                }
            }
        }

Following is what I am getting in the response section of generated Swagger doc -

enter image description here

enter image description here

Update

After the solution mentined by Helen, the Response sample part is getting generated correctly, but the response schema is still confusing -

enter image description here

Sandeepan Nath
  • 9,966
  • 17
  • 86
  • 144
  • 1
    Possible duplicate of [Return an array of object in Swaggerhub](https://stackoverflow.com/questions/46167981/return-an-array-of-object-in-swaggerhub) – Helen Oct 23 '18 at 08:59
  • 1
    Your array definition is not correct. `couponReportData` should be `type: array` whose `items` is a `type: object` with the `uuid` property. See the linked question ^^ to get the idea. – Helen Oct 23 '18 at 09:01
  • @Helen thanks for the solution. Please see my update. I am still having some issue. – Sandeepan Nath Oct 23 '18 at 10:39

0 Answers0