Redoc: Payload json body is wrong example for array

Created on 16 May 2018  路  9Comments  路  Source: Redocly/redoc

In request body schemas, I have an array of string field.
But in payload, it's show only a string.

Most helpful comment

@ntloi95 could you please share your schema and a screenshot of how this is rendered by ReDoc

All 9 comments

@ntloi95 could you please share your schema and a screenshot of how this is rendered by ReDoc

This is error field. It's integrations
image
This is payload json
image
This is full schemas
image

Thanks, could you also share the corresponding definition spec/schema ?

So sorry, I click to close button because of mistake.
This is definition. I remove some unnecessary things.

{
    "user": {
        "description": "User defines data model for User.",
        "properties": {
            "id": {
                "description": "The id of user.",
                "example": "Wu8LGFBgDAuDzFA8",
                "type": "string"
            },
            "integrations": {
                "description": "Array of fitness partners user may have connected to our app.",
                "example": [
                    "jawbone",
                    "underarmour"
                ],
                "items": {
                    "$ref": "#/components/schemas/integration"
                },
                "type": "array"
            }
        },
        "type": "object"
    },
    "userResponse": {
        "description": "UserResponse represents a response item for User.",
        "properties": {
            "id": {
                "description": "The id of user.",
                "example": "Wu8LGFBgDAuDzFA8",
                "type": "string"
            },
            "integrations": {
                "description": "Array of fitness partners user may have connected to our app.",
                "example": [
                    "jawbone",
                    "underarmour"
                ],
                "items": {
                    "$ref": "#/components/schemas/integration"
                },
                "type": "array"
            }
        },
        "type": "object"
    }
}

Wrong on payload is showing userResponse

"responses": {
    "200": {
        "content": {
            "application/json": {
                "schema": {
                    "$ref": "#/components/schemas/userResponse"
                }
            }
        },
        "description": "Update user success."
    }
}

I tried your spec and I can't reproduce your issue locally. For me it shows correct example:

image

Could you share a full simplified schema on which this issue can be reproduced? You can upload it somewhere (e.g. gist) and put link to it into demo: http://rebilly.github.io/ReDoc/

And then share the demo-link here. Thanks!

Hi,
This is simplified schema I edited. It can reproduce bug.

https://raw.githubusercontent.com/ntloi95/hack/master/redoc-v6.json

image

You have an issue in your spec:

"requestBody": {
  "content": {
    "application/json": {
      "schema": {
        "properties": {
          "integrations": {
            "description": "Integrations",
            "enum": [ // <---- HERE
                "jawbone",
                "underarmour",
                "healthkit",
                "googlefit"
            ],
            "in": "body",
            "items": {
              "$ref": "#/components/schemas/integration"
            },
            "name": "integrations",
            "type": "array"
          }
        },
        "type": "object"
      }
    }
  },
  "required": true

Enum on this level according to the spec means that value of this field (integrations MUST be one of the enum values (strings) while field type is array so this schema is invalid.
If you need to specify possible values for items you should put enum inside items. But in your case, just remove enum as you anyway have same enum in integration definition

ReDoc is rendering your spec correctly

Remove "enum" is ok. ReDoc render correctly.
Thank you very much indeed.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

shreyas-agnihotri picture shreyas-agnihotri  路  3Comments

gauravmokhasi picture gauravmokhasi  路  4Comments

JFCote picture JFCote  路  3Comments

typekpb picture typekpb  路  4Comments

dwilding picture dwilding  路  4Comments