swagger-api / swagger-api/swagger-ui

JS error with a required parameter using anyOf

Open
#5,831 2 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Q&A (please complete the following information)
  • OS: [e.g. macOS] Linux
  • Browser: [e.g. chrome, safari] Chrome
  • Version: [e.g. 22] 79.0.3945.88
  • Method of installation: [e.g. npm, dist assets] Included from https://cdn.jsdelivr.net/npm/swagger-ui-dist@3/swagger-ui-bundle.js
  • Swagger-UI version: [e.g. 3.10.0]: swagger-ui-dist@3 as provided by JSDelivr
  • Swagger/OpenAPI version: [e.g. Swagger 2.0, OpenAPI 3.0]: 3.0.2
Content & configuration

Example Swagger/OpenAPI definition:

openapi: 3.0.2
info:
  title: FastAPI
  version: 0.1.0
paths:
  '/{param}':
    get:
      summary: Test
      operationId: test__param__get
      parameters:
        - required: true
          schema:
            title: Param
            anyOf:
              - type: integer
              - type: string
          name: param
          in: path
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema: {}
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
components:
  schemas:
    HTTPValidationError:
      title: HTTPValidationError
      type: object
      properties:
        detail:
          title: Detail
          type: array
          items:
            $ref: '#/components/schemas/ValidationError'
    ValidationError:
      title: ValidationError
      required:
        - loc
        - msg
        - type
      type: object
      properties:
        loc:
          title: Location
          type: array
          items:
            type: string
        msg:
          title: Message
          type: string
        type:
          title: Error Type
          type: string

Swagger-UI configuration options:

const ui = SwaggerUIBundle({
    url: '/openapi.json',
oauth2RedirectUrl: window.location.origin + '/docs/oauth2-redirect',
    dom_id: '#swagger-ui',
    presets: [
    SwaggerUIBundle.presets.apis,
    SwaggerUIBundle.SwaggerUIStandalonePreset
    ],
    layout: "BaseLayout",
    deepLinking: true
})
(no query string)
Describe the bug you're encountering
To reproduce...
  • Click "Try it out"
  • Click "Execute"

The spinner keeps spinning, and there's an error in the console:

FastAPI - Swagger UI - Google Chrome_030

The console error is:

Error: Required parameter param is not provided
    at index.js:3893
    at Array.forEach (<anonymous>)
    at Object.jn [as buildRequest] (index.js:3863)
    at actions.js:415
    at Object.dispatch (utils.js:137)
    at dispatch (<anonymous>:1:28545)
    at bindActionCreators.js:3
    at wrap-actions.js:33
    at Object.r (system.js:174)
    at Object.executeRequest (system.js:461)
Expected behavior

I imagine it would be the input with a red color and shaking, as when a value is required but doesn't use anyOf.

Like:

Selection_031

Screenshots

Attached above as part of the explanation.

Additional context or thoughts

Related to https://github.com/tiangolo/fastapi/issues/915

If using FastAPI, it can be generated with:

from typing import Union
from fastapi import FastAPI

app = FastAPI()


@app.get('/{param}')
def test(param: Union[int, str]):
    return param

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

The report identifies the bundled stack at index.js:3893 and the request path through actions.js:415; first reproduce the required path parameter using anyOf and inspect the corresponding source in the repository. Compare it with the existing required-parameter behavior, then add or update regression coverage so Execute no longer leaves the spinner running and the required field shows the expected validation state.

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
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.