Java Code Examples for com.thoughtworks.qdox.model.JavaParameter#getName()
The following examples show how to use
com.thoughtworks.qdox.model.JavaParameter#getName() .
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: SpringMVCRequestHeaderHandler.java From smart-doc with Apache License 2.0 | 4 votes |
/** * handle Spring MVC Request Header * * @param method JavaMethod * @return list of ApiReqHeader */ public List<ApiReqHeader> handle(JavaMethod method) { List<ApiReqHeader> apiReqHeaders = new ArrayList<>(); for (JavaParameter javaParameter : method.getParameters()) { List<JavaAnnotation> javaAnnotations = javaParameter.getAnnotations(); String className = method.getDeclaringClass().getCanonicalName(); Map<String, String> paramMap = DocUtil.getParamsComments(method, DocTags.PARAM, className); String paramName = javaParameter.getName(); ApiReqHeader apiReqHeader; for (JavaAnnotation annotation : javaAnnotations) { String annotationName = annotation.getType().getValue(); if (SpringMvcAnnotations.REQUEST_HERDER.equals(annotationName)) { apiReqHeader = new ApiReqHeader(); Map<String, Object> requestHeaderMap = annotation.getNamedParameterMap(); if (requestHeaderMap.get(DocAnnotationConstants.VALUE_PROP) != null) { apiReqHeader.setName(StringUtil.removeQuotes((String) requestHeaderMap.get(DocAnnotationConstants.VALUE_PROP))); } else { apiReqHeader.setName(paramName); } StringBuilder desc = new StringBuilder(); String comments = paramMap.get(paramName); desc.append(comments); if (requestHeaderMap.get(DocAnnotationConstants.DEFAULT_VALUE_PROP) != null) { apiReqHeader.setValue(StringUtil.removeQuotes((String) requestHeaderMap.get(DocAnnotationConstants.DEFAULT_VALUE_PROP))); desc.append("(defaultValue: ") .append(StringUtil.removeQuotes((String) requestHeaderMap.get(DocAnnotationConstants.DEFAULT_VALUE_PROP))) .append(")"); } apiReqHeader.setDesc(desc.toString()); if (requestHeaderMap.get(DocAnnotationConstants.REQUIRED_PROP) != null) { apiReqHeader.setRequired(!Boolean.FALSE.toString().equals(requestHeaderMap.get(DocAnnotationConstants.REQUIRED_PROP))); } else { apiReqHeader.setRequired(true); } String typeName = javaParameter.getType().getValue().toLowerCase(); apiReqHeader.setType(DocClassUtil.processTypeNameForParams(typeName)); apiReqHeaders.add(apiReqHeader); break; } } } return apiReqHeaders; }
Example 2
Source File: SwaggerGenerator.java From onos with Apache License 2.0 | 4 votes |
private void processParameters(JavaMethod javaMethod, ObjectNode methodNode, String method, DocletTag tag) { ArrayNode parameters = mapper.createArrayNode(); methodNode.set("parameters", parameters); boolean required = true; for (JavaParameter javaParameter : javaMethod.getParameters()) { ObjectNode individualParameterNode = mapper.createObjectNode(); Optional<JavaAnnotation> optional = javaParameter.getAnnotations().stream().filter( annotation -> annotation.getType().getName().equals(PATH_PARAM) || annotation.getType().getName().equals(QUERY_PARAM)).findAny(); JavaAnnotation pathType = optional.orElse(null); String annotationName = javaParameter.getName(); if (pathType != null) { //the parameter is a path or query parameter individualParameterNode.put("name", pathType.getNamedParameter("value") .toString().replace("\"", "")); if (pathType.getType().getName().equals(PATH_PARAM)) { individualParameterNode.put("in", "path"); } else if (pathType.getType().getName().equals(QUERY_PARAM)) { individualParameterNode.put("in", "query"); } individualParameterNode.put("type", getType(javaParameter.getType())); } else { // the parameter is a body parameter individualParameterNode.put("name", annotationName); individualParameterNode.put("in", "body"); // Adds the reference to the Json model for the input // that goes in the post or put operation if (tag != null && (method.toLowerCase().equals("post") || method.toLowerCase().equals("put"))) { ObjectNode schema = mapper.createObjectNode(); tag.getParameters().stream().forEach(param -> { schema.put("$ref", "#/definitions/" + param); }); individualParameterNode.set("schema", schema); } } for (DocletTag p : javaMethod.getTagsByName("param")) { if (p.getValue().contains(annotationName)) { String description = ""; if (p.getValue().split(" ", 2).length >= 2) { description = p.getValue().split(" ", 2)[1].trim(); if (description.contains("optional")) { required = false; } } else { throw new RuntimeException(String.format("No description for parameter \"%s\" in " + "method \"%s\" in %s (line %d)", p.getValue(), javaMethod.getName(), javaMethod.getDeclaringClass().getName(), javaMethod.getLineNumber())); } individualParameterNode.put("description", description); } } individualParameterNode.put("required", required); parameters.add(individualParameterNode); } }
Example 3
Source File: OnosSwaggerMojo.java From onos with Apache License 2.0 | 4 votes |
private void processParameters(JavaMethod javaMethod, ObjectNode methodNode, String method, DocletTag tag) { ArrayNode parameters = mapper.createArrayNode(); methodNode.set("parameters", parameters); boolean required = true; for (JavaParameter javaParameter : javaMethod.getParameters()) { ObjectNode individualParameterNode = mapper.createObjectNode(); Optional<JavaAnnotation> optional = javaParameter.getAnnotations().stream().filter( annotation -> annotation.getType().getName().equals(PATH_PARAM) || annotation.getType().getName().equals(QUERY_PARAM)).findAny(); JavaAnnotation pathType = optional.orElse(null); String annotationName = javaParameter.getName(); if (pathType != null) { //the parameter is a path or query parameter individualParameterNode.put("name", pathType.getNamedParameter("value") .toString().replace("\"", "")); if (pathType.getType().getName().equals(PATH_PARAM)) { individualParameterNode.put("in", "path"); } else if (pathType.getType().getName().equals(QUERY_PARAM)) { individualParameterNode.put("in", "query"); } individualParameterNode.put("type", getType(javaParameter.getType())); } else { // the parameter is a body parameter individualParameterNode.put("name", annotationName); individualParameterNode.put("in", "body"); // Adds the reference to the Json model for the input // that goes in the post or put operation if (tag != null && (method.toLowerCase().equals("post") || method.toLowerCase().equals("put"))) { ObjectNode schema = mapper.createObjectNode(); tag.getParameters().forEach(param -> { schema.put("$ref", "#/definitions/" + param); }); individualParameterNode.set("schema", schema); } } for (DocletTag p : javaMethod.getTagsByName("param")) { if (p.getValue().contains(annotationName)) { String description = ""; if (p.getValue().split(" ", 2).length >= 2) { description = p.getValue().split(" ", 2)[1].trim(); if (description.contains("optional")) { required = false; } } else { getLog().warn(String.format( "No description for parameter \"%s\" in " + "method \"%s\" in %s (line %d)", p.getValue(), javaMethod.getName(), javaMethod.getDeclaringClass().getName(), javaMethod.getLineNumber())); } individualParameterNode.put("description", description); } } individualParameterNode.put("required", required); parameters.add(individualParameterNode); } }