Skip to content
This repository was archived by the owner on Dec 27, 2024. It is now read-only.

Commit ea1671e

Browse files
committed
feat: support hyphen character in path variables #65
Close #65
1 parent a4e8af4 commit ea1671e

3 files changed

Lines changed: 42 additions & 4 deletions

File tree

lib/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ function mapParameters (type) {
162162
}
163163

164164
function extractPathParameters (path, paramsMeta) {
165-
const matched = path.match(/{\s*[\w]+\s*}/g) || []
165+
const matched = path.match(/{\s*[\w-]+\s*}/g) || []
166166
return matched.map(match => {
167167
const name = match.slice(1, -1)
168168
const { type = 'string', description, example } = paramsMeta[name] || {}

test/resources/input/PathParams.json

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"info": {
3-
"_postman_id": "c2a620d9-979e-4f39-b6bc-22282ce4b21a",
3+
"_postman_id": "da50fa53-6326-4c7c-bfd8-6041a2c625d9",
44
"name": "Path Params",
55
"description": "Collection to test path parameters",
66
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
@@ -27,6 +27,27 @@
2727
},
2828
"response": []
2929
},
30+
{
31+
"name": "Get one customer",
32+
"request": {
33+
"method": "GET",
34+
"header": [],
35+
"url": {
36+
"raw": "https://api.io/customer/{{customer-id}}",
37+
"protocol": "https",
38+
"host": [
39+
"api",
40+
"io"
41+
],
42+
"path": [
43+
"customer",
44+
"{{customer-id}}"
45+
]
46+
},
47+
"description": "Obtain one customer info"
48+
},
49+
"response": []
50+
},
3051
{
3152
"name": "Get one users with description",
3253
"request": {
@@ -53,7 +74,7 @@
5374
{
5475
"listen": "prerequest",
5576
"script": {
56-
"id": "3d4c9432-87d0-46d1-8e0a-7bf78b95838f",
77+
"id": "8d6ddd6c-f1a8-4a68-91e0-07ab38f881a8",
5778
"type": "text/javascript",
5879
"exec": [
5980
""
@@ -63,7 +84,7 @@
6384
{
6485
"listen": "test",
6586
"script": {
66-
"id": "bfa95668-f3ba-423f-93d3-152fbba765af",
87+
"id": "e9cb3ab3-f140-42b3-8c12-17667c92c907",
6788
"type": "text/javascript",
6889
"exec": [
6990
""

test/resources/output/PathParams.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,23 @@ paths:
2323
description: Successful response
2424
content:
2525
application/json: {}
26+
'/customer/{customer-id}':
27+
get:
28+
tags:
29+
- default
30+
summary: Get one customer
31+
description: Obtain one customer info
32+
parameters:
33+
- name: customer-id
34+
in: path
35+
schema:
36+
type: string
37+
required: true
38+
responses:
39+
'200':
40+
description: Successful response
41+
content:
42+
application/json: {}
2643
'/desc/{user_id}':
2744
get:
2845
tags:

0 commit comments

Comments
 (0)