swagger-api / swagger-api/swagger-ui

Computed URL correct but not honored when executing

Open
#5,770 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Hacktoberfest type: bug
Dominant language
JavaScript
Stars
29k
Forks
9.3k
Avg merge
2d 23h
Merged PRs (30d)
25

Description

Q&A (please complete the following information)
  • OS: macOS
  • Browser: chrome
  • Version: 79
  • Method of installation: Docker Hub latest
  • Swagger-UI version: 3.24.3
  • Swagger/OpenAPI version: OpenAPI 3.0
Content & configuration

Nothing out of the ordinary. Just running docker version

Example Swagger/OpenAPI definition:

openapi: 3.0.0
info:
  title: Todo API
  description: Todo API
  version: 1.0.0
servers:
  - url: '{scheme}://{host}:{port}{basePath}'
    description: Generic request that defaults to values for local service
    variables:
      scheme:
        description: request scheme
        enum:
          - http
          - https
        default: http    
      host:
        description: server host
        default: localhost
      port:
        description: the port of the service
        default: '8000'
      basePath:
        description: Base path options, leave empty for use with mock service
        enum:
          - ''
          - /services/opp/todos/1.0.0
        default: /services/opp/todos/1.0.0
tags:
  - name: Tasks
    description: Tasks
paths:
  /todos:
    get:
      tags:
        - Tasks
      summary: List the available tasks
      description: |
        The list of tasks can be filtered by their status.
      operationId: todo.todos.api.query
      parameters:
        - name: id 
          in: query
          description: Todo ID to filter on
          schema:
            type: string
          example: 42
        - name: page_token
          in: query
          description: Pagination page token
          schema:
            type: string
        - name: per_page
          in: query
          description: The max number of items to include per page or results.
          schema:
            type: integer
        - name: status
          in: query
          description: Filters the tasks by their status
          required: false
          schema:
            type: string
            enum:
              - done
              - waiting
              - working
          example: working
      responses:
        '200':
          description: Successfully 
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Todos'
        '422':
          description: Invalid query parameter key or value
          content:
            'application/problem+json':
              schema:
                $ref: '#/components/schemas/ProblemDetail'

Swagger-UI configuration options:
NA

Describe the bug you're encountering

Depending on the default value for basePath above, the UI will not honor the computed path (which is computed correctly in the UI).

If the default is the current value, when you select the empty string enum for the base path, the executed path just uses the default base path even though the computed URL is correct. No matter how you switch it, it does not work.

However, if you change the spec to use the empty string as the default, then switching the base path is honored by the UI when executing.

To reproduce...

Steps to reproduce the behavior:

  1. Load the UI.
  2. Click on basePath and switch to the empty base path
  3. Got to GET /todos and click try it
  4. Click Execute
  5. Look at the generated curl statement.
  6. See that is uses the wrong server url
Expected behavior

The computed URL should always be the value used for the server URL in a request.

Screenshots

image

image

Additional context or thoughts

Running this against a stoplight prism mock server running the spec.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by loading the supplied OpenAPI 3.0 definition in Swagger UI and reproduce the request after switching the basePath server variable to the empty value. Trace the server-variable URL handling used when generating the curl statement; done means the executed request uses the currently computed server URL regardless of which default was defined.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.