diff --git a/src/__tests__/fixtures/oas-references/baseline.json b/src/__tests__/fixtures/oas-references/baseline.json index f7729d4..b6aae13 100644 --- a/src/__tests__/fixtures/oas-references/baseline.json +++ b/src/__tests__/fixtures/oas-references/baseline.json @@ -8,7 +8,6 @@ "location": "[root].interactions[1]", "value": { "description": "should fail with missing parameters", - "providerState": "", "request": { "method": "POST", "path": "/login", @@ -51,7 +50,6 @@ "location": "[root].interactions[1]", "value": { "description": "should fail with missing parameters", - "providerState": "", "request": { "method": "POST", "path": "/login", @@ -122,5 +120,91 @@ "value": false }, "type": "error" + }, + { + "code": "request.path-or-method.unknown", + "message": "Path or method not defined in spec file: GET /wildcards/foo", + "mockDetails": { + "interactionDescription": "should error (but not crash) for wildcard routes", + "interactionState": "[none]", + "location": "[root].interactions[4].request.path", + "value": "/wildcards/foo" + }, + "specDetails": { + "location": "[root].paths", + "pathMethod": null, + "pathName": null, + "value": { + "/login": { + "post": { + "parameters": [ + { + "in": "query", + "name": "account", + "required": true, + "schema": { + "type": "string" + } + }, + { + "in": "query", + "name": "nested", + "required": true, + "schema": { + "type": "string" + } + } + ], + "requestBody": { + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "username": { + "type": "string" + } + }, + "required": [ + "username" + ] + } + } + } + }, + "responses": { + "201": { + "description": "Response body", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "id": { + "type": "string" + } + }, + "required": [ + "id" + ] + } + } + } + } + } + } + }, + "/wildcards/*": { + "get": { + "responses": { + "200": { + "description": "description" + } + } + } + } + } + }, + "type": "error" } ] \ No newline at end of file diff --git a/src/__tests__/fixtures/oas-references/oas.yaml b/src/__tests__/fixtures/oas-references/oas.yaml index b890121..9eec5cd 100644 --- a/src/__tests__/fixtures/oas-references/oas.yaml +++ b/src/__tests__/fixtures/oas-references/oas.yaml @@ -14,6 +14,11 @@ paths: responses: "201": $ref: "#/components/responses/Response.Body" + /wildcards/*: + get: + responses: + "200": + description: description components: parameters: diff --git a/src/__tests__/fixtures/oas-references/pact.json b/src/__tests__/fixtures/oas-references/pact.json index 1992eab..16cb884 100644 --- a/src/__tests__/fixtures/oas-references/pact.json +++ b/src/__tests__/fixtures/oas-references/pact.json @@ -4,7 +4,6 @@ "interactions": [ { "description": "should pass when json body matches spec", - "providerState": "", "request": { "method": "POST", "path": "/login", @@ -25,7 +24,6 @@ }, { "description": "should fail with missing parameters", - "providerState": "", "request": { "method": "POST", "path": "/login", @@ -45,7 +43,6 @@ }, { "description": "should fail with bad request body", - "providerState": "", "request": { "method": "POST", "path": "/login", @@ -64,7 +61,6 @@ }, { "description": "should fail with bad response body", - "providerState": "", "request": { "method": "POST", "path": "/login", @@ -82,6 +78,16 @@ "username": "bob" } } + }, + { + "description": "should error (but not crash) for wildcard routes", + "request": { + "method": "GET", + "path": "/wildcards/foo" + }, + "response": { + "status": 200 + } } ] } diff --git a/src/__tests__/fixtures/oas-references/results.json b/src/__tests__/fixtures/oas-references/results.json index a7adff2..4f2289a 100644 --- a/src/__tests__/fixtures/oas-references/results.json +++ b/src/__tests__/fixtures/oas-references/results.json @@ -68,5 +68,21 @@ "value": false }, "type": "error" + }, + { + "code": "request.path-or-method.unknown", + "message": "Path or method not defined in spec file: GET /wildcards/foo", + "mockDetails": { + "interactionDescription": "should error (but not crash) for wildcard routes", + "interactionState": "[none]", + "location": "[root].interactions[4].request.path", + "value": "/wildcards/foo" + }, + "specDetails": { + "location": "[root].paths", + "pathMethod": null, + "pathName": null + }, + "type": "error" } ] \ No newline at end of file diff --git a/src/compare/setup.ts b/src/compare/setup.ts index 78ba840..3edd547 100644 --- a/src/compare/setup.ts +++ b/src/compare/setup.ts @@ -59,16 +59,21 @@ export function setupRouter( operation.parameters = parameters; } operation.security ||= oas.security; - router.on(method.toUpperCase() as HTTPMethod, path, () => {}, { - method, - oas, - operation, - path: oasPath, - securitySchemes: - (oas as OpenAPIV2.Document).securityDefinitions || - (oas as OpenAPIV3.Document).components?.securitySchemes || - {}, - }); + router.on( + method.toUpperCase() as HTTPMethod, + path.replaceAll(/\*+/g, "{:wildcard}"), + () => {}, + { + method, + oas, + operation, + path: oasPath, + securitySchemes: + (oas as OpenAPIV2.Document).securityDefinitions || + (oas as OpenAPIV3.Document).components?.securitySchemes || + {}, + }, + ); } } return router;