37
37
import javax .ws .rs .Path ;
38
38
import javax .ws .rs .PathParam ;
39
39
import javax .ws .rs .QueryParam ;
40
+ import javax .ws .rs .core .Response .Status ;
40
41
41
42
import org .restdoc .annotations .RestDocAccept ;
42
43
import org .restdoc .annotations .RestDocHeader ;
@@ -239,17 +240,19 @@ private void addResourceMethod(final String basepath, final Method method) {
239
240
this .ext .newResource (restResource );
240
241
}
241
242
242
- if (restResource .getMethods ().containsKey (methodType )) {
243
- this .logger .warn ("Duplicate method detected for resource: " + path + " -> " + methodType );
244
- return ;
243
+ final MethodDefinition def ;
244
+ if (!restResource .getMethods ().containsKey (methodType )) {
245
+ def = new MethodDefinition ();
246
+ def .setDescription (methodDescription );
247
+ def .setResponse (new ResponseDefinition ());
248
+ } else {
249
+ def = restResource .getMethods ().get (methodType );
245
250
}
246
251
247
- final MethodDefinition def = new MethodDefinition ();
248
- def .setDescription (methodDescription );
249
252
def .getHeaders ().putAll (methodRequestHeader );
250
253
def .getAccepts ().addAll (this .getAccepts (method , parameterTypes , parameterAnnotations ));
251
254
def .getStatusCodes ().putAll (this .getStatusCodes (method ));
252
- def . setResponse ( this . getMethodResponse ( method ) );
255
+ this . addMethodResponse ( def . getResponse (), method );
253
256
254
257
restResource .getMethods ().put (methodType , def );
255
258
@@ -329,17 +332,19 @@ protected void parseMethodParameter(final List<String> queryParams, final Map<St
329
332
}
330
333
}
331
334
332
- private ResponseDefinition getMethodResponse ( final Method method ) {
333
- final ResponseDefinition def = new ResponseDefinition () ;
335
+ private void addMethodResponse ( final ResponseDefinition def , final Method method ) {
336
+ boolean typeFound = false ;
334
337
if (method .isAnnotationPresent (RestDocResponse .class )) {
335
338
final RestDocResponse docResponse = method .getAnnotation (RestDocResponse .class );
336
339
final RestDocType [] types = docResponse .types ();
337
340
for (final RestDocType restDocType : types ) {
338
341
if (!restDocType .schemaClass ().equals (Object .class )) {
339
342
final String schema = SchemaResolver .getSchemaFromType (restDocType .schemaClass (), this .schemaMap , this .ext );
340
343
def .type (restDocType .type (), schema );
344
+ typeFound = true ;
341
345
} else {
342
346
def .type (restDocType .type (), restDocType .schema ());
347
+ typeFound = true ;
343
348
}
344
349
}
345
350
@@ -348,7 +353,7 @@ private ResponseDefinition getMethodResponse(final Method method) {
348
353
def .header (restDocHeader .name (), restDocHeader .description (), restDocHeader .required ());
349
354
}
350
355
}
351
- if (def . getTypes (). isEmpty () && !method .getReturnType ().equals (Void .TYPE )) {
356
+ if (! typeFound && !method .getReturnType ().equals (Void .TYPE )) {
352
357
final String schema = SchemaResolver .getSchemaFromTypeOrNull (method .getGenericReturnType (), this .schemaMap , this .ext );
353
358
String [] mediaTypes = MediaTypeResolver .getProducesMediaType (method );
354
359
if (mediaTypes != null ) {
@@ -357,17 +362,23 @@ private ResponseDefinition getMethodResponse(final Method method) {
357
362
}
358
363
}
359
364
}
360
- return def ;
361
365
}
362
366
363
367
private Map <String , String > getStatusCodes (final Method method ) {
364
368
final Map <String , String > codeMap = Maps .newHashMap ();
365
369
if (method .isAnnotationPresent (RestDocReturnCodes .class )) {
366
370
final RestDocReturnCode [] returnCodes = method .getAnnotation (RestDocReturnCodes .class ).value ();
367
371
for (final RestDocReturnCode rdrc : returnCodes ) {
368
- codeMap .put (rdrc .code (), rdrc .description ());
372
+ String description = rdrc .description ();
373
+ if (description .isEmpty ()) {
374
+ description = Status .fromStatusCode (Integer .valueOf (rdrc .code ())).getReasonPhrase ();
375
+ }
376
+ codeMap .put (rdrc .code (), description );
369
377
}
370
378
}
379
+ if (method .getReturnType ().equals (Void .TYPE )) {
380
+ codeMap .put (String .valueOf (Status .NO_CONTENT .getStatusCode ()), Status .NO_CONTENT .getReasonPhrase ());
381
+ }
371
382
return codeMap ;
372
383
}
373
384
0 commit comments