mirror of
https://github.com/LukeHagar/libopenapi.git
synced 2025-12-06 04:20:11 +00:00
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:
@@ -391,7 +391,7 @@ func TestStripeAsDoc(t *testing.T) {
|
||||
info, _ := datamodel.ExtractSpecInfo(data)
|
||||
var err error
|
||||
lowDoc, err = lowv3.CreateDocumentFromConfig(info, datamodel.NewDocumentConfiguration())
|
||||
assert.Len(t, utils.UnwrapErrors(err), 3)
|
||||
assert.Len(t, utils.UnwrapErrors(err), 2)
|
||||
d := NewDocument(lowDoc)
|
||||
assert.NotNil(t, d)
|
||||
}
|
||||
|
||||
@@ -259,7 +259,7 @@ func TestCreateDocumentStripe(t *testing.T) {
|
||||
data, _ := os.ReadFile("../../../test_specs/stripe.yaml")
|
||||
info, _ := datamodel.ExtractSpecInfo(data)
|
||||
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, "Stripe API", d.Info.Value.Title.Value)
|
||||
|
||||
@@ -166,6 +166,7 @@ func TestDocument_RenderAndReload_ChangeCheck_Burgershop(t *testing.T) {
|
||||
|
||||
// should noth be nil.
|
||||
assert.Nil(t, errs)
|
||||
assert.Nil(t, errs)
|
||||
assert.NotNil(t, rend)
|
||||
assert.Nil(t, compReport)
|
||||
|
||||
@@ -197,10 +198,28 @@ func TestDocument_RenderAndReload_ChangeCheck_Stripe(t *testing.T) {
|
||||
tc := compReport.TotalChanges()
|
||||
bc := compReport.TotalBreakingChanges()
|
||||
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.
|
||||
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()))
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -332,7 +332,8 @@ func (resolver *Resolver) VisitReference(ref *Reference, seen map[string]bool, j
|
||||
loop := append(journey, foundDup)
|
||||
|
||||
visitedDefinitions := make(map[string]bool)
|
||||
isInfiniteLoop, _ := resolver.isInfiniteCircularDependency(foundDup, visitedDefinitions, nil)
|
||||
isInfiniteLoop, _ := resolver.isInfiniteCircularDependency(foundDup,
|
||||
visitedDefinitions, nil)
|
||||
|
||||
isArray := false
|
||||
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
|
||||
}
|
||||
|
||||
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 {
|
||||
return false, visitedDefinitions
|
||||
}
|
||||
|
||||
for refDefinition := range ref.RequiredRefProperties {
|
||||
r, _ := resolver.specIndex.SearchIndexForReference(refDefinition)
|
||||
if initialRef != nil && initialRef.FullDefinition == r.FullDefinition {
|
||||
@@ -400,7 +401,7 @@ func (resolver *Resolver) isInfiniteCircularDependency(ref *Reference, visitedDe
|
||||
continue
|
||||
}
|
||||
|
||||
visitedDefinitions[r.Definition] = true
|
||||
visitedDefinitions[r.FullDefinition] = true
|
||||
|
||||
ir := initialRef
|
||||
if ir == nil {
|
||||
@@ -408,6 +409,7 @@ func (resolver *Resolver) isInfiniteCircularDependency(ref *Reference, visitedDe
|
||||
}
|
||||
|
||||
var isChildICD bool
|
||||
|
||||
isChildICD, visitedDefinitions = resolver.isInfiniteCircularDependency(r, visitedDefinitions, ir)
|
||||
if isChildICD {
|
||||
return true, visitedDefinitions
|
||||
|
||||
@@ -454,7 +454,7 @@ func TestResolver_ResolveComponents_Stripe_NoRolodex(t *testing.T) {
|
||||
assert.NotNil(t, resolver)
|
||||
|
||||
circ := resolver.CheckForCircularReferences()
|
||||
assert.Len(t, circ, 3)
|
||||
assert.Len(t, circ, 2)
|
||||
|
||||
_, err := yaml.Marshal(resolver.resolvedRoot)
|
||||
assert.NoError(t, err)
|
||||
@@ -483,8 +483,8 @@ func TestResolver_ResolveComponents_Stripe(t *testing.T) {
|
||||
// after resolving, the rolodex will have errors.
|
||||
rolo.Resolve()
|
||||
|
||||
assert.Len(t, rolo.GetCaughtErrors(), 3)
|
||||
assert.Len(t, rolo.GetRootIndex().GetResolver().GetNonPolymorphicCircularErrors(), 3)
|
||||
assert.Len(t, rolo.GetCaughtErrors(), 2)
|
||||
assert.Len(t, rolo.GetRootIndex().GetResolver().GetNonPolymorphicCircularErrors(), 2)
|
||||
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",
|
||||
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() {
|
||||
|
||||
@@ -65,27 +65,27 @@ func TestSpecIndex_ExtractRefsStripe(t *testing.T) {
|
||||
|
||||
index := NewSpecIndexWithConfig(&rootNode, CreateOpenAPIIndexConfig())
|
||||
|
||||
assert.Len(t, index.allRefs, 385)
|
||||
assert.Equal(t, 537, len(index.allMappedRefs))
|
||||
assert.Equal(t, 626, len(index.allRefs))
|
||||
assert.Equal(t, 871, len(index.allMappedRefs))
|
||||
combined := index.GetAllCombinedReferences()
|
||||
assert.Equal(t, 537, len(combined))
|
||||
assert.Equal(t, 871, len(combined))
|
||||
|
||||
assert.Len(t, index.rawSequencedRefs, 1972)
|
||||
assert.Equal(t, 246, index.pathCount)
|
||||
assert.Equal(t, 402, index.operationCount)
|
||||
assert.Equal(t, 537, index.schemaCount)
|
||||
assert.Equal(t, len(index.rawSequencedRefs), 2712)
|
||||
assert.Equal(t, 336, index.pathCount)
|
||||
assert.Equal(t, 494, index.operationCount)
|
||||
assert.Equal(t, 871, index.schemaCount)
|
||||
assert.Equal(t, 0, index.globalTagsCount)
|
||||
assert.Equal(t, 0, index.globalLinksCount)
|
||||
assert.Equal(t, 0, index.componentParamCount)
|
||||
assert.Equal(t, 143, index.operationParamCount)
|
||||
assert.Equal(t, 88, index.componentsInlineParamDuplicateCount)
|
||||
assert.Equal(t, 55, index.componentsInlineParamUniqueCount)
|
||||
assert.Equal(t, 1516, index.enumCount)
|
||||
assert.Len(t, index.GetAllEnums(), 1516)
|
||||
assert.Equal(t, 162, index.operationParamCount)
|
||||
assert.Equal(t, 102, index.componentsInlineParamDuplicateCount)
|
||||
assert.Equal(t, 60, index.componentsInlineParamUniqueCount)
|
||||
assert.Equal(t, 2579, index.enumCount)
|
||||
assert.Equal(t, len(index.GetAllEnums()), 2579)
|
||||
assert.Len(t, index.GetPolyAllOfReferences(), 0)
|
||||
assert.Len(t, index.GetPolyOneOfReferences(), 275)
|
||||
assert.Len(t, index.GetPolyAnyOfReferences(), 553)
|
||||
assert.Len(t, index.GetAllReferenceSchemas(), 1972)
|
||||
assert.Len(t, index.GetPolyOneOfReferences(), 315)
|
||||
assert.Len(t, index.GetPolyAnyOfReferences(), 708)
|
||||
assert.Len(t, index.GetAllReferenceSchemas(), 2712)
|
||||
assert.NotNil(t, index.GetRootServersNode())
|
||||
assert.Len(t, index.GetAllRootServers(), 1)
|
||||
assert.Equal(t, "", index.GetSpecAbsolutePath())
|
||||
@@ -101,9 +101,9 @@ func TestSpecIndex_ExtractRefsStripe(t *testing.T) {
|
||||
index.SetCircularReferences([]*CircularReferenceResult{new(CircularReferenceResult)})
|
||||
assert.Len(t, index.GetCircularReferences(), 1)
|
||||
|
||||
assert.Len(t, index.GetRefsByLine(), 537)
|
||||
assert.Len(t, index.GetLinesWithReferences(), 1972)
|
||||
assert.Len(t, index.GetAllExternalDocuments(), 0)
|
||||
assert.Equal(t, 871, len(index.GetRefsByLine()))
|
||||
assert.Equal(t, 2712, len(index.GetLinesWithReferences()), 1972)
|
||||
assert.Equal(t, 0, len(index.GetAllExternalDocuments()))
|
||||
}
|
||||
|
||||
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.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, 1696, rolo.RolodexTotalFiles())
|
||||
|
||||
@@ -334,7 +334,7 @@ func TestSpecIndex_DigitalOcean_FullCheckoutLocalResolve_RecursiveLookup(t *test
|
||||
assert.Len(t, rolo.GetCaughtErrors(), 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, 1682, rolo.RolodexTotalFiles())
|
||||
|
||||
@@ -1469,16 +1469,16 @@ func ExampleNewSpecIndex() {
|
||||
len(index.GetAllSchemas()),
|
||||
len(index.GetAllEnums()),
|
||||
len(index.GetPolyOneOfReferences())+len(index.GetPolyAnyOfReferences()))
|
||||
// Output: There are 537 references
|
||||
// 246 paths
|
||||
// 402 operations
|
||||
// 537 component schemas
|
||||
// 1972 reference schemas
|
||||
// 11749 inline schemas
|
||||
// 2612 inline schemas that are objects or arrays
|
||||
// 14258 total schemas
|
||||
// 1516 enums
|
||||
// 828 polymorphic references
|
||||
// Output: There are 871 references
|
||||
// 336 paths
|
||||
// 494 operations
|
||||
// 871 component schemas
|
||||
// 2712 reference schemas
|
||||
// 15928 inline schemas
|
||||
// 3857 inline schemas that are objects or arrays
|
||||
// 19511 total schemas
|
||||
// 2579 enums
|
||||
// 1023 polymorphic references
|
||||
}
|
||||
|
||||
func TestSpecIndex_GetAllPathsHavePathAndParent(t *testing.T) {
|
||||
|
||||
81630
test_specs/stripe-old.yaml
Normal file
81630
test_specs/stripe-old.yaml
Normal file
File diff suppressed because it is too large
Load Diff
147093
test_specs/stripe.yaml
147093
test_specs/stripe.yaml
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user