Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Combining multiple files can create circular references #74

Open
WillowP opened this issue Feb 8, 2022 · 1 comment
Open

Combining multiple files can create circular references #74

WillowP opened this issue Feb 8, 2022 · 1 comment

Comments

@WillowP
Copy link

WillowP commented Feb 8, 2022

Hello, thank you for this excellent tool! I hope this isn't a duplicate, I didn't see anything that jumped out at me.

Problem

I have a bit of openapi spec like this:

# File 1
type: object
required:
  - Prop1
  - Prop2
properties:
  Prop1:
    $ref: './modules/Prop1.yml'
  Prop2:
    $ref: './modules/Prop2.yml'

# File 2: './modules/Prop1.yml'
allOf:
  - $ref: './Base.yml'
  - type: object
    properties:
      title:
        type: string

# File 3: './modules/Prop2.yml'
allOf:
  - $ref: './Base.yml'
  - type: object
    properties:
      title:
        type: string

# File 4: './modules/Base.yml'
type: object
properties:
  some_shared_property:
    type: string

When I run swagger-cli bundle, without setting --dereference, I end up with a $ref that looks like this inside the definition for Prop2:

"$ref": "#/...path_to_first_file_object/properties/Prop1/allOf/0"

Since Prop1 and Prop2 both live inside of #/...path_to_first_file_object/properties, this is causing a circular reference. I get the error: $refs must reference a valid location in the document when I try to view the output on https://editor.swagger.io/

Expected behaviour:

I'd expect the circular reference to be avoided.

If this isn't enough info, I'd be happy to provide more :)

Workaround

Run with --dereference. I might also try changing the way I've structured this to move the first reference to the Base object somewhere else.

@thomasklein-toptal
Copy link

+1

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants