From d89814f93ade5527de4735eb4789a4139134883d Mon Sep 17 00:00:00 2001 From: Pongsatorn Manusopit Date: Sat, 28 Aug 2021 17:31:29 +0700 Subject: [PATCH 1/5] fix --- e2e/api-spec.json | 3 +++ e2e/src/cats/cats.controller.ts | 1 + e2e/validate-schema.e2e-spec.ts | 3 +++ lib/decorators/helpers.ts | 9 ++++++++- 4 files changed, 15 insertions(+), 1 deletion(-) diff --git a/e2e/api-spec.json b/e2e/api-spec.json index 873135539..116e4e536 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", diff --git a/e2e/src/cats/cats.controller.ts b/e2e/src/cats/cats.controller.ts index 1ea981fea..b71edf8fe 100644 --- a/e2e/src/cats/cats.controller.ts +++ b/e2e/src/cats/cats.controller.ts @@ -59,6 +59,7 @@ export class CatsController { @ApiExtension('x-codeSamples', [ { lang: 'JavaScript', source: "console.log('Hello World');" } ]) + @ApiExtension('x-multiple', { test:"test"}) 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..1a2e2b42d 100644 --- a/e2e/validate-schema.e2e-spec.ts +++ b/e2e/validate-schema.e2e-spec.ts @@ -59,6 +59,9 @@ 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' + ); } catch (err) { console.log(doc); expect(err).toBeUndefined(); diff --git a/lib/decorators/helpers.ts b/lib/decorators/helpers.ts index a16fc634c..e1ecd5787 100644 --- a/lib/decorators/helpers.ts +++ b/lib/decorators/helpers.ts @@ -86,7 +86,14 @@ export function createMixedDecorator( descriptor?: TypedPropertyDescriptor ): any => { if (descriptor) { - Reflect.defineMetadata(metakey, metadata, descriptor.value); + const responses = Reflect.getMetadata(metakey, descriptor.value) || {}; + let metadatas; + if (Array.isArray(metadata)) { + metadatas = [...(responses.length ? responses : []), ...metadata]; + } else { + metadatas = Object.assign(Object.assign({}, responses), metadata); + } + Reflect.defineMetadata(metakey, metadatas, descriptor.value); return descriptor; } Reflect.defineMetadata(metakey, metadata, target); From 8331807d22c63c2afbc52e30b9ba5e840456b2fe Mon Sep 17 00:00:00 2001 From: Pongsatorn Manusopit Date: Sat, 28 Aug 2021 17:48:02 +0700 Subject: [PATCH 2/5] add test --- e2e/api-spec.json | 4 +++- e2e/src/cats/cats.controller.ts | 2 ++ e2e/validate-schema.e2e-spec.ts | 2 ++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/e2e/api-spec.json b/e2e/api-spec.json index 116e4e536..bb8439481 100644 --- a/e2e/api-spec.json +++ b/e2e/api-spec.json @@ -163,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 b71edf8fe..daaf54ef3 100644 --- a/e2e/src/cats/cats.controller.ts +++ b/e2e/src/cats/cats.controller.ts @@ -60,6 +60,8 @@ export class CatsController { { 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 1a2e2b42d..4e97c9427 100644 --- a/e2e/validate-schema.e2e-spec.ts +++ b/e2e/validate-schema.e2e-spec.ts @@ -62,6 +62,8 @@ describe('Validate OpenAPI schema', () => { 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(); From 80ce744e1ba074e885ab86ddfd8d3346260124ed Mon Sep 17 00:00:00 2001 From: Pongsatorn Manusopit Date: Tue, 7 Sep 2021 15:27:50 +0700 Subject: [PATCH 3/5] fix --- e2e/src/cats/cats.controller.ts | 2 +- lib/decorators/helpers.ts | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/e2e/src/cats/cats.controller.ts b/e2e/src/cats/cats.controller.ts index daaf54ef3..89300f136 100644 --- a/e2e/src/cats/cats.controller.ts +++ b/e2e/src/cats/cats.controller.ts @@ -59,7 +59,7 @@ export class CatsController { @ApiExtension('x-codeSamples', [ { lang: 'JavaScript', source: "console.log('Hello World');" } ]) - @ApiExtension('x-multiple', { test:"test"}) + @ApiExtension('x-multiple', { test: "test" }) @ApiTags("tag1") @ApiTags("tag2") findAll(@Query() paginationQuery: PaginationQuery) {} diff --git a/lib/decorators/helpers.ts b/lib/decorators/helpers.ts index e1ecd5787..49fb3e7e3 100644 --- a/lib/decorators/helpers.ts +++ b/lib/decorators/helpers.ts @@ -86,12 +86,12 @@ export function createMixedDecorator( descriptor?: TypedPropertyDescriptor ): any => { if (descriptor) { - const responses = Reflect.getMetadata(metakey, descriptor.value) || {}; + const previousMetadata = Reflect.getMetadata(metakey, descriptor.value) || {}; let metadatas; if (Array.isArray(metadata)) { - metadatas = [...(responses.length ? responses : []), ...metadata]; + metadatas = [...(previousMetadata.length ? previousMetadata : []), ...metadata]; } else { - metadatas = Object.assign(Object.assign({}, responses), metadata); + metadatas = {... previousMetadata, ...metadata}; } Reflect.defineMetadata(metakey, metadatas, descriptor.value); return descriptor; From a59ac61684954e8dcf1757f771fb53f7cfa71333 Mon Sep 17 00:00:00 2001 From: Pongsatorn Manusopit Date: Mon, 13 Sep 2021 17:40:43 +0700 Subject: [PATCH 4/5] fix --- lib/decorators/helpers.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/decorators/helpers.ts b/lib/decorators/helpers.ts index 49fb3e7e3..e818816c3 100644 --- a/lib/decorators/helpers.ts +++ b/lib/decorators/helpers.ts @@ -86,12 +86,13 @@ export function createMixedDecorator( descriptor?: TypedPropertyDescriptor ): any => { if (descriptor) { - const previousMetadata = Reflect.getMetadata(metakey, descriptor.value) || {}; let metadatas; if (Array.isArray(metadata)) { - metadatas = [...(previousMetadata.length ? previousMetadata : []), ...metadata]; + const previousMetadata = Reflect.getMetadata(metakey, descriptor.value) || []; + metadatas = [...previousMetadata, ...metadata]; } else { - metadatas = {... previousMetadata, ...metadata}; + const previousMetadata = Reflect.getMetadata(metakey, descriptor.value) || {}; + metadatas = {...previousMetadata, ...metadata}; } Reflect.defineMetadata(metakey, metadatas, descriptor.value); return descriptor; From be46b23371c2f6269f5e586f43d9c42b5bc488f1 Mon Sep 17 00:00:00 2001 From: Kamil Mysliwiec Date: Tue, 28 Sep 2021 12:27:52 +0200 Subject: [PATCH 5/5] Update lib/decorators/helpers.ts --- lib/decorators/helpers.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/decorators/helpers.ts b/lib/decorators/helpers.ts index e818816c3..899b6e78e 100644 --- a/lib/decorators/helpers.ts +++ b/lib/decorators/helpers.ts @@ -86,7 +86,7 @@ export function createMixedDecorator( descriptor?: TypedPropertyDescriptor ): any => { if (descriptor) { - let metadatas; + let metadatas: any; if (Array.isArray(metadata)) { const previousMetadata = Reflect.getMetadata(metakey, descriptor.value) || []; metadatas = [...previousMetadata, ...metadata];