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;
}
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;
}
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();
}
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();
}
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);
}
}
Aggregations