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

Loading openapi schema with loop references ends-up with endless loop and crashing with "stack overflow" error #542

Closed
panush opened this issue May 16, 2022 · 4 comments

Comments

@panush
Copy link

panush commented May 16, 2022

I'm using kin-openapi v0.89.0.
when trying to load the below openapi (with a reference loop in it), kin-openapi is crashing after getting into an endless loop (see attached file)
kin-openapi-endless-loop-error.txt

openapi: "3.0.0"
info:
  version: 1.0.0
  title: Swagger Petstore
  license:
    name: MIT
servers:
  - url: http://petstore.swagger.io/v1
paths:
  /pets:
    patch:
      requestBody:
        content:
          application/json:
            schema:
              oneOf:
                - $ref: '#/components/schemas/Cat'
                - $ref: '#/components/schemas/Kitten'
              discriminator:
                propertyName: pet_type
      responses:
        '200':
          description: Updated
components:
  schemas:
    Cat:
      anyOf: 
        - $ref: '#/components/schemas/Kitten'
        - type: object
          properties:
            hunts:
              type: boolean
            age:
              type: integer
            offspring:
    Kitten: 
      $ref: '#/components/schemas/Cat'
@fenollp
Copy link
Collaborator

fenollp commented Jun 8, 2022

Hi @panush please use backticks to share your YAML. See https://docs.github.com/en/get-started/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax#quoting-code

Am I correct in assuming that components' Cat's offspring field is empty?

fenollp added a commit to fenollp/kin-openapi that referenced this issue Jun 9, 2022
Signed-off-by: Pierre Fenoll <pierrefenoll@gmail.com>
@fenollp
Copy link
Collaborator

fenollp commented Jun 20, 2022

I investigated a bit but ran out of time. FYI this can be used as a temporary work around:

components:
  schemas:
    Kitten:
      $ref: '#/components/schemas/Cat' # before
      allOf:                           # after
        $ref: '#/components/schemas/Cat'

I'd appreciate help on this issue. I don't have much available time these days.

fenollp added a commit to fenollp/kin-openapi that referenced this issue Aug 13, 2022
Signed-off-by: Pierre Fenoll <pierrefenoll@gmail.com>
fenollp added a commit to fenollp/kin-openapi that referenced this issue Aug 29, 2022
Signed-off-by: Pierre Fenoll <pierrefenoll@gmail.com>
@TristanSpeakEasy
Copy link
Contributor

@panush do the recent PR that was merged sort your issue here?

@maciej
Copy link

maciej commented Feb 10, 2023

It seems to be fixed, see https://go.dev/play/p/cC6HQ4xXC_M.

Returns with:

err: invalid schema: value MUST be an object

@fenollp perhaps you can close the issue?

@fenollp fenollp closed this as completed Feb 13, 2023
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

4 participants