From 3c9415be9c67a040bddee0dcfdecb9603889ed27 Mon Sep 17 00:00:00 2001 From: quobix Date: Wed, 20 Sep 2023 08:51:25 -0400 Subject: [PATCH] tuned test to bump coverage Signed-off-by: quobix --- datamodel/low/v3/create_document_test.go | 58 ++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/datamodel/low/v3/create_document_test.go b/datamodel/low/v3/create_document_test.go index 563ab536..5f72764a 100644 --- a/datamodel/low/v3/create_document_test.go +++ b/datamodel/low/v3/create_document_test.go @@ -80,6 +80,64 @@ func TestCircularReferenceError(t *testing.T) { assert.Len(t, err, 3) } +func TestCircularReference_IgnoreArray(t *testing.T) { + + spec := `openapi: 3.1.0 +components: + schemas: + ProductCategory: + type: "object" + properties: + name: + type: "string" + children: + type: "array" + items: + $ref: "#/components/schemas/ProductCategory" + description: "Array of sub-categories in the same format." + required: + - "name" + - "children"` + + info, _ := datamodel.ExtractSpecInfo([]byte(spec)) + circDoc, err := CreateDocumentFromConfig(info, &datamodel.DocumentConfiguration{ + AllowFileReferences: false, + AllowRemoteReferences: false, + IgnoreArrayCircularReferences: true, + }) + assert.NotNil(t, circDoc) + assert.Len(t, err, 0) +} + +func TestCircularReference_IgnorePoly(t *testing.T) { + + spec := `openapi: 3.1.0 +components: + schemas: + ProductCategory: + type: "object" + properties: + name: + type: "string" + children: + type: "object" + anyOf: + - $ref: "#/components/schemas/ProductCategory" + description: "Array of sub-categories in the same format." + required: + - "name" + - "children"` + + info, _ := datamodel.ExtractSpecInfo([]byte(spec)) + circDoc, err := CreateDocumentFromConfig(info, &datamodel.DocumentConfiguration{ + AllowFileReferences: false, + AllowRemoteReferences: false, + IgnorePolymorphicCircularReferences: true, + }) + assert.NotNil(t, circDoc) + assert.Len(t, err, 0) +} + func BenchmarkCreateDocument_Stripe(b *testing.B) { data, _ := os.ReadFile("../../../test_specs/stripe.yaml") info, _ := datamodel.ExtractSpecInfo(data)