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 web page hangs when endpoint has several required parameters, but at least one is not provided #8007

Closed
scott-fisher-iii opened this issue May 3, 2022 · 7 comments

Comments

@scott-fisher-iii
Copy link

This is an odd one and I haven't had a chance to dig into the code to see what is happening in the Swagger-UI code.

In one of my company's API products, we have 2 endpoints that have several required parameters (mix of path and query parameters).
One of the problem endpoints has 9 required parameters (6 path; 3 query) and the other has 7 required parameters (6 path; 1 query).

If a user fills in all but one of the required parameters (happens if more than one are left out too), when they click the "Execute" button, the web page hangs. The request interceptor and thus the underlying API are never called. There is no indication to the user where the hang up occurs, the UI just has the spinning "Loading" circle under a now disabled "Execute" button.

The browser console does indicate the following error where Action was the one required parameter not provided:

Error: Required parameter Action is not provided
    at swagger-ui-bundle.js:2:225276
    at Array.forEach (<anonymous>)
    at Object.Ln [as buildRequest] (swagger-ui-bundle.js:2:224654)
    at swagger-ui-bundle.js:2:157834
    at swagger-ui-bundle.js:2:263154
    at swagger-ui-bundle.js:2:781296
    at swagger-ui-bundle.js:2:174068
    at Object.r (swagger-ui-bundle.js:2:960838)
    at Object.executeRequest (swagger-ui-bundle.js:2:965216)
    at swagger-ui-bundle.js:2:159085

There seems to be an issue around when there are 7 or more required parameters vs. less than 7. For endpoints that have less than 7 required parameters, the expected behavior (see below) shows. When there are 7 or more required parameters, the UI hangs as described.

The API presently uses the NuGet package "Swashbuckle.AspNetCore" Version="6.3.1" (which uses Swagger-UI v4.10.3) and can be recreated using Chrome and Edge (Chromium).

Expected
When a required parameter is not provided, indicate in the UI (highlight and focus) regardless of how many required parameters are included in that endpoint.

@immae
Copy link

immae commented Nov 7, 2022

Same problem here but it happens as soon as two fields (more precisely, two required fields, two optional and a request body)

FWIW: the first required field is a drop-down list with a default value so it’s not "blankable" in the swagger, but leaving the second required field ends with a hanging request with similar trace to above

@ChoppinBlockParty
Copy link

ChoppinBlockParty commented Dec 20, 2022

Confirm. Anybody knows a version to downgrade to?

@ChoppinBlockParty
Copy link

- name: accessToken
  description: Access Token
  in: query
  required: true
  type: string

If I have the above parameter the loading hangs and gives the below error in console

system.js:490 Error: Required parameter accessToken is not provided
    at index.js:233:13
    at Array.forEach (<anonymous>)
    at Object.Lr [as buildRequest] (index.js:200:22)
    at actions.js:452:24
    at utils.js:177:16
    at redux.js:546:12
    at wrap-actions.js:33:10
    at Object.n (system.js:175:26)
    at Object.executeRequest (system.js:487:17)
    at actions.js:499:22
(anonymous) @ system.js:490

No way to cancel loading, have to reload the whole page and lose all the input.

If required: false is set, then it works fine. But obviously required parameter is missing.

@juggernot325
Copy link

This is still an issue. I'm on swagger-ui-react 4.15.2. Here's an example of an endpoint definition where this occurs.

    "/api/v2/permissions/{permission_id}": {
        "get": {
            "description": "Gets an authorization permission's details.",
            "tags": [
                "Auth"
            ],
            "summary": "Get Permission",
            "parameters": [
                {
                    "$ref": "#/definitions/parameters.PreferHeader"
                },
                {
                    "type": "string",
                    "description": "ID of the permission record to retrieve details for.",
                    "name": "permission_id",
                    "in": "path",
                    "required": true
                }
            ],
            "responses": {
                "200": {
                    "description": "OK",
                    "schema": {
                        "$ref": "#/definitions/api.BasicResponse"
                    }
                },
                "401": {
                    "description": "Unauthorized",
                    "schema": {
                        "$ref": "#/definitions/api.ErrorWrapper"
                    }
                },
                "500": {
                    "description": "Internal Server Error",
                    "schema": {
                        "$ref": "#/definitions/api.ErrorWrapper"
                    }
                }
            }
        }
    },

@excitoon
Copy link

I traced it for you guys @scott-fisher-iii @char0n , Swagger is getting stuck when there is no type specified on required field.

Screenshot from 2024-03-12 14-49-29

@excitoon
Copy link

excitoon commented Mar 12, 2024

- name: accessToken
  description: Access Token
  in: query
  required: true
  type: string

@ChoppinBlockParty If this is OpenAPI, you must specify schema: type: ..., not type: ....

@glowcloud
Copy link
Contributor

As noted by @excitoon, the type of parameter should be specified inside schema:

- name: accessToken
  description: Access Token
  in: query
  required: true
  schema:
    type: string

but there was still an issue for when the schema was empty or had no type specified, which was addressed in #9863

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

No branches or pull requests

6 participants