Search in sources :

Example 16 with FieldConfig

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

the class CSharpGapicSnippetsTransformer method generatePagedFlattenedMethod.

private StaticLangApiMethodSnippetView generatePagedFlattenedMethod(MethodContext methodContext, String suffix, boolean requiresNamedArguments) {
    StaticLangApiMethodView method = apiMethodTransformer.generatePagedFlattenedMethod(methodContext, csharpCommonTransformer.pagedMethodAdditionalParams());
    SurfaceNamer namer = methodContext.getNamer();
    PageStreamingConfig pageStreaming = methodContext.getMethodConfig().getPageStreaming();
    FieldConfig resourceFieldConfig = pageStreaming.getResourcesFieldConfig();
    String callerResponseTypeName = namer.getAndSaveCallerPagedResponseTypeName(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)

Example 17 with FieldConfig

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

the class PythonGapicSurfaceTestTransformer method createTestCaseViews.

private List<TestCaseView> createTestCaseViews(GapicInterfaceContext context) {
    ImmutableList.Builder<TestCaseView> testCaseViews = ImmutableList.builder();
    // certain string until all of the types have been disambiguated.
    for (int i = 0; i < 2; ++i) {
        testCaseViews = ImmutableList.builder();
        SymbolTable testNameTable = new SymbolTable();
        for (MethodModel method : context.getSupportedMethods()) {
            GapicMethodContext methodContext = context.asRequestMethodContext(method);
            ClientMethodType clientMethodType = ClientMethodType.OptionalArrayMethod;
            if (methodContext.getMethodConfig().isLongRunningOperation()) {
                clientMethodType = ClientMethodType.OperationOptionalArrayMethod;
            } else if (methodContext.getMethodConfig().isPageStreaming()) {
                clientMethodType = ClientMethodType.PagedOptionalArrayMethod;
            }
            Iterable<FieldConfig> fieldConfigs = methodContext.getMethodConfig().getRequiredFieldConfigs();
            InitCodeOutputType initCodeOutputType = method.getRequestStreaming() ? InitCodeOutputType.SingleObject : InitCodeOutputType.FieldList;
            InitCodeContext initCodeContext = InitCodeContext.newBuilder().initObjectType(methodContext.getMethodModel().getInputType()).suggestedName(Name.from("request")).initFieldConfigStrings(methodContext.getMethodConfig().getSampleCodeInitFields()).initValueConfigMap(InitCodeTransformer.createCollectionMap(methodContext)).initFields(FieldConfig.toFieldTypeIterable(fieldConfigs)).outputType(initCodeOutputType).fieldConfigMap(FieldConfig.toFieldConfigMap(fieldConfigs)).valueGenerator(valueGenerator).build();
            testCaseViews.add(testCaseTransformer.createTestCaseView(methodContext, testNameTable, initCodeContext, clientMethodType));
        }
    }
    return testCaseViews.build();
}
Also used : MethodModel(com.google.api.codegen.config.MethodModel) GapicMethodContext(com.google.api.codegen.transformer.GapicMethodContext) ClientMethodType(com.google.api.codegen.viewmodel.ClientMethodType) TestCaseView(com.google.api.codegen.viewmodel.testing.TestCaseView) ImmutableList(com.google.common.collect.ImmutableList) FieldConfig(com.google.api.codegen.config.FieldConfig) SymbolTable(com.google.api.codegen.util.SymbolTable) InitCodeContext(com.google.api.codegen.metacode.InitCodeContext) InitCodeOutputType(com.google.api.codegen.metacode.InitCodeContext.InitCodeOutputType)

Example 18 with FieldConfig

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

the class RubyGapicSurfaceTestTransformer method createUnitTestCaseInitCodeContext.

private InitCodeContext createUnitTestCaseInitCodeContext(GapicInterfaceContext context, MethodModel method) {
    MethodContext requestMethodContext = context.asRequestMethodContext(method);
    MethodContext dynamicMethodContext = context.asDynamicMethodContext(method);
    MethodConfig methodConfig = requestMethodContext.getMethodConfig();
    Iterable<FieldConfig> fieldConfigs = methodConfig.getRequiredFieldConfigs();
    InitCodeOutputType outputType = method.getRequestStreaming() ? InitCodeOutputType.SingleObject : InitCodeOutputType.FieldList;
    return InitCodeContext.newBuilder().initObjectType(method.getInputType()).suggestedName(Name.from("request")).initFieldConfigStrings(methodConfig.getSampleCodeInitFields()).initValueConfigMap(InitCodeTransformer.createCollectionMap(dynamicMethodContext)).initFields(FieldConfig.toFieldTypeIterable(fieldConfigs)).outputType(outputType).fieldConfigMap(FieldConfig.toFieldConfigMap(fieldConfigs)).build();
}
Also used : MethodConfig(com.google.api.codegen.config.MethodConfig) FieldConfig(com.google.api.codegen.config.FieldConfig) GapicMethodContext(com.google.api.codegen.transformer.GapicMethodContext) MethodContext(com.google.api.codegen.transformer.MethodContext) InitCodeOutputType(com.google.api.codegen.metacode.InitCodeContext.InitCodeOutputType)

Example 19 with FieldConfig

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

the class DynamicLangApiMethodTransformer method removePageTokenFieldConfig.

private Iterable<FieldConfig> removePageTokenFieldConfig(GapicMethodContext context, Iterable<FieldConfig> fieldConfigs) {
    MethodConfig methodConfig = context.getMethodConfig();
    if (methodConfig == null || !methodConfig.isPageStreaming()) {
        return fieldConfigs;
    }
    final FieldModel requestTokenField = methodConfig.getPageStreaming().getRequestTokenField();
    return Iterables.filter(fieldConfigs, new Predicate<FieldConfig>() {

        @Override
        public boolean apply(FieldConfig fieldConfig) {
            return !fieldConfig.getField().equals(requestTokenField);
        }
    });
}
Also used : MethodConfig(com.google.api.codegen.config.MethodConfig) FieldConfig(com.google.api.codegen.config.FieldConfig) FieldModel(com.google.api.codegen.config.FieldModel)

Example 20 with FieldConfig

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

the class InitCodeTransformer method generateRequestAssertViews.

/**
 * Generates assert views for the test of the tested method and its fields.
 */
List<ClientTestAssertView> generateRequestAssertViews(MethodContext methodContext, InitCodeContext initContext) {
    InitCodeNode rootNode = InitCodeNode.createTree(InitCodeContext.newBuilder().initObjectType(methodContext.getMethodModel().getInputType()).initFields(initContext.initFields()).initValueConfigMap(createCollectionMap(methodContext)).suggestedName(Name.from("request")).fieldConfigMap(initContext.fieldConfigMap()).build());
    List<ClientTestAssertView> assertViews = new ArrayList<>();
    SurfaceNamer namer = methodContext.getNamer();
    // Add request fields checking
    for (InitCodeNode fieldItemTree : rootNode.getChildren().values()) {
        FieldConfig fieldConfig = fieldItemTree.getFieldConfig();
        String getterMethod = namer.getFieldGetFunctionName(methodContext.getFeatureConfig(), fieldConfig);
        String expectedValueIdentifier = getVariableName(methodContext, fieldItemTree);
        String expectedTransformFunction = null;
        String actualTransformFunction = null;
        if (methodContext.getFeatureConfig().useResourceNameFormatOption(fieldConfig)) {
            if (fieldConfig.requiresParamTransformationFromAny()) {
                expectedTransformFunction = namer.getToStringMethod();
                actualTransformFunction = namer.getToStringMethod();
            } else if (fieldConfig.requiresParamTransformation()) {
                if (methodContext.getFeatureConfig().useResourceNameConverters(fieldConfig)) {
                    expectedTransformFunction = namer.getToStringMethod();
                } else {
                    expectedTransformFunction = namer.getResourceOneofCreateMethod(methodContext.getTypeTable(), fieldConfig);
                }
            } else if (methodContext.getFeatureConfig().useResourceNameConverters(fieldConfig)) {
                if (fieldConfig.getField().isRepeated()) {
                    actualTransformFunction = namer.getResourceTypeParseListMethodName(methodContext.getTypeTable(), fieldConfig);
                } else if (fieldConfig.getResourceNameConfig().getResourceNameType() == ResourceNameType.ONEOF) {
                    actualTransformFunction = namer.getResourceTypeParentParseMethod(methodContext.getTypeTable(), fieldConfig);
                } else {
                    actualTransformFunction = namer.getResourceTypeParseMethodName(methodContext.getTypeTable(), fieldConfig);
                }
            }
        }
        boolean isMap = fieldConfig.getField().isMap();
        boolean isArray = fieldConfig.getField().isRepeated() && !isMap;
        String enumTypeName = null;
        TypeModel fieldType = fieldItemTree.getType();
        if (fieldType.isEnum() && !fieldType.isRepeated()) {
            enumTypeName = methodContext.getTypeTable().getNicknameFor(fieldType);
        }
        String messageTypeName = null;
        if (fieldType.isMessage()) {
            messageTypeName = methodContext.getTypeTable().getFullNameForMessageType(fieldType);
        }
        assertViews.add(createAssertView(expectedValueIdentifier, expectedTransformFunction, actualTransformFunction, isMap, isArray, getterMethod, enumTypeName, messageTypeName));
    }
    return assertViews;
}
Also used : ClientTestAssertView(com.google.api.codegen.viewmodel.testing.ClientTestAssertView) InitCodeNode(com.google.api.codegen.metacode.InitCodeNode) FieldConfig(com.google.api.codegen.config.FieldConfig) ArrayList(java.util.ArrayList) TypeModel(com.google.api.codegen.config.TypeModel)

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