How using ref into examples Swagger?

Viewed 4528

JSON spec:

"responses": {
          "200": {
            "description": "Успешный ответ сервиса",
            "schema": {
              "$ref": "#/definitions/BaseResponse"
            },
            "examples": {
              "application/json": {
                "status": true,
                "response": {
                  "$ref": "#/definitions/Product"
                },
                "errors": null
              }
            }
          }
}

Result: enter image description here

But I need:

{
  "status": true,
  "response": {
      "ProductNumber": "number",
      "Barcode": "number",
      "Length": 12,
      "Width": 34,
      "Height": 423,
      "Volume": 1232
    }
  },
  "errors": null
}

How I can using $refs into example array for custom format response? It's a typical case, but I cannot found documentation for it. Thank you for you feedback.

2 Answers

I'v tried many solutions, the only one that seems to work is using 'examples' key and not 'example'. then put a single example (you should name it) and put the $ref under it.

just like this:

"responses": {
          "200": {
            "description": "Успешный ответ сервиса",
            "schema": 
              "$ref": "#/definitions/BaseResponse"
            "examples":
              "example_name": # You can give as an example name any name you want
                $ref: "#/examples/200_res"

examples:
  200_res:
    description: example for 200_res
    value:
      {
        "status": true,
        "response": {
          "ProductNumber": "number",
          "Barcode": "number",
          "Length": 12,
          "Width": 34,
          "Height": 423,
          "Volume": 1232
        },
        "errors": null
      }

also notice you have problems with your { } at the example you added

Related