Fix issue with non-working IgnorePoly flag.

This commit is contained in:
Ilja Lapkovskis
2024-01-25 20:39:01 +02:00
committed by quobix
parent 442b048575
commit b01b967433
3 changed files with 31 additions and 15 deletions

View File

@@ -369,7 +369,9 @@ func (resolver *Resolver) VisitReference(ref *Reference, seen map[string]bool, j
IsInfiniteLoop: isInfiniteLoop,
}
if resolver.IgnoreArray && isArray {
if resolver.IgnorePoly && !isArray {
resolver.ignoredPolyReferences = append(resolver.ignoredPolyReferences, circRef)
} else if resolver.IgnoreArray && isArray {
resolver.ignoredArrayReferences = append(resolver.ignoredArrayReferences, circRef)
} else {
if !resolver.circChecked {

View File

@@ -217,22 +217,36 @@ components:
}
func TestResolver_CheckForCircularReferences_IgnorePoly_Any(t *testing.T) {
circular := []byte(`openapi: 3.0.0
circular := []byte(`openapi: 3.1.0
paths:
/one:
get:
responses:
'200':
content:
application/json:
schema:
$ref: '#/components/schemas/One'
components:
schemas:
ProductCategory:
type: "object"
One:
properties:
name:
type: "string"
children:
type: "object"
anyOf:
- $ref: "#/components/schemas/ProductCategory"
description: "Array of sub-categories in the same format."
thing:
oneOf:
- "$ref": "#/components/schemas/Two"
- "$ref": "#/components/schemas/Three"
required:
- "name"
- "children"`)
- thing
Two:
description: "test two"
properties:
testThing:
"$ref": "#/components/schemas/One"
Three:
description: "test three"
properties:
testThing:
"$ref": "#/components/schemas/One"`)
var rootNode yaml.Node
_ = yaml.Unmarshal(circular, &rootNode)

View File

@@ -1441,8 +1441,8 @@ components:
rolodex.SetRootNode(&rootNode)
err := rolodex.IndexTheRolodex()
assert.Error(t, err)
assert.Len(t, rolodex.GetCaughtErrors(), 1)
assert.NoError(t, err)
assert.Len(t, rolodex.GetCaughtErrors(), 0)
}
func TestRolodex_IndexCircularLookup_ignorePoly(t *testing.T) {