diff --git a/e2e/api-spec.json b/e2e/api-spec.json index 873135539..bb8439481 100644 --- a/e2e/api-spec.json +++ b/e2e/api-spec.json @@ -64,6 +64,9 @@ }, "get": { "operationId": "CatsController_findAll", + "x-multiple": { + "test": "test" + }, "x-codeSamples": [ { "lang": "JavaScript", @@ -160,7 +163,9 @@ } }, "tags": [ - "cats" + "cats", + "tag2", + "tag1" ], "security": [ { diff --git a/e2e/src/cats/cats.controller.ts b/e2e/src/cats/cats.controller.ts index 1ea981fea..89300f136 100644 --- a/e2e/src/cats/cats.controller.ts +++ b/e2e/src/cats/cats.controller.ts @@ -59,6 +59,9 @@ export class CatsController { @ApiExtension('x-codeSamples', [ { lang: 'JavaScript', source: "console.log('Hello World');" } ]) + @ApiExtension('x-multiple', { test: "test" }) + @ApiTags("tag1") + @ApiTags("tag2") findAll(@Query() paginationQuery: PaginationQuery) {} @ApiQuery({ type: PaginationQuery }) diff --git a/e2e/validate-schema.e2e-spec.ts b/e2e/validate-schema.e2e-spec.ts index d3f29fa39..4e97c9427 100644 --- a/e2e/validate-schema.e2e-spec.ts +++ b/e2e/validate-schema.e2e-spec.ts @@ -59,6 +59,11 @@ describe('Validate OpenAPI schema', () => { expect(api.paths['/api/cats']['get']['x-codeSamples'][0]['lang']).toEqual( 'JavaScript' ); + expect(api.paths['/api/cats']['get']['x-multiple']['test']).toEqual( + 'test' + ); + expect(api.paths['/api/cats']['get']['tags']).toContain('tag1'); + expect(api.paths['/api/cats']['get']['tags']).toContain('tag2'); } catch (err) { console.log(doc); expect(err).toBeUndefined(); diff --git a/lib/decorators/helpers.ts b/lib/decorators/helpers.ts index a16fc634c..899b6e78e 100644 --- a/lib/decorators/helpers.ts +++ b/lib/decorators/helpers.ts @@ -86,7 +86,15 @@ export function createMixedDecorator( descriptor?: TypedPropertyDescriptor ): any => { if (descriptor) { - Reflect.defineMetadata(metakey, metadata, descriptor.value); + let metadatas: any; + if (Array.isArray(metadata)) { + const previousMetadata = Reflect.getMetadata(metakey, descriptor.value) || []; + metadatas = [...previousMetadata, ...metadata]; + } else { + const previousMetadata = Reflect.getMetadata(metakey, descriptor.value) || {}; + metadatas = {...previousMetadata, ...metadata}; + } + Reflect.defineMetadata(metakey, metadatas, descriptor.value); return descriptor; } Reflect.defineMetadata(metakey, metadata, target);