Skip to content

Commit 3f5e025

Browse files
committed
fix: handle asterisk in path (which find-my-way treats as wildcards
1 parent c0831d0 commit 3f5e025

File tree

5 files changed

+132
-16
lines changed

5 files changed

+132
-16
lines changed

src/__tests__/fixtures/oas-references/baseline.json

Lines changed: 86 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
"location": "[root].interactions[1]",
99
"value": {
1010
"description": "should fail with missing parameters",
11-
"providerState": "",
1211
"request": {
1312
"method": "POST",
1413
"path": "/login",
@@ -51,7 +50,6 @@
5150
"location": "[root].interactions[1]",
5251
"value": {
5352
"description": "should fail with missing parameters",
54-
"providerState": "",
5553
"request": {
5654
"method": "POST",
5755
"path": "/login",
@@ -122,5 +120,91 @@
122120
"value": false
123121
},
124122
"type": "error"
123+
},
124+
{
125+
"code": "request.path-or-method.unknown",
126+
"message": "Path or method not defined in spec file: GET /wildcards/foo",
127+
"mockDetails": {
128+
"interactionDescription": "should error (but not crash) for wildcard routes",
129+
"interactionState": "[none]",
130+
"location": "[root].interactions[4].request.path",
131+
"value": "/wildcards/foo"
132+
},
133+
"specDetails": {
134+
"location": "[root].paths",
135+
"pathMethod": null,
136+
"pathName": null,
137+
"value": {
138+
"/login": {
139+
"post": {
140+
"parameters": [
141+
{
142+
"in": "query",
143+
"name": "account",
144+
"required": true,
145+
"schema": {
146+
"type": "string"
147+
}
148+
},
149+
{
150+
"in": "query",
151+
"name": "nested",
152+
"required": true,
153+
"schema": {
154+
"type": "string"
155+
}
156+
}
157+
],
158+
"requestBody": {
159+
"content": {
160+
"application/json": {
161+
"schema": {
162+
"type": "object",
163+
"properties": {
164+
"username": {
165+
"type": "string"
166+
}
167+
},
168+
"required": [
169+
"username"
170+
]
171+
}
172+
}
173+
}
174+
},
175+
"responses": {
176+
"201": {
177+
"description": "Response body",
178+
"content": {
179+
"application/json": {
180+
"schema": {
181+
"type": "object",
182+
"properties": {
183+
"id": {
184+
"type": "string"
185+
}
186+
},
187+
"required": [
188+
"id"
189+
]
190+
}
191+
}
192+
}
193+
}
194+
}
195+
}
196+
},
197+
"/wildcards/*": {
198+
"get": {
199+
"responses": {
200+
"200": {
201+
"description": "description"
202+
}
203+
}
204+
}
205+
}
206+
}
207+
},
208+
"type": "error"
125209
}
126210
]

src/__tests__/fixtures/oas-references/oas.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ paths:
1414
responses:
1515
"201":
1616
$ref: "#/components/responses/Response.Body"
17+
/wildcards/*:
18+
get:
19+
responses:
20+
"200":
21+
description: description
1722

1823
components:
1924
parameters:

src/__tests__/fixtures/oas-references/pact.json

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
"interactions": [
55
{
66
"description": "should pass when json body matches spec",
7-
"providerState": "",
87
"request": {
98
"method": "POST",
109
"path": "/login",
@@ -25,7 +24,6 @@
2524
},
2625
{
2726
"description": "should fail with missing parameters",
28-
"providerState": "",
2927
"request": {
3028
"method": "POST",
3129
"path": "/login",
@@ -45,7 +43,6 @@
4543
},
4644
{
4745
"description": "should fail with bad request body",
48-
"providerState": "",
4946
"request": {
5047
"method": "POST",
5148
"path": "/login",
@@ -64,7 +61,6 @@
6461
},
6562
{
6663
"description": "should fail with bad response body",
67-
"providerState": "",
6864
"request": {
6965
"method": "POST",
7066
"path": "/login",
@@ -82,6 +78,16 @@
8278
"username": "bob"
8379
}
8480
}
81+
},
82+
{
83+
"description": "should error (but not crash) for wildcard routes",
84+
"request": {
85+
"method": "GET",
86+
"path": "/wildcards/foo"
87+
},
88+
"response": {
89+
"status": 200
90+
}
8591
}
8692
]
8793
}

src/__tests__/fixtures/oas-references/results.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,5 +68,21 @@
6868
"value": false
6969
},
7070
"type": "error"
71+
},
72+
{
73+
"code": "request.path-or-method.unknown",
74+
"message": "Path or method not defined in spec file: GET /wildcards/foo",
75+
"mockDetails": {
76+
"interactionDescription": "should error (but not crash) for wildcard routes",
77+
"interactionState": "[none]",
78+
"location": "[root].interactions[4].request.path",
79+
"value": "/wildcards/foo"
80+
},
81+
"specDetails": {
82+
"location": "[root].paths",
83+
"pathMethod": null,
84+
"pathName": null
85+
},
86+
"type": "error"
7187
}
7288
]

src/compare/setup.ts

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,16 +59,21 @@ export function setupRouter(
5959
operation.parameters = parameters;
6060
}
6161
operation.security ||= oas.security;
62-
router.on(method.toUpperCase() as HTTPMethod, path, () => {}, {
63-
method,
64-
oas,
65-
operation,
66-
path: oasPath,
67-
securitySchemes:
68-
(oas as OpenAPIV2.Document).securityDefinitions ||
69-
(oas as OpenAPIV3.Document).components?.securitySchemes ||
70-
{},
71-
});
62+
router.on(
63+
method.toUpperCase() as HTTPMethod,
64+
path.replaceAll(/\*+/g, "{:wildcard}"),
65+
() => {},
66+
{
67+
method,
68+
oas,
69+
operation,
70+
path: oasPath,
71+
securitySchemes:
72+
(oas as OpenAPIV2.Document).securityDefinitions ||
73+
(oas as OpenAPIV3.Document).components?.securitySchemes ||
74+
{},
75+
},
76+
);
7277
}
7378
}
7479
return router;

0 commit comments

Comments
 (0)