mohsen1 / multi-file-swagger-example

Multi-file Swagger example
http://azimi.me/2015/07/16/split-swagger-into-smaller-files.html
168 stars 39 forks source link

Version 2.3.0 Not Resolving External File References Properly #23

Open Machine-X- opened 5 years ago

Machine-X- commented 5 years ago

Seems as though version 2.3.0 is not resolving external references properly in the combined file.

Setup:

index.yaml

`swagger: '2.0'

info: description: 'API' version: '1.0.0' title: 'API'

paths: /foo: get: responses: 200: content: application/json: schema: $ref: 'foo.yaml#/Foo' /bar: get: responses: 200: content: application/json: schema: $ref: 'foo.yaml#/Foo' `

foo.yaml

Foo: type: object properties: bar: type: string

When using version 2.3.0 running multi-file-swagger -o yaml "index.yaml" > "foobar-2-3-0.yaml" The output is: swagger: '2.0' info: description: API version: 1.0.0 title: API paths: /foo: get: responses: '200': null content: application/json: schema: &ref_0 type: object properties: bar: type: string /bar: get: responses: '200': null content: application/json: schema: *ref_0

You can see that schema: *ref_0 is not desired.

When using version 2.2.0 running multi-file-swagger -o yaml "index.yaml" > "foobar-2-2-0.yaml" The output is: swagger: '2.0' info: description: API version: 1.0.0 title: API paths: /foo: get: responses: '200': null content: application/json: schema: type: object properties: bar: type: string /bar: get: responses: '200': null content: application/json: schema: type: object properties: bar: type: string

Here you can see everything is resolved properly.

Using npm version 6.10.3 as well. Thanks!

ClaudioConsolmagno commented 4 years ago

@Machine-X- I struggled to read your issue due to formatting but I kinda get what you are saying. What you are missing is that &ref_0 is setting an anchor and *ref_0 is using it. This is a feature of yaml, see some examples here. Version 2.2.0 didn't use aliases but version 2.3.0 does. When the yaml is parsed (e.g. by swagger) those anchors get resolved so there shouldn't be a consequential difference between versions after everything gets resolved.

If that wasn't your issue, please post a test case (nicely formatted) so that I can replicate on my side.

Thanks!