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

Erroneous errors in latest Swagger UI version #9208

Closed
chuck-flowers opened this issue Sep 13, 2023 · 5 comments
Closed

Erroneous errors in latest Swagger UI version #9208

chuck-flowers opened this issue Sep 13, 2023 · 5 comments

Comments

@chuck-flowers
Copy link

Q&A (please complete the following information)

  • OS: Docker node:18
  • Browser: Brave
  • Version: Brave 1.57.64 [e.g. 22]
  • Method of installation: npm (swagger-ui-dist)
  • Swagger-UI version: 5.7.0
  • Swagger/OpenAPI version: OpenAPI 3.0

Content & configuration

Example Swagger/OpenAPI definition (redacted):

{
  "openapi": "3.0.0",
  "info": {
    "title": "ACME API",
    "version": "1.0.0"
  },
  "servers": [
    {
      "url": "http://localhost:8080"
    }
  ],
  "security": [
    {
      "BasicAuth": []
    }
  ],
  "paths": {
    "/v1/customer/group/{foo}/pieces/completedAt": {
      "parameters": [],
      "get": {
        "operationId": "foo",
        "parameters": [
          {
            "name": "foo",
            "in": "path",
            "schema": {
              "type": "string"
            },
            "required": true
          },
          {
            "name": "start",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date-time"
            },
            "required": true
          },
          {
            "name": "end",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date-time"
            },
            "required": true
          },
          {
            "name": "xService",
            "in": "query",
            "schema": {
              "type": "array",
              "items": {
                "type": "string"
              },
              "default": []
            },
            "required": false
          }
        ],
        "responses": {
          "200": {
            "description": "TODO",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/v1P"
                  }
                }
              }
            }
          },
          "400": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/v1PD"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "BasicAuth": {
        "type": "http",
        "scheme": "basic"
      }
    },
    "schemas": {
      "v1P": {
        "type": "object",
        "properties": {
        },
        "additionalProperties": false
      },
      "v1PD": {
        "type": "object",
        "properties": {
          "type": {
            "type": "string",
            "description": "A URI reference that identifies the problem type. "
          },
          "title": {
            "type": "string",
            "description": "A short, human-readable summary of the problem type."
          },
          "status": {
            "type": "integer",
            "description": "The HTTP status code generated by the origin server for this occurrence of the problem."
          },
          "detail": {
            "type": "string",
            "description": "A human-readable explanation specific to this occurrence of the problem."
          },
          "instance": {
            "type": "string",
            "description": "A URI reference that identifies the specific occurrence of the problem."
          }
        },
        "required": [
          "title"
        ],
        "additionalProperties": false,
        "description": "The problem details data modeled defined at https://datatracker.ietf.org/doc/html/rfc7807#section-3.1 "
      }
    }
  }
}

Swagger-UI configuration options:

SwaggerUI({
   url: '/docs/openapi.json'
})
Not sure what query string config means

Describe the bug you're encountering

Erroneous error messages are showing up at the the top of the documenation page. This happens in 5.7.0 but not in 5.6.2.

To reproduce...

Steps to reproduce the behavior:

  1. Go to the Swagger UI page
  2. Click the endpoint documenation

Expected behavior

No errors should appear

Screenshots

image
image

Additional context or thoughts

I'm having trouble tracing where the error is happening based on the browser console but based on the stack trace it seems to be originating from the @swagger-api/apidom-reference in the url.mjs module

@minizwergi
Copy link

There might be an issue with the latest update of the swagger-client and related code in /core/index.js d89726a

@char0n
Copy link
Member

char0n commented Sep 14, 2023

Hi everybody,

The regression will most likely be in swagger-client which was recently heavily refactored. Specifically we've changed how URLs are resolved. Instead of legacy and deprecated url we now use https://url.spec.whatwg.org/.

Let me investigate what went wrong and why.

@char0n
Copy link
Member

char0n commented Sep 14, 2023

I can reproduce by passing spec option directly to SwaggerUI.

SwaggerUI({
   spec: {...},
})

@char0n
Copy link
Member

char0n commented Sep 14, 2023

Addressed in #9214.

Explanation: if we pass spec option without url option, or if we pass a relative URI Reference as a value of url option, we make it absolute just before the resolution. This is aligned with OpenAPI and JSON Schema specs.

Before we were running resolution on relative URI References, which was just wrong.

@char0n
Copy link
Member

char0n commented Sep 14, 2023

Resolved in https://github.com/swagger-api/swagger-ui/releases/tag/v5.7.1

@char0n char0n closed this as completed Sep 14, 2023
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

3 participants