From 44b219a0231f33f7930fcb4fef8d40e148afa815 Mon Sep 17 00:00:00 2001 From: Dave Shanley Date: Fri, 11 Nov 2022 13:07:38 -0500 Subject: [PATCH] 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 --- datamodel/high/base/schema.go | 13 +++++++++---- index/spec_index_test.go | 2 +- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/datamodel/high/base/schema.go b/datamodel/high/base/schema.go index 2a625ce..35f6480 100644 --- a/datamodel/high/base/schema.go +++ b/datamodel/high/base/schema.go @@ -242,38 +242,43 @@ func NewSchema(schema *base.Schema) *Schema { var not []*SchemaProxy var items []*SchemaProxy + children := 0 if !schema.AllOf.IsEmpty() { + children++ go buildOutSchema(schema.AllOf.Value, &allOf, polyCompletedChan, errChan) } if !schema.AnyOf.IsEmpty() { + children++ go buildOutSchema(schema.AnyOf.Value, &anyOf, polyCompletedChan, errChan) } if !schema.OneOf.IsEmpty() { + children++ go buildOutSchema(schema.OneOf.Value, &oneOf, polyCompletedChan, errChan) } if !schema.Not.IsEmpty() { + children++ go buildOutSchema(schema.Not.Value, ¬, polyCompletedChan, errChan) } if !schema.Items.IsEmpty() { + children++ go buildOutSchema(schema.Items.Value, &items, polyCompletedChan, errChan) } completeChildren := 0 completedProps := 0 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+totalChildren > 0 { + if totalProps+children > 0 { allDone: for true { select { case <-polyCompletedChan: completeChildren++ - if totalProps == completedProps && totalChildren == completeChildren { + if totalProps == completedProps && children == completeChildren { break allDone } case <-propsChan: completedProps++ - if totalProps == completedProps && totalChildren == completeChildren { + if totalProps == completedProps && children == completeChildren { break allDone } } diff --git a/index/spec_index_test.go b/index/spec_index_test.go index 6e39477..d8bdebb 100644 --- a/index/spec_index_test.go +++ b/index/spec_index_test.go @@ -376,7 +376,7 @@ func TestSpecIndex_TestEmptyBrokenReferences(t *testing.T) { assert.Equal(t, 2, index.GetOperationsParameterCount()) assert.Equal(t, 1, index.GetInlineDuplicateParamCount()) assert.Equal(t, 1, index.GetInlineUniqueParamCount()) - assert.Len(t, index.refErrors, 7) + assert.Len(t, index.refErrors, 6) }