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

[swagger-ui-react] Required headers fail validation (with values) #5521

Closed
pwan001-dev opened this issue Aug 8, 2019 · 2 comments
Closed

Comments

@pwan001-dev
Copy link

pwan001-dev commented Aug 8, 2019

Q&A (please complete the following information)

  • OS: macOS
  • Browser: chrome
  • Version: 76
  • Method of installation: npm
  • swagger-ui-react version: 3.23.4
  • react version: 16.8.6
  • Swagger/OpenAPI version: Swagger 2.0

Example Swagger/OpenAPI definition:

{
  "swagger": "2.0",
  "info": {
    "version": "1.0.0"
  },
  "host": "foo.bar.com",
  "tags": [
    {
      "name": "foo"
    }
  ],
  "schemes": [
    "https"
  ],
  "paths": {
    "/v1/foo": {
      "get": {
        "tags": [
          "foo"
        ],
        "summary": "sum",
        "description": "desc",
        "operationId": "foo1",
        "parameters": [
          {
            "name": "param1",
            "in": "query",
            "description": "param1",
            "required": true,
            "type": "string",
            "default": "{param1}"
          },
          {
            "name": "Content-Type",
            "in": "header",
            "required": true,
            "type": "String",
            "default": "application/json"
          }
        ],
        "responses": {
          "200": {
            "description": "OK"
          },
          "400": {
            "description": "Bad Request"
          },
          "499": {
            "description": "Application Error"
          },
          "503": {
            "description": "Service Unavailable"
          },
          "500": {
            "description": "Internal Server Error"
          }
        },
        "security": [
          {
            "privateAuthUser": []
          }
        ]
      }
    }
  }
}

^ Apologies if this isn't valid, modified to obscure details.

Describe the bug you're encountering

Swagger definitions that have required header fields always fail validation even values are present. It may be related to default header values being provided initially, but changing their values manually doesn't fix the problem.

I have confirmed that required query params work fine.

To reproduce...

Unfortunately I'm unable to provide a quick test for this as I'm only involved in the UI portion. If required, I can spend time setting up a concrete sample.

Expected behavior

Required fields (with pre-populated defaults) should Execute without error (given the values are valid).

Screenshots

swagger-bug

Additional context or thoughts

I saw this related issue: #4745
However, it looked like the resolution was to use swagger-ui-react which doesn't apply here. If I missed something relevant, apologies.

@pwan001-dev pwan001-dev changed the title [swagger-ui-react] Required fields fail validation (with values) [swagger-ui-react] Required headers fail validation (with values) Aug 8, 2019
@hkosova
Copy link
Contributor

hkosova commented Aug 8, 2019

Your definition is not valid, you need to replace "type": "String" with "type": "string" (note the lowercase "s"). "Try it out" should work fine after this fix.

You can use https://editor.swagger.io to check your API definitions for syntax errors.

On an unrelated note, the Content-Type and Accept headers should be defined by the consumes and produces keywords rather than header parameters:

operationId: something
consumes:
  - application/json   # This is the request's "Content-Type"
produces:
  - application/json   # This is the request's "Accept" header and the response's "Content-Type"

@pwan001-dev
Copy link
Author

Ahh sorry for the noob mistake, I'll forward this on. On the UI side, we just switched to swagger-ui-react from an old swagger implementation where these errors in swagger definitions didn't manifest.

Thanks for the help!

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