swagger-api/swagger-ui

Failed to construct 'URL' when schema is provided for POST path

piotrwalczak1 opened this issue · 10 comments

  • OS: Linux
  • Browser: chrome
  • Version: 4.14.0
  • Method of installation: npm
  • Swagger-UI version: 4.14.0
  • Swagger/OpenAPI version: 3.0

Content & configuration

Example Swagger/OpenAPI definition:

openapi: "3.0.0"
info:
  title: "whatever"
  version: "1.0.0"
servers:
  - url: "https://sample-url.com/dev"
paths:
  /deprovisioning:
    post:
      requestBody:
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/deprovisioningModelBodyValidator"
        required: true
  /provisioning:
    post:
      requestBody:
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/provisioningModelBodyValidator"
        required: true

components:
  schemas:
    deprovisioningModelBodyValidator:
      type: object
      properties:
        thingName:
          type: string
      required:
        - thingName
    provisioningModelBodyValidator:
      type: object
      properties:
        macAddress:
          type: string
      required:
        - macAddress

Swagger-UI configuration options:

import SwaggerUI from "swagger-ui";
import "swagger-ui/dist/swagger-ui.css";

// const spec = require('./openapi.yaml');
import * as spec from "./openapi.yaml";

const ui = SwaggerUI({
  spec,
  dom_id: "#swagger",
});

ui.initOAuth({
  appName: "Swagger UI Webpack Demo",
  // See https://demo.identityserver.io/ for configuration details.
  clientId: "implicit",
});

Describe the bug you're encountering

I am getting the Failed to construct 'URL': Invalid URL when trying to use the webpack example with the yaml provided. As soon as I click the endpoint path, I am getting the error. The config I provided is perfectly fine when using online swagger editor.

Expected behavior

It should work, as yaml is in open api standard

Screenshots

image
image

I can confirm that I am experiencing the same issue. I do not know how to resolve this issue.

Could anyone solve it? I have the same error

char0n commented

You either have to pin swagger-client to https://github.com/swagger-api/swagger-js/releases/tag/v3.20.2 or use SwaggerUI >=5.7.1.

Same problem with swagger-ui-express

char0n commented

All rihgt, seems like a serious regression. I’ll introduce backward compatible patch to swagger-client to allow EOL swageer-ui versions to function properly without pinning swagger-client version.

same problem with flask_swagger_ui

char0n commented

Backward compatible Relative URI Reference resolution introduced for swagger-client in swagger-api/swagger-js#3148

char0n commented

This issue have been addressed in swagger-client@3.22.2. If you reinstall your SwaggerUI version, the latest swagger-client will be installed as transitive dependency and will resolve the issue.

This issue have been addressed in swagger-client@3.22.2. If you reinstall your SwaggerUI version, the latest swagger-client will be installed as transitive dependency and will resolve the issue.

Should I wait for this npm module to release its new version for this to be resolved?

char0n commented

This issue have been addressed in swagger-client@3.22.2. If you reinstall your SwaggerUI version, the latest swagger-client will be installed as transitive dependency and will resolve the issue.

Should I wait for this npm module to release its new version for this to be resolved?

Nope, no need to release anything here. Just re-installing this npm module (swagger-ui/swagger-ui-react) will automatically install latest swagger-client .