diff --git a/src/server/parameter-processor.ts b/src/server/parameter-processor.ts index 86d6989..7c887ea 100644 --- a/src/server/parameter-processor.ts +++ b/src/server/parameter-processor.ts @@ -80,6 +80,8 @@ export class ParameterProcessor { return paramValue === undefined ? paramValue : parseFloat(paramValue as string); case 'Boolean': return paramValue === undefined ? paramValue : paramValue === 'true' || paramValue === true; + case 'Array': + return paramValue === undefined ? paramValue : [].concat(paramValue); default: let converter = ServerContainer.get().paramConverters.get(paramType); if (!converter) { diff --git a/test/integration/datatypes.spec.ts b/test/integration/datatypes.spec.ts index b4ca066..2275853 100644 --- a/test/integration/datatypes.spec.ts +++ b/test/integration/datatypes.spec.ts @@ -145,6 +145,12 @@ export class TestParamsService { return `limit:${limit}|prefix:${prefix}|expand:${expand}`; } + @GET + @Path('array-query') + public testArrayQuery(@QueryParam('prefix') prefixes: Array): string { + return prefixes === undefined ? 'undefined' : JSON.stringify(prefixes); + } + @POST @Path('upload') public testUploadFile(@FileParam('myFile') file: Express.Multer.File, @@ -242,7 +248,7 @@ describe('Data Types Tests', () => { }); }); - it('should be able to receive parametes as Objects', (done) => { + it('should be able to receive parameters as Objects', (done) => { const person = new Person(123, 'Person 123', 35); request.put({ body: JSON.stringify(person), @@ -423,6 +429,33 @@ describe('Data Types Tests', () => { done(); }); }); + + it('should use undefined as value for missing array query param', (done) => { + request({ + url: 'http://localhost:5674/testparams/array-query' + }, (error, response, body) => { + expect(body).to.eq('undefined'); + done(); + }); + }); + + it('should handle an array of values for duplicate query param names', (done) => { + request({ + url: 'http://localhost:5674/testparams/array-query?&prefix=abc&prefix=123' + }, (error, response, body) => { + expect(body).to.eq('["abc","123"]'); + done(); + }); + }); + + it('should allow an array of one when expected query param type is an array', (done) => { + request({ + url: 'http://localhost:5674/testparams/array-query?&prefix=abc' + }, (error, response, body) => { + expect(body).to.eq('["abc"]'); + done(); + }); + }); }); describe('Download Service', () => { it('should return a file', (done) => {