swagger-editor icon indicating copy to clipboard operation
swagger-editor copied to clipboard

Path references parameters from another path but Swagger Editor thinks it's referencing all parameters

Open javiermrzfever opened this issue 1 year ago • 0 comments

Q&A (please complete the following information)

  • OS: macOS
  • Browser: chrome
  • Version: Chrome 105.0.5195.125
  • Method of installation: None (Online editor)
  • Swagger-Editor version: Online editor
  • Swagger/OpenAPI version: Swagger 2.0, OpenAPI 3.0

Example Swagger/OpenAPI definition:

components:
  parameters:
    myPathParam:
      name: myPathParam
      in: path
      required: true
      schema:
        type: string
    myQueryParam:
      name: myQueryParam
      in: query
      schema:
        type: string
info:
  title: My API
  version: 1.0.0
openapi: 3.0.0
paths:
  "/foo/{myPathParam}/":
    get:
      operationId: getFoo
      tags:
        - "1"
      parameters:
        - name: myPathParam
          in: path
          required: true
          schema:
            type: string
        - name: myQueryParam
          in: query
          schema:
            type: string
      responses:
        "200":
          description: Description
          content:
            application/json:
              schema:
                type: object
  "/bar/{myPathParam}/":
    get:
      operationId: getBar
      tags:
        - "1"
      parameters:
        - $ref: "#/paths/~1foo~1%7BmyPathParam%7D~1/get/parameters/0"
        - $ref: "#/paths/~1foo~1%7BmyPathParam%7D~1/get/parameters/1"
      responses:
        "200":
          description: Description
          content:
            application/json:
              schema:
                type: object
  "/sessions/{sessionId}/":
    get:
      operationId: getSession
      parameters:
        - in: path
          name: sessionId
          schema:
            type: number
          required: true
      tags:
        - "2"
      responses:
        "200":
          description: Description
          content:
            application/json:
              schema:
                type: object

Swagger-Editor configuration options: I'm using the online editor (https://editor.swagger.io/)

Describe the bug you're encountering

I am using parameter referencing. I have 2 paths that share parameters by referencing (/foo/{myPathParam}/ and /bar/{myPathParam}/), and a lot more that don't share params with them (in this example, I only chose one of those other paths for our mental health: /sessions/{sessionId}/).

Because of how swagger works, it inlines the parameters in the 1st path (/foo/{myPathParam}/), and the 2nd path (/bar/{myPathParam}/) references the parameters in the 1st path.

Here comes the bug. Even if that reference from the 2nd path to the 1st path seems correct (see example), it seems that the editor understands that that reference is referencing the parameters of ALL the paths. So with one extra path, the error will be the one provided in the Screenshots section.

And when having a lot more paths, it shows an error for each param of those multiple paths.

The interesting thing is that the endpoints doc per sé is generated correctly, but a lot of errors are shown anyway.

To reproduce...

Steps to reproduce the behavior:

  1. Go to https://editor.swagger.io/
  2. Copy & Paste the example provided
  3. The error in the screenshot provided should appear.

Expected behavior

The second path should only need the params that is referencing, not those of all paths.

Screenshots

image

javiermrzfever avatar Sep 23 '22 12:09 javiermrzfever