Skip to content

Commit

Permalink
Add nil check for required properties
Browse files Browse the repository at this point in the history
  • Loading branch information
psm14 authored and daveshanley committed Jan 26, 2024
1 parent 0e30ba4 commit 4491f4b
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions functions/openapi/schema_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,13 @@ func (st SchemaTypeCheck) validateObject(schema *base.Schema, context *model.Rul

if len(schema.Value.Required) > 0 {
for i, required := range schema.Value.Required {
if schema.Value.Properties == nil {
result := st.buildResult("object contains `required` fields but no `properties`",
fmt.Sprintf("%s.%s[%d]", schema.GenerateJSONPath(), "required", i),
schema, schema.Value.GoLow().Required.KeyNode, context)
results = append(results, result)
break
}
if schema.Value.Properties.GetOrZero(required) == nil {
result := st.buildResult(fmt.Sprintf("`required` field `%s` is not defined in `properties`", required),
fmt.Sprintf("%s.%s[%d]", schema.GenerateJSONPath(), "required", i),
Expand Down

0 comments on commit 4491f4b

Please sign in to comment.