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

kin-openapi bug found: circular schema reference not handled error is thrown randomly #764

Closed
mthaak opened this issue Feb 9, 2023 · 3 comments

Comments

@mthaak
Copy link

mthaak commented Feb 9, 2023

Sometimes I can use oapi-codegen to generate Go types and sometimes it fails:

> oapi-codegen -config oapi-config.yml spec.yaml
: kin-openapi bug found: circular schema reference not handled - #/components/schemas/QueryComponent -> #/components/schemas/AndQuery -> #/components/schemas/AndQueryGroup -> #/components/schemas/QueryComponent -> #/components/schemas/AndQuery -> #/components/schemas/AndQueryGroup -> #/components/schemas/QueryComponent -> #/components/schemas/OrQuery -> #/components/schemas/OrQueryGroup -> #/components/schemas/QueryComponent error loading swagger spec in spec.yaml

This flakiness is especially confusing. I get around it by just re-running but it's strange.

This is spec.yaml:

openapi: 3.0.3
info:
  title: API
  version: 1.0.0
paths: { }
components:
  schemas:
    QueryComponent:
      oneOf:
        - $ref: '#/components/schemas/AndQuery'
        - $ref: '#/components/schemas/OrQuery'

    OrQuery:
      required:
        - dis_max
      properties:
        dis_max:
          $ref: '#/components/schemas/OrQueryGroup'

    OrQueryGroup:
      description: A query that returns the OR of the child queries
      required:
        - queries
      properties:
        queries:
          type: array
          items:
            $ref: '#/components/schemas/QueryComponent'

    AndQuery:
      required:
        - bool
      properties:
        bool:
          $ref: '#/components/schemas/AndQueryGroup'

    AndQueryGroup:
      description: A query that returns the AND of the child queries
      properties:
        filter:
          type: array
          items:
            $ref: '#/components/schemas/QueryComponent'
        must_not:
          type: array
          items:
            $ref: '#/components/schemas/QueryComponent'

    Request:
      properties:
        query:
          $ref: '#/components/schemas/QueryComponent'
fenollp added a commit to fenollp/kin-openapi that referenced this issue Feb 9, 2023
Signed-off-by: Pierre Fenoll <pierrefenoll@gmail.com>
@fenollp
Copy link
Collaborator

fenollp commented Feb 9, 2023

Hi! Thanks for reporting.

I've tried reproducing the issue with go run github.com/getkin/kin-openapi/cmd/validate@latest -- your_file.yml in a loop and could not reproduce getting an error. What platform / go version / lib version are you using?

The flakiness I attribute to visiting and validation using Go's map iteration which is being worked on: #695 but requires preliminary work: #763. This issue is known and one of the causes of #643 being stuck.

Anyway: #765

@mthaak
Copy link
Author

mthaak commented Feb 10, 2023

Thanks for the response and trying to reproduce it!

We use the latest oapi-codegen v1.12.4 which uses kin-openapi v0.107.0. That version does not have the cmd/validate though..

We use go version go1.19.4 linux/amd64

@fenollp
Copy link
Collaborator

fenollp commented Feb 10, 2023

We use the latest oapi-codegen v1.12.4 which uses kin-openapi v0.107.0

Did you open an issue there then?

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

No branches or pull requests

2 participants