Java Code Examples for com.thoughtworks.qdox.model.JavaMethod#getTagByName()

The following examples show how to use com.thoughtworks.qdox.model.JavaMethod#getTagByName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SpringMVCRequestMappingHandler.java    From smart-doc with Apache License 2.0 4 votes vote down vote up
/**
 * handle spring request mapping
 *
 * @param serverUrl         server url
 * @param controllerBaseUrl spring mvc controller base url
 * @param method            JavaMethod
 * @return RequestMapping
 */
public RequestMapping handle(String serverUrl, String controllerBaseUrl, JavaMethod method) {
    List<JavaAnnotation> annotations = method.getAnnotations();
    String url;
    String methodType = null;
    String shortUrl = null;
    String mediaType = null;

    boolean deprecated = false;
    for (JavaAnnotation annotation : annotations) {
        String annotationName = annotation.getType().getName();
        Object produces = annotation.getNamedParameter("produces");
        if (produces != null) {
            mediaType = produces.toString();
        }
        if ("Deprecated".equals(annotationName)) {
            deprecated = true;
        }
        if (SpringMvcAnnotations.REQUEST_MAPPING.equals(annotationName) || DocGlobalConstants.REQUEST_MAPPING_FULLY.equals(annotationName)) {
            shortUrl = DocUtil.handleMappingValue(annotation);
            Object nameParam = annotation.getNamedParameter("method");
            if (null != nameParam) {
                methodType = nameParam.toString();
                methodType = DocUtil.handleHttpMethod(methodType);
            } else {
                methodType = Methods.GET.getValue();
            }
        } else if (SpringMvcAnnotations.GET_MAPPING.equals(annotationName) || DocGlobalConstants.GET_MAPPING_FULLY.equals(annotationName)) {
            shortUrl = DocUtil.handleMappingValue(annotation);
            methodType = Methods.GET.getValue();
        } else if (SpringMvcAnnotations.POST_MAPPING.equals(annotationName) || DocGlobalConstants.POST_MAPPING_FULLY.equals(annotationName)) {
            shortUrl = DocUtil.handleMappingValue(annotation);
            methodType = Methods.POST.getValue();
        } else if (SpringMvcAnnotations.PUT_MAPPING.equals(annotationName) || DocGlobalConstants.PUT_MAPPING_FULLY.equals(annotationName)) {
            shortUrl = DocUtil.handleMappingValue(annotation);
            methodType = Methods.PUT.getValue();

        } else if (SpringMvcAnnotations.PATCH_MAPPING.equals(annotationName) || DocGlobalConstants.PATCH_MAPPING_FULLY.equals(annotationName)) {
            shortUrl = DocUtil.handleMappingValue(annotation);
            methodType = Methods.PATCH.getValue();

        } else if (SpringMvcAnnotations.DELETE_MAPPING.equals(annotationName) || DocGlobalConstants.DELETE_MAPPING_FULLY.equals(annotationName)) {
            shortUrl = DocUtil.handleMappingValue(annotation);
            methodType = Methods.DELETE.getValue();

        }
    }
    if (shortUrl != null) {
        if (null != method.getTagByName(IGNORE)) {
            return null;
        }
        shortUrl = StringUtil.removeQuotes(shortUrl);
        String[] urls = shortUrl.split(",");
        if (urls.length > 1) {
            url = DocUrlUtil.getMvcUrls(serverUrl, controllerBaseUrl, Arrays.asList(urls));
            shortUrl = DocUrlUtil.getMvcUrls("", controllerBaseUrl, Arrays.asList(urls));
        } else {
            url = UrlUtil.simplifyUrl(serverUrl + "/" + controllerBaseUrl + "/" + shortUrl);
            shortUrl = UrlUtil.simplifyUrl("/" + controllerBaseUrl + "/" + shortUrl);
        }
        return RequestMapping.builder().setMediaType(mediaType).setMethodType(methodType)
                .setUrl(url).setShortUrl(shortUrl).setDeprecated(deprecated);
    }
    return null;
}
 
