swagger-ui icon indicating copy to clipboard operation
swagger-ui copied to clipboard

JS error with a required parameter using anyOf

Open tiangolo opened this issue 6 years ago • 1 comments

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

tiangolo avatar Feb 13 '20 21:02 tiangolo

@tim-lai can you assign this one to me?

Crossbears avatar Oct 08 '24 04:10 Crossbears

What can be done here?

jmehnle avatar Mar 07 '25 00:03 jmehnle