Search in sources :

Example 6 with ApiField

use of com.emc.apidocs.model.ApiField in project coprhd-controller by CoprHD.

the class ApiPrimitiveMaker method makeOutput.

/**
 * Make a list of output fields for this primitive
 *
 * @param method
 *            the ApiMethod that is used to generate the primitive
 *
 * @return the list of output fields
 */
private static Iterable<FieldSpec> makeOutput(final ApiMethod method) {
    final ImmutableList.Builder<FieldSpec> builder = ImmutableList.<FieldSpec>builder();
    final ImmutableList.Builder<String> parameters = new ImmutableList.Builder<String>();
    final ParameterFieldName.Output fieldName = new ParameterFieldName.Output();
    if (null != method.output && null != method.output.fields) {
        builder.add(makeStringConstant("RESPONSE", method.getFqReturnType()));
        for (final ApiField field : method.output.fields) {
            final ImmutableList<FieldSpec> responseParameters = makeResponseParameters(fieldName, method.output.name, field);
            for (final FieldSpec responseParameter : responseParameters) {
                parameters.add(responseParameter.name);
            }
            builder.addAll(responseParameters);
        }
    } else {
        builder.add(makeStringConstant("RESPONSE", ""));
    }
    return builder.add(FieldSpec.builder(ParameterizedTypeName.get(List.class, OutputParameter.class), "OUTPUT").addModifiers(Modifier.PRIVATE, Modifier.FINAL, Modifier.STATIC).initializer("new $T().add($L).build()", ParameterizedTypeName.get(ImmutableList.Builder.class, OutputParameter.class), Joiner.on(",").join(parameters.build())).build()).build();
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) Builder(com.google.common.collect.ImmutableList.Builder) FieldSpec(com.squareup.javapoet.FieldSpec) ApiField(com.emc.apidocs.model.ApiField)

Example 7 with ApiField

use of com.emc.apidocs.model.ApiField in project coprhd-controller by CoprHD.

the class PlayRoutesParser method addParameterInfo.

private static void addParameterInfo(String javadocText, ApiMethod method) {
    Matcher paramMatcher = paramPattern.matcher(javadocText);
    while (paramMatcher.find()) {
        if (paramMatcher.group(1).equals("response")) {
            method.responseDescription = paramMatcher.group(2);
        } else {
            ApiField field = new ApiField();
            field.name = paramMatcher.group(1);
            field.description = paramMatcher.group(2);
            if (method.path.contains("{" + field.name + "}")) {
                method.pathParameters.add(field);
            } else {
                method.queryParameters.add(field);
            }
        }
    }
}
Also used : Matcher(java.util.regex.Matcher) ApiField(com.emc.apidocs.model.ApiField)

Example 8 with ApiField

use of com.emc.apidocs.model.ApiField in project coprhd-controller by CoprHD.

the class Utils method generateXml.

/**
 * Returns an XML Payload format for the given Api Class
 */
public static String generateXml(ApiClass element) {
    StringBuffer buffer = new StringBuffer(XML_START + element.name + XML_END + "\n");
    for (ApiField field : element.fields) {
        generateXml(field, 1, buffer);
    }
    buffer.append(XML_START).append("/").append(element.name).append(XML_END);
    return buffer.toString();
}
Also used : ApiField(com.emc.apidocs.model.ApiField)

Example 9 with ApiField

use of com.emc.apidocs.model.ApiField in project coprhd-controller by CoprHD.

the class Utils method dumpAsXml.

public static void dumpAsXml(ApiClass apiClass, int level) {
    printTabs(level);
    System.out.print("<" + apiClass.name);
    for (ApiField attribute : apiClass.attributes) {
        System.out.print(" " + attribute.name + "=\"\"");
    }
    if (apiClass.fields.isEmpty()) {
        System.out.println("/>");
    } else {
        System.out.println(">");
    }
    for (ApiField element : apiClass.fields) {
        if (element.isPrimitive()) {
            printTabs(level + 1);
            System.out.println("<" + element.name + "/>       " + element.primitiveType + "  [" + element.description + "]");
        } else {
            printTabs(level + 1);
            System.out.println("<" + element.name + ">      " + element.description + (element.collection ? "MANY" : ""));
            dumpAsXml(element.type, level + 2);
            printTabs(level + 1);
            System.out.println("</" + element.name + ">");
        }
    }
    if (!apiClass.fields.isEmpty()) {
        printTabs(level);
        System.out.println("</" + apiClass.name + ">");
    }
}
Also used : ApiField(com.emc.apidocs.model.ApiField)

Example 10 with ApiField

use of com.emc.apidocs.model.ApiField in project coprhd-controller by CoprHD.

the class JaxbClassProcessor method convertToApiClass.

