APIDevTools / swagger-cli

Swagger 2.0 and OpenAPI 3.0 command-line tool
https://apitools.dev/swagger-cli
MIT License
515 stars 69 forks source link

Dereferencing caches last used `$ref` #55

Closed boesing closed 2 years ago

boesing commented 3 years ago

Hey there,

I am experiencing a strange issue when using dereferencing.

Having two files:

foo.yaml

openapi: "3.0.0"
info: {}
paths:
  /foo/bar:
    get:
      responses:
        200:
          description: OK

bar.yaml

openapi: 3.0.0
info: {}
paths:
  /foo/bar:
    get:
      $ref: 'foo.yaml#/paths/~1foo~1bar/get'
      tags:
        - foo
        - bar
      parameters:
        - in: query
          required: true
          name: "foo"
          schema:
            $ref: '#/components/parameters/QueryParameterFoo'

components:
  parameters:
    QueryParameterFoo:
      type: string

When using swagger-cli bundle bar.yaml --dereference, I get the following error:

Error resolving $ref pointer "foo.yaml#/components/parameters/QueryParameterFoo". 
Token "components" does not exist.

The error is correct, the file foo.yaml does not have the parameter QueryParameterFoo within components/parameters, but I've never referenced that 🤷‍♂️

So what I assume is, that the dereferencing somehow thinks, that it has to look within foo.yaml when passing to the next $ref.

I am on v2.3.5 - gonna re-check on v4.

Update

When updating to v4.0.4, the error message is less verbose but ends up with the same problem: Token "components" does not exist.

Am I using the $ref wrong or is this supposed to be a bug?

boesing commented 3 years ago

@JamesMessinger Is anything missing to triage this issue? Is this a bug? Is this intentional?

If there is anything I can do, please let me know.

DmytroMysak commented 3 years ago

Same error ((( I have some objects in a separate YAML file and use it in the same schema 2 times as a result of error: Code:

        properties1:
            $ref: "./ExtraProperties.yaml"
        properties2:
            $ref: "./ExtraProperties.yaml"

Wrong generated file:

          properties1:
                   type: object
                   .....
          properties2:
                  $ref: '#/components/schemas/CreateObject/properties/properties1'
boesing commented 2 years ago

Closing here as it seems that this repository is unmaintained as of this writing.