Search in sources :

Example 11 with FieldConfig

use of com.google.api.codegen.config.FieldConfig in project toolkit by googleapis.

the class StaticLangApiMethodTransformer method setFlattenedMethodFields.

private void setFlattenedMethodFields(MethodContext context, List<ParamWithSimpleDoc> additionalParams, Synchronicity synchronicity, StaticLangApiMethodView.Builder methodViewBuilder) {
    MethodModel method = context.getMethodModel();
    SurfaceNamer namer = context.getNamer();
    Iterable<FieldConfig> fieldConfigs = context.getFlatteningConfig().getFlattenedFieldConfigs().values();
    methodViewBuilder.initCode(initCodeTransformer.generateInitCode(context.cloneWithEmptyTypeTable(), createInitCodeContext(context, fieldConfigs, InitCodeOutputType.FieldList)));
    methodViewBuilder.doc(ApiMethodDocView.newBuilder().mainDocLines(namer.getDocLines(method, context.getMethodConfig())).paramDocs(getMethodParamDocs(context, fieldConfigs, additionalParams)).throwsDocLines(namer.getThrowsDocLines(context.getMethodConfig())).returnsDocLines(namer.getReturnDocLines(context.getSurfaceInterfaceContext(), context, synchronicity)).build());
    List<RequestObjectParamView> params = new ArrayList<>();
    for (FieldConfig fieldConfig : fieldConfigs) {
        params.add(resourceObjectTransformer.generateRequestObjectParam(context, fieldConfig));
    }
    methodViewBuilder.forwardingMethodParams(params);
    List<RequestObjectParamView> nonforwardingParams = new ArrayList<>(params);
    nonforwardingParams.addAll(ParamWithSimpleDoc.asRequestObjectParamViews(additionalParams));
    methodViewBuilder.methodParams(nonforwardingParams);
    methodViewBuilder.requestObjectParams(params);
    methodViewBuilder.pathTemplateChecks(generatePathTemplateChecks(context, fieldConfigs));
}
Also used : MethodModel(com.google.api.codegen.config.MethodModel) FieldConfig(com.google.api.codegen.config.FieldConfig) ArrayList(java.util.ArrayList) RequestObjectParamView(com.google.api.codegen.viewmodel.RequestObjectParamView)

Example 12 with FieldConfig

use of com.google.api.codegen.config.FieldConfig in project toolkit by googleapis.

the class TestCaseTransformer method createSmokeTestInitContext.

public InitCodeContext createSmokeTestInitContext(MethodContext context) {
    SmokeTestConfig testConfig = context.getInterfaceConfig().getSmokeTestConfig();
    InitCodeContext.InitCodeOutputType outputType;
    ImmutableMap<String, FieldConfig> fieldConfigMap;
    if (context.isFlattenedMethodContext()) {
        outputType = InitCodeContext.InitCodeOutputType.FieldList;
        fieldConfigMap = FieldConfig.toFieldConfigMap(context.getFlatteningConfig().getFlattenedFieldConfigs().values());
    } else {
        outputType = InitCodeContext.InitCodeOutputType.SingleObject;
        fieldConfigMap = FieldConfig.toFieldConfigMap(context.getMethodConfig().getRequiredFieldConfigs());
    }
    // Store project ID variable name into the symbol table since it is used
    // by the execute method as a parameter.
    SymbolTable table = new SymbolTable();
    table.getNewSymbol(Name.from(InitFieldConfig.PROJECT_ID_VARIABLE_NAME));
    InitCodeContext.Builder contextBuilder = InitCodeContext.newBuilder().initObjectType(testConfig.getMethod().getInputType()).suggestedName(Name.from("request")).outputType(outputType).initValueConfigMap(InitCodeTransformer.createCollectionMap(context)).initFieldConfigStrings(testConfig.getInitFieldConfigStrings()).symbolTable(table).fieldConfigMap(fieldConfigMap);
    if (context.isFlattenedMethodContext()) {
        contextBuilder.initFields(context.getFlatteningConfig().getFlattenedFields());
    }
    return contextBuilder.build();
}
Also used : InitFieldConfig(com.google.api.codegen.metacode.InitFieldConfig) FieldConfig(com.google.api.codegen.config.FieldConfig) SmokeTestConfig(com.google.api.codegen.config.SmokeTestConfig) SymbolTable(com.google.api.codegen.util.SymbolTable) InitCodeContext(com.google.api.codegen.metacode.InitCodeContext)

