swagger-parser
swagger-parser copied to clipboard
Deep references to external schemes are incorrectly resolved
I have a master swagger.yaml, which looks like
...
definitions:
core.object:
$ref: "./definitions/core/object.yaml#/definitions/core.object"
...
My ./definitions/core/object.yaml
looks like:
swagger: "2.0"
definitions:
core.object:
type: object
properties:
id:
type: integer
type:
type: string
required:
- id
- type
discriminator: type
When bundle()
method produces the following output for me (does not resolve /definitions/core.object
part of the reference):
definitions:
core.object:
swagger: 2.0
definitions:
core.object:
type: object
properties:
id:
type: integer
type:
type: string
required:
- id
- type
discriminator: type
Interesting, but dereference()
produces correct output for me:
definitions:
core.object:
type: object
properties:
id:
type: integer
type:
type: string
required:
- id
- type
discriminator: type
I also tried require('json-schema-ref-parser').bundle(...)
and it also produces correct output. So looks like the issue is specifically with require('swagger-parser').bundle()
method...
Are you sure you're using the latest version of Swagger Parser? The require('swagger-parser').bundle()
method is simply a pass-through to require('json-schema-ref-parser').bundle()
method. There's no additional logic inside Swagger Parser, so if JSON Schema $Ref Parser works, then so should Swagger Parser.
@BigstickCarpet, just installed it today. It's "3.4.1". BTW, swagger-cli console app also produces bad results for me.
Looks like I tried json-schema-ref-parser
version 3.1.2 and it works fine. While swagger-parser
installed 1.4.1
for itself into its own node_modules and uses it
https://github.com/BigstickCarpet/swagger-parser/blob/master/package.json#L80
It looks like time to upgrade this dependency ;)
I tried to make a quick fix but failed because of parse() method aguments incompatibility in SwaggerParser and $RefParser. Looks like normalizeArgs() method should be copied to SwaggerParser. But I'm not sure if it's good solution. @BigstickCarpet, do you have better idea for?
@isadovskiy - Ah, now I remember. I was in the middle of a refactoring a few months ago, and then I started a new job and kinda dropped the ball on all my opensource projects for a while. I guess this issue will be my motivation to pick-up where I left off before. It's not as simple as upgrading the dependency or making a minor code change, unfortunately.
@BigstickCarpet I made a change in my repo - https://github.com/isadovskiy/swagger-parser/pull/2/commits/942be0ca0e08b50445081c61fbb091bc14853df1. Seems it fixed the issue. However i'm not sure about side effects. Also it's not so elegant since I copied normalizeArgs() method.
👍 Cool. You can use that fork for now, and I'll let you know as soon as I get the permanent fix committed here.
Thanks! i'll be waiting for solid fix.
Looks like Options object is also incompatible...
I'm experiencing the same issue now using either swagger parser or CLI. Was a fix made since then?
My referenced get nested into a parameter definition, leading to weird issue in Swagger Editor. On the other side, --dereference
works like a charm but leads to unused definition warnings in Swagger Editor.
Thanks for your help!