Skip to content

Commit 3eebc33

Browse files
committed
fix: response content-type matching should be per-status code
1 parent 4ddee81 commit 3eebc33

File tree

5 files changed

+9
-15
lines changed

5 files changed

+9
-15
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@
140140
"code": "response.content-type.incompatible",
141141
"message": "Response Content-Type header is incompatible with the mime-types the spec defines to produce",
142142
"mockDetails": {
143-
"interactionDescription": "should error on unknown response content type",
143+
"interactionDescription": "should error on unknown response content type, per status code",
144144
"interactionState": "[none]",
145145
"location": "[root].interactions[6].response.headers.Content-Type",
146146
"value": "text/html"

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ paths:
2626
content:
2727
application/json:
2828
schema: {}
29+
"201":
30+
description: OK
31+
content:
32+
text/html:
33+
schema: {}
2934
/delete:
3035
delete:
3136
responses:

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@
8686
}
8787
},
8888
{
89-
"description": "should error on unknown response content type",
89+
"description": "should error on unknown response content type, per status code",
9090
"request": {
9191
"method": "GET",
9292
"path": "/different-response-types"

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@
8787
"code": "response.content-type.incompatible",
8888
"message": "Response Content-Type header is incompatible with the mime-types the spec defines to produce",
8989
"mockDetails": {
90-
"interactionDescription": "should error on unknown response content type",
90+
"interactionDescription": "should error on unknown response content type, per status code",
9191
"interactionState": "[none]",
9292
"location": "[root].interactions[6].response.headers.content-type",
9393
"value": "text/html"

src/compare/responseHeader.ts

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,6 @@ export function* compareResHeader(
2424
): Iterable<Result> {
2525
const { method, oas, operation, path } = route.store;
2626

27-
const allAvailableResponseContentTypes =
28-
operation.produces ||
29-
Object.entries(operation.responses).reduce(
30-
(acc: string[], [_status, response]) => {
31-
return [
32-
...acc,
33-
...Object.keys(dereferenceOas(response || {}, oas)?.content || {}),
34-
];
35-
},
36-
[],
37-
);
3827
const availableResponseContentType =
3928
operation.produces ||
4029
Object.keys(
@@ -59,7 +48,7 @@ export function* compareResHeader(
5948
const responseContentType =
6049
responseHeaders.get("content-type")?.split(";")[0] || "";
6150

62-
if (responseContentType && !allAvailableResponseContentTypes.length) {
51+
if (responseContentType && !availableResponseContentType.length) {
6352
yield {
6453
code: "response.content-type.unknown",
6554
message:

0 commit comments

Comments
 (0)