Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can not parse openapi spec with recursive references #309

Closed
hottestseason opened this issue Feb 28, 2021 · 3 comments · Fixed by #310
Closed

Can not parse openapi spec with recursive references #309

hottestseason opened this issue Feb 28, 2021 · 3 comments · Fixed by #310

Comments

@hottestseason
Copy link
Contributor

hottestseason commented Feb 28, 2021

It looks this library fail to parse spec which has recursive references like this
https://github.com/hottestseason/kin-openapi/tree/f9ccdc2e69d360c4f17a7c94189526457e90b1f3/openapi3/testdata/recursiveRef

openapi: "3.0.3"
info:
  title: Recursive refs example
  version: "1.0"
paths:
  /foo:
    $ref: ./paths/foo.yml
components:
  schemas:
    Foo:
      $ref: ./components/Foo.yml
    Bar:
      $ref: ./components/Bar.yml
get:
  responses:
    "200":
      description: OK
      content:
        application/json:
          schema:
            type: object
            properties:
              foo:
                $ref: ../openapi.yml#/components/schemas/Foo
type: object
properties:
  bar:
    type: array
    items:
      $ref: ../openapi.yml#/components/schemas/Bar
type: string
example: bar

It works when loading bundled version such as using swagger-cli bundle

@roee88
Copy link

roee88 commented May 5, 2021

@fenollp I don't think that this one is fixed. A minimal example to reproduce:

openapi: 3.0.1
info:
  title: Recursive refs example
  version: "1.0"
paths: {}
components:
  schemas:
    Complex:
      type: object
      properties:
        parent:
          $ref: '#/components/schemas/Complex'

Should I open a different issue?

@chrisdostert
Copy link

@fenollp @hottestseason thanks for all the hard work and a the great project. I'm still seeing this as well so I don't think it's fixed yet. The issue I'm hitting is the same as @roee88 's example where my schema is recursive. The result is, golang model generation hangs indefinitely.

@fenollp
Copy link
Collaborator

fenollp commented Nov 3, 2021

Ah sorry I missed that @roee88
Yes please open a dedicated issue and maybe a PR with the looping snippet.
There are loop detection mechanisms in place and they appear not to handle this kind of code...

visitedSchema map[*Schema]struct{}

PRs welcomed!

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

Successfully merging a pull request may close this issue.

4 participants