All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.github.kangjianqun.fast.common.apidoc.parser.PlayControllerParser Maven / Gradle / Ivy

package io.github.kangjianqun.fast.common.apidoc.parser;

import com.github.javaparser.ast.body.MethodDeclaration;

import java.util.Arrays;

/**
 * user for play framework
 */
public class PlayControllerParser extends AbsControllerParser {

    @Override
    protected void afterHandleMethod(RequestNode requestNode, MethodDeclaration md) {
        PlayRoutesParser.RouteNode routeNode = PlayRoutesParser.INSTANCE.getRouteNode(getControllerFile(), md.getNameAsString());
        if (routeNode == null) return;

        String method = routeNode.method.toUpperCase();
        if ("*".equals(method)) {
            requestNode.setMethod(Arrays.asList(RequestMethod.GET.name(), RequestMethod.POST.name()));
        } else {
            requestNode.addMethod(RequestMethod.valueOf(method).name());
        }

        requestNode.setUrl(routeNode.routeUrl);

        md.getParameters().forEach(p -> {
            String paraName = p.getName().asString();
            ParamNode paramNode = requestNode.getParamNodeByName(paraName);
            if (paramNode != null) {
                p.getAnnotationByName("Required").ifPresent(r -> paramNode.setRequired(true));
            }
        });
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy