Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/server/parameter-processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
35 changes: 34 additions & 1 deletion test/integration/datatypes.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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>): string {
return prefixes === undefined ? 'undefined' : JSON.stringify(prefixes);
}

@POST
@Path('upload')
public testUploadFile(@FileParam('myFile') file: Express.Multer.File,
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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) => {
Expand Down