Skip to content

Commit 5b5766b

Browse files
martinsirbedaveshanley
authored andcommitted
Update tests
1 parent fcb62d5 commit 5b5766b

File tree

1 file changed

+40
-7
lines changed

1 file changed

+40
-7
lines changed

requests/validate_request_test.go

+40-7
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,8 @@ func TestValidateRequestSchema(t *testing.T) {
1818
assertValidRequestSchema assert.BoolAssertionFunc
1919
expectedErrorsCount int
2020
}{
21-
"FailRequestBodyValidation": {
22-
// KeywordLocation: /allOf/1/$ref/properties/properties/additionalProperties/$dynamicRef/allOf/3/$ref/properties/exclusiveMinimum/type
23-
// Message: expected number, but got boolean
24-
request: &http.Request{
25-
Method: http.MethodPost,
26-
Body: io.NopCloser(strings.NewReader(`{"exclusiveNumber": 13}`)),
27-
},
21+
"FailOnBooleanExclusiveMinimum": {
22+
request: postRequestWithBody(`{"exclusiveNumber": 13}`),
2823
schema: &base.Schema{
2924
Type: []string{"object"},
3025
},
@@ -39,6 +34,37 @@ properties:
3934
assertValidRequestSchema: assert.False,
4035
expectedErrorsCount: 1,
4136
},
37+
"PassWithCorrectExclusiveMinimum": {
38+
request: postRequestWithBody(`{"exclusiveNumber": 15}`),
39+
schema: &base.Schema{
40+
Type: []string{"object"},
41+
},
42+
renderedSchema: []byte(`type: object
43+
properties:
44+
exclusiveNumber:
45+
type: number
46+
description: This number is properly constrained by a numeric exclusive minimum.
47+
exclusiveMinimum: 12
48+
minimum: 12`),
49+
jsonSchema: []byte(`{"properties":{"exclusiveNumber":{"type":"number","description":"This number is properly constrained by a numeric exclusive minimum.","exclusiveMinimum":12,"minimum":12}},"type":"object"}`),
50+
assertValidRequestSchema: assert.True,
51+
expectedErrorsCount: 0,
52+
},
53+
"PassWithValidStringType": {
54+
request: postRequestWithBody(`{"greeting": "Hello, world!"}`),
55+
schema: &base.Schema{
56+
Type: []string{"object"},
57+
},
58+
renderedSchema: []byte(`type: object
59+
properties:
60+
greeting:
61+
type: string
62+
description: A simple greeting
63+
example: "Hello, world!"`),
64+
jsonSchema: []byte(`{"properties":{"greeting":{"type":"string","description":"A simple greeting","example":"Hello, world!"}},"type":"object"}`),
65+
assertValidRequestSchema: assert.True,
66+
expectedErrorsCount: 0,
67+
},
4268
} {
4369
tc := tc
4470
t.Run(name, func(t *testing.T) {
@@ -51,3 +77,10 @@ properties:
5177
})
5278
}
5379
}
80+
81+
func postRequestWithBody(payload string) *http.Request {
82+
return &http.Request{
83+
Method: http.MethodPost,
84+
Body: io.NopCloser(strings.NewReader(payload)),
85+
}
86+
}

0 commit comments

Comments
 (0)