diff --git a/src/__tests__/fixtures/request-parameters-path-extra/pact.json b/src/__tests__/fixtures/request-parameters-path-extra/pact.json index 1fc56c3..9a208e7 100644 --- a/src/__tests__/fixtures/request-parameters-path-extra/pact.json +++ b/src/__tests__/fixtures/request-parameters-path-extra/pact.json @@ -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": { @@ -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 @@ -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 @@ -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": { diff --git a/src/__tests__/fixtures/request-parameters-path-extra/results.json b/src/__tests__/fixtures/request-parameters-path-extra/results.json index 84b319c..c0a84a1 100644 --- a/src/__tests__/fixtures/request-parameters-path-extra/results.json +++ b/src/__tests__/fixtures/request-parameters-path-extra/results.json @@ -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": { @@ -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": { @@ -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": { @@ -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": { @@ -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": { @@ -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": { diff --git a/src/compare/requestPath.ts b/src/compare/requestPath.ts index 9b7dcb7..6cdafd2 100644 --- a/src/compare/requestPath.ts +++ b/src/compare/requestPath.ts @@ -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",