Skip to content

Commit

Permalink
Store all Response examples by name
Browse files Browse the repository at this point in the history
Allow use multiple times the @response decorator with the same status and different examples.
  • Loading branch information
MiguelSavignano authored Mar 2, 2024
1 parent daadfe6 commit 70e5d9f
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions packages/cli/src/metadataGeneration/methodGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,17 +189,18 @@ export class MethodGenerator {
}

private getMethodResponses(): Tsoa.Response[] {
const examplesByName = {};
const decorators = this.getDecoratorsByIdentifier(this.node, 'Response');
if (!decorators || !decorators.length) {
return [];
}

return decorators.map(decorator => {
const [name, description, example, produces] = getDecoratorValues(decorator, this.current.typeChecker);

examplesByName[name] = examplesByName[name] ? [...examplesByName[name], example] : [example];
return {
description: description || '',
examples: example === undefined ? undefined : [example],
examples: examplesByName[name] || undefined,
name: name || '200',
produces: this.getProducesAdapter(produces),
schema: this.getSchemaFromDecorator(decorator, 0),
Expand Down

0 comments on commit 70e5d9f

Please sign in to comment.