Skip to content
This repository has been archived by the owner on May 5, 2018. It is now read-only.

Commit

Permalink
Merge pull request #5 from phillip-hall/fixes/collectionFormat
Browse files Browse the repository at this point in the history
Update to README
  • Loading branch information
jsdevel committed Feb 18, 2016
2 parents fabcba3 + 134202c commit f932414
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 12 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
## Highlights

* Effortlessly coerce header, path, and query request properties to defined types in
* Effortlessly coerce header, path, query and formData request properties to defined types in
an openapi parameters list.
* Handles array types.
* Performant.
* Extensively tested.
* Small footprint.
* Currently supports openapi 2.0 (a.k.a. swagger 2.0) parameter lists.
* Supports _collectionFormat_ for _formData array_ parameters.

## Example

Expand Down
4 changes: 0 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ var COERCION_STRATEGIES = {
});

return input;
} else {
return [itemCoercer(input)];
}
},

Expand Down Expand Up @@ -149,7 +147,5 @@ function pathsep(format) {
return '\t';
case 'pipes':
return '|';
case 'multi':
return '&';
}
}
40 changes: 33 additions & 7 deletions test/data-driven/coerce-array-with-collectionFormat.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module.exports = {
parameters: [
{
in: 'formData',
name: 'data1',
name: 'csv',
type: 'array',
items: {
type: 'string'
Expand All @@ -13,9 +13,33 @@ module.exports = {

{
in: 'formData',
name: 'data2',
type: 'integer'
}
name: 'ssv',
type: 'array',
items: {
type: 'string'
},
collectionFormat: 'ssv'
},

{
in: 'formData',
name: 'tsv',
type: 'array',
items: {
type: 'string'
},
collectionFormat: 'tsv'
},

{
in: 'formData',
name: 'pipes',
type: 'array',
items: {
type: 'string'
},
collectionFormat: 'pipes'
},
]
},

Expand All @@ -27,7 +51,7 @@ module.exports = {
'Content-Type': 'application/x-www-form-urlencoded'
},

requestBody: 'data1=foo,bar&data2=5',
requestBody: 'csv=foo,bar&ssv=foo bar&tsv=foo\tbar&pipes=foo|bar',

headers: null,

Expand All @@ -36,7 +60,9 @@ module.exports = {
query: null,

body: {
data1: ['foo', 'bar'],
data2: 5
csv: ['foo', 'bar'],
ssv: ['foo', 'bar'],
tsv: ['foo', 'bar'],
pipes: ['foo', 'bar']
}
};

0 comments on commit f932414

Please sign in to comment.