Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Payload json body is wrong example for array #494

Closed
ntloi95 opened this issue May 16, 2018 · 9 comments
Closed

Payload json body is wrong example for array #494

ntloi95 opened this issue May 16, 2018 · 9 comments

Comments

@ntloi95
Copy link

ntloi95 commented May 16, 2018

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

@RomanHotsiy
Copy link
Member

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

@ntloi95
Copy link
Author

ntloi95 commented May 16, 2018

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

@RomanHotsiy
Copy link
Member

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

@ntloi95 ntloi95 closed this as completed May 16, 2018
@ntloi95 ntloi95 reopened this May 16, 2018
@ntloi95
Copy link
Author

ntloi95 commented May 16, 2018

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"
    }
}

@ntloi95
Copy link
Author

ntloi95 commented May 16, 2018

Wrong on payload is showing userResponse

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

@RomanHotsiy
Copy link
Member

RomanHotsiy commented May 16, 2018

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!

@ntloi95
Copy link
Author

ntloi95 commented May 17, 2018

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

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

image

@RomanHotsiy
Copy link
Member

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

@ntloi95
Copy link
Author

ntloi95 commented May 17, 2018

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants