Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 62 additions & 2 deletions src/__tests__/fixtures/request-parameters-path-extra/pact.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@
"status": 200
}
},
{
"description": "should pass when path matches simple exploded spec, with only one item",
"request": {
"method": "GET",
"path": "/simple/explode-true/1"
},
"response": {
"status": 200
}
},
{
"description": "should pass when path matches simple non-exploded spec",
"request": {
Expand All @@ -22,11 +32,31 @@
"status": 200
}
},
{
"description": "should pass when path matches simple non-exploded spec, with only one item",
"request": {
"method": "GET",
"path": "/simple/explode-false/1"
},
"response": {
"status": 200
}
},
{
"description": "should pass when path matches label exploded spec",
"request": {
"method": "GET",
"path": "/label/explode-true/.1,2,3"
"path": "/label/explode-true/.1.2.3"
},
"response": {
"status": 200
}
},
{
"description": "should pass when path matches label exploded spec, with only one item",
"request": {
"method": "GET",
"path": "/label/explode-true/.1"
},
"response": {
"status": 200
Expand All @@ -42,11 +72,31 @@
"status": 200
}
},
{
"description": "should pass when path matches label non-exploded spec, with only one item",
"request": {
"method": "GET",
"path": "/label/explode-false/.1"
},
"response": {
"status": 200
}
},
{
"description": "should pass when path matches matrix exploded spec",
"request": {
"method": "GET",
"path": "/matrix/explode-true/;1,2,3"
"path": "/matrix/explode-true/;1;2;3"
},
"response": {
"status": 200
}
},
{
"description": "should pass when path matches matrix exploded spec, with only one item",
"request": {
"method": "GET",
"path": "/matrix/explode-true/;1"
},
"response": {
"status": 200
Expand All @@ -62,6 +112,16 @@
"status": 200
}
},
{
"description": "should pass when path matches matrix non-exploded spec, with only one item",
"request": {
"method": "GET",
"path": "/matrix/explode-false/;1"
},
"response": {
"status": 200
}
},
{
"description": "should error when path does not match simple exploded integer array spec",
"request": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"mockDetails": {
"interactionDescription": "should error when path does not match simple exploded integer array spec",
"interactionState": "[none]",
"location": "[root].interactions[6].request.path",
"location": "[root].interactions[12].request.path",
"value": "/simple/explode-true/1,2,abc"
},
"specDetails": {
Expand Down Expand Up @@ -44,7 +44,7 @@
"mockDetails": {
"interactionDescription": "should error when path does not match simple non-exploded integer array spec",
"interactionState": "[none]",
"location": "[root].interactions[7].request.path",
"location": "[root].interactions[13].request.path",
"value": "/simple/explode-false/1,2,abc"
},
"specDetails": {
Expand Down Expand Up @@ -83,7 +83,7 @@
"mockDetails": {
"interactionDescription": "should error when path does not match label exploded integer array spec",
"interactionState": "[none]",
"location": "[root].interactions[8].request.path",
"location": "[root].interactions[14].request.path",
"value": "/label/explode-true/1,2,abc"
},
"specDetails": {
Expand All @@ -99,7 +99,7 @@
"mockDetails": {
"interactionDescription": "should error when path does not match label non-exploded integer array spec",
"interactionState": "[none]",
"location": "[root].interactions[9].request.path",
"location": "[root].interactions[15].request.path",
"value": "/label/explode-false/1,2,abc"
},
"specDetails": {
Expand All @@ -115,7 +115,7 @@
"mockDetails": {
"interactionDescription": "should error when path does not match matrix exploded integer array spec",
"interactionState": "[none]",
"location": "[root].interactions[10].request.path",
"location": "[root].interactions[16].request.path",
"value": "/matrix/explode-true/1,2,abc"
},
"specDetails": {
Expand All @@ -131,7 +131,7 @@
"mockDetails": {
"interactionDescription": "should error when path does not match matrix non-exploded integer array spec",
"interactionState": "[none]",
"location": "[root].interactions[11].request.path",
"location": "[root].interactions[17].request.path",
"value": "/matrix/explode-false/1,2,abc"
},
"specDetails": {
Expand Down
16 changes: 15 additions & 1 deletion src/compare/requestPath.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,21 @@ export function* compareReqPath(
const validate = getValidateFunction(ajv, schemaId, () =>
minimumSchema(schema, oas),
);
if (!validate(value)) {

let separator = ",";
if (parameter.style?.toLowerCase() === "label" && parameter.explode) {
separator = ".";
}
if (parameter.style?.toLowerCase() === "matrix" && parameter.explode) {
separator = ";";
}
if (
!validate(
schema.type === "array" && typeof value === "string"
? value.split(separator)
: value,
)
) {
for (const _error of validate.errors!) {
yield {
code: "request.path-or-method.unknown",
Expand Down