Skip to content

Commit 0129e53

Browse files
authored
fix: ignore 204 response headers (#37)
1 parent 3272eb7 commit 0129e53

File tree

5 files changed

+79
-14
lines changed

5 files changed

+79
-14
lines changed

src/__tests__/fixtures/response-header/baseline.json

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,55 @@
11
[
2+
{
3+
"code": "response.header.undefined",
4+
"message": "Standard http response header is not defined in the spec file: content-length",
5+
"mockDetails": {
6+
"interactionDescription": "should pass with 204 status, ignoring content-length and content-type",
7+
"interactionState": "[none]",
8+
"location": "[root].interactions[2].response.headers.content-length",
9+
"value": "0"
10+
},
11+
"specDetails": {
12+
"location": "[root].paths./delete.delete.responses.204",
13+
"pathMethod": "delete",
14+
"pathName": "/delete",
15+
"value": {
16+
"description": "OK",
17+
"content": {}
18+
}
19+
},
20+
"type": "warning"
21+
},
22+
{
23+
"code": "response.content-type.unknown",
24+
"message": "Response Content-Type header is defined but the spec does not specify any mime-types to produce",
25+
"mockDetails": {
26+
"interactionDescription": "should pass with 204 status, ignoring content-length and content-type",
27+
"interactionState": "[none]",
28+
"location": "[root].interactions[2].response.headers.content-type",
29+
"value": "text/plain"
30+
},
31+
"specDetails": {
32+
"location": "[root].paths./delete.delete",
33+
"pathMethod": "delete",
34+
"pathName": "/delete",
35+
"value": {
36+
"responses": {
37+
"204": {
38+
"description": "OK",
39+
"content": {}
40+
}
41+
}
42+
}
43+
},
44+
"type": "warning"
45+
},
246
{
347
"code": "response.header.undefined",
448
"message": "Standard http response header is not defined in the spec file: age",
549
"mockDetails": {
650
"interactionDescription": "should warn about missing standard response headers",
751
"interactionState": "[none]",
8-
"location": "[root].interactions[2].response.headers.age",
52+
"location": "[root].interactions[3].response.headers.age",
953
"value": "60"
1054
},
1155
"specDetails": {
@@ -41,7 +85,7 @@
4185
"mockDetails": {
4286
"interactionDescription": "should error on incompatible response headers",
4387
"interactionState": "[none]",
44-
"location": "[root].interactions[3].response.headers.specified",
88+
"location": "[root].interactions[4].response.headers.specified",
4589
"value": "abc"
4690
},
4791
"specDetails": {
@@ -62,7 +106,7 @@
62106
"mockDetails": {
63107
"interactionDescription": "should error on unspecified response headers",
64108
"interactionState": "[none]",
65-
"location": "[root].interactions[4].response.headers.unspecified",
109+
"location": "[root].interactions[5].response.headers.unspecified",
66110
"value": "foo"
67111
},
68112
"specDetails": {
@@ -98,7 +142,7 @@
98142
"mockDetails": {
99143
"interactionDescription": "should error on unknown response content type",
100144
"interactionState": "[none]",
101-
"location": "[root].interactions[5].response.headers.Content-Type",
145+
"location": "[root].interactions[6].response.headers.Content-Type",
102146
"value": "text/html"
103147
},
104148
"specDetails": {

src/__tests__/fixtures/response-header/oas.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,9 @@ paths:
2626
content:
2727
application/json:
2828
schema: {}
29+
/delete:
30+
delete:
31+
responses:
32+
"204":
33+
description: OK
34+
content: {}

src/__tests__/fixtures/response-header/pact.json

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
"interactions": [
55
{
66
"description": "should pass with successful headers",
7-
"providerState": "",
87
"request": {
98
"method": "GET",
109
"path": "/path"
@@ -18,7 +17,6 @@
1817
},
1918
{
2019
"description": "should pass about specified standard http response header",
21-
"providerState": "",
2220
"request": {
2321
"method": "GET",
2422
"path": "/path"
@@ -31,9 +29,22 @@
3129
}
3230
}
3331
},
32+
{
33+
"description": "should pass with 204 status, ignoring content-length and content-type",
34+
"request": {
35+
"method": "DELETE",
36+
"path": "/delete"
37+
},
38+
"response": {
39+
"status": 204,
40+
"headers": {
41+
"content-length": "0",
42+
"content-type": "text/plain"
43+
}
44+
}
45+
},
3446
{
3547
"description": "should warn about missing standard response headers",
36-
"providerState": "",
3748
"request": {
3849
"method": "GET",
3950
"path": "/path"
@@ -48,7 +59,6 @@
4859
},
4960
{
5061
"description": "should error on incompatible response headers",
51-
"providerState": "",
5262
"request": {
5363
"method": "GET",
5464
"path": "/path"
@@ -63,7 +73,6 @@
6373
},
6474
{
6575
"description": "should error on unspecified response headers",
66-
"providerState": "",
6776
"request": {
6877
"method": "GET",
6978
"path": "/path"
@@ -78,7 +87,6 @@
7887
},
7988
{
8089
"description": "should error on unknown response content type",
81-
"providerState": "",
8290
"request": {
8391
"method": "GET",
8492
"path": "/different-response-types"

src/__tests__/fixtures/response-header/results.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"mockDetails": {
66
"interactionDescription": "should warn about missing standard response headers",
77
"interactionState": "[none]",
8-
"location": "[root].interactions[2].response.headers.age"
8+
"location": "[root].interactions[3].response.headers.age"
99
},
1010
"specDetails": {
1111
"location": "[root].paths./path.get",
@@ -44,7 +44,7 @@
4444
"mockDetails": {
4545
"interactionDescription": "should error on incompatible response headers",
4646
"interactionState": "[none]",
47-
"location": "[root].interactions[3].response.headers.specified",
47+
"location": "[root].interactions[4].response.headers.specified",
4848
"value": "abc"
4949
},
5050
"specDetails": {
@@ -61,7 +61,7 @@
6161
"mockDetails": {
6262
"interactionDescription": "should error on unspecified response headers",
6363
"interactionState": "[none]",
64-
"location": "[root].interactions[4].response.headers.unspecified",
64+
"location": "[root].interactions[5].response.headers.unspecified",
6565
"value": "foo"
6666
},
6767
"specDetails": {
@@ -89,7 +89,7 @@
8989
"mockDetails": {
9090
"interactionDescription": "should error on unknown response content type",
9191
"interactionState": "[none]",
92-
"location": "[root].interactions[5].response.headers.content-type",
92+
"location": "[root].interactions[6].response.headers.content-type",
9393
"value": "text/html"
9494
},
9595
"specDetails": {

src/compare/responseHeader.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,13 @@ export function* compareResHeader(
4747
interaction.response.headers as Record<string, string>,
4848
);
4949

50+
// no content response
51+
// -------------------
52+
if (interaction.response.status === 204) {
53+
responseHeaders.delete("content-length");
54+
responseHeaders.delete("content-type");
55+
}
56+
5057
// response content-type
5158
// ---------------------
5259
const responseContentType =

0 commit comments

Comments
 (0)