diff --git a/README.md b/README.md index edb6fb7..4d9e600 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/index.js b/index.js index 631c302..eaa9c97 100644 --- a/index.js +++ b/index.js @@ -51,8 +51,6 @@ var COERCION_STRATEGIES = { }); return input; - } else { - return [itemCoercer(input)]; } }, @@ -149,7 +147,5 @@ function pathsep(format) { return '\t'; case 'pipes': return '|'; - case 'multi': - return '&'; } } diff --git a/test/data-driven/coerce-array-with-collectionFormat.js b/test/data-driven/coerce-array-with-collectionFormat.js index 548d91f..56f172a 100644 --- a/test/data-driven/coerce-array-with-collectionFormat.js +++ b/test/data-driven/coerce-array-with-collectionFormat.js @@ -3,7 +3,7 @@ module.exports = { parameters: [ { in: 'formData', - name: 'data1', + name: 'csv', type: 'array', items: { type: 'string' @@ -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' + }, ] }, @@ -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, @@ -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'] } };