swagger-api / swagger-ui

Swagger UI is a collection of HTML, JavaScript, and CSS assets that dynamically generate beautiful documentation from a Swagger-compliant API.
https://swagger.io
Apache License 2.0
26.56k stars 8.96k forks source link

Undocument response with 4XX responses #6175

Open mrkovalchuk opened 4 years ago

mrkovalchuk commented 4 years ago

Swagger/OpenAPI schema for endpoint:

{
  "post": {
    "responses": {
      "201": {
        "description": "Successful Response",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/EnvelopedEndpointResponse"
            }
          }
        }
      },
      "4XX": {
        "description": "Bad request",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorModel"
            }
          },
          "text/csv": {
            "schema": {
              "$ref": "#/components/schemas/ErrorModel"
            }
          }
        }
      }
    },
    "tags": [
      "courses"
    ],
    "summary": "Create Something",
    "operationId": "create_something",
    "requestBody": {
      "content": {
        "application/json": {
          "schema": {
            "$ref": "#/components/schemas/CourseSomethingRequest"
          }
        }
      },
      "required": true
    },
    "security": [
      {
        "APIKeyCookie": []
      }
    ]
  }
}

Query: curl -X POST "http://localhost:3000/api/something/" -H "accept: application/json" -H "Content-Type: application/json" -d "{\"title\":\"string\",\"subtitle\":\"string\",\"slug\":\"string\",\"description\":\"string\",\"theme\":\"string\",\"picture\":\"string\",\"quiz_picture\":\"string\",\"complexity\":0}"

Good day.

Server generate schema with some endpoints with one, which schema little bit hight on text. On Screenshot#1 and on endpoint schema you can see defined response. For responses use {int}XX notation https://swagger.io/docs/specification/describing-responses/. I execute query to server. But schema mark response "Undocument".

In js code I found this (in operaion.jsx -> Operation):

if(responses && response && response.size > 0) {
  let notDocumented = !responses.get(String(response.get("status"))) && !responses.get("default")
  response = response.set("notDocumented", notDocumented)
}

Try to look in component on page

response from props:

{
  "error": true,
  "name": "Error",
  "message": "Unauthorized",
  "statusCode": 401,
  "ok": false,
  "url": "http://localhost:3000/api/somethings/",
  "status": 401,
  "statusText": "Unauthorized",
  "headers": {
    "access-control-allow-credentials": "true",
    "access-control-allow-origin": "http://localhost:3000",
    "content-length": "75",
    "content-type": "application/json",
    "date": [
      "Thu",
      "25 Jun 2020 10:50:23 GMT"
    ],
    "server": "uvicorn",
    "vary": "Origin"
  },
  "text": "{\"status\":\"error\",\"error\":{\"code\":\"unauthorized\",\"message\":\"Unauthorized\"}}",
  "data": "{\"status\":\"error\",\"error\":{\"code\":\"unauthorized\",\"message\":\"Unauthorized\"}}",
  "body": {
    "status": "error",
    "error": {
      "code": "unauthorized",
      "message": "Unauthorized"
    }
  },
  "obj": {
    "status": "error",
    "error": {
      "code": "unauthorized",
      "message": "Unauthorized"
    }
  },
  "notDocumented": true
}

In total: 4XX response defined, 401 response - Undocumented.

Expected behavior

401 response for 4XX is valid

Screenshots

Screenshot#1 Defined responses image

Screenshot#2 Actual response image

It's look like a bug. Sorry if not.

sidverma32 commented 2 years ago

From above summary , what i have understood is that for "401" => "undocumented" string is showing which sounds inappropriate instead rename to "unauthorized" or an empty string would be suffice? right @mrkovalchuk

Can i take this issue?

sanjaraiy commented 3 weeks ago

/assign