Skip to content

Commit

Permalink
Added test for openapi 3.1 null type
Browse files Browse the repository at this point in the history
  • Loading branch information
inf0serj authored and daveshanley committed Jan 23, 2024
1 parent fadb7ee commit 3330e3a
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions functions/openapi/schema_type_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

0 comments on commit 3330e3a

Please sign in to comment.