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, 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) resolver.ignoredArrayReferences = append(resolver.ignoredArrayReferences, circRef)
} else { } else {
if !resolver.circChecked { if !resolver.circChecked {

View File

@@ -217,22 +217,36 @@ components:
} }
func TestResolver_CheckForCircularReferences_IgnorePoly_Any(t *testing.T) { 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: components:
schemas: schemas:
ProductCategory: One:
type: "object"
properties: properties:
name: thing:
type: "string" oneOf:
children: - "$ref": "#/components/schemas/Two"
type: "object" - "$ref": "#/components/schemas/Three"
anyOf:
- $ref: "#/components/schemas/ProductCategory"
description: "Array of sub-categories in the same format."
required: required:
- "name" - thing
- "children"`) Two:
description: "test two"
properties:
testThing:
"$ref": "#/components/schemas/One"
Three:
description: "test three"
properties:
testThing:
"$ref": "#/components/schemas/One"`)
var rootNode yaml.Node var rootNode yaml.Node
_ = yaml.Unmarshal(circular, &rootNode) _ = yaml.Unmarshal(circular, &rootNode)

View File

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