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

Semantic Error raised only if paths are defined in a certain order

Open istrupin opened this issue 3 years ago • 5 comments

Q&A (please complete the following information)

  • OS: macOS
  • Browser: safari, Firefox
  • Version: Safari 14, Firefox 82
  • Method of installation: docker and editor.swagger.io
  • Swagger-Editor version: v3.14.4
  • Swagger/OpenAPI version: OpenAPI 3.0.1

Content & configuration

Example Swagger/OpenAPI definition:


openapi: 3.0.1
info:
  title: pet API
  version: 1.0.0
paths:
  '/v0/pets/{pet_id}':
    get:
      operationId: getPipeline
      parameters:
        - name: pet_id
          in: path
          required: true
          schema:
            type: string
      responses:
        '200':
          description: Ok
          content:
            application/json:
              schema:
                allOf:
                  - $ref: '#/components/schemas/response_wrapper'
                  - type: object
                    properties:
                      data:
                        $ref: '#/components/schemas/pet'
  '/v0/pets/{pet_id}/executions':
    get:
      operationId: getHistoricalExecutions
      parameters:
        - $ref: '#/paths/~1v0~1pets~1%7Bpet_id%7D/get/parameters/0'
        - name: num_executions
          in: query
          required: true
          schema:
            minimum: 1
            type: integer
            default: 1
      responses:
        '200':
          description: Ok
          content:
            application/json:
              schema:
                allOf:
                  - $ref: '#/components/schemas/response_wrapper'
                  - type: object
                    properties:
                      data:
                        type: array
                        items:
                          $ref: '#/components/schemas/checkup'
  '/v0/kennels/{id}':
    get:
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
      responses:
        '200':
          description: ''      
components:
  schemas:
    pet:
      type: object
      properties:
        schedule:
          type: string
    response_wrapper:
      type: object
      properties:
        data:
           $ref: '#/components/schemas/pet'
    checkup:
      type: object
      properties:
        execution_id:
          type: string

Describe the bug you're encountering

When configured as above, I see this error: image

To reproduce...

Steps to reproduce the behavior:

  1. Go to 'https://editor.swagger.io/' OR run docker container
  2. Paste API Definition from above
  3. See error
  4. Move route "'/v0/kennels/{id}'" either as the 1st or 2nd route from the tops
  5. See error dissappear

Expected behavior

I would expect to not see this error regardless of the route ordering

Screenshots

  1. /v0/kennels/{id}' as last defined route shows error image

  2. /v0/kennels/{id}' as first route shows no error image

Additional context or thoughts

This seems to happen with this specific combination of parameters and references -- This is the minimal version I could make of a much larger API that still displays this same behavior. The API definition is generated, which is why the references are messy (parameters pointing to parameters of other routes rather than context/parameter definitions).

istrupin avatar Oct 26 '20 23:10 istrupin

Same issue

bu4ak avatar Feb 17 '21 10:02 bu4ak

In my case, this was fixed after I define parameters at the parameters section:

components:
    parameters:
        - name: id
          in: path
          required: true

bu4ak avatar Feb 17 '21 12:02 bu4ak

or, when I compile yaml with swagger cli with the dereference option, this also helps

swagger-cli bundle src/openapi.yaml --dereference

bu4ak avatar Feb 17 '21 12:02 bu4ak

Agreed regarding dereferencing -- that seems to get it running again, though it does lead to a pretty messy file.

istrupin avatar Feb 17 '21 17:02 istrupin

Any updates on this?

javiermrzfever avatar Sep 23 '22 11:09 javiermrzfever