APIDevTools / swagger-cli

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

Error: Token "Components" Does Not Exist #73

Open jonesll23 opened 2 years ago

jonesll23 commented 2 years ago

Although we didn't make any code changes, sometime around November 22nd 2021, we started getting an error when compiling our API documentation: Token "components" does not exist. However, the components file is still visible, accessible, and hasn't been changed in almost a year.

Is there anything you'd suggest to help troubleshoot this issue? Thanks for your help.

rpsirois commented 2 years ago

Bump.

FernandoBasso commented 2 years ago
$ tree -C -L 1 ./
./
├── endpoints
├── schemas
└── apispec.yml

$ swagger-cli --version
4.0.4

$ swagger-cli bundle --type yaml apispec.yml 
Token "components" does not exist.

The endpoints and schemas directory contains path and schema definitions. We successfully preview the documentation with both Swagger UI and Redoc, so I presume our specification is valid. Still, I can't figure out the reason for that error.

Any assistance would be appreciated.

EDIT: Just realized it my spec does not validate...

$ swagger-cli validate --type yaml ./xapi-spec.yml 
Token "components" does not exist.
okybr commented 2 years ago

any work-arounds for this, at least? :)

evgenipetrov9 commented 2 years ago

Same issue here.

FernandoBasso commented 2 years ago

I was able to solve the issue. The problem was that we had some:

$ref: '#/components/schemas/MyCookie'

But #/ will try to find components in the current file. As soon as changed to things like this, it worked:

$ref: '../cookies.yml#/components/schemas/MyCookie'

or

$ref: '../params.yml#/components/schemas/MyParam'

This way, we are referencing components in a specific file and not in "the current file".

adamkusmirek commented 1 year ago

It would be nice if the behaviour in swagger-cli would match the preview behaviour, as in. That requires deciding on whether to interpret $ref: #/ as a reference inside the current file or whether to interpret it as a reference inside the current document (which is the merged result).

The latter is apparently the behaviour used by Swagger UI and IMHO makes a lot more sense as it makes the component files more file-path agnostic.