Fixed resolving bug with polymorphic schemas.

Multiple polymorphic, deeply embedded schemas cause resolving issues as a channel waits forever due to a counting issue.

This has been resolved.

Signed-off-by: Dave Shanley <dshanley@splunk.com>
This commit is contained in:
Dave Shanley
2022-11-11 13:07:38 -05:00
parent 98725586fa
commit 44b219a023
2 changed files with 10 additions and 5 deletions

View File

@@ -242,38 +242,43 @@ func NewSchema(schema *base.Schema) *Schema {
var not []*SchemaProxy var not []*SchemaProxy
var items []*SchemaProxy var items []*SchemaProxy
children := 0
if !schema.AllOf.IsEmpty() { if !schema.AllOf.IsEmpty() {
children++
go buildOutSchema(schema.AllOf.Value, &allOf, polyCompletedChan, errChan) go buildOutSchema(schema.AllOf.Value, &allOf, polyCompletedChan, errChan)
} }
if !schema.AnyOf.IsEmpty() { if !schema.AnyOf.IsEmpty() {
children++
go buildOutSchema(schema.AnyOf.Value, &anyOf, polyCompletedChan, errChan) go buildOutSchema(schema.AnyOf.Value, &anyOf, polyCompletedChan, errChan)
} }
if !schema.OneOf.IsEmpty() { if !schema.OneOf.IsEmpty() {
children++
go buildOutSchema(schema.OneOf.Value, &oneOf, polyCompletedChan, errChan) go buildOutSchema(schema.OneOf.Value, &oneOf, polyCompletedChan, errChan)
} }
if !schema.Not.IsEmpty() { if !schema.Not.IsEmpty() {
children++
go buildOutSchema(schema.Not.Value, &not, polyCompletedChan, errChan) go buildOutSchema(schema.Not.Value, &not, polyCompletedChan, errChan)
} }
if !schema.Items.IsEmpty() { if !schema.Items.IsEmpty() {
children++
go buildOutSchema(schema.Items.Value, &items, polyCompletedChan, errChan) go buildOutSchema(schema.Items.Value, &items, polyCompletedChan, errChan)
} }
completeChildren := 0 completeChildren := 0
completedProps := 0 completedProps := 0
totalProps := len(schema.Properties.Value) totalProps := len(schema.Properties.Value)
totalChildren := len(schema.AllOf.Value) + len(schema.OneOf.Value) + len(schema.AnyOf.Value) + len(schema.Items.Value) + len(schema.Not.Value) if totalProps+children > 0 {
if totalProps+totalChildren > 0 {
allDone: allDone:
for true { for true {
select { select {
case <-polyCompletedChan: case <-polyCompletedChan:
completeChildren++ completeChildren++
if totalProps == completedProps && totalChildren == completeChildren { if totalProps == completedProps && children == completeChildren {
break allDone break allDone
} }
case <-propsChan: case <-propsChan:
completedProps++ completedProps++
if totalProps == completedProps && totalChildren == completeChildren { if totalProps == completedProps && children == completeChildren {
break allDone break allDone
} }
} }

View File

@@ -376,7 +376,7 @@ func TestSpecIndex_TestEmptyBrokenReferences(t *testing.T) {
assert.Equal(t, 2, index.GetOperationsParameterCount()) assert.Equal(t, 2, index.GetOperationsParameterCount())
assert.Equal(t, 1, index.GetInlineDuplicateParamCount()) assert.Equal(t, 1, index.GetInlineDuplicateParamCount())
assert.Equal(t, 1, index.GetInlineUniqueParamCount()) assert.Equal(t, 1, index.GetInlineUniqueParamCount())
assert.Len(t, index.refErrors, 7) assert.Len(t, index.refErrors, 6)
} }