swagger-api / swagger-ui

Swagger UI is a collection of HTML, JavaScript, and CSS assets that dynamically generate beautiful documentation from a Swagger-compliant API.
https://swagger.io
Apache License 2.0
26.51k stars 8.96k forks source link

Url parameters not using provided value in Swagger UI #10176

Open akuchcik opened 1 week ago

akuchcik commented 1 week ago

I'm resending conversation and issue report from https://github.com/springdoc/springdoc-openapi :

Any value provided inside the parameter input field is ignored and the resulted url only has {parameter} inside it instead of the actual value.

image

Issue occurs when using springdoc-openapi-starter-webmvc-ui with custom yaml file Using the same file with docker image swaggerapi/swagger-ui doesn't result with this issue and works as expected

I found out that the reason for this is the "=" (equals sign) in the path. This path works: /data/logging-status/broker/{broker-identifier} but this path doesn't work: /data/logging-status/broker={broker-identifier}

I created a new spring boot application with minimal requirements https://github.com/akuchcik/springdoc-url-parameter-bug :

Custom yaml file (same problem on 3.1.0 version):

openapi: 3.0.2
info:
  title: Swagger Petstore - OpenAPI 3.0
  version: 1.0.19
servers:
- url: /rests
paths:
  /pet/{petId}:
    get:
      tags:
        - pet
      parameters:
        - name: petId
          in: path
          description: ID of pet to return
          required: true
          schema:
            type: string
      responses:
        "200":
          description: successful operation
          content:
            application/xml:
              schema:
                $ref: '#/components/schemas/Pet'
            application/json:
              schema:
                $ref: '#/components/schemas/Pet'
        "400":
          description: Invalid ID supplied
        "404":
          description: Pet not found
  "/data/logging-status/broker={broker-identifier}":
    get:
      tags:
        - logging
      parameters:
        - name: broker-identifier
          in: path
          description: Id of broker
          required: true
          schema:
            type: string
      responses:
        "200":
          description: successful operation
          content:
            application/xml:
              schema:
                $ref: '#/components/schemas/Pet'
            application/json:
              schema:
                $ref: '#/components/schemas/Pet'
        "400":
          description: Invalid ID supplied
        "404":
          description: Pet not found
components:
  schemas:
    Category:
      type: object
      properties:
        id:
          type: integer
          format: int64
          example: 1
        name:
          type: string
          example: Dogs
      xml:
        name: category
    Tag:
      type: object
      properties:
        id:
          type: integer
          format: int64
        name:
          type: string
      xml:
        name: tag
    Pet:
      required:
        - name
        - photoUrls
      type: object
      properties:
        id:
          type: integer
          format: int64
          example: 10
        name:
          type: string
          example: doggie
        category:
          $ref: '#/components/schemas/Category'
        photoUrls:
          type: array
          xml:
            wrapped: true
          items:
            type: string
            xml:
              name: photoUrl
        tags:
          type: array
          xml:
            wrapped: true
          items:
            $ref: '#/components/schemas/Tag'
        status:
          type: string
          description: pet status in the store
          enum:
            - available
            - pending
            - sold
      xml:
        name: pet
  securitySchemes:
    basicAuth:
      type: http
      scheme: basic

Reply from @bnasslahsen : Your expected behavior is invalid. You are declaring broker-identifier as path variable, whereas it should be declared as query parameter.

NOTE: OpenAPI defines a unique operation as a combination of a path and an HTTP method:

Answer: if I define it as query the resulted url looks like this: "http://localhost:8080/data/logging-status/broker={broker-identifier}?broker-identifier=test" image

It just adds a query at the end of the url. I am not using a query as I'm not using "?" after the path. I am specifying an entry in a list. This describing of entries/keys in a list of elements is defined in RESTCONF Protocol - RFC 8040. When using docker image swaggerapi/swagger-ui it is working as expected.

REPLY: @akuchcikm,

Is the OpenAPI spec correct ? If it's the case, then it's not a sprindoc issue. You should reach the https://github.com/swagger-api/swagger-ui/issues instead.

LINK TO THE ORIGINAL REPORTED ISSUE: https://github.com/springdoc/springdoc-openapi/issues/2764

akuchcik commented 1 week ago

When using env variable URL instead of URLS in docker image swaggerapi/swagger-ui I get the same error, but when using springdoc that problem persists in both cases (setting url or urls in custom swagger controller).

falbert-ptc commented 6 days ago

Looks similar to https://github.com/swagger-api/swagger-ui/issues/9979 It looks like a regression introduced in 5.17.8 and later