Search in sources :

Example 6 with ParameterSchema

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);
    }
}
Also used : ClassTemplateSpec(com.linkedin.pegasus.generator.spec.ClassTemplateSpec) ActionParamBindingMethodSpec(com.linkedin.restli.tools.clientgen.builderspec.ActionParamBindingMethodSpec) ParameterSchema(com.linkedin.restli.restspec.ParameterSchema)

Example 7 with ParameterSchema

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()));
    }
}
Also used : DynamicRecordMetadata(com.linkedin.data.template.DynamicRecordMetadata) ParameterSchema(com.linkedin.restli.restspec.ParameterSchema) ParameterSchemaArray(com.linkedin.restli.restspec.ParameterSchemaArray) ActionSchema(com.linkedin.restli.restspec.ActionSchema)

Example 8 with ParameterSchema

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;
}
Also used : ParameterSchema(com.linkedin.restli.restspec.ParameterSchema) ParameterSchemaArray(com.linkedin.restli.restspec.ParameterSchemaArray) CustomAnnotationContentSchemaMap(com.linkedin.restli.restspec.CustomAnnotationContentSchemaMap) DataMap(com.linkedin.data.DataMap)

Example 9 with ParameterSchema

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;
}
Also used : HashMap(java.util.HashMap) JClass(com.sun.codemodel.JClass) ArrayList(java.util.ArrayList) ParameterSchema(com.linkedin.restli.restspec.ParameterSchema) JInvocation(com.sun.codemodel.JInvocation) ActionSchema(com.linkedin.restli.restspec.ActionSchema) DynamicRecordMetadata(com.linkedin.data.template.DynamicRecordMetadata) ActionSchemaArray(com.linkedin.restli.restspec.ActionSchemaArray) ParameterSchemaArray(com.linkedin.restli.restspec.ParameterSchemaArray) JVar(com.sun.codemodel.JVar)

Example 10 with ParameterSchema

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);
            }
        }
    }
}
Also used : TyperefDataSchema(com.linkedin.data.schema.TyperefDataSchema) ArrayDataSchema(com.linkedin.data.schema.ArrayDataSchema) DataSchema(com.linkedin.data.schema.DataSchema) NamedDataSchema(com.linkedin.data.schema.NamedDataSchema) PrimitiveDataSchema(com.linkedin.data.schema.PrimitiveDataSchema) ArrayDataSchema(com.linkedin.data.schema.ArrayDataSchema) JClass(com.sun.codemodel.JClass) ParameterSchema(com.linkedin.restli.restspec.ParameterSchema)

Aggregations

ParameterSchema (com.linkedin.restli.restspec.ParameterSchema)13 DataSchema (com.linkedin.data.schema.DataSchema)5 ArrayDataSchema (com.linkedin.data.schema.ArrayDataSchema)4 ParameterSchemaArray (com.linkedin.restli.restspec.ParameterSchemaArray)4 DynamicRecordMetadata (com.linkedin.data.template.DynamicRecordMetadata)3 ActionSchema (com.linkedin.restli.restspec.ActionSchema)3 JClass (com.sun.codemodel.JClass)3 EnumDataSchema (com.linkedin.data.schema.EnumDataSchema)2 MapDataSchema (com.linkedin.data.schema.MapDataSchema)2 NamedDataSchema (com.linkedin.data.schema.NamedDataSchema)2 RecordDataSchema (com.linkedin.data.schema.RecordDataSchema)2 TyperefDataSchema (com.linkedin.data.schema.TyperefDataSchema)2 FieldDef (com.linkedin.data.template.FieldDef)2 ClassTemplateSpec (com.linkedin.pegasus.generator.spec.ClassTemplateSpec)2 MetadataSchema (com.linkedin.restli.restspec.MetadataSchema)2 JVar (com.sun.codemodel.JVar)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 DataMap (com.linkedin.data.DataMap)1 DataSchemaTraverse (com.linkedin.data.schema.DataSchemaTraverse)1