Skip to content

Commit

Permalink
Addressed issues #428 and #424
Browse files Browse the repository at this point in the history
Signed-off-by: quobix <dave@quobix.com>
  • Loading branch information
daveshanley committed Jan 24, 2024
1 parent 2fffb5c commit 0e30ba4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 42 deletions.
30 changes: 0 additions & 30 deletions functions/openapi/schema_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,22 +83,7 @@ func (st SchemaTypeCheck) validateNumber(schema *base.Schema, context *model.Rul
}
}

if schema.Value.Minimum != nil {
if *schema.Value.Minimum < 0 {
result := st.buildResult("`minimum` should be a number greater than or equal to `0`",
fmt.Sprintf("%s.%s", schema.GenerateJSONPath(), "minimum"),
schema, schema.Value.GoLow().Minimum.KeyNode, context)
results = append(results, result)
}
}

if schema.Value.Maximum != nil {
if *schema.Value.Maximum < 0 {
result := st.buildResult("`maximum` should be a number greater than or equal to `0`",
fmt.Sprintf("%s.%s", schema.GenerateJSONPath(), "maximum"),
schema, schema.Value.GoLow().Maximum.KeyNode, context)
results = append(results, result)
}
if schema.Value.Minimum != nil {
if *schema.Value.Maximum < *schema.Value.Minimum {
result := st.buildResult("`maximum` should be a number greater than or equal to `minimum`",
Expand All @@ -109,22 +94,7 @@ func (st SchemaTypeCheck) validateNumber(schema *base.Schema, context *model.Rul
}
}

if schema.Value.ExclusiveMinimum != nil {
if schema.Value.ExclusiveMinimum.IsB() && schema.Value.ExclusiveMinimum.B < 0 {
result := st.buildResult("`exclusiveMinimum` should be a number greater than or equal to `0`",
fmt.Sprintf("%s.%s", schema.GenerateJSONPath(), "exclusiveMinimum"),
schema, schema.Value.GoLow().ExclusiveMinimum.KeyNode, context)
results = append(results, result)
}
}

if schema.Value.ExclusiveMaximum != nil {
if schema.Value.ExclusiveMaximum.IsB() && schema.Value.ExclusiveMaximum.B < 0 {
result := st.buildResult("`exclusiveMaximum` should be a number greater than or equal to `0`",
fmt.Sprintf("%s.%s", schema.GenerateJSONPath(), "exclusiveMaximum"),
schema, schema.Value.GoLow().ExclusiveMaximum.KeyNode, context)
results = append(results, result)
}
if schema.Value.ExclusiveMinimum != nil {
if schema.Value.ExclusiveMinimum.IsB() && schema.Value.ExclusiveMinimum.B > schema.Value.ExclusiveMaximum.B {
result := st.buildResult("`exclusiveMaximum` should be greater than or equal to `exclusiveMinimum`",
Expand Down
17 changes: 5 additions & 12 deletions functions/openapi/schema_type_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,9 +277,7 @@ components:
def := SchemaTypeCheck{}
res := def.RunRule(nil, ctx)

assert.Len(t, res, 1)
assert.Equal(t, "`minimum` should be a number greater than or equal to `0`", res[0].Message)
assert.Equal(t, "$.components.schemas['Gum'].minimum", res[0].Path)
assert.Len(t, res, 0)
}

func TestSchemaType_Minimum_Zero(t *testing.T) {
Expand Down Expand Up @@ -407,9 +405,7 @@ components:
def := SchemaTypeCheck{}
res := def.RunRule(nil, ctx)

assert.Len(t, res, 1)
assert.Equal(t, "`maximum` should be a number greater than or equal to `0`", res[0].Message)
assert.Equal(t, "$.components.schemas['Gum'].maximum", res[0].Path)
assert.Len(t, res, 0)
}

func TestSchemaType_MinMaximum(t *testing.T) {
Expand Down Expand Up @@ -476,9 +472,8 @@ components:
def := SchemaTypeCheck{}
res := def.RunRule(nil, ctx)

assert.Len(t, res, 1)
assert.Equal(t, "`exclusiveMinimum` should be a number greater than or equal to `0`", res[0].Message)
assert.Equal(t, "$.components.schemas['Gum'].exclusiveMinimum", res[0].Path)
assert.Len(t, res, 0)

}

func TestSchemaType_ExclusiveMinimum_Zero(t *testing.T) {
Expand Down Expand Up @@ -542,9 +537,7 @@ components:
def := SchemaTypeCheck{}
res := def.RunRule(nil, ctx)

assert.Len(t, res, 1)
assert.Equal(t, "`exclusiveMaximum` should be a number greater than or equal to `0`", res[0].Message)
assert.Equal(t, "$.components.schemas['Gum'].exclusiveMaximum", res[0].Path)
assert.Len(t, res, 0)
}

func TestSchemaType_ExclusiveMaximum_Zero(t *testing.T) {
Expand Down

0 comments on commit 0e30ba4

Please sign in to comment.