Example 2
Source File: SwaggerGenerator.java    From onos with Apache License 2.0 4 votes vote down vote up
private void processRestMethod(JavaMethod javaMethod, String method,
                               Map<String, ObjectNode> pathMap,
                               String resourcePath, ArrayNode tagArray,
                               ObjectNode definitions, File srcDirectory) {
    String fullPath = resourcePath, consumes = "", produces = "",
            comment = javaMethod.getComment();
    DocletTag tag = javaMethod.getTagByName("onos.rsModel");
    for (JavaAnnotation annotation : javaMethod.getAnnotations()) {
        String name = annotation.getType().getName();
        if (name.equals(PATH)) {
            fullPath = resourcePath + "/" + getPath(annotation);
            fullPath = fullPath.replaceFirst("^//", "/");
        }
        if (name.equals(CONSUMES)) {
            consumes = getIOType(annotation);
        }
        if (name.equals(PRODUCES)) {
            produces = getIOType(annotation);
        }
    }
    ObjectNode methodNode = mapper.createObjectNode();
    methodNode.set("tags", tagArray);

    addSummaryDescriptions(methodNode, comment);
    addJsonSchemaDefinition(srcDirectory, definitions, tag);

    processParameters(javaMethod, methodNode, method, tag);

    processConsumesProduces(methodNode, "consumes", consumes);
    processConsumesProduces(methodNode, "produces", produces);
    if (tag == null || !(tag.getParameters().size() > 1)) {
        addResponses(javaMethod, methodNode, tag, false);
    } else {
        addResponses(javaMethod, methodNode, tag, true);
    }

    ObjectNode operations = pathMap.get(fullPath);
    if (operations == null) {
        operations = mapper.createObjectNode();
        operations.set(method, methodNode);
        pathMap.put(fullPath, operations);
    } else {
        operations.set(method, methodNode);
    }
}
 
Example 3
Source File: OnosSwaggerMojo.java    From onos with Apache License 2.0 4 votes vote down vote up
private void processRestMethod(JavaMethod javaMethod, String method,
                               Map<String, ObjectNode> pathMap,
                               String resourcePath, ArrayNode tagArray, ObjectNode definitions) {
    String fullPath = resourcePath, consumes = "", produces = "",
            comment = javaMethod.getComment();
    DocletTag tag = javaMethod.getTagByName("onos.rsModel");
    for (JavaAnnotation annotation : javaMethod.getAnnotations()) {
        String name = annotation.getType().getName();
        if (name.equals(PATH)) {
            fullPath = resourcePath + "/" + getPath(annotation);
            fullPath = fullPath.replaceFirst("^//", "/");
        }
        if (name.equals(CONSUMES)) {
            consumes = getIOType(annotation);
        }
        if (name.equals(PRODUCES)) {
            produces = getIOType(annotation);
        }
    }
    ObjectNode methodNode = mapper.createObjectNode();
    methodNode.set("tags", tagArray);

    addSummaryDescriptions(methodNode, comment);
    addJsonSchemaDefinition(definitions, tag);

    processParameters(javaMethod, methodNode, method, tag);

    processConsumesProduces(methodNode, "consumes", consumes);
    processConsumesProduces(methodNode, "produces", produces);
    if (tag == null || ((method.toLowerCase().equals("post") || method.toLowerCase().equals("put"))
            && !(tag.getParameters().size() > 1))) {
        addResponses(methodNode, tag, false);
    } else {
        addResponses(methodNode, tag, true);
    }

    ObjectNode operations = pathMap.get(fullPath);
    if (operations == null) {
        operations = mapper.createObjectNode();
        operations.set(method, methodNode);
        pathMap.put(fullPath, operations);
    } else {
        operations.set(method, methodNode);
    }
}