Skip to content

Commit

Permalink
Merge pull request #169 from redbubble/allow-action-uri-overrides
Browse files Browse the repository at this point in the history
Add ability to parse action url overrides
  • Loading branch information
subinvarghesein authored Aug 29, 2018
2 parents e0d7cd4 + a8b1465 commit 620e0cf
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 3 deletions.
15 changes: 13 additions & 2 deletions lib/parse/blueprint.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,22 @@ module.exports = function(filePath, autoOptions, routeMap) {
routeMap[key] = routeMap[key] || { urlExpression: key, methods: {} };
parseParameters(parsedUrl, resource.parameters, routeMap);
resource.actions.forEach(function(action){
parseAction(parsedUrl, action, routeMap);
saveRouteToTheList(parsedUrl, action);
var actionUrl = setupActionUrl(action, parsedUrl, routeMap);
parseAction(actionUrl, action, routeMap);
saveRouteToTheList(actionUrl, action);
});
}

function setupActionUrl(action, resourceUrl, routeMap) {
if (action.attributes.uriTemplate !== '') {
var actionUrl = urlParser.parse(action.attributes.uriTemplate);
var actionKey = actionUrl.url;
routeMap[actionKey] = routeMap[actionKey] || { urlExpression: actionKey, methods: {} };
return actionUrl;
}
return resourceUrl;
}

/**
* Adds route and its action to the allRoutesList. It appends the action when route already exists in the list.
* @param resource Route URI
Expand Down
18 changes: 18 additions & 0 deletions test/api/simple-api-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,24 @@ describe('Simple-API', function(){
});
});

describe('/api/things/old', function(){
describe('GET', function(){
it('should respond with json collection from contract example', function(done){
request.get('/api/things/old')
.expect(200)
.expect('Content-type', 'application/json;charset=UTF-8')
.expect([
{text: 'NES',id: '1'},
{text: 'Atari', id: '2'},
{text: 'The Beatles', id: '3'},
{text: 'Grandma', id: '4'},
{text: '80s', id: '5'}
])
.end(helper.endCb(done));
});
});
});

describe('/api/things/{thingId}', function(){
describe('GET', function(){
it('should respond with json object from contract example', function(done){
Expand Down
31 changes: 30 additions & 1 deletion test/example/md/simple-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,36 @@ Lists all the things from the API
"id": "5"
}
]

### Retrieve all the old things [GET /api/things/old]

+ Response 200 (application/json;charset=UTF-8)

+ Body

[
{
"text":"NES",
"id": "1"
},
{
"text":"Atari",
"id": "2"
},
{
"text":"The Beatles",
"id": "3"
},
{
"text":"Grandma",
"id": "4"
},
{
"text":"80s",
"id": "5"
}
]

### Create a new thing [POST]

+ Request (application/json)
Expand Down

0 comments on commit 620e0cf

Please sign in to comment.