Skip to content

Commit cabcd4f

Browse files
committed
autogenerate resource id if not present
1 parent 3bf2c73 commit cabcd4f

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

src/main/java/org/restdoc/server/impl/RestDocGenerator.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,12 @@ private void addResourceMethod(final String basepath, final Method method) {
182182
path += "{?" + string + "}";
183183
}
184184

185-
final String id = docAnnotation.id();
185+
final String id;
186+
if ((docAnnotation.id() != null) && !docAnnotation.id().isEmpty()) {
187+
id = docAnnotation.id();
188+
} else {
189+
id = method.getName();
190+
}
186191
final String resourceDescription = docAnnotation.resourceDescription();
187192

188193
final String methodDescription = docAnnotation.methodDescription();

src/main/java/org/restdoc/server/impl/annotations/RestDoc.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
/**
2727
* @return the description of the resource method
2828
*/
29-
String methodDescription();
29+
String methodDescription() default "";
3030

3131
/**
3232
* @return the id of the resource

src/test/java/org/restdoc/server/impl/MyRSBean.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public String getMessageList() {
7171
*/
7272
@GET
7373
@Path(".json")
74-
@RestDoc(id = "messageList2", resourceDescription = "A list of messages", methodDescription = "List all messages")
74+
@RestDoc(resourceDescription = "A list of messages", methodDescription = "List all messages")
7575
@RestDocResponse(headers = {@RestDocHeader(name = "X-Call", description = "Remaining calls", required = false)})
7676
@RestDocReturnCodes({@RestDocReturnCode(code = "200", description = "All went well"), @RestDocReturnCode(code = "403", description = "Access not allowed")})
7777
@Produces("application/json")

0 commit comments

Comments
 (0)