Example 13 with FieldConfig

use of com.google.api.codegen.config.FieldConfig in project toolkit by googleapis.

the class TestCaseTransformer method createPageStreamingResponseViews.

private List<PageStreamingResponseView> createPageStreamingResponseViews(MethodContext methodContext) {
    MethodConfig methodConfig = methodContext.getMethodConfig();
    SurfaceNamer namer = methodContext.getNamer();
    List<PageStreamingResponseView> pageStreamingResponseViews = new ArrayList<>();
    if (!methodConfig.isPageStreaming()) {
        return pageStreamingResponseViews;
    }
    FieldConfig resourcesFieldConfig = methodConfig.getPageStreaming().getResourcesFieldConfig();
    FieldModel resourcesField = resourcesFieldConfig.getField();
    String resourceTypeName = methodContext.getTypeTable().getAndSaveNicknameForElementType(resourcesField);
    // Construct the list of function calls needed to retrieve paged resource from response object.
    ImmutableList.Builder<String> resourcesFieldGetFunctionList = new ImmutableList.Builder<>();
    for (FieldModel field : resourcesFieldConfig.getFieldPath()) {
        resourcesFieldGetFunctionList.add(namer.getFieldGetFunctionName(field));
    }
    pageStreamingResponseViews.add(PageStreamingResponseView.newBuilder().resourceTypeName(resourceTypeName).resourcesFieldGetterNames(resourcesFieldGetFunctionList.build()).resourcesIterateMethod(namer.getPagedResponseIterateMethod()).resourcesVarName(namer.localVarName(Name.from("resources"))).build());
    if (methodContext.getFeatureConfig().useResourceNameFormatOption(resourcesFieldConfig)) {
        resourceTypeName = methodContext.getNamer().getAndSaveElementResourceTypeName(methodContext.getTypeTable(), resourcesFieldConfig);
        resourcesFieldGetFunctionList = new ImmutableList.Builder<>();
        for (FieldModel field : resourcesFieldConfig.getFieldPath()) {
            resourcesFieldGetFunctionList.add(namer.getFieldGetFunctionName(methodContext.getFeatureConfig(), resourcesFieldConfig));
        }
        String expectedTransformFunction = null;
        if (methodContext.getFeatureConfig().useResourceNameConverters(resourcesFieldConfig)) {
            expectedTransformFunction = namer.getResourceTypeParseMethodName(methodContext.getTypeTable(), resourcesFieldConfig);
        }
        pageStreamingResponseViews.add(PageStreamingResponseView.newBuilder().resourceTypeName(resourceTypeName).resourcesFieldGetterNames(resourcesFieldGetFunctionList.build()).resourcesIterateMethod(namer.getPagedResponseIterateMethod(methodContext.getFeatureConfig(), resourcesFieldConfig)).expectedValueTransformFunction(expectedTransformFunction).resourcesVarName(namer.localVarName(Name.from("resource_names"))).build());
    }
    return pageStreamingResponseViews;
}
Also used : MethodConfig(com.google.api.codegen.config.MethodConfig) InitFieldConfig(com.google.api.codegen.metacode.InitFieldConfig) FieldConfig(com.google.api.codegen.config.FieldConfig) ImmutableList(com.google.common.collect.ImmutableList) PageStreamingResponseView(com.google.api.codegen.viewmodel.testing.PageStreamingResponseView) ArrayList(java.util.ArrayList) FieldModel(com.google.api.codegen.config.FieldModel)

Example 14 with FieldConfig

use of com.google.api.codegen.config.FieldConfig in project toolkit by googleapis.

the class CSharpGapicSmokeTestTransformer method createSmokeTestCaseApiMethodView.

