Skip to content

Commit df6a773

Browse files
authored
fix: tweak behaviour for request body for consistency with SMV (#19)
1 parent 0cf2abe commit df6a773

File tree

15 files changed

+442
-98
lines changed

15 files changed

+442
-98
lines changed

src/__tests__/fixtures/request-body-swagger2/baseline.json

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,43 @@
11
[
2+
{
3+
"code": "request.content-type.missing",
4+
"message": "Request content type header is not defined but spec specifies mime-types to consume",
5+
"mockDetails": {
6+
"interactionDescription": "should pass for 4xx responses even with missing content types",
7+
"interactionState": "[none]",
8+
"location": "[root].interactions[4]",
9+
"value": {
10+
"description": "should pass for 4xx responses even with missing content types",
11+
"request": {
12+
"method": "POST",
13+
"path": "/login",
14+
"body": "bad=request"
15+
},
16+
"response": {
17+
"status": 400,
18+
"body": {}
19+
}
20+
}
21+
},
22+
"specDetails": {
23+
"location": "[root].paths./login.post.consumes",
24+
"pathMethod": "post",
25+
"pathName": "/login",
26+
"value": [
27+
"application/json",
28+
"application/x-www-form-urlencoded",
29+
"multipart/form-data"
30+
]
31+
},
32+
"type": "warning"
33+
},
234
{
335
"code": "request.body.incompatible",
436
"message": "Request body is incompatible with the request body schema in the spec file: must be object",
537
"mockDetails": {
638
"interactionDescription": "should error on empty body",
739
"interactionState": "[none]",
8-
"location": "[root].interactions[4].request.body",
40+
"location": "[root].interactions[6].request.body",
941
"value": ""
1042
},
1143
"specDetails": {
@@ -22,7 +54,7 @@
2254
"mockDetails": {
2355
"interactionDescription": "should error on schema mismatch for json body",
2456
"interactionState": "[none]",
25-
"location": "[root].interactions[5].request.body",
57+
"location": "[root].interactions[7].request.body",
2658
"value": {
2759
"email": "[email protected]"
2860
}
@@ -44,7 +76,7 @@
4476
"mockDetails": {
4577
"interactionDescription": "should error on schema mismatch for form body",
4678
"interactionState": "[none]",
47-
"location": "[root].interactions[6].request.body",
79+
"location": "[root].interactions[8].request.body",
4880
"value": "[email protected]"
4981
},
5082
"specDetails": {

src/__tests__/fixtures/request-body-swagger2/oas.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@ paths:
1818
responses:
1919
"201":
2020
description: OK
21+
schema: {}
2122
"400":
2223
description: Bad Request
24+
schema: {}
2325

2426
definitions:
2527
request:

src/__tests__/fixtures/request-body-swagger2/pact.json

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
"interactions": [
55
{
66
"description": "should pass when json body matches spec",
7-
"providerState": "",
87
"request": {
98
"method": "POST",
109
"path": "/login",
@@ -22,7 +21,6 @@
2221
},
2322
{
2423
"description": "should pass when form body matches spec",
25-
"providerState": "",
2624
"request": {
2725
"method": "POST",
2826
"path": "/login",
@@ -66,9 +64,34 @@
6664
"status": 400
6765
}
6866
},
67+
{
68+
"description": "should pass for 4xx responses even with missing content types",
69+
"request": {
70+
"method": "POST",
71+
"path": "/login",
72+
"body": "bad=request"
73+
},
74+
"response": {
75+
"status": 400,
76+
"body": {}
77+
}
78+
},
79+
{
80+
"description": "should error with missing body",
81+
"request": {
82+
"method": "POST",
83+
"path": "/login",
84+
"headers": {
85+
"Content-Type": "application/json"
86+
}
87+
},
88+
"response": {
89+
"status": 201,
90+
"body": {}
91+
}
92+
},
6993
{
7094
"description": "should error on empty body",
71-
"providerState": "",
7295
"request": {
7396
"method": "POST",
7497
"path": "/login",
@@ -83,7 +106,6 @@
83106
},
84107
{
85108
"description": "should error on schema mismatch for json body",
86-
"providerState": "",
87109
"request": {
88110
"method": "POST",
89111
"path": "/login",
@@ -100,7 +122,6 @@
100122
},
101123
{
102124
"description": "should error on schema mismatch for form body",
103-
"providerState": "",
104125
"request": {
105126
"method": "POST",
106127
"path": "/login",

src/__tests__/fixtures/request-body-swagger2/results.json

Lines changed: 61 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,69 @@
11
[
2+
{
3+
"code": "request.content-type.missing",
4+
"message": "Request content type header is not defined but spec specifies mime-types to consume",
5+
"mockDetails": {
6+
"interactionDescription": "should pass for 4xx responses even with missing content types",
7+
"interactionState": "[none]",
8+
"location": "[root].interactions[4].request.headers.content-type",
9+
"value": null
10+
},
11+
"specDetails": {
12+
"location": "[root].paths./login.post",
13+
"pathMethod": "post",
14+
"pathName": "/login",
15+
"value": {
16+
"consumes": [
17+
"application/json",
18+
"application/x-www-form-urlencoded",
19+
"multipart/form-data"
20+
],
21+
"parameters": [
22+
{
23+
"in": "body",
24+
"name": "ignored",
25+
"schema": {
26+
"$ref": "#/definitions/request"
27+
}
28+
}
29+
],
30+
"responses": {
31+
"201": {
32+
"description": "OK",
33+
"schema": {}
34+
},
35+
"400": {
36+
"description": "Bad Request",
37+
"schema": {}
38+
}
39+
}
40+
}
41+
},
42+
"type": "warning"
43+
},
44+
{
45+
"code": "request.body.incompatible",
46+
"message": "Request body is incompatible with the request body schema in the spec file: must be object",
47+
"mockDetails": {
48+
"interactionDescription": "should error with missing body",
49+
"interactionState": "[none]",
50+
"location": "[root].interactions[5].request.body."
51+
},
52+
"specDetails": {
53+
"location": "[root].paths./login.post.requestBody.content.application/json.schema.definitions.request.type",
54+
"pathMethod": "post",
55+
"pathName": "/login",
56+
"value": "object"
57+
},
58+
"type": "error"
59+
},
260
{
361
"code": "request.body.incompatible",
462
"message": "Request body is incompatible with the request body schema in the spec file: must be object",
563
"mockDetails": {
664
"interactionDescription": "should error on empty body",
765
"interactionState": "[none]",
8-
"location": "[root].interactions[4].request.body.",
66+
"location": "[root].interactions[6].request.body.",
967
"value": ""
1068
},
1169
"specDetails": {
@@ -22,7 +80,7 @@
2280
"mockDetails": {
2381
"interactionDescription": "should error on schema mismatch for json body",
2482
"interactionState": "[none]",
25-
"location": "[root].interactions[5].request.body.",
83+
"location": "[root].interactions[7].request.body.",
2684
"value": {
2785
"email": "[email protected]"
2886
}
@@ -44,7 +102,7 @@
44102
"mockDetails": {
45103
"interactionDescription": "should error on schema mismatch for form body",
46104
"interactionState": "[none]",
47-
"location": "[root].interactions[6].request.body.",
105+
"location": "[root].interactions[8].request.body.",
48106
"value": {
49107
"email": "[email protected]"
50108
}

src/__tests__/fixtures/request-body/baseline.json

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,43 @@
11
[
2+
{
3+
"code": "request.content-type.missing",
4+
"message": "Request content type header is not defined but spec specifies mime-types to consume",
5+
"mockDetails": {
6+
"interactionDescription": "should pass for 4xx responses even with missing content types",
7+
"interactionState": "[none]",
8+
"location": "[root].interactions[4]",
9+
"value": {
10+
"description": "should pass for 4xx responses even with missing content types",
11+
"request": {
12+
"method": "POST",
13+
"path": "/login",
14+
"body": "bad=request"
15+
},
16+
"response": {
17+
"status": 400,
18+
"body": {}
19+
}
20+
}
21+
},
22+
"specDetails": {
23+
"location": "[root].paths./login.post.requestBody.content",
24+
"pathMethod": "post",
25+
"pathName": "/login",
26+
"value": [
27+
"application/json",
28+
"application/x-www-form-urlencoded",
29+
"multipart/form-data"
30+
]
31+
},
32+
"type": "warning"
33+
},
234
{
335
"code": "request.body.incompatible",
436
"message": "Request body is incompatible with the request body schema in the spec file: must be object",
537
"mockDetails": {
6-
"interactionDescription": "should pass when json body matches spec",
38+
"interactionDescription": "should error with missing body",
739
"interactionState": "[none]",
8-
"location": "[root].interactions[0].request.body"
40+
"location": "[root].interactions[5].request.body"
941
},
1042
"specDetails": {
1143
"location": "[root].paths./login.post.requestBody.content.application/json.schema.type",
@@ -21,7 +53,7 @@
2153
"mockDetails": {
2254
"interactionDescription": "should error on empty body",
2355
"interactionState": "[none]",
24-
"location": "[root].interactions[5].request.body",
56+
"location": "[root].interactions[6].request.body",
2557
"value": ""
2658
},
2759
"specDetails": {
@@ -38,7 +70,7 @@
3870
"mockDetails": {
3971
"interactionDescription": "should error on schema mismatch for json body",
4072
"interactionState": "[none]",
41-
"location": "[root].interactions[6].request.body",
73+
"location": "[root].interactions[7].request.body",
4274
"value": {
4375
"email": "[email protected]"
4476
}
@@ -60,7 +92,7 @@
6092
"mockDetails": {
6193
"interactionDescription": "should error on schema mismatch for form body",
6294
"interactionState": "[none]",
63-
"location": "[root].interactions[7].request.body",
95+
"location": "[root].interactions[8].request.body",
6496
"value": "[email protected]"
6597
},
6698
"specDetails": {

src/__tests__/fixtures/request-body/pact.json

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,6 @@
44
"interactions": [
55
{
66
"description": "should pass when json body matches spec",
7-
"providerState": "",
8-
"request": {
9-
"method": "POST",
10-
"path": "/login"
11-
},
12-
"response": {
13-
"status": 201,
14-
"body": {}
15-
}
16-
},
17-
{
18-
"description": "should pass when json body matches spec",
19-
"providerState": "",
207
"request": {
218
"method": "POST",
229
"path": "/login",
@@ -35,7 +22,6 @@
3522
},
3623
{
3724
"description": "should pass when form body matches spec",
38-
"providerState": "",
3925
"request": {
4026
"method": "POST",
4127
"path": "/login",
@@ -83,14 +69,36 @@
8369
}
8470
},
8571
{
86-
"description": "should error on empty body",
87-
"providerState": "",
72+
"description": "should pass for 4xx responses even with missing content types",
73+
"request": {
74+
"method": "POST",
75+
"path": "/login",
76+
"body": "bad=request"
77+
},
78+
"response": {
79+
"status": 400,
80+
"body": {}
81+
}
82+
},
83+
{
84+
"description": "should error with missing body",
8885
"request": {
8986
"method": "POST",
9087
"path": "/login",
9188
"headers": {
9289
"Content-Type": "application/json"
93-
},
90+
}
91+
},
92+
"response": {
93+
"status": 201,
94+
"body": {}
95+
}
96+
},
97+
{
98+
"description": "should error on empty body",
99+
"request": {
100+
"method": "POST",
101+
"path": "/login",
94102
"body": ""
95103
},
96104
"response": {
@@ -100,7 +108,6 @@
100108
},
101109
{
102110
"description": "should error on schema mismatch for json body",
103-
"providerState": "",
104111
"request": {
105112
"method": "POST",
106113
"path": "/login",
@@ -118,7 +125,6 @@
118125
},
119126
{
120127
"description": "should error on schema mismatch for form body",
121-
"providerState": "",
122128
"request": {
123129
"method": "POST",
124130
"path": "/login",

0 commit comments

Comments
 (0)