diff --git a/lib/transformEndpoints.js b/lib/transformEndpoints.js index 2e8dab1..f4030cf 100644 --- a/lib/transformEndpoints.js +++ b/lib/transformEndpoints.js @@ -158,7 +158,7 @@ function toOpenapi(text) { def.parameters = parameters; } - path = `${path}${group}`; + path = buildPathKey(path, group); if (!endpoints[path]) { endpoints[path] = {}; @@ -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; diff --git a/tests/endpoints/expectations/complex.paths.json b/tests/endpoints/expectations/complex.paths.json index f9faf26..e0ca124 100644 --- a/tests/endpoints/expectations/complex.paths.json +++ b/tests/endpoints/expectations/complex.paths.json @@ -1,6 +1,6 @@ { "paths": { - "/parent/:a/resources/:b (variant)": { + "/parent/{a}/resources/{b} (variant)": { "patch": { "summary": "Update resources", "description": "Update resources", diff --git a/tests/endpoints/expectations/crudlBasic.paths.json b/tests/endpoints/expectations/crudlBasic.paths.json index 008720b..96ea8ab 100644 --- a/tests/endpoints/expectations/crudlBasic.paths.json +++ b/tests/endpoints/expectations/crudlBasic.paths.json @@ -65,7 +65,7 @@ ] } }, - "/my1Resources/:id": { + "/my1Resources/{id}": { "get": { "summary": "**Retrieve** _my1Resource_", "description": "**Retrieve** _my1Resource_", @@ -211,7 +211,7 @@ ] } }, - "/my2Resources/:id": { + "/my2Resources/{id}": { "delete": { "summary": "**Delete** _my2Resource_", "description": "**Delete** _my2Resource_", diff --git a/tests/endpoints/expectations/crudlCustomModels.paths.json b/tests/endpoints/expectations/crudlCustomModels.paths.json index f9ef1c0..405ef97 100644 --- a/tests/endpoints/expectations/crudlCustomModels.paths.json +++ b/tests/endpoints/expectations/crudlCustomModels.paths.json @@ -65,7 +65,7 @@ ] } }, - "/my1Resources/:id": { + "/my1Resources/{id}": { "get": { "summary": "**Retrieve** _customKey_", "description": "**Retrieve** _customKey_", @@ -235,7 +235,7 @@ ] } }, - "/my2Resources/:id": { + "/my2Resources/{id}": { "get": { "summary": "**Retrieve** _customKey_", "description": "**Retrieve** _customKey_", @@ -405,7 +405,7 @@ ] } }, - "/my3Resources/:id": { + "/my3Resources/{id}": { "get": { "summary": "**Retrieve** _my3Resource_", "description": "**Retrieve** _my3Resource_", diff --git a/tests/endpoints/expectations/crudlOverride.paths.json b/tests/endpoints/expectations/crudlOverride.paths.json index 9618449..d337776 100644 --- a/tests/endpoints/expectations/crudlOverride.paths.json +++ b/tests/endpoints/expectations/crudlOverride.paths.json @@ -26,7 +26,7 @@ } } }, - "/my1Resources/:id": { + "/my1Resources/{id}": { "get": { "summary": "**Retrieve** _my1Resource_", "description": "**Retrieve** _my1Resource_", diff --git a/tests/endpoints/expectations/differentCodeStyles.paths.json b/tests/endpoints/expectations/differentCodeStyles.paths.json index f9faf26..e0ca124 100644 --- a/tests/endpoints/expectations/differentCodeStyles.paths.json +++ b/tests/endpoints/expectations/differentCodeStyles.paths.json @@ -1,6 +1,6 @@ { "paths": { - "/parent/:a/resources/:b (variant)": { + "/parent/{a}/resources/{b} (variant)": { "patch": { "summary": "Update resources", "description": "Update resources",