use of com.linkedin.restli.restspec.ParameterSchema in project rest.li by linkedin.
the class ExampleRequestResponseGenerator method addParams.
private void addParams(RestfulRequestBuilder<?, ?, ?> builder, ParameterSchemaArray parameters) {
if (parameters != null) {
for (ParameterSchema parameter : parameters) {
if (// ignoring legacy case where items was used for arrays
!parameter.hasItems()) {
DataSchema dataSchema = RestSpecCodec.textToSchema(parameter.getType(), _schemaResolver);
Object value = _dataGenerator.buildData(parameter.getName(), dataSchema);
builder.setParam(parameter.getName(), value);
}
}
}
}
use of com.linkedin.restli.restspec.ParameterSchema in project rest.li by linkedin.
the class JavaRequestBuilderGenerator method generateActionMethod.
private void generateActionMethod(JDefinedClass facadeClass, JExpression baseUriExpr, JClass keyClass, ActionSchema action, JVar resourceSpecField, String resourceName, List<String> pathKeys, Map<String, JClass> pathKeyTypes, Map<String, JClass> assocKeysTypes, Map<String, List<String>> pathToAssocKeys, JExpression requestOptionsExpr) throws JClassAlreadyExistsException {
final JClass returnType = getActionReturnType(facadeClass, action.getReturns());
final JClass vanillaActionBuilderClass = getCodeModel().ref(ActionRequestBuilderBase.class).narrow(keyClass, returnType);
final String actionName = action.getName();
final String actionBuilderClassName = CodeUtil.capitalize(resourceName) + "Do" + CodeUtil.capitalize(actionName) + METHOD_BUILDER_SUFFIX.get(_version);
final JDefinedClass actionBuilderClass = facadeClass.getPackage()._class(JMod.PUBLIC, actionBuilderClassName);
annotate(actionBuilderClass, null);
checkVersionAndDeprecateBuilderClass(actionBuilderClass, false);
actionBuilderClass._extends(vanillaActionBuilderClass.narrow(actionBuilderClass));
final JMethod actionBuilderConstructor = actionBuilderClass.constructor(JMod.PUBLIC);
final JVar uriParam = actionBuilderConstructor.param(_stringClass, "baseUriTemplate");
final JVar classParam = actionBuilderConstructor.param(getCodeModel().ref(Class.class).narrow(returnType), "returnClass");
final JVar resourceSpecParam = actionBuilderConstructor.param(_resourceSpecClass, "resourceSpec");
final JVar actionsRequestOptionsParam = actionBuilderConstructor.param(RestliRequestOptions.class, "requestOptions");
actionBuilderConstructor.body().invoke(SUPER).arg(uriParam).arg(classParam).arg(resourceSpecParam).arg(actionsRequestOptionsParam);
actionBuilderConstructor.body().add(JExpr._super().invoke("name").arg(actionName));
final JMethod actionMethod = facadeClass.method(JMod.PUBLIC, actionBuilderClass, "action" + CodeUtil.capitalize(actionName));
actionMethod.body()._return(JExpr._new(actionBuilderClass).arg(baseUriExpr).arg(returnType.dotclass()).arg(resourceSpecField).arg(requestOptionsExpr));
if (action.getParameters() != null) {
for (ParameterSchema param : action.getParameters()) {
final String paramName = param.getName();
final boolean isOptional = RestLiToolsUtils.isParameterOptional(param);
final JavaBinding binding = getJavaBindingType(param.getType(), facadeClass);
final JMethod typesafeMethod = _version == RestliVersion.RESTLI_2_0_0 ? actionBuilderClass.method(JMod.PUBLIC, actionBuilderClass, RestLiToolsUtils.nameCamelCase(paramName + "Param")) : actionBuilderClass.method(JMod.PUBLIC, actionBuilderClass, "param" + CodeUtil.capitalize(paramName));
final JVar typesafeMethodParam = typesafeMethod.param(binding.valueClass, "value");
final JClass dataTemplateUtil = getCodeModel().ref(DataTemplateUtil.class);
final JExpression dataSchema = dataTemplateUtil.staticInvoke("getSchema").arg(binding.schemaClass.dotclass());
typesafeMethod.body().add(JExpr._super().invoke(isOptional ? "setParam" : "setReqParam").arg(resourceSpecField.invoke("getRequestMetadata").arg(actionName).invoke("getFieldDef").arg(paramName)).arg(typesafeMethodParam));
typesafeMethod.body()._return(JExpr._this());
}
}
generatePathKeyBindingMethods(pathKeys, actionBuilderClass, pathKeyTypes, assocKeysTypes, pathToAssocKeys);
generateClassJavadoc(actionBuilderClass, action);
generateFactoryMethodJavadoc(actionMethod, action);
}
use of com.linkedin.restli.restspec.ParameterSchema in project rest.li by linkedin.
the class SnapshotGenerator method findModelsFinder.
private void findModelsFinder(FinderSchema finderSchema, Map<String, NamedDataSchema> foundTypes, List<NamedDataSchema> typeOrder) {
ParameterSchemaArray parameters = finderSchema.getParameters();
if (parameters != null) {
for (ParameterSchema parameterSchema : parameters) {
findModelsParameter(parameterSchema, foundTypes, typeOrder);
}
}
MetadataSchema metadata = finderSchema.getMetadata();
if (metadata != null) {
String type = metadata.getType();
recordType(type, foundTypes, typeOrder);
}
}
use of com.linkedin.restli.restspec.ParameterSchema in project rest.li by linkedin.
the class RequestBuilderSpecGenerator method generateQueryParamBindingMethods.
private void generateQueryParamBindingMethods(ParameterSchemaArray parameters, RequestBuilderSpec requestBuilderClass) {
for (ParameterSchema param : parameters) {
final String paramName = param.getName();
final DataSchema typeSchema = RestSpecCodec.textToSchema(param.getType(), _schemaResolver);
final ClassTemplateSpec typeClassSpec = schemaToTemplateSpec(typeSchema);
final boolean isOptional = RestLiToolsUtils.isParameterOptional(param);
final String setMethodName = RestLiToolsUtils.nameCamelCase(paramName + "Param");
final QueryParamBindingMethodSpec spec = new QueryParamBindingMethodSpec(setMethodName);
spec.setParamName(paramName);
spec.setNeedAddParamMethod(false);
spec.setOptional(isOptional);
spec.setArgType(typeClassSpec);
spec.setDoc(param.getDoc());
requestBuilderClass.addQueryParamMethod(spec);
if (typeSchema instanceof ArrayDataSchema) {
final DataSchema itemsSchema = ((ArrayDataSchema) typeSchema).getItems();
final ClassTemplateSpec itemSpecClass = schemaToTemplateSpec(itemsSchema);
final String addMethodName = RestLiToolsUtils.nameCamelCase("add" + RestLiToolsUtils.normalizeCaps(paramName) + "Param");
final QueryParamBindingMethodSpec addSpec = new QueryParamBindingMethodSpec(addMethodName);
addSpec.setParamName(paramName);
addSpec.setNeedAddParamMethod(true);
addSpec.setOptional(isOptional);
addSpec.setArgType(itemSpecClass);
addSpec.setDoc(param.getDoc());
requestBuilderClass.addQueryParamMethod(addSpec);
}
}
}
use of com.linkedin.restli.restspec.ParameterSchema in project rest.li by linkedin.
the class ResourceCompatibilityChecker method checkParameterArrayField.
/**
* @return whether the check passes
*/
private boolean checkParameterArrayField(RecordDataSchema.Field field, ParameterSchemaArray prevArray, ParameterSchemaArray currArray) {
final HashMap<String, Integer> currRemainder = new HashMap<String, Integer>();
if (!checkComplexArrayField(field, "name", prevArray, currArray, currRemainder, false)) {
return false;
}
_infoPath.push(field.getName());
boolean result = true;
for (int paramIndex : currRemainder.values()) {
// all parameters only appear in curr must not be required
final ParameterSchema param = currArray.get(paramIndex);
if (isQueryParameterOptional(param.isOptional(), param.getDefault(GetMode.DEFAULT))) {
_infoMap.addRestSpecInfo(CompatibilityInfo.Type.PARAMETER_NEW_OPTIONAL, _infoPath, param.getName());
} else {
_infoMap.addRestSpecInfo(CompatibilityInfo.Type.PARAMETER_NEW_REQUIRED, _infoPath, param.getName());
result = false;
}
}
_infoPath.pop();
// all parameter errors have been recorded, avoid duplicate errors by returning true
return result;
}
Aggregations