@@ -269,12 +269,54 @@ public void escaping() throws Exception {
269269 public void deprecated () throws Exception {
270270 HandlerMethod handlerMethod = createHandlerMethod ("removeItem" );
271271 mockFieldComment (DeprecatedItem .class , "index" , "item's index" );
272- mockDeprecated (DeprecatedItem .class , "index" , "use index2" );
272+ mockFieldComment (DeprecatedItem .class , "index2" , "item's index2" );
273+ mockFieldComment (DeprecatedItem .class , "index3" , "item's index3" );
274+ mockFieldComment (DeprecatedItem .class , "index4" , "item's index4" );
275+ mockFieldComment (DeprecatedItem .class , "index5" , "item's index5" );
276+ mockMethodComment (DeprecatedItem .class , "getIndex6" , "item's index6" );
277+
278+ // index2 and getIndex4 have @deprecated Javadoc
279+ mockDeprecatedField (DeprecatedItem .class , "index2" , "use something else" );
280+ mockDeprecatedMethod (DeprecatedItem .class , "getIndex4" , "use something else" );
273281
274282 this .snippets .expect (RESPONSE_FIELDS ).withContents (
275283 tableWithHeader ("Path" , "Type" , "Optional" , "Description" )
276284 .row ("index" , "Integer" , "true" ,
277- "**Deprecated.** Use index2.\n \n Item's index." ));
285+ "**Deprecated.**\n \n Item's index." )
286+ .row ("index2" , "Integer" , "true" ,
287+ "**Deprecated.** Use something else.\n \n Item's index2." )
288+ .row ("index3" , "Integer" , "true" ,
289+ "**Deprecated.**\n \n Item's index3." )
290+ .row ("index4" , "Integer" , "true" ,
291+ "**Deprecated.** Use something else.\n \n Item's index4." )
292+ .row ("index5" , "Integer" , "true" ,
293+ "**Deprecated.**\n \n Item's index5." )
294+ .row ("index6" , "Integer" , "true" ,
295+ "**Deprecated.**\n \n Item's index6." ));
296+
297+ new JacksonResponseFieldSnippet ().document (operationBuilder
298+ .attribute (HandlerMethod .class .getName (), handlerMethod )
299+ .attribute (ObjectMapper .class .getName (), mapper )
300+ .attribute (JavadocReader .class .getName (), javadocReader )
301+ .attribute (ConstraintReader .class .getName (), constraintReader )
302+ .build ());
303+ }
304+
305+ @ Test
306+ public void comment () throws Exception {
307+ HandlerMethod handlerMethod = createHandlerMethod ("commentItem" );
308+ mockFieldComment (CommentedItem .class , "field" , "field" );
309+ mockFieldComment (CommentedItem .class , "field2" , "field 2" );
310+ mockFieldComment (CommentedItem .class , "field3" , "field 3" );
311+ mockMethodComment (CommentedItem .class , "getField3" , "method 3" ); // preferred
312+ mockMethodComment (CommentedItem .class , "getField4" , "method 4" );
313+
314+ this .snippets .expect (RESPONSE_FIELDS ).withContents (
315+ tableWithHeader ("Path" , "Type" , "Optional" , "Description" )
316+ .row ("field" , "String" , "true" , "Field." )
317+ .row ("field2" , "String" , "true" , "Field 2." )
318+ .row ("field3" , "String" , "true" , "Method 3." )
319+ .row ("field4" , "String" , "true" , "Method 4." ));
278320
279321 new JacksonResponseFieldSnippet ().document (operationBuilder
280322 .attribute (HandlerMethod .class .getName (), handlerMethod )
@@ -299,7 +341,17 @@ private void mockFieldComment(Class<?> type, String fieldName, String comment) {
299341 .thenReturn (comment );
300342 }
301343
302- private void mockDeprecated (Class <?> type , String fieldName , String comment ) {
344+ private void mockMethodComment (Class <?> type , String methodName , String comment ) {
345+ when (javadocReader .resolveMethodComment (type , methodName ))
346+ .thenReturn (comment );
347+ }
348+
349+ private void mockDeprecatedMethod (Class <?> type , String methodName , String comment ) {
350+ when (javadocReader .resolveMethodTag (type , methodName , "deprecated" ))
351+ .thenReturn (comment );
352+ }
353+
354+ private void mockDeprecatedField (Class <?> type , String fieldName , String comment ) {
303355 when (javadocReader .resolveFieldTag (type , fieldName , "deprecated" ))
304356 .thenReturn (comment );
305357 }
@@ -352,6 +404,10 @@ public String processItem() {
352404 public DeprecatedItem removeItem () {
353405 return null ;
354406 }
407+
408+ public CommentedItem commentItem () {
409+ return null ;
410+ }
355411 }
356412
357413 private static class Item {
@@ -367,8 +423,66 @@ public Item(String field1) {
367423 }
368424
369425 private static class DeprecatedItem {
426+ // dep. annot on field, no getter
370427 @ Deprecated
371428 private int index ;
429+
430+ // dep. Javadoc on field, no getter
431+ private int index2 ;
432+
433+ // field, dep. annot on getter
434+ private int index3 ;
435+
436+ // field, dep. Javadoc on getter
437+ private int index4 ;
438+
439+ // dep. annot on field, getter
440+ @ Deprecated
441+ private int index5 ;
442+
443+ @ Deprecated
444+ public int getIndex3 () {
445+ return index3 ;
446+ }
447+
448+ // deprecation Javadoc
449+ public int getIndex4 () {
450+ return index4 ;
451+ }
452+
453+ public int getIndex5 () {
454+ return index5 ;
455+ }
456+
457+ // no real field
458+ @ Deprecated
459+ public int getIndex6 () {
460+ return 0 ;
461+ }
462+ }
463+
464+ private static class CommentedItem {
465+ // comment on field only, no getter
466+ private String field ;
467+
468+ // comment on field, empty on getter
469+ private String field2 ;
470+
471+ // comment on field and getter
472+ private String field3 ;
473+
474+ public String getField2 () {
475+ return field2 ;
476+ }
477+
478+ public String getField3 () {
479+ return field3 ;
480+ }
481+
482+ // comment only on getter
483+ public String getField4 () {
484+ return null ;
485+ }
372486 }
373487
374488 private static class ProcessingResponse {
0 commit comments