Skip to content

Wrong URL used when executing the request from swagger ui when a server url starts with a variable #10111

Open
@brampouwelse-luminis

Description

@brampouwelse-luminis

Q&A (please complete the following information)

  • OS: macOS
  • Browser: chrome
  • Version: 128
  • Method of installation: npm
  • Swagger-UI version: 5.17.14
  • Swagger/OpenAPI version: OpenAPI 3.0

Content & configuration

Example Swagger/OpenAPI definition:

---
openapi: "3.0.1"
info:
  title: "Random Yes/No"
  version: "1.0.0"
servers:
- url: "{server}/api"
  variables:
    server:
      default: "https://yesno.wtf"
paths:
  /:
    get:
      description: "Yes or no"
      responses:
        "200": 
          description: "OK"
          content:
            "application/json":
              schema:
                properties:
                  answer:
                    type: string
                  forced: 
                    type: boolean
                  image: 
                    type: string
                    format: uri

Describe the bug you're encountering

The wrong URL used when executing the request from swagger ui when a server url starts with a variable.

I feel this should work as the spec not having any validation issues and there is a similar example in the exaples section on this page https://swagger.io/docs/specification/api-host-and-base-path/ (see SaaS and On-Premise).

To reproduce...

Steps to reproduce the behavior:

  1. Go to https://editor.swagger.io/
  2. Paste the spec from the issue in the editor
  3. Click "Try it out"
  4. Click "Execute"

A request is now performed but it failed due to the request url getting prefixed with https://editor.swagger.io/

Expected behavior

A get request to https://yesno.wtf/api/

When manually replacing the {server} variable in the url with with the default value the hostname is not prefixed and the correct server url is used.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions