Skip to content

Instantly share code, notes, and snippets.

@dwelch2344
Created May 14, 2013 14:30
Show Gist options
  • Select an option

  • Save dwelch2344/5576391 to your computer and use it in GitHub Desktop.

Select an option

Save dwelch2344/5576391 to your computer and use it in GitHub Desktop.
Quick little POC for self-documenting the controller layer in a SpringMVC app
public class ApiDocExample{
@Inject
private RequestMappingHandlerMapping mapping;
public void foobar(){
Map<RequestMappingInfo, HandlerMethod> map = mapping.getHandlerMethods();
for( RequestMappingInfo info : map.keySet() ){
HandlerMethod method = map.get(info);
ApiOperation annotation = method.getMethodAnnotation(ApiOperation.class);
if( annotation != null ){
String className = method.getBeanType().getSimpleName();
Set<String> patterns = info.getPatternsCondition().getPatterns();
MethodParameter rt = method.getReturnType();
String rtc = rt.getParameterType().getSimpleName();
System.out.println( rtc + " " + className + "(" + patterns + ")");
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment