swagger-api / swagger-api/swagger-ui

Undocument response with 4XX responses

Open
#6,175 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Hacktoberfest type: bug
Dominant language
JavaScript
Stars
29k
Forks
9.3k
Avg merge
2d 23h
Merged PRs (30d)
25

Description

  • OS: macOS
  • Browser: chrome
  • Version: 83.0.4103.106
  • Method of installation: part of fastapi
  • Swagger-UI version: 3.27.0
  • Swagger/OpenAPI version: OpenAPI 3.0

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in operation.jsx at the Operation response handling shown in the issue, where notDocumented is set by matching the response status. Check how a concrete 401 status should match the documented 4XX response, then verify that the response is no longer marked undocumented while preserving exact-status and default matching.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, openapi
Domain
api, frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.