private static void processParameterAnnotations(MethodDoc methodDoc, MethodModel methodModel) { Parameter[] params = methodDoc.parameters(); // Start with false here. If we find the userId parameter this will be changed to true. methodModel.setIsAuthenticationRequired(false); Map<String, ParameterModel> paramMap = new HashMap<String, ParameterModel>(); if (params != null) { for (Parameter param : params) { AnnotationDesc[] paramAnnos = param.annotations(); if (paramAnnos != null) { for (AnnotationDesc ad : paramAnnos) { String qualifiedName = ad.annotationType().qualifiedName(); Map<String, Object> annotationMap = mapAnnotation(ad); System.out.println(annotationMap); if (RequestBody.class.getName().equals(qualifiedName)) { // Request body String schema = SchemaUtils.getEffectiveSchema(param.type().qualifiedTypeName()); if (schema != null) { Link link = new Link("${" + param.type().qualifiedTypeName() + "}", param.typeName()); methodModel.setRequestBody(link); } } else if (PathVariable.class.getName().equals(qualifiedName)) { // Path parameter ParameterModel paramModel = new ParameterModel(); paramModel.setName(param.name()); methodModel.addPathVariable(paramModel); paramMap.put(param.name(), paramModel); } else if (RequestParam.class.getName().equals(qualifiedName)) { // if this is the userId parameter then we do now show it, // rather it means this method requires authentication. if (AuthorizationConstants.USER_ID_PARAM.equals( annotationMap.get(REQUEST_PARAMETER_VALUE))) { methodModel.setIsAuthenticationRequired(true); } else { ParameterModel paramModel = new ParameterModel(); paramModel.setName(param.name()); paramModel.setIsOptional(!(isRequired(annotationMap))); methodModel.addParameter(paramModel); paramMap.put(param.name(), paramModel); } } } } } } ParamTag[] paramTags = methodDoc.paramTags(); if (paramTags != null) { for (ParamTag paramTag : paramTags) { ParameterModel paramModel = paramMap.get(paramTag.parameterName()); if (paramModel != null) { paramModel.setDescription(paramTag.parameterComment()); } } } System.out.println(methodModel); // Lookup the parameter descriptions }
private static Link extractResponseLink(MethodDoc methodDoc) { // this means there is a response body for this method. Type returnType = methodDoc.returnType(); String schema = SchemaUtils.getEffectiveSchema(returnType.qualifiedTypeName()); if (schema == null) return null; Link reponseLink = new Link(); StringBuilder builder = new StringBuilder(); builder.append("${").append(returnType.qualifiedTypeName()).append("}"); reponseLink.setHref(builder.toString()); reponseLink.setDisplay(returnType.simpleTypeName()); return reponseLink; }