Tufin / oasdiff

OpenAPI Diff and Breaking Changes
https://www.oasdiff.com
Apache License 2.0
739 stars 62 forks source link

Circular references in separate files results in stack overflow error #442

Closed jacobdekeizer closed 3 months ago

jacobdekeizer commented 11 months ago

Describe the bug We have an open api specification with circular references where each object is stored in a separate file. This results in a stack overflow error:

runtime: goroutine stack exceeds 1000000000-byte limit
runtime: sp=0x140ade80340 stack=[0x140ade80000, 0x140cde80000]
fatal error: stack overflow

runtime stack:
runtime.throw({0x1048394c0?, 0x104347498?})

I am on the latest version and the pr #418 did not fix the issue for our scenario.

To Reproduce

I've made two example files based on the example files in pr #418:

circular2.yaml

openapi: 3.0.0
info:
    title: Circular Reference Example
    version: 1.0.0
paths:
    /sample:
        put:
            requestBody:
                required: true
                content:
                    application/json:
                        schema:
                            $ref: './AwsEnvironmentSettings.yaml'
            responses:
                '200':
                    description: Ok

AwsEnvironmentSettings.yaml

type: object
properties:
    children:
        type: array
        items:
            $ref: './AWSEnvironmentSettings.yaml'
description: test

Steps to reproduce the behavior:

  1. Create the 2 files above
  2. oasdiff breaking ./circular2.yaml ./circular2.yaml
reuvenharrison commented 11 months ago

Looks like a problem in underlying kin-openapi This can be used to replicate with your files above:

func TestLoadCircular(t *testing.T) {
    loader := NewLoader()
    loader.IsExternalRefsAllowed = true
    _, err := loader.LoadFromFile("testdata/circular2.yaml")
    require.NoError(t, err)
}

Thanks for reporting!

anikitin commented 8 months ago

I faced the same issue recently.

reuvenharrison commented 3 months ago

Fixed by https://github.com/Tufin/oasdiff/pull/575