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

Deep references to external schemes are incorrectly resolved

Open isadovskiy opened this issue 7 years ago • 10 comments

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...

isadovskiy avatar Aug 04 '16 14:08 isadovskiy

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.

JamesMessinger avatar Aug 04 '16 14:08 JamesMessinger

@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

isadovskiy avatar Aug 04 '16 17:08 isadovskiy

https://github.com/BigstickCarpet/swagger-parser/blob/master/package.json#L80

It looks like time to upgrade this dependency ;)

isadovskiy avatar Aug 04 '16 17:08 isadovskiy

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 avatar Aug 08 '16 11:08 isadovskiy

@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.

JamesMessinger avatar Aug 08 '16 14:08 JamesMessinger

@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.

isadovskiy avatar Aug 08 '16 15:08 isadovskiy

👍 Cool. You can use that fork for now, and I'll let you know as soon as I get the permanent fix committed here.

JamesMessinger avatar Aug 08 '16 18:08 JamesMessinger

Thanks! i'll be waiting for solid fix.

isadovskiy avatar Aug 08 '16 18:08 isadovskiy

Looks like Options object is also incompatible...

isadovskiy avatar Aug 09 '16 12:08 isadovskiy

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!

arnaudbreton avatar Mar 31 '17 21:03 arnaudbreton