Added in fix for stackoverflow issue

discovered while running tests, vacuum explodes with the new stripe spec. It’s a `FullDefintion` vs `Definition` misfire.

Signed-off-by: quobix <dave@quobix.com>
This commit is contained in:
quobix
2023-11-30 12:52:07 -05:00
parent 5c372820fc
commit 190330ca9b
8 changed files with 174622 additions and 54206 deletions

View File

@@ -391,7 +391,7 @@ func TestStripeAsDoc(t *testing.T) {
info, _ := datamodel.ExtractSpecInfo(data) info, _ := datamodel.ExtractSpecInfo(data)
var err error var err error
lowDoc, err = lowv3.CreateDocumentFromConfig(info, datamodel.NewDocumentConfiguration()) lowDoc, err = lowv3.CreateDocumentFromConfig(info, datamodel.NewDocumentConfiguration())
assert.Len(t, utils.UnwrapErrors(err), 3) assert.Len(t, utils.UnwrapErrors(err), 2)
d := NewDocument(lowDoc) d := NewDocument(lowDoc)
assert.NotNil(t, d) assert.NotNil(t, d)
} }

View File

@@ -259,7 +259,7 @@ func TestCreateDocumentStripe(t *testing.T) {
data, _ := os.ReadFile("../../../test_specs/stripe.yaml") data, _ := os.ReadFile("../../../test_specs/stripe.yaml")
info, _ := datamodel.ExtractSpecInfo(data) info, _ := datamodel.ExtractSpecInfo(data)
d, err := CreateDocumentFromConfig(info, &datamodel.DocumentConfiguration{}) d, err := CreateDocumentFromConfig(info, &datamodel.DocumentConfiguration{})
assert.Len(t, utils.UnwrapErrors(err), 3) assert.Len(t, utils.UnwrapErrors(err), 2)
assert.Equal(t, "3.0.0", d.Version.Value) assert.Equal(t, "3.0.0", d.Version.Value)
assert.Equal(t, "Stripe API", d.Info.Value.Title.Value) assert.Equal(t, "Stripe API", d.Info.Value.Title.Value)

View File

@@ -166,6 +166,7 @@ func TestDocument_RenderAndReload_ChangeCheck_Burgershop(t *testing.T) {
// should noth be nil. // should noth be nil.
assert.Nil(t, errs) assert.Nil(t, errs)
assert.Nil(t, errs)
assert.NotNil(t, rend) assert.NotNil(t, rend)
assert.Nil(t, compReport) assert.Nil(t, compReport)
@@ -197,10 +198,28 @@ func TestDocument_RenderAndReload_ChangeCheck_Stripe(t *testing.T) {
tc := compReport.TotalChanges() tc := compReport.TotalChanges()
bc := compReport.TotalBreakingChanges() bc := compReport.TotalBreakingChanges()
assert.Equal(t, 0, bc) assert.Equal(t, 0, bc)
assert.Equal(t, 519, tc) assert.Equal(t, 820, tc)
// there should be no other changes than the 519 descriptions. // there should be no other changes than the 519 descriptions.
assert.Equal(t, 0, len(filtered)) assert.Equal(t, 1, len(filtered))
}
func TestDocument_ResolveStripe(t *testing.T) {
bs, _ := os.ReadFile("test_specs/stripe.yaml")
docConfig := datamodel.NewDocumentConfiguration()
docConfig.SkipCircularReferenceCheck = true
docConfig.BasePath = "."
docConfig.AllowRemoteReferences = true
docConfig.AllowFileReferences = true
doc, _ := NewDocumentWithConfiguration(bs, docConfig)
model, _ := doc.BuildV3Model()
rolo := model.Index.GetRolodex()
rolo.Resolve()
assert.Equal(t, 2, len(model.Index.GetRolodex().GetCaughtErrors()))
} }

View File

@@ -332,7 +332,8 @@ func (resolver *Resolver) VisitReference(ref *Reference, seen map[string]bool, j
loop := append(journey, foundDup) loop := append(journey, foundDup)
visitedDefinitions := make(map[string]bool) visitedDefinitions := make(map[string]bool)
isInfiniteLoop, _ := resolver.isInfiniteCircularDependency(foundDup, visitedDefinitions, nil) isInfiniteLoop, _ := resolver.isInfiniteCircularDependency(foundDup,
visitedDefinitions, nil)
isArray := false isArray := false
if r.ParentNodeSchemaType == "array" || slices.Contains(r.ParentNodeTypes, "array") { if r.ParentNodeSchemaType == "array" || slices.Contains(r.ParentNodeTypes, "array") {
@@ -382,11 +383,11 @@ func (resolver *Resolver) VisitReference(ref *Reference, seen map[string]bool, j
return ref.Node.Content return ref.Node.Content
} }
func (resolver *Resolver) isInfiniteCircularDependency(ref *Reference, visitedDefinitions map[string]bool, initialRef *Reference) (bool, map[string]bool) { func (resolver *Resolver) isInfiniteCircularDependency(ref *Reference, visitedDefinitions map[string]bool,
initialRef *Reference) (bool, map[string]bool) {
if ref == nil { if ref == nil {
return false, visitedDefinitions return false, visitedDefinitions
} }
for refDefinition := range ref.RequiredRefProperties { for refDefinition := range ref.RequiredRefProperties {
r, _ := resolver.specIndex.SearchIndexForReference(refDefinition) r, _ := resolver.specIndex.SearchIndexForReference(refDefinition)
if initialRef != nil && initialRef.FullDefinition == r.FullDefinition { if initialRef != nil && initialRef.FullDefinition == r.FullDefinition {
@@ -400,7 +401,7 @@ func (resolver *Resolver) isInfiniteCircularDependency(ref *Reference, visitedDe
continue continue
} }
visitedDefinitions[r.Definition] = true visitedDefinitions[r.FullDefinition] = true
ir := initialRef ir := initialRef
if ir == nil { if ir == nil {
@@ -408,6 +409,7 @@ func (resolver *Resolver) isInfiniteCircularDependency(ref *Reference, visitedDe
} }
var isChildICD bool var isChildICD bool
isChildICD, visitedDefinitions = resolver.isInfiniteCircularDependency(r, visitedDefinitions, ir) isChildICD, visitedDefinitions = resolver.isInfiniteCircularDependency(r, visitedDefinitions, ir)
if isChildICD { if isChildICD {
return true, visitedDefinitions return true, visitedDefinitions

View File

@@ -454,7 +454,7 @@ func TestResolver_ResolveComponents_Stripe_NoRolodex(t *testing.T) {
assert.NotNil(t, resolver) assert.NotNil(t, resolver)
circ := resolver.CheckForCircularReferences() circ := resolver.CheckForCircularReferences()
assert.Len(t, circ, 3) assert.Len(t, circ, 2)
_, err := yaml.Marshal(resolver.resolvedRoot) _, err := yaml.Marshal(resolver.resolvedRoot)
assert.NoError(t, err) assert.NoError(t, err)
@@ -483,8 +483,8 @@ func TestResolver_ResolveComponents_Stripe(t *testing.T) {
// after resolving, the rolodex will have errors. // after resolving, the rolodex will have errors.
rolo.Resolve() rolo.Resolve()
assert.Len(t, rolo.GetCaughtErrors(), 3) assert.Len(t, rolo.GetCaughtErrors(), 2)
assert.Len(t, rolo.GetRootIndex().GetResolver().GetNonPolymorphicCircularErrors(), 3) assert.Len(t, rolo.GetRootIndex().GetResolver().GetNonPolymorphicCircularErrors(), 2)
assert.Len(t, rolo.GetRootIndex().GetResolver().GetPolymorphicCircularErrors(), 0) assert.Len(t, rolo.GetRootIndex().GetResolver().GetPolymorphicCircularErrors(), 0)
} }
@@ -733,7 +733,7 @@ func ExampleNewResolver() {
// //
fmt.Printf("There are %d circular reference errors, %d of them are polymorphic errors, %d are not", fmt.Printf("There are %d circular reference errors, %d of them are polymorphic errors, %d are not",
len(circularErrors), len(resolver.GetPolymorphicCircularErrors()), len(resolver.GetNonPolymorphicCircularErrors())) len(circularErrors), len(resolver.GetPolymorphicCircularErrors()), len(resolver.GetNonPolymorphicCircularErrors()))
// Output: There are 3 circular reference errors, 0 of them are polymorphic errors, 3 are not // Output: There are 2 circular reference errors, 0 of them are polymorphic errors, 2 are not
} }
func ExampleResolvingError() { func ExampleResolvingError() {

View File

@@ -65,27 +65,27 @@ func TestSpecIndex_ExtractRefsStripe(t *testing.T) {
index := NewSpecIndexWithConfig(&rootNode, CreateOpenAPIIndexConfig()) index := NewSpecIndexWithConfig(&rootNode, CreateOpenAPIIndexConfig())
assert.Len(t, index.allRefs, 385) assert.Equal(t, 626, len(index.allRefs))
assert.Equal(t, 537, len(index.allMappedRefs)) assert.Equal(t, 871, len(index.allMappedRefs))
combined := index.GetAllCombinedReferences() combined := index.GetAllCombinedReferences()
assert.Equal(t, 537, len(combined)) assert.Equal(t, 871, len(combined))
assert.Len(t, index.rawSequencedRefs, 1972) assert.Equal(t, len(index.rawSequencedRefs), 2712)
assert.Equal(t, 246, index.pathCount) assert.Equal(t, 336, index.pathCount)
assert.Equal(t, 402, index.operationCount) assert.Equal(t, 494, index.operationCount)
assert.Equal(t, 537, index.schemaCount) assert.Equal(t, 871, index.schemaCount)
assert.Equal(t, 0, index.globalTagsCount) assert.Equal(t, 0, index.globalTagsCount)
assert.Equal(t, 0, index.globalLinksCount) assert.Equal(t, 0, index.globalLinksCount)
assert.Equal(t, 0, index.componentParamCount) assert.Equal(t, 0, index.componentParamCount)
assert.Equal(t, 143, index.operationParamCount) assert.Equal(t, 162, index.operationParamCount)
assert.Equal(t, 88, index.componentsInlineParamDuplicateCount) assert.Equal(t, 102, index.componentsInlineParamDuplicateCount)
assert.Equal(t, 55, index.componentsInlineParamUniqueCount) assert.Equal(t, 60, index.componentsInlineParamUniqueCount)
assert.Equal(t, 1516, index.enumCount) assert.Equal(t, 2579, index.enumCount)
assert.Len(t, index.GetAllEnums(), 1516) assert.Equal(t, len(index.GetAllEnums()), 2579)
assert.Len(t, index.GetPolyAllOfReferences(), 0) assert.Len(t, index.GetPolyAllOfReferences(), 0)
assert.Len(t, index.GetPolyOneOfReferences(), 275) assert.Len(t, index.GetPolyOneOfReferences(), 315)
assert.Len(t, index.GetPolyAnyOfReferences(), 553) assert.Len(t, index.GetPolyAnyOfReferences(), 708)
assert.Len(t, index.GetAllReferenceSchemas(), 1972) assert.Len(t, index.GetAllReferenceSchemas(), 2712)
assert.NotNil(t, index.GetRootServersNode()) assert.NotNil(t, index.GetRootServersNode())
assert.Len(t, index.GetAllRootServers(), 1) assert.Len(t, index.GetAllRootServers(), 1)
assert.Equal(t, "", index.GetSpecAbsolutePath()) assert.Equal(t, "", index.GetSpecAbsolutePath())
@@ -101,9 +101,9 @@ func TestSpecIndex_ExtractRefsStripe(t *testing.T) {
index.SetCircularReferences([]*CircularReferenceResult{new(CircularReferenceResult)}) index.SetCircularReferences([]*CircularReferenceResult{new(CircularReferenceResult)})
assert.Len(t, index.GetCircularReferences(), 1) assert.Len(t, index.GetCircularReferences(), 1)
assert.Len(t, index.GetRefsByLine(), 537) assert.Equal(t, 871, len(index.GetRefsByLine()))
assert.Len(t, index.GetLinesWithReferences(), 1972) assert.Equal(t, 2712, len(index.GetLinesWithReferences()), 1972)
assert.Len(t, index.GetAllExternalDocuments(), 0) assert.Equal(t, 0, len(index.GetAllExternalDocuments()))
} }
func TestSpecIndex_Asana(t *testing.T) { func TestSpecIndex_Asana(t *testing.T) {
@@ -260,7 +260,7 @@ func TestSpecIndex_DigitalOcean_FullCheckoutLocalResolve(t *testing.T) {
assert.Len(t, rolo.GetCaughtErrors(), 0) assert.Len(t, rolo.GetCaughtErrors(), 0)
assert.Len(t, rolo.GetIgnoredCircularReferences(), 0) assert.Len(t, rolo.GetIgnoredCircularReferences(), 0)
assert.Equal(t, int64(1331498), rolo.RolodexFileSize()) assert.Equal(t, int64(1330184), rolo.RolodexFileSize())
assert.Equal(t, "1.27 MB", rolo.RolodexFileSizeAsString()) assert.Equal(t, "1.27 MB", rolo.RolodexFileSizeAsString())
assert.Equal(t, 1696, rolo.RolodexTotalFiles()) assert.Equal(t, 1696, rolo.RolodexTotalFiles())
@@ -334,7 +334,7 @@ func TestSpecIndex_DigitalOcean_FullCheckoutLocalResolve_RecursiveLookup(t *test
assert.Len(t, rolo.GetCaughtErrors(), 0) assert.Len(t, rolo.GetCaughtErrors(), 0)
assert.Len(t, rolo.GetIgnoredCircularReferences(), 0) assert.Len(t, rolo.GetIgnoredCircularReferences(), 0)
assert.Equal(t, int64(1269882), rolo.RolodexFileSize()) assert.Equal(t, int64(1270079), rolo.RolodexFileSize())
assert.Equal(t, "1.21 MB", rolo.RolodexFileSizeAsString()) assert.Equal(t, "1.21 MB", rolo.RolodexFileSizeAsString())
assert.Equal(t, 1682, rolo.RolodexTotalFiles()) assert.Equal(t, 1682, rolo.RolodexTotalFiles())
@@ -1469,16 +1469,16 @@ func ExampleNewSpecIndex() {
len(index.GetAllSchemas()), len(index.GetAllSchemas()),
len(index.GetAllEnums()), len(index.GetAllEnums()),
len(index.GetPolyOneOfReferences())+len(index.GetPolyAnyOfReferences())) len(index.GetPolyOneOfReferences())+len(index.GetPolyAnyOfReferences()))
// Output: There are 537 references // Output: There are 871 references
// 246 paths // 336 paths
// 402 operations // 494 operations
// 537 component schemas // 871 component schemas
// 1972 reference schemas // 2712 reference schemas
// 11749 inline schemas // 15928 inline schemas
// 2612 inline schemas that are objects or arrays // 3857 inline schemas that are objects or arrays
// 14258 total schemas // 19511 total schemas
// 1516 enums // 2579 enums
// 828 polymorphic references // 1023 polymorphic references
} }
func TestSpecIndex_GetAllPathsHavePathAndParent(t *testing.T) { func TestSpecIndex_GetAllPathsHavePathAndParent(t *testing.T) {

81630
test_specs/stripe-old.yaml Normal file

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff