br.com.anteros.jsondoc.springmvc.scanner.builder.SpringVerbBuilder Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of Anteros-JSONDoc-SpringMVC Show documentation
Show all versions of Anteros-JSONDoc-SpringMVC Show documentation
The support for Spring MVC of the jsondoc project.
The newest version!
package br.com.anteros.jsondoc.springmvc.scanner.builder;
import java.lang.reflect.Method;
import java.util.LinkedHashSet;
import java.util.Set;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import br.com.anteros.jsondoc.core.pojo.ApiVerb;
public class SpringVerbBuilder {
/**
* From Spring's documentation: When [RequestMapping method is] used at the type level, all method-level mappings inherit this HTTP method restriction
* @param method
* @param controller
* @return
*/
public static Set buildVerb(Method method) {
Set apiVerbs = new LinkedHashSet();
Class> controller = method.getDeclaringClass();
if(controller.isAnnotationPresent(RequestMapping.class)) {
RequestMapping requestMapping = controller.getAnnotation(RequestMapping.class);
getApiVerbFromRequestMapping(apiVerbs, requestMapping);
}
if(method.isAnnotationPresent(RequestMapping.class)) {
RequestMapping requestMapping = method.getAnnotation(RequestMapping.class);
getApiVerbFromRequestMapping(apiVerbs, requestMapping);
}
if(apiVerbs.isEmpty()) {
apiVerbs.add(ApiVerb.GET);
}
return apiVerbs;
}
private static void getApiVerbFromRequestMapping(Set apiVerbs, RequestMapping requestMapping) {
if(requestMapping.method().length > 0) {
for (RequestMethod requestMethod : requestMapping.method()) {
apiVerbs.add(ApiVerb.valueOf(requestMethod.name()));
}
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy