Skip to content

Commit

Permalink
clean uriTemplate from query string parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
nazieb committed Apr 11, 2017
1 parent 815749d commit b346625
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "optimusjs",
"version": "0.1.9",
"version": "0.1.11",
"description": "Transform API Blueprint into any other formats",
"main": "dist/index.js",
"bin": {
Expand Down
16 changes: 13 additions & 3 deletions src/formatters/swagger.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ function processResourceGroups(resourceGroups, defaultTag) {
result.tags.push(tag);

for (let resource of group.resources) {
const uri = resource.uriTemplate;

const uri = cleanQueryParam(resource.uriTemplate);
const params = getResourceParams(resource);

const actions = getActions(resource.actions);
Expand All @@ -53,7 +52,11 @@ function processResourceGroups(resourceGroups, defaultTag) {
actions[method]["parameters"] = mergeResourceAndActionParams(params, actions[method]["parameters"]);
}

result.paths[uri] = actions;
if (!result.paths.hasOwnProperty(uri)) {
result.paths[uri] = actions;
} else {
result.paths[uri] = Object.assign(result.paths[uri], actions);
}
}
}

Expand Down Expand Up @@ -415,4 +418,11 @@ function isDateTimeValue(dateString) {
}
}
return false;
}

function cleanQueryParam(uri) {
uri = uri.replace(/\{\?.*}/g, "");
uri = uri.replace(/\?.*}/g, "}");

return uri;
}

0 comments on commit b346625

Please sign in to comment.