Skip to content

Commit

Permalink
feat(parameters): exclude default custom parameters option in route c…
Browse files Browse the repository at this point in the history
…onfig
  • Loading branch information
theoomoregbee committed Jul 28, 2019
1 parent c321bd9 commit 1cd62e6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
4 changes: 3 additions & 1 deletion README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,8 @@ We can extend and add extra information on the second above for sails hook swagg
required: true,
type: 'string',
description: 'This is a custom required parameter'
}]
}],
excludeParameters: ['#/parameters/TokenHeaderParam']
}
}
}
Expand All @@ -173,6 +174,7 @@ We can extend and add extra information on the second above for sails hook swagg
* **body**: if the route is taking in form post, and it follows our normal attribute from [sails model](http://sailsjs.com/documentation/concepts/models-and-orm/attributes)
* **query**: for any query you expecting from the user consuming the service method, you can also reference the default created above (*WhereQueryParam*, *LimitQueryParam*, *SkipQueryParam*, *SortQueryParam*, *PopulateQueryParam*, *PageQueryParam*, *SelectQueryParam*, *TokenHeaderParam*, *IDPathParam*) and add your own following the swagger specification.
* We can also add custom personalized **parameters** if required.
* **excludeParameters**: if you want to exclude some of the defaults paramters from the generated swagger json.

**NB** it overrides the default route params attached from the sails generator

Expand Down
14 changes: 13 additions & 1 deletion lib/generators.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,9 @@ function _generatePaths(generated_routes, tags, customBlueprintMaps) {
parameter = formatter.blueprint_parameter(route.action, customBlueprintMaps);
}

// contains just ref string to our default/defined parameters
var excludeParameters = route.excludeParameters || []

if (!parameter) //which means is not in our parameters, then use the keys to get and add token for us incase of any route using header information
parameter = _getPathParamsFromKeys(route.keys).concat({$ref: '#/parameters/TokenHeaderParam'});

Expand All @@ -260,7 +263,8 @@ function _generatePaths(generated_routes, tags, customBlueprintMaps) {
consumes: ['application/json'],
parameters: parameter.concat(_getQueryParamsFromParameters(route.parameters))
.concat(_getQueryParamsFromRouteQuery(route.query))
.concat(_getBodyParamsFromRouteBody(route.body)),
.concat(_getBodyParamsFromRouteBody(route.body))
.filter(_isNotExcludedParameters(excludeParameters)),
responses: {
'200': {description: 'The requested resource'},
'404': {description: 'Resource not found'},
Expand Down Expand Up @@ -429,6 +433,14 @@ function _getBodyParamsFromRouteBody(body) {
return param;
}

// check if the parameters should be excluded or not
function _isNotExcludedParameters (toBeExcluded) {
return function (parameter) {
const ref = parameter['$ref']
return !(ref && _.includes(toBeExcluded, ref))
}
}


module.exports = {
tags: _generateModels,
Expand Down

0 comments on commit 1cd62e6

Please sign in to comment.