Skip to content

Commit

Permalink
Fix path params to match Swagger spec (:id => {id})
Browse files Browse the repository at this point in the history
  • Loading branch information
Ajaxy committed Dec 24, 2018
1 parent e07ebc1 commit 45863f0
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 9 deletions.
6 changes: 5 additions & 1 deletion lib/transformEndpoints.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ function toOpenapi(text) {
def.parameters = parameters;
}

path = `${path}${group}`;
path = buildPathKey(path, group);

if (!endpoints[path]) {
endpoints[path] = {};
Expand Down Expand Up @@ -258,4 +258,8 @@ function removeMarkdownLinks(str) {
return str.replace(/\[([^\]]+)]\([^)]+\)/g, '$1');
}

function buildPathKey(pathStr, group) {
return `${pathStr.replace(/:(.*?)(\/|$)/g, '{$1}$2')}${group}`;
}

module.exports = toOpenapi;
2 changes: 1 addition & 1 deletion tests/endpoints/expectations/complex.paths.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"paths": {
"/parent/:a/resources/:b (variant)": {
"/parent/{a}/resources/{b} (variant)": {
"patch": {
"summary": "Update resources",
"description": "Update resources",
Expand Down
4 changes: 2 additions & 2 deletions tests/endpoints/expectations/crudlBasic.paths.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
]
}
},
"/my1Resources/:id": {
"/my1Resources/{id}": {
"get": {
"summary": "**Retrieve** _my1Resource_",
"description": "**Retrieve** _my1Resource_",
Expand Down Expand Up @@ -211,7 +211,7 @@
]
}
},
"/my2Resources/:id": {
"/my2Resources/{id}": {
"delete": {
"summary": "**Delete** _my2Resource_",
"description": "**Delete** _my2Resource_",
Expand Down
6 changes: 3 additions & 3 deletions tests/endpoints/expectations/crudlCustomModels.paths.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
]
}
},
"/my1Resources/:id": {
"/my1Resources/{id}": {
"get": {
"summary": "**Retrieve** _customKey_",
"description": "**Retrieve** _customKey_",
Expand Down Expand Up @@ -235,7 +235,7 @@
]
}
},
"/my2Resources/:id": {
"/my2Resources/{id}": {
"get": {
"summary": "**Retrieve** _customKey_",
"description": "**Retrieve** _customKey_",
Expand Down Expand Up @@ -405,7 +405,7 @@
]
}
},
"/my3Resources/:id": {
"/my3Resources/{id}": {
"get": {
"summary": "**Retrieve** _my3Resource_",
"description": "**Retrieve** _my3Resource_",
Expand Down
2 changes: 1 addition & 1 deletion tests/endpoints/expectations/crudlOverride.paths.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
}
}
},
"/my1Resources/:id": {
"/my1Resources/{id}": {
"get": {
"summary": "**Retrieve** _my1Resource_",
"description": "**Retrieve** _my1Resource_",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"paths": {
"/parent/:a/resources/:b (variant)": {
"/parent/{a}/resources/{b} (variant)": {
"patch": {
"summary": "Update resources",
"description": "Update resources",
Expand Down

0 comments on commit 45863f0

Please sign in to comment.