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

Commit

Permalink
feat: support hyphen character in path variables #65
Browse files Browse the repository at this point in the history
Close #65
  • Loading branch information
joolfe committed Aug 25, 2020
1 parent a4e8af4 commit ea1671e
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ function mapParameters (type) {
}

function extractPathParameters (path, paramsMeta) {
const matched = path.match(/{\s*[\w]+\s*}/g) || []
const matched = path.match(/{\s*[\w-]+\s*}/g) || []
return matched.map(match => {
const name = match.slice(1, -1)
const { type = 'string', description, example } = paramsMeta[name] || {}
Expand Down
27 changes: 24 additions & 3 deletions test/resources/input/PathParams.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"info": {
"_postman_id": "c2a620d9-979e-4f39-b6bc-22282ce4b21a",
"_postman_id": "da50fa53-6326-4c7c-bfd8-6041a2c625d9",
"name": "Path Params",
"description": "Collection to test path parameters",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
Expand All @@ -27,6 +27,27 @@
},
"response": []
},
{
"name": "Get one customer",
"request": {
"method": "GET",
"header": [],
"url": {
"raw": "https://api.io/customer/{{customer-id}}",
"protocol": "https",
"host": [
"api",
"io"
],
"path": [
"customer",
"{{customer-id}}"
]
},
"description": "Obtain one customer info"
},
"response": []
},
{
"name": "Get one users with description",
"request": {
Expand All @@ -53,7 +74,7 @@
{
"listen": "prerequest",
"script": {
"id": "3d4c9432-87d0-46d1-8e0a-7bf78b95838f",
"id": "8d6ddd6c-f1a8-4a68-91e0-07ab38f881a8",
"type": "text/javascript",
"exec": [
""
Expand All @@ -63,7 +84,7 @@
{
"listen": "test",
"script": {
"id": "bfa95668-f3ba-423f-93d3-152fbba765af",
"id": "e9cb3ab3-f140-42b3-8c12-17667c92c907",
"type": "text/javascript",
"exec": [
""
Expand Down
17 changes: 17 additions & 0 deletions test/resources/output/PathParams.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,23 @@ paths:
description: Successful response
content:
application/json: {}
'/customer/{customer-id}':
get:
tags:
- default
summary: Get one customer
description: Obtain one customer info
parameters:
- name: customer-id
in: path
schema:
type: string
required: true
responses:
'200':
description: Successful response
content:
application/json: {}
'/desc/{user_id}':
get:
tags:
Expand Down

0 comments on commit ea1671e

Please sign in to comment.