swagger-router
Advanced tools
Comparing version 0.2.4 to 0.2.5
@@ -18,3 +18,4 @@ "use strict"; | ||
if (typeof destination !== 'object' || typeof source !== 'object') { | ||
throw new Error('Illegal spec. Merge source and destination must be objects'); | ||
throw new Error('Illegal argument. ' + | ||
'Merge source and destination must be objects'); | ||
} | ||
@@ -29,2 +30,20 @@ | ||
return result; | ||
}, | ||
strip: function(object, properties) { | ||
if (typeof object !== 'object') { | ||
throw new Error('Illegal argument. ' + | ||
'Strip can only be applied to objects'); | ||
} | ||
object = Object.assign({}, object); | ||
if (typeof properties === 'string') { | ||
delete object[properties]; | ||
} else if (Array.isArray(properties)) { | ||
properties.forEach(function(prop) { | ||
delete object[prop]; | ||
}); | ||
} else { | ||
throw new Error('Illegal argument. ' + | ||
'Strip "properties" argument must be string or array'); | ||
} | ||
return object; | ||
} | ||
@@ -31,0 +50,0 @@ }; |
{ | ||
"name": "swagger-router", | ||
"version": "0.2.4", | ||
"version": "0.2.5", | ||
"description": "An efficient swagger 2 based router with support for multiple APIs. For use in RESTBase.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -129,1 +129,3 @@ # Swagger 2 router | ||
with merged properties, but without overriding. | ||
- `$$.strip(object, properties)` - removes field names listed in `properties` array from an `object`. `properties` | ||
could also be a string, if a single field should be removed. |
@@ -318,2 +318,29 @@ "use strict"; | ||
}); | ||
it('should strip the object', function() { | ||
var template = new Template({ | ||
method: 'get', | ||
uri: 'test.com', | ||
headers: '{$$.strip($.request.headers, "removed_header")}', | ||
body: '{$$.strip($.request.body, ["removed_field1", "removed_field2"])}' | ||
}); | ||
var result = template.expand({ | ||
request: { | ||
headers: { | ||
not_removed_header: 'value', | ||
removed_header: 'value' | ||
}, | ||
body: { | ||
not_removed_field: 'value', | ||
removed_field1: 'value', | ||
removed_field2: 'value' | ||
} | ||
} | ||
}); | ||
assert.deepEqual(result.headers.not_removed_header, 'value'); | ||
assert.deepEqual(result.headers.removed_header, undefined); | ||
assert.deepEqual(result.body.not_removed_field, 'value'); | ||
assert.deepEqual(result.body.removed_field1, undefined); | ||
assert.deepEqual(result.body.removed_field2, undefined); | ||
}); | ||
}); |
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
79515
24
1734
131
1