@@ -6,7 +6,6 @@ import { getJSDocDescription, getJSDocTag, isExistJSDocTag } from '../utils/jsDo
66import { getDecorators } from '../utils/decoratorUtils' ;
77import { normalizePath } from '../utils/pathUtils' ;
88import * as pathUtil from 'path' ;
9- // import * as _ from 'lodash';
109
1110export class MethodGenerator {
1211 private method : string ;
@@ -32,10 +31,7 @@ export class MethodGenerator {
3231
3332 const identifier = this . node . name as ts . Identifier ;
3433 const type = resolveType ( this . node . type , this . genericTypeMap ) ;
35- const responses = this . getMethodResponses ( ) ;
36- if ( 0 === responses . length ) {
37- responses . push ( this . getMethodSuccessResponse ( type ) ) ;
38- }
34+ const responses = this . mergeResponses ( this . getMethodResponses ( ) , this . getMethodSuccessResponse ( type ) ) ;
3935
4036 return {
4137 consumes : this . getDecoratorValues ( 'Accept' ) ,
@@ -176,6 +172,25 @@ export class MethodGenerator {
176172 return this . getExamplesValue ( argument ) ;
177173 }
178174
175+ private mergeResponses ( responses : Array < ResponseType > , defaultResponse : ResponseType ) {
176+ if ( ! responses || ! responses . length ) {
177+ return [ defaultResponse ] ;
178+ }
179+
180+ const index = responses . findIndex ( ( resp ) => resp . status === defaultResponse . status ) ;
181+
182+ if ( defaultResponse . examples ) {
183+ if ( index >= 0 ) {
184+ if ( ! responses [ index ] . examples ) {
185+ responses [ index ] . examples = defaultResponse . examples ;
186+ }
187+ } else {
188+ responses . push ( defaultResponse ) ;
189+ }
190+ }
191+ return responses ;
192+ }
193+
179194 private supportsPathMethod ( method : string ) {
180195 return [ 'GET' , 'POST' , 'PATCH' , 'DELETE' , 'PUT' , 'OPTIONS' , 'HEAD' ] . some ( m => m === method ) ;
181196 }
0 commit comments