private StaticLangApiMethodView createSmokeTestCaseApiMethodView(GapicInterfaceContext context, MethodContext methodContext) {
    SurfaceNamer namer = context.getNamer();
    MethodConfig methodConfig = methodContext.getMethodConfig();
    StaticLangApiMethodView.Builder apiMethodView;
    if (methodConfig.isPageStreaming()) {
        apiMethodView = apiMethodTransformer.generatePagedFlattenedMethod(methodContext).toBuilder();
        FieldConfig resourceFieldConfig = methodContext.getMethodConfig().getPageStreaming().getResourcesFieldConfig();
        String callerResponseTypeName = namer.getAndSaveCallerPagedResponseTypeName(methodContext, resourceFieldConfig);
        apiMethodView.responseTypeName(callerResponseTypeName);
    } else if (methodConfig.isLongRunningOperation()) {
        ArrayList<ParamWithSimpleDoc> emptyParams = new ArrayList<ParamWithSimpleDoc>();
        apiMethodView = apiMethodTransformer.generateOperationFlattenedMethod(methodContext, emptyParams).toBuilder();
    } else {
        apiMethodView = apiMethodTransformer.generateFlattenedMethod(methodContext).toBuilder();
    }
    InitCodeTransformer initCodeTransformer = new InitCodeTransformer();
    InitCodeView initCodeView = initCodeTransformer.generateInitCode(methodContext, testCaseTransformer.createSmokeTestInitContext(methodContext));
    apiMethodView.initCode(initCodeView);
    return apiMethodView.build();
}
Also used : MethodConfig(com.google.api.codegen.config.MethodConfig) StaticLangApiMethodView(com.google.api.codegen.viewmodel.StaticLangApiMethodView) ParamWithSimpleDoc(com.google.api.codegen.transformer.ParamWithSimpleDoc) FieldConfig(com.google.api.codegen.config.FieldConfig) ArrayList(java.util.ArrayList) InitCodeTransformer(com.google.api.codegen.transformer.InitCodeTransformer) SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer) InitCodeView(com.google.api.codegen.viewmodel.InitCodeView)

Example 15 with FieldConfig

use of com.google.api.codegen.config.FieldConfig in project toolkit by googleapis.

the class CSharpGapicSnippetsTransformer method generatePagedFlattenedAsyncMethod.

private StaticLangApiMethodSnippetView generatePagedFlattenedAsyncMethod(MethodContext methodContext, String suffix, boolean requiresNamedArguments) {
    StaticLangApiMethodView method = apiMethodTransformer.generatePagedFlattenedAsyncMethod(methodContext, csharpCommonTransformer.pagedMethodAdditionalParams());
    SurfaceNamer namer = methodContext.getNamer();
    PageStreamingConfig pageStreaming = methodContext.getMethodConfig().getPageStreaming();
    FieldConfig resourceFieldConfig = pageStreaming.getResourcesFieldConfig();
    String callerResponseTypeName = namer.getAndSaveCallerAsyncPagedResponseTypeName(methodContext, resourceFieldConfig);
    return StaticLangApiMethodSnippetView.newBuilder().method(method).snippetMethodName(method.name() + suffix).callerResponseTypeName(callerResponseTypeName).apiClassName(namer.getApiWrapperClassName(methodContext.getInterfaceConfig())).apiVariableName(method.apiVariableName()).requiresNamedArguments(requiresNamedArguments).build();
}
Also used : StaticLangApiMethodView(com.google.api.codegen.viewmodel.StaticLangApiMethodView) FieldConfig(com.google.api.codegen.config.FieldConfig) PageStreamingConfig(com.google.api.codegen.config.PageStreamingConfig) SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer)

Aggregations

FieldConfig (com.google.api.codegen.config.FieldConfig)30 ArrayList (java.util.ArrayList)14 MethodModel (com.google.api.codegen.config.MethodModel)10 FieldModel (com.google.api.codegen.config.FieldModel)9 PageStreamingConfig (com.google.api.codegen.config.PageStreamingConfig)8 MethodConfig (com.google.api.codegen.config.MethodConfig)6 SurfaceNamer (com.google.api.codegen.transformer.SurfaceNamer)6 StaticLangApiMethodView (com.google.api.codegen.viewmodel.StaticLangApiMethodView)6 InitCodeContext (com.google.api.codegen.metacode.InitCodeContext)4 InitCodeOutputType (com.google.api.codegen.metacode.InitCodeContext.InitCodeOutputType)4 GapicMethodContext (com.google.api.codegen.transformer.GapicMethodContext)4 SymbolTable (com.google.api.codegen.util.SymbolTable)4 ImmutableList (com.google.common.collect.ImmutableList)4 SingleResourceNameConfig (com.google.api.codegen.config.SingleResourceNameConfig)3 InitCodeNode (com.google.api.codegen.metacode.InitCodeNode)3 InitFieldConfig (com.google.api.codegen.metacode.InitFieldConfig)2 MethodContext (com.google.api.codegen.transformer.MethodContext)2 ClientMethodType (com.google.api.codegen.viewmodel.ClientMethodType)2 InitCodeView (com.google.api.codegen.viewmodel.InitCodeView)2 RequestObjectParamView (com.google.api.codegen.viewmodel.RequestObjectParamView)2