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 }
/** * Parses a method parameter type definition * * @param docParameter * @param paramComment * @return */ protected static Param ParseParameter(Parameter docParameter, ParamTag paramComment) { assert (docParameter != null); Param xmlParameter = new Param(); xmlParameter.name = docParameter.name(); xmlParameter.type = ParseType(docParameter.type()); if (paramComment != null) { xmlParameter.comment = paramComment.parameterComment(); } xmlParameter.annotationInstances = ParseAnnotationInstances(docParameter.annotations(), docParameter.typeName()); return xmlParameter; }
private static List<DocParameter> generateParameters(final MethodDoc methodDoc) { List<DocParameter> paramsList = new LinkedList<DocParameter>(); for (Parameter parameter : methodDoc.parameters()) { String name = parameter.name(); DocParameter docParameter = new DocParameter(name, parameter.type()); docParameter.setAnnotations(generateAnnotations(parameter.annotations())); Map<String, String> paramTagsComments = Utils.getParamTagsComments(methodDoc); String description = paramTagsComments.get(name); if (description == null) { logger.warning( "Missing description of parameter " + name + " of method " + methodDoc.name()); description = ""; } docParameter.setDescription(description); paramsList.add(docParameter); } return paramsList; }
public static AnnotationDesc findAnnotation( final Parameter parameter, final Class<?>... soughtAnnotations) { return findAnnotation(parameter.annotations(), soughtAnnotations); }