@@ -80,6 +80,64 @@ func TestCircularReferenceError(t *testing.T) {
8080 assert .Len (t , err , 3 )
8181}
8282
83+ func TestCircularReference_IgnoreArray (t * testing.T ) {
84+
85+ spec := `openapi: 3.1.0
86+ components:
87+ schemas:
88+ ProductCategory:
89+ type: "object"
90+ properties:
91+ name:
92+ type: "string"
93+ children:
94+ type: "array"
95+ items:
96+ $ref: "#/components/schemas/ProductCategory"
97+ description: "Array of sub-categories in the same format."
98+ required:
99+ - "name"
100+ - "children"`
101+
102+ info , _ := datamodel .ExtractSpecInfo ([]byte (spec ))
103+ circDoc , err := CreateDocumentFromConfig (info , & datamodel.DocumentConfiguration {
104+ AllowFileReferences : false ,
105+ AllowRemoteReferences : false ,
106+ IgnoreArrayCircularReferences : true ,
107+ })
108+ assert .NotNil (t , circDoc )
109+ assert .Len (t , err , 0 )
110+ }
111+
112+ func TestCircularReference_IgnorePoly (t * testing.T ) {
113+
114+ spec := `openapi: 3.1.0
115+ components:
116+ schemas:
117+ ProductCategory:
118+ type: "object"
119+ properties:
120+ name:
121+ type: "string"
122+ children:
123+ type: "object"
124+ anyOf:
125+ - $ref: "#/components/schemas/ProductCategory"
126+ description: "Array of sub-categories in the same format."
127+ required:
128+ - "name"
129+ - "children"`
130+
131+ info , _ := datamodel .ExtractSpecInfo ([]byte (spec ))
132+ circDoc , err := CreateDocumentFromConfig (info , & datamodel.DocumentConfiguration {
133+ AllowFileReferences : false ,
134+ AllowRemoteReferences : false ,
135+ IgnorePolymorphicCircularReferences : true ,
136+ })
137+ assert .NotNil (t , circDoc )
138+ assert .Len (t , err , 0 )
139+ }
140+
83141func BenchmarkCreateDocument_Stripe (b * testing.B ) {
84142 data , _ := os .ReadFile ("../../../test_specs/stripe.yaml" )
85143 info , _ := datamodel .ExtractSpecInfo (data )
0 commit comments