From 9ab875ea511fd521b146ff13680c0daf5e7f144c Mon Sep 17 00:00:00 2001 From: Clooooode Date: Sat, 12 Oct 2024 14:32:25 +0800 Subject: [PATCH 1/2] test: add missing undefined example check @ Response --- tests/unit/swagger/definitionsGeneration/metadata.spec.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/unit/swagger/definitionsGeneration/metadata.spec.ts b/tests/unit/swagger/definitionsGeneration/metadata.spec.ts index 7d241896b..57bf76c7d 100644 --- a/tests/unit/swagger/definitionsGeneration/metadata.spec.ts +++ b/tests/unit/swagger/definitionsGeneration/metadata.spec.ts @@ -177,6 +177,7 @@ describe('Metadata generation', () => { const unauthResponse = method.responses[2]; expect(unauthResponse.name).to.equal('401'); expect(unauthResponse.description).to.equal('Unauthorized'); + expect(unauthResponse.examples).to.be.undefined; const defaultResponse = method.responses[3]; expect(defaultResponse.name).to.equal('default'); From e3600e01ec97d4584d08010065a9c2c04ccf5cca Mon Sep 17 00:00:00 2001 From: Clooooode Date: Sat, 12 Oct 2024 14:35:06 +0800 Subject: [PATCH 2/2] fix: missing example undefined chec @ method generator --- packages/cli/src/metadataGeneration/methodGenerator.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/cli/src/metadataGeneration/methodGenerator.ts b/packages/cli/src/metadataGeneration/methodGenerator.ts index b7b38f929..a2e0175e5 100644 --- a/packages/cli/src/metadataGeneration/methodGenerator.ts +++ b/packages/cli/src/metadataGeneration/methodGenerator.ts @@ -197,7 +197,11 @@ export class MethodGenerator { return decorators.map(decorator => { const [name, description, example, produces] = getDecoratorValues(decorator, this.current.typeChecker); - responseExamplesByName[name] = responseExamplesByName[name] ? [...responseExamplesByName[name], example] : [example]; + + if (example !== undefined) { + responseExamplesByName[name] = responseExamplesByName[name] ? [...responseExamplesByName[name], example] : [example]; + } + return { description: description || '', examples: responseExamplesByName[name] || undefined,