Search in sources :

Example 11 with RequestObjectParamView

use of com.google.api.codegen.viewmodel.RequestObjectParamView in project toolkit by googleapis.

the class DynamicLangApiMethodTransformer method generateRequestObjectParam.

private RequestObjectParamView generateRequestObjectParam(GapicMethodContext context, FieldConfig fieldConfig) {
    SurfaceNamer namer = context.getNamer();
    FeatureConfig featureConfig = context.getFeatureConfig();
    ModelTypeTable typeTable = context.getTypeTable();
    FieldModel field = fieldConfig.getField();
    Iterable<FieldModel> requiredFields = context.getMethodConfig().getRequiredFields();
    boolean isRequired = false;
    for (FieldModel f : requiredFields) {
        if (f.getSimpleName().equals(field.getSimpleName())) {
            isRequired = true;
        }
    }
    RequestObjectParamView.Builder param = RequestObjectParamView.newBuilder();
    param.name(namer.getVariableName(field));
    param.keyName(namer.getFieldKey(field));
    param.nameAsMethodName(namer.getFieldGetFunctionName(featureConfig, fieldConfig));
    param.typeName(typeTable.getAndSaveNicknameFor(field));
    param.elementTypeName(typeTable.getAndSaveNicknameForElementType(field));
    param.setCallName(namer.getFieldSetFunctionName(featureConfig, fieldConfig));
    param.getCallName(namer.getFieldGetFunctionName(featureConfig, fieldConfig));
    param.isMap(field.isMap());
    param.isArray(!field.isMap() && field.isRepeated());
    param.isPrimitive(field.isPrimitive());
    param.isOptional(!isRequired);
    if (!isRequired) {
        param.optionalDefault(namer.getOptionalFieldDefaultValue(fieldConfig, context));
    }
    return param.build();
}
Also used : FieldModel(com.google.api.codegen.config.FieldModel) RequestObjectParamView(com.google.api.codegen.viewmodel.RequestObjectParamView)

Aggregations

RequestObjectParamView (com.google.api.codegen.viewmodel.RequestObjectParamView)11 MethodModel (com.google.api.codegen.config.MethodModel)7 ArrayList (java.util.ArrayList)7 FieldConfig (com.google.api.codegen.config.FieldConfig)4 MethodSampleView (com.google.api.codegen.viewmodel.MethodSampleView)4 PathTemplateCheckView (com.google.api.codegen.viewmodel.PathTemplateCheckView)4 FieldModel (com.google.api.codegen.config.FieldModel)2 GrpcStreamingType (com.google.api.codegen.config.GrpcStreamingConfig.GrpcStreamingType)2 MethodConfig (com.google.api.codegen.config.MethodConfig)2 InitCodeOutputType (com.google.api.codegen.metacode.InitCodeContext.InitCodeOutputType)2 ApiCallableImplType (com.google.api.codegen.viewmodel.ApiCallableImplType)2 InitCodeView (com.google.api.codegen.viewmodel.InitCodeView)2 ParamDocView (com.google.api.codegen.viewmodel.ParamDocView)2 RequestObjectMethodDetailView (com.google.api.codegen.viewmodel.RequestObjectMethodDetailView)2 SimpleParamDocView (com.google.api.codegen.viewmodel.SimpleParamDocView)2 DiscoGapicInterfaceContext (com.google.api.codegen.config.DiscoGapicInterfaceContext)1 DiscoveryMethodModel (com.google.api.codegen.config.DiscoveryMethodModel)1 InterfaceModel (com.google.api.codegen.config.InterfaceModel)1 SchemaTransformationContext (com.google.api.codegen.discogapic.SchemaTransformationContext)1 SurfaceNamer (com.google.api.codegen.transformer.SurfaceNamer)1