Skip to content

"Resolve error" when definition url is relative AND the definition contains self-referencing schema #5945

Open
@domaindrivendev

Description

@domaindrivendev

Q&A (please complete the following information)

  • OS: Windows 10
  • Browser: Chrome
  • Version: 80.0.3987.149
  • Method of installation: npm
  • Swagger-UI version: 3.25.0
  • Swagger/OpenAPI version: OpenAPI 3.0

Content & configuration

Example Swagger/OpenAPI definition:

NOTE: The Product schema's self-referencing property. Without this the error doesn't occur.

openapi: 3.0.1
info:
  title: Test API
  version: v1
paths:
  /products:
    post:
      tags:
        - Products
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/Product'
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                type: integer
                format: int32
components:
  schemas:
    Product:
      type: object
      properties:
        id:
          type: integer
          format: int32
          readOnly: true
        description:
          type: string
          nullable: true
        parentProduct:
          $ref: '#/components/schemas/Product'

Swagger-UI configuration options:

NOTE: The relative url. If this is absolute or root-relative, the error doesn't occur.

      const ui = SwaggerUIBundle({
        url: "v1/swagger.json",
        dom_id: '#swagger-ui',
        deepLinking: true,
        presets: [
          SwaggerUIBundle.presets.apis,
          SwaggerUIStandalonePreset
        ],
        plugins: [
          SwaggerUIBundle.plugins.DownloadUrl
        ],
        layout: "StandaloneLayout"
      })

Describe the bug you're encountering

The UI displays an error (see screenshot) with the Swagger/OpenAPI definition and UI configuration shown above. I'm pretty certain it's the combination of self-referencing schema's and a "page-relative" url in the swagger-ui config that's producing this issue.

To reproduce...

Steps to reproduce the behavior:

  1. With the above definition and ui config, navigate to the UI
  2. Try to expand the Product schema in the "Schemas" section at the bottom of the UI
  3. See error

Expected behavior

No error and the schema is expanded correctly

Screenshots

screenshot

Additional context or thoughts

This is particularly problematic for cases where the Swagger/OpenAPI definition and UI are hosted together (e.g. Swashbuckle), and in a reverse-proxy / virtual directory environment.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions