Search in sources :

Example 11 with ApiField

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

the class MethodProcessor method getApiParameters.

public static List<ApiField> getApiParameters(MethodDoc method, String parameterAnnotation) {
    List<ApiField> apiParams = Lists.newArrayList();
    for (Parameter parameter : method.parameters()) {
        if (AnnotationUtils.hasAnnotation(parameter, parameterAnnotation)) {
            ApiField apiParam = new ApiField();
            apiParam.name = AnnotationUtils.getAnnotationValue(parameter, parameterAnnotation, KnownAnnotations.Value_Element, parameter.name());
            if (parameter.type().asClassDoc() != null) {
                apiParam.type = JaxbClassProcessor.convertToApiClass(parameter.type().asClassDoc());
            }
            for (ParamTag paramTag : method.paramTags()) {
                if (paramTag.parameterName().equals(parameter.name())) {
                    apiParam.description = paramTag.parameterComment();
                }
            }
            apiParams.add(apiParam);
        }
    }
    return apiParams;
}
Also used : ParamTag(com.sun.javadoc.ParamTag) Parameter(com.sun.javadoc.Parameter) ApiField(com.emc.apidocs.model.ApiField)

Example 12 with ApiField

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

the class ApiClassDiffTests method newField.

private static ApiField newField(String name) {
    ApiField field = new ApiField();
    field.name = name;
    field.primitiveType = "String";
    return field;
}
Also used : ApiField(com.emc.apidocs.model.ApiField)

Example 13 with ApiField

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

the class ApiPrimitiveMaker method makeInput.

/**
 * Make the Input parameter fields and the input parameter array for this
 * primitive
 *
 * @param method
 *            ApiMethod that is used to generate the primitive
 * @param requestFields
 *            The fields built from the request
 *
 * @return the List of input fields
 */
private static Iterable<FieldSpec> makeInput(final ApiMethod method, ImmutableMap<String, FieldSpec> requestFields) {
    final ImmutableList.Builder<FieldSpec> builder = ImmutableList.<FieldSpec>builder();
    final ImmutableList.Builder<String> path_parameters = new ImmutableList.Builder<String>();
    final ImmutableList.Builder<String> query_parameters = new ImmutableList.Builder<String>();
    final ImmutableList.Builder<String> body_parameters = new ImmutableList.Builder<String>();
    final ParameterFieldName.Input name = new ParameterFieldName.Input();
    body_parameters.addAll(requestFields.keySet());
    builder.addAll(requestFields.values());
    for (ApiField pathParameter : method.pathParameters) {
        FieldSpec param = makeInputParameter(name, pathParameter, true);
        path_parameters.add(param.name);
        builder.add(param);
    }
    for (ApiField queryParameter : method.queryParameters) {
        FieldSpec param = makeInputParameter(name, queryParameter, queryParameter.required);
        query_parameters.add(param.name);
        builder.add(param);
    }
    builder.add(FieldSpec.builder(ParameterizedTypeName.get(ImmutableList.class, InputParameter.class), "PATH_INPUT").addModifiers(Modifier.PRIVATE, Modifier.FINAL, Modifier.STATIC).initializer("new $T().add($L).build()", ParameterizedTypeName.get(ImmutableList.Builder.class, InputParameter.class), Joiner.on(",").join(path_parameters.build())).build());
    builder.add(FieldSpec.builder(ParameterizedTypeName.get(ImmutableList.class, InputParameter.class), "QUERY_INPUT").addModifiers(Modifier.PRIVATE, Modifier.FINAL, Modifier.STATIC).initializer("new $T().add($L).build()", ParameterizedTypeName.get(ImmutableList.Builder.class, InputParameter.class), Joiner.on(",").join(query_parameters.build())).build());
    builder.add(FieldSpec.builder(ParameterizedTypeName.get(ImmutableList.class, InputParameter.class), "BODY_INPUT").addModifiers(Modifier.PRIVATE, Modifier.FINAL, Modifier.STATIC).initializer("new $T().add($L).build()", ParameterizedTypeName.get(ImmutableList.Builder.class, InputParameter.class), Joiner.on(",").join(body_parameters.build())).build());
    return builder.add(FieldSpec.builder(ParameterizedTypeName.get(ClassName.get(Map.class), ClassName.get(String.class), ParameterizedTypeName.get(List.class, InputParameter.class)), "INPUT").addModifiers(Modifier.PRIVATE, Modifier.FINAL, Modifier.STATIC).initializer("$T.of($T.INPUT_PARAMS, $L, $T.PATH_PARAMS, $L, $T.QUERY_PARAMS, $L)", ImmutableMap.class, CustomServicesConstants.class, "BODY_INPUT", CustomServicesConstants.class, "PATH_INPUT", CustomServicesConstants.class, "QUERY_INPUT").build()).build();
}
Also used : CustomServicesConstants(com.emc.storageos.primitives.CustomServicesConstants) ImmutableList(com.google.common.collect.ImmutableList) Builder(com.google.common.collect.ImmutableList.Builder) FieldSpec(com.squareup.javapoet.FieldSpec) ImmutableMap(com.google.common.collect.ImmutableMap) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) ApiField(com.emc.apidocs.model.ApiField) InputParameter(com.emc.storageos.primitives.input.InputParameter) BasicInputParameter(com.emc.storageos.primitives.input.BasicInputParameter)

Example 14 with ApiField

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

the class ApiPrimitiveMaker method makeBody.

private static String makeBody(final ParameterFieldName.Request fieldName, final String parameterNamePrefix, final ApiClass input, final ImmutableMap.Builder<String, FieldSpec> requestFields) {
    // throw an exception
    if (null == input.fields) {
        throw new RuntimeException("input with no fields!!");
    }
    final StringBuilder body = new StringBuilder();
    String separator = "{\n";
    if (null != input.fields) {
        for (ApiField field : input.fields) {
            final String prefix;
            final String suffix;
            final String name;
            if (field.collection) {
                prefix = "[";
                suffix = "]";
            } else {
                prefix = "";
                suffix = "";
            }
            if (null != field.wrapperName && !field.wrapperName.isEmpty()) {
                name = field.wrapperName;
            } else {
                name = field.name;
            }
            body.append(separator + "\"" + name + "\": " + prefix);
            final String parameterName = makeInputParameterName(parameterNamePrefix, field);
            if (field.isPrimitive()) {
                final FieldSpec param = makeInputParameter(fieldName, parameterName, field, field.required);
                requestFields.put(param.name, param);
                body.append("$" + parameterName);
            } else {
                body.append(makeBody(fieldName, parameterName, field.type, requestFields));
            }
            body.append(suffix);
            separator = ",\n";
        }
    }
    if (body.length() > 0) {
        body.append("\n}");
    }
    // We don't use attributes in the ViPR API
    if (null != input.attributes && input.attributes.size() > 0) {
        throw new RuntimeException("Attributes not supported");
    }
    return body.toString();
}
Also used : ApiField(com.emc.apidocs.model.ApiField) FieldSpec(com.squareup.javapoet.FieldSpec)

Example 15 with ApiField

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

the class Utils method generateXml.

private static void generateXml(ApiField element, int level, StringBuffer response) {
    if (!element.wrapperName.equals("")) {
        // Output <WRAPPER>
        response.append(repeatSpace(level));
        response.append(XML_START).append(element.wrapperName).append(XML_END).append(NEW_LINE);
        level = level + 1;
    }
    if (!element.hasChildElements()) {
        // Output as <name></name>
        response.append(repeatSpace(level));
        response.append(XML_START).append(element.name);
        addAttributes(element.type, response);
        response.append(XML_END);
        response.append(XML_START).append("/").append(element.name).append(XML_END).append(NEW_LINE);
    } else {
        response.append(repeatSpace(level));
        response.append(XML_START).append(element.name).append(XML_END).append(NEW_LINE);
        addAttributes(element.type, response);
        for (ApiField field : element.type.fields) {
            generateXml(field, level + 1, response);
        }
        response.append(repeatSpace(level));
        response.append(XML_START).append("/").append(element.name).append(XML_END).append(NEW_LINE);
    }
    if (!element.wrapperName.equals("")) {
        // OUTPUT </WRAPPER>
        level = level - 1;
        response.append(repeatSpace(level));
        response.append(XML_START).append("/").append(element.wrapperName).append(XML_END).append(NEW_LINE);
    }
}
Also used : ApiField(com.emc.apidocs.model.ApiField)

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