public static ApiClass convertToApiClass(ClassDoc classDoc) {
    ApiClass classDescriptor = new ApiClass();
    classDescriptor.name = AnnotationUtils.getAnnotationValue(classDoc, KnownAnnotations.XMLElement_Annotation, "name", null);
    if (classDescriptor.name == null) {
        classDescriptor.name = AnnotationUtils.getAnnotationValue(classDoc, KnownAnnotations.XMLRoot_Annotation, "name", classDoc.simpleTypeName());
    }
    ClassDoc currentClass = classDoc;
    while (currentClass.qualifiedName().startsWith("com.emc")) {
        String xmlAccessType = getXmlAccessType(classDoc);
        // Read Fields
        for (FieldDoc field : currentClass.fields(false)) {
            if (shouldIncludeField(field, xmlAccessType)) {
                ApiField fieldDescriptor = new ApiField();
                fieldDescriptor.name = AnnotationUtils.getAnnotationValue(field, KnownAnnotations.XMLElement_Annotation, "name", field.name());
                fieldDescriptor.required = AnnotationUtils.getAnnotationValue(field, KnownAnnotations.XMLElement_Annotation, "required", false);
                fieldDescriptor.description = field.commentText();
                if (AnnotationUtils.hasAnnotation(field, KnownAnnotations.XMLElementWrapper_Annotation)) {
                    fieldDescriptor.wrapperName = AnnotationUtils.getAnnotationValue(field, KnownAnnotations.XMLElementWrapper_Annotation, "name", Utils.lowerCaseFirstChar(field.name()));
                }
                addFieldType(field.type(), fieldDescriptor);
                addValidValues(field, fieldDescriptor);
                classDescriptor.addField(fieldDescriptor);
            }
            if (AnnotationUtils.hasAnnotation(field, KnownAnnotations.XMLAttribute_Annotation)) {
                ApiField attributeDescriptor = new ApiField();
                attributeDescriptor.name = AnnotationUtils.getAnnotationValue(field, KnownAnnotations.XMLAttribute_Annotation, "name", field.name());
                attributeDescriptor.required = AnnotationUtils.getAnnotationValue(field, KnownAnnotations.XMLAttribute_Annotation, "required", false);
                attributeDescriptor.description = field.commentText();
                addFieldType(field.type(), attributeDescriptor);
                addValidValues(field, attributeDescriptor);
                classDescriptor.addAttribute(attributeDescriptor);
            }
        }
        // Read Public Property Methods
        for (MethodDoc method : currentClass.methods()) {
            if (shouldIncludeMethod(method, xmlAccessType, currentClass)) {
                ApiField methodDescriptor = new ApiField();
                final String defaultName = method.name().startsWith("get") ? Utils.lowerCaseFirstChar(method.name().substring(3)) : method.name();
                final MemberDoc member = findJAXBAnnotatedMember(method);
                if (null == member) {
                    methodDescriptor.name = defaultName;
                    methodDescriptor.required = false;
                } else {
                    methodDescriptor.name = AnnotationUtils.getAnnotationValue(member, KnownAnnotations.XMLElement_Annotation, "name", defaultName);
                    methodDescriptor.required = AnnotationUtils.getAnnotationValue(member, KnownAnnotations.XMLElement_Annotation, "required", false);
                    if (AnnotationUtils.hasAnnotation(member, KnownAnnotations.XMLElementWrapper_Annotation)) {
                        methodDescriptor.wrapperName = AnnotationUtils.getAnnotationValue(member, KnownAnnotations.XMLElementWrapper_Annotation, "name", null);
                        if (methodDescriptor.wrapperName == null) {
                            if (method.name().startsWith("get")) {
                                methodDescriptor.wrapperName = Utils.lowerCaseFirstChar(method.name().substring(3));
                            } else if (method.name().startsWith("is")) {
                                methodDescriptor.wrapperName = Utils.lowerCaseFirstChar(method.name().substring(2));
                            } else {
                                throw new RuntimeException("Unable to work out JavaBean property name " + method.qualifiedName());
                            }
                        }
                    }
                }
                methodDescriptor.description = method.commentText();
                // process JsonProperty annotation
                String jsonName = AnnotationUtils.getAnnotationValue(method, KnownAnnotations.JsonProperty_Annotation, KnownAnnotations.Value_Element, null);
                if (jsonName != null) {
                    methodDescriptor.jsonName = jsonName;
                }
                addFieldType(method.returnType(), methodDescriptor);
                addValidValues(method, methodDescriptor);
                classDescriptor.addField(methodDescriptor);
            }
        }
        currentClass = currentClass.superclass();
    }
    return classDescriptor;
}
Also used : FieldDoc(com.sun.javadoc.FieldDoc) MethodDoc(com.sun.javadoc.MethodDoc) ApiClass(com.emc.apidocs.model.ApiClass) MemberDoc(com.sun.javadoc.MemberDoc) ApiField(com.emc.apidocs.model.ApiField) ClassDoc(com.sun.javadoc.ClassDoc)

Aggregations

ApiField (com.emc.apidocs.model.ApiField)18 FieldSpec (com.squareup.javapoet.FieldSpec)4 ApiClass (com.emc.apidocs.model.ApiClass)3 ImmutableList (com.google.common.collect.ImmutableList)3 Builder (com.google.common.collect.ImmutableList.Builder)2 ParamTag (com.sun.javadoc.ParamTag)2 Matcher (java.util.regex.Matcher)2 CustomServicesConstants (com.emc.storageos.primitives.CustomServicesConstants)1 BasicInputParameter (com.emc.storageos.primitives.input.BasicInputParameter)1 InputParameter (com.emc.storageos.primitives.input.InputParameter)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ClassDoc (com.sun.javadoc.ClassDoc)1 FieldDoc (com.sun.javadoc.FieldDoc)1 MemberDoc (com.sun.javadoc.MemberDoc)1 MethodDoc (com.sun.javadoc.MethodDoc)1 Parameter (com.sun.javadoc.Parameter)1 Tag (com.sun.javadoc.Tag)1 List (java.util.List)1 Map (java.util.Map)1 Node (org.w3c.dom.Node)1