From 3330e3a519b4ea4d6a5cb041147840573c2a4b07 Mon Sep 17 00:00:00 2001 From: Serhii Poperechnyi Date: Mon, 22 Jan 2024 14:33:46 +0100 Subject: [PATCH] Added test for openapi 3.1 null type --- functions/openapi/schema_type_test.go | 31 +++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/functions/openapi/schema_type_test.go b/functions/openapi/schema_type_test.go index c14703e6..3ba4fdcd 100644 --- a/functions/openapi/schema_type_test.go +++ b/functions/openapi/schema_type_test.go @@ -960,3 +960,34 @@ components: assert.Equal(t, "`required` field `hello` is not defined in `properties`", res[0].Message) assert.Equal(t, "$.components.schemas['Gum'].required[0]", res[0].Path) } + +func TestSchemaType_Null(t *testing.T) { + + yml := `openapi: 3.1 +components: + schemas: + Gum: + type: null` + + document, err := libopenapi.NewDocument([]byte(yml)) + if err != nil { + panic(fmt.Sprintf("cannot create new document: %e", err)) + } + + m, _ := document.BuildV3Model() + path := "$" + + drDocument := drModel.NewDrDocument(m) + + rule := buildOpenApiTestRuleAction(path, "schema-type-check", "", nil) + ctx := buildOpenApiTestContext(model.CastToRuleAction(rule.Then), nil) + + ctx.Document = document + ctx.DrDocument = drDocument + ctx.Rule = &rule + + def := SchemaTypeCheck{} + res := def.RunRule(nil, ctx) + + assert.Empty(t, res) +}