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
88 changes: 86 additions & 2 deletions src/__tests__/fixtures/oas-references/baseline.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
"location": "[root].interactions[1]",
"value": {
"description": "should fail with missing parameters",
"providerState": "",
"request": {
"method": "POST",
"path": "/login",
Expand Down Expand Up @@ -51,7 +50,6 @@
"location": "[root].interactions[1]",
"value": {
"description": "should fail with missing parameters",
"providerState": "",
"request": {
"method": "POST",
"path": "/login",
Expand Down Expand Up @@ -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"
}
]
5 changes: 5 additions & 0 deletions src/__tests__/fixtures/oas-references/oas.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ paths:
responses:
"201":
$ref: "#/components/responses/Response.Body"
/wildcards/*:
get:
responses:
"200":
description: description

components:
parameters:
Expand Down
14 changes: 10 additions & 4 deletions src/__tests__/fixtures/oas-references/pact.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"interactions": [
{
"description": "should pass when json body matches spec",
"providerState": "",
"request": {
"method": "POST",
"path": "/login",
Expand All @@ -25,7 +24,6 @@
},
{
"description": "should fail with missing parameters",
"providerState": "",
"request": {
"method": "POST",
"path": "/login",
Expand All @@ -45,7 +43,6 @@
},
{
"description": "should fail with bad request body",
"providerState": "",
"request": {
"method": "POST",
"path": "/login",
Expand All @@ -64,7 +61,6 @@
},
{
"description": "should fail with bad response body",
"providerState": "",
"request": {
"method": "POST",
"path": "/login",
Expand All @@ -82,6 +78,16 @@
"username": "bob"
}
}
},
{
"description": "should error (but not crash) for wildcard routes",
"request": {
"method": "GET",
"path": "/wildcards/foo"
},
"response": {
"status": 200
}
}
]
}
16 changes: 16 additions & 0 deletions src/__tests__/fixtures/oas-references/results.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
]
25 changes: 15 additions & 10 deletions src/compare/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down