use of com.linkedin.restli.restspec.ParameterSchema in project rest.li by linkedin.
the class RequestBuilderSpecGenerator method generateActionParamBindingMethods.
private void generateActionParamBindingMethods(ParameterSchemaArray parameters, ActionBuilderSpec requestBuilderClass) {
for (ParameterSchema param : parameters) {
final String paramName = param.getName();
final ClassTemplateSpec typeClassSpec = classToTemplateSpec(param.getType());
final boolean isOptional = RestLiToolsUtils.isParameterOptional(param);
final String setMethodName = RestLiToolsUtils.nameCamelCase(paramName + "Param");
ActionParamBindingMethodSpec spec = new ActionParamBindingMethodSpec(setMethodName);
spec.setParamName(paramName);
spec.setOptional(isOptional);
spec.setArgType(typeClassSpec);
spec.setDoc(param.getDoc());
requestBuilderClass.addActionParamMethod(spec);
}
}
use of com.linkedin.restli.restspec.ParameterSchema in project rest.li by linkedin.
the class TestResourceSchemaToResourceSpecTranslator method compareActions.
private void compareActions(ResourceSpec actual, ResourceSpec expected, ActionSchemaArray actions) {
for (ActionSchema action : actions) {
ParameterSchemaArray parameters = action.getParameters();
DynamicRecordMetadata actualRequest = actual.getRequestMetadata(action.getName());
DynamicRecordMetadata expectedRequest = expected.getRequestMetadata(action.getName());
if (expectedRequest != null) {
Assert.assertNotNull(actualRequest);
Assert.assertEquals(actualRequest.getRecordDataSchema(), expectedRequest.getRecordDataSchema());
if (parameters != null) {
for (ParameterSchema parameter : parameters) {
compareFieldDef(actualRequest.getFieldDef(parameter.getName()), expectedRequest.getFieldDef(parameter.getName()));
}
}
} else {
Assert.assertNull(actualRequest);
}
compareParameters(actual.getActionResponseMetadata(action.getName()), expected.getActionResponseMetadata(action.getName()));
}
}
use of com.linkedin.restli.restspec.ParameterSchema in project rest.li by linkedin.
the class ResourceModelEncoder method createParameters.
private ParameterSchemaArray createParameters(final ResourceMethodDescriptor resourceMethodDescriptor) {
ParameterSchemaArray parameterSchemaArray = new ParameterSchemaArray();
for (Parameter<?> param : resourceMethodDescriptor.getParameters()) {
//only custom parameters need to be specified in the IDL
if (!param.isCustom()) {
continue;
}
// assocKeys are listed outside the parameters list
if (param.getParamType() == Parameter.ParamType.KEY || param.getParamType() == Parameter.ParamType.ASSOC_KEY_PARAM) {
continue;
}
ParameterSchema paramSchema = new ParameterSchema();
paramSchema.setName(param.getName());
paramSchema.setType(buildDataSchemaType(param.getType(), param.getDataSchema()));
final Object defaultValueData = param.getDefaultValueData();
if (defaultValueData == null && param.isOptional()) {
paramSchema.setOptional(true);
} else if (defaultValueData != null) {
paramSchema.setDefault(defaultValueData.toString());
}
String paramDoc = _docsProvider.getParamDoc(resourceMethodDescriptor.getMethod(), param.getName());
if (paramDoc != null) {
paramSchema.setDoc(paramDoc);
}
final DataMap customAnnotation = param.getCustomAnnotationData();
if (!customAnnotation.isEmpty()) {
paramSchema.setAnnotations(new CustomAnnotationContentSchemaMap(customAnnotation));
}
parameterSchemaArray.add(paramSchema);
}
return parameterSchemaArray;
}
use of com.linkedin.restli.restspec.ParameterSchema in project rest.li by linkedin.
the class JavaRequestBuilderGenerator method methodMetadataMapInit.
private JVar methodMetadataMapInit(JDefinedClass facadeClass, ActionSchemaArray resourceActions, ActionSchemaArray entityActions, JBlock staticInit) {
// CreateMetadata (only for actions right now)
final JClass MetadataMapClass = getCodeModel().ref(HashMap.class).narrow(_stringClass, getCodeModel().ref(DynamicRecordMetadata.class));
final JVar requestMetadataMap = staticInit.decl(MetadataMapClass, "requestMetadataMap").init(JExpr._new(MetadataMapClass));
final JClass fieldDefListClass = getCodeModel().ref(ArrayList.class).narrow(getCodeModel().ref(FieldDef.class).narrow(getCodeModel().ref(Object.class).wildcard()));
// get all actions into a single ActionSchemaArray
final int resourceActionsSize = resourceActions == null ? 0 : resourceActions.size();
final int entityActionsSize = entityActions == null ? 0 : entityActions.size();
final ActionSchemaArray allActionSchema = new ActionSchemaArray(resourceActionsSize + entityActionsSize);
allActionSchema.addAll(resourceActions == null ? new ActionSchemaArray() : resourceActions);
allActionSchema.addAll(entityActions == null ? new ActionSchemaArray() : entityActions);
for (ActionSchema actionSchema : allActionSchema) {
final String varName = actionSchema.getName() + "Params";
final JVar currMethodParams = staticInit.decl(fieldDefListClass, varName).init(JExpr._new(fieldDefListClass));
final ParameterSchemaArray parameters = actionSchema.getParameters();
for (ParameterSchema parameterSchema : parameters == null ? new ParameterSchemaArray() : parameters) {
final JInvocation fieldDefParam = createFieldDef(parameterSchema.getName(), parameterSchema.getType(), facadeClass);
staticInit.add(currMethodParams.invoke("add").arg(fieldDefParam));
}
final String methodName = actionSchema.getName();
final JInvocation newSchema = createMetadata(methodName, currMethodParams);
staticInit.add(requestMetadataMap.invoke("put").arg(methodName).arg(newSchema));
}
return requestMetadataMap;
}
use of com.linkedin.restli.restspec.ParameterSchema in project rest.li by linkedin.
the class JavaRequestBuilderGenerator method generateQueryParamBindingMethods.
private void generateQueryParamBindingMethods(JDefinedClass facadeClass, ParameterSchemaArray parameters, JDefinedClass derivedBuilderClass) {
for (ParameterSchema param : parameters) {
if ("array".equals(param.getType())) {
final JClass paramItemsClass = getJavaBindingType(param.getItems(), facadeClass).valueClass;
final JClass paramClass = getCodeModel().ref(Iterable.class).narrow(paramItemsClass);
generateQueryParamSetMethod(derivedBuilderClass, param, paramClass, paramItemsClass);
generateQueryParamAddMethod(derivedBuilderClass, param, paramItemsClass);
} else {
final DataSchema typeSchema = RestSpecCodec.textToSchema(param.getType(), _schemaResolver);
final JClass paramClass = getJavaBindingType(typeSchema, facadeClass).valueClass;
generateQueryParamSetMethod(derivedBuilderClass, param, paramClass, paramClass);
// for backwards compatibility, add the method with Iterable<Foo> parameter
if (typeSchema instanceof ArrayDataSchema) {
final DataSchema itemsSchema = ((ArrayDataSchema) typeSchema).getItems();
final JClass paramItemsClass = getJavaBindingType(itemsSchema, facadeClass).valueClass;
final JClass iterableItemsClass = getCodeModel().ref(Iterable.class).narrow(paramItemsClass);
generateQueryParamSetMethod(derivedBuilderClass, param, iterableItemsClass, paramItemsClass);
generateQueryParamAddMethod(derivedBuilderClass, param, paramItemsClass);
}
}
}
}
Aggregations