Skip to content

Commit

Permalink
fix: add extra test to validate api query decorator
Browse files Browse the repository at this point in the history
Added an extra test to validate the api query decorator change regarding isArray prop
This change is needed to create valid OpenAPI documents.

Closes #1221
  • Loading branch information
Brecht Tourlousse committed Feb 22, 2021
1 parent d3c0b5c commit 532640d
Showing 1 changed file with 61 additions and 2 deletions.
63 changes: 61 additions & 2 deletions test/explorer/swagger-explorer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -784,6 +784,20 @@ describe('SwaggerExplorer', () => {

@Controller('')
class FooController {
@Get('foos/:objectId')
@ApiParam({
name: 'objectId',
enum: ParamEnum
})
@ApiQuery({ name: 'order', enum: QueryEnum })
@ApiQuery({ name: 'page', enum: ['d', 'e', 'f'], isArray: true })
find(): Promise<Foo[]> {
return Promise.resolve([]);
}
}

@Controller('')
class Foo2Controller {
@Get('foos/:objectId')
@ApiParam({
name: 'objectId',
Expand Down Expand Up @@ -829,11 +843,15 @@ describe('SwaggerExplorer', () => {
expect(routes[0].root.parameters).toEqual([
{
in: 'query',
isArray: true,
name: 'page',
required: true,
schema: {
enum: ['d', 'e', 'f'],
type: 'string'
items: {
type: 'string',
enum: ['d', 'e', 'f'],
},
type: "array"
}
},
{
Expand All @@ -857,6 +875,47 @@ describe('SwaggerExplorer', () => {
]);
});

it('should properly define enum and not add isArray prop to params', () => {
const explorer = new SwaggerExplorer(schemaObjectFactory);
const routes = explorer.exploreController(
{
instance: new Foo2Controller(),
metatype: Foo2Controller
} as InstanceWrapper<Foo2Controller>,
'path'
);

expect(routes[0].root.parameters).toEqual([
{
in: 'query',
name: 'page',
required: true,
schema: {
type: 'string',
enum: ['d', 'e', 'f'],
}
},
{
in: 'query',
name: 'order',
required: true,
schema: {
type: 'string',
enum: ['d', 'e', 'f']
}
},
{
in: 'path',
name: 'objectId',
required: true,
schema: {
type: 'string',
enum: ['a', 'b', 'c']
}
}
])
})

it('should properly define enum as schema with lazy function', () => {
const explorer = new SwaggerExplorer(schemaObjectFactory);
const routes = explorer.exploreController(
Expand Down

0 comments on commit 532640d

Please sign in to comment.