Skip to content

Commit a43fce0

Browse files
committed
fix: don't parse path parameters of type string
1 parent 992d03c commit a43fce0

File tree

5 files changed

+156
-18
lines changed

5 files changed

+156
-18
lines changed

src/__tests__/fixtures/request-parameters-path/oas.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,17 @@ info:
33
title: path parameters
44
version: 1.0.0
55
paths:
6+
/string/{id}:
7+
get:
8+
parameters:
9+
- in: path
10+
name: id
11+
required: true
12+
schema:
13+
type: string
14+
responses:
15+
"200":
16+
description: description
617
/integer/{id}:
718
get:
819
parameters:

src/__tests__/fixtures/request-parameters-path/opc-results.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"mockDetails": {
66
"interactionDescription": "should error with missing parameter",
77
"interactionState": "[none]",
8-
"location": "[root].interactions[6].request.path",
8+
"location": "[root].interactions[7].request.path",
99
"value": "/integer/"
1010
},
1111
"specDetails": {
@@ -38,7 +38,7 @@
3838
"mockDetails": {
3939
"interactionDescription": "should error when path does not match integer spec",
4040
"interactionState": "[none]",
41-
"location": "[root].interactions[7].request.path",
41+
"location": "[root].interactions[8].request.path",
4242
"value": "/integer/abc"
4343
},
4444
"specDetails": {
@@ -71,7 +71,7 @@
7171
"mockDetails": {
7272
"interactionDescription": "should error when path does not match boolean spec",
7373
"interactionState": "[none]",
74-
"location": "[root].interactions[8].request.path",
74+
"location": "[root].interactions[9].request.path",
7575
"value": "/boolean/abc"
7676
},
7777
"specDetails": {
@@ -104,7 +104,7 @@
104104
"mockDetails": {
105105
"interactionDescription": "should error when path does not match object spec",
106106
"interactionState": "[none]",
107-
"location": "[root].interactions[9].request.path",
107+
"location": "[root].interactions[10].request.path",
108108
"value": "/exploded-object/string=abc,number=abc"
109109
},
110110
"specDetails": {
@@ -147,7 +147,7 @@
147147
"mockDetails": {
148148
"interactionDescription": "should error when path does not match object spec",
149149
"interactionState": "[none]",
150-
"location": "[root].interactions[10].request.path",
150+
"location": "[root].interactions[11].request.path",
151151
"value": "/exploded-object/string=abc,number=abc"
152152
},
153153
"specDetails": {
@@ -190,7 +190,7 @@
190190
"mockDetails": {
191191
"interactionDescription": "should error when path and method does not exist in spec",
192192
"interactionState": "[none]",
193-
"location": "[root].interactions[11].request.path",
193+
"location": "[root].interactions[12].request.path",
194194
"value": "/does-not-exist"
195195
},
196196
"specDetails": {
@@ -206,7 +206,7 @@
206206
"mockDetails": {
207207
"interactionDescription": "should error when path does not exist in spec",
208208
"interactionState": "[none]",
209-
"location": "[root].interactions[12].request.path",
209+
"location": "[root].interactions[13].request.path",
210210
"value": "/integer/1"
211211
},
212212
"specDetails": {
@@ -222,7 +222,7 @@
222222
"mockDetails": {
223223
"interactionDescription": "should not raise subsequent errors when request.path-or-method.unknown",
224224
"interactionState": "[none]",
225-
"location": "[root].interactions[13].request.path",
225+
"location": "[root].interactions[14].request.path",
226226
"value": "/integer/1"
227227
},
228228
"specDetails": {

src/__tests__/fixtures/request-parameters-path/pact.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,16 @@
22
"consumer": { "name": "consumer" },
33
"provider": { "name": "provider" },
44
"interactions": [
5+
{
6+
"description": "should pass when path matches string spec",
7+
"request": {
8+
"method": "GET",
9+
"path": "/string/a,b,c"
10+
},
11+
"response": {
12+
"status": 200
13+
}
14+
},
515
{
616
"description": "should pass when path matches integer spec",
717
"request": {

src/__tests__/fixtures/request-parameters-path/smv-results.json

Lines changed: 121 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"mockDetails": {
66
"interactionDescription": "should pass for path with trailing slash",
77
"interactionState": "[none]",
8-
"location": "[root].interactions[5].response.body",
8+
"location": "[root].interactions[6].response.body",
99
"value": {
1010
"number": 123
1111
}
@@ -24,14 +24,33 @@
2424
"mockDetails": {
2525
"interactionDescription": "should error with missing parameter",
2626
"interactionState": "[none]",
27-
"location": "[root].interactions[6].request.path",
27+
"location": "[root].interactions[7].request.path",
2828
"value": "/integer/"
2929
},
3030
"specDetails": {
3131
"location": "[root].paths",
3232
"pathMethod": null,
3333
"pathName": null,
3434
"value": {
35+
"/string/{id}": {
36+
"get": {
37+
"parameters": [
38+
{
39+
"in": "path",
40+
"name": "id",
41+
"required": true,
42+
"schema": {
43+
"type": "string"
44+
}
45+
}
46+
],
47+
"responses": {
48+
"200": {
49+
"description": "description"
50+
}
51+
}
52+
}
53+
},
3554
"/integer/{id}": {
3655
"get": {
3756
"parameters": [
@@ -151,14 +170,33 @@
151170
"mockDetails": {
152171
"interactionDescription": "should error when path does not match integer spec",
153172
"interactionState": "[none]",
154-
"location": "[root].interactions[7].request.path",
173+
"location": "[root].interactions[8].request.path",
155174
"value": "/integer/abc"
156175
},
157176
"specDetails": {
158177
"location": "[root].paths",
159178
"pathMethod": null,
160179
"pathName": null,
161180
"value": {
181+
"/string/{id}": {
182+
"get": {
183+
"parameters": [
184+
{
185+
"in": "path",
186+
"name": "id",
187+
"required": true,
188+
"schema": {
189+
"type": "string"
190+
}
191+
}
192+
],
193+
"responses": {
194+
"200": {
195+
"description": "description"
196+
}
197+
}
198+
}
199+
},
162200
"/integer/{id}": {
163201
"get": {
164202
"parameters": [
@@ -278,14 +316,33 @@
278316
"mockDetails": {
279317
"interactionDescription": "should error when path does not match boolean spec",
280318
"interactionState": "[none]",
281-
"location": "[root].interactions[8].request.path",
319+
"location": "[root].interactions[9].request.path",
282320
"value": "/boolean/abc"
283321
},
284322
"specDetails": {
285323
"location": "[root].paths",
286324
"pathMethod": null,
287325
"pathName": null,
288326
"value": {
327+
"/string/{id}": {
328+
"get": {
329+
"parameters": [
330+
{
331+
"in": "path",
332+
"name": "id",
333+
"required": true,
334+
"schema": {
335+
"type": "string"
336+
}
337+
}
338+
],
339+
"responses": {
340+
"200": {
341+
"description": "description"
342+
}
343+
}
344+
}
345+
},
289346
"/integer/{id}": {
290347
"get": {
291348
"parameters": [
@@ -405,14 +462,33 @@
405462
"mockDetails": {
406463
"interactionDescription": "should error when path and method does not exist in spec",
407464
"interactionState": "[none]",
408-
"location": "[root].interactions[11].request.path",
465+
"location": "[root].interactions[12].request.path",
409466
"value": "/does-not-exist"
410467
},
411468
"specDetails": {
412469
"location": "[root].paths",
413470
"pathMethod": null,
414471
"pathName": null,
415472
"value": {
473+
"/string/{id}": {
474+
"get": {
475+
"parameters": [
476+
{
477+
"in": "path",
478+
"name": "id",
479+
"required": true,
480+
"schema": {
481+
"type": "string"
482+
}
483+
}
484+
],
485+
"responses": {
486+
"200": {
487+
"description": "description"
488+
}
489+
}
490+
}
491+
},
416492
"/integer/{id}": {
417493
"get": {
418494
"parameters": [
@@ -532,14 +608,33 @@
532608
"mockDetails": {
533609
"interactionDescription": "should error when path does not exist in spec",
534610
"interactionState": "[none]",
535-
"location": "[root].interactions[12].request.path",
611+
"location": "[root].interactions[13].request.path",
536612
"value": "/integer/1"
537613
},
538614
"specDetails": {
539615
"location": "[root].paths",
540616
"pathMethod": null,
541617
"pathName": null,
542618
"value": {
619+
"/string/{id}": {
620+
"get": {
621+
"parameters": [
622+
{
623+
"in": "path",
624+
"name": "id",
625+
"required": true,
626+
"schema": {
627+
"type": "string"
628+
}
629+
}
630+
],
631+
"responses": {
632+
"200": {
633+
"description": "description"
634+
}
635+
}
636+
}
637+
},
543638
"/integer/{id}": {
544639
"get": {
545640
"parameters": [
@@ -659,14 +754,33 @@
659754
"mockDetails": {
660755
"interactionDescription": "should not raise subsequent errors when request.path-or-method.unknown",
661756
"interactionState": "[none]",
662-
"location": "[root].interactions[13].request.path",
757+
"location": "[root].interactions[14].request.path",
663758
"value": "/integer/1"
664759
},
665760
"specDetails": {
666761
"location": "[root].paths",
667762
"pathMethod": null,
668763
"pathName": null,
669764
"value": {
765+
"/string/{id}": {
766+
"get": {
767+
"parameters": [
768+
{
769+
"in": "path",
770+
"name": "id",
771+
"required": true,
772+
"schema": {
773+
"type": "string"
774+
}
775+
}
776+
],
777+
"responses": {
778+
"200": {
779+
"description": "description"
780+
}
781+
}
782+
}
783+
},
670784
"/integer/{id}": {
671785
"get": {
672786
"parameters": [

src/compare/requestPath.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,12 @@ export function* compareReqPath(
3434
const schema: SchemaObject = dereferencedParameter.schema || {
3535
type: dereferencedParameter.type,
3636
};
37-
const value = parseValue(
38-
route.params[cleanPathParameter(dereferencedParameter.name)],
39-
);
37+
const value =
38+
schema?.type === "string"
39+
? route.params[cleanPathParameter(dereferencedParameter.name)]
40+
: parseValue(
41+
route.params[cleanPathParameter(dereferencedParameter.name)],
42+
);
4043

4144
// ignore when OAS has unused parameter in the operation parameters
4245
if (!(cleanPathParameter(dereferencedParameter.name) in route.params)) {

0 commit comments

Comments
 (0)