Search in sources :

Example 36 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(initContext.cloneWithEmptySymbolTable());
    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, fieldConfig);
                } else {
                    actualTransformFunction = namer.getResourceTypeParseMethodName(methodContext.getTypeTable(), fieldConfig);
                }
            }
        }
        boolean isMap = fieldConfig.getField().isMap();
        boolean isArray = fieldConfig.getField().isRepeated() && !isMap;
        boolean isFloatingPointNumber = fieldConfig.getField().getType().isFloatType() || fieldConfig.getField().getType().isDoubleType();
        TypeModel fieldType = fieldItemTree.getType();
        String messageTypeName = null;
        if (fieldType.isMessage()) {
            messageTypeName = methodContext.getTypeTable().getFullNameForMessageType(fieldType);
        }
        assertViews.add(createAssertView(expectedValueIdentifier, expectedTransformFunction, actualTransformFunction, isMap, isArray, isFloatingPointNumber, getterMethod, 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)

Example 37 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 38 with FieldConfig

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

the class NodeJSGapicSurfaceTestTransformer method createTestCaseViews.

private List<TestCaseView> createTestCaseViews(GapicInterfaceContext context) {
    ArrayList<TestCaseView> testCaseViews = new ArrayList<>();
    SymbolTable testNameTable = new SymbolTable();
    for (MethodModel method : context.getSupportedMethods()) {
        GapicMethodContext methodContext = context.asRequestMethodContext(method);
        if (methodContext.getMethodConfig().getGrpcStreamingType() == GrpcStreamingType.ClientStreaming) {
            // Issue: https://github.com/googleapis/toolkit/issues/946
            continue;
        }
        Collection<FieldConfig> fieldConfigs = methodContext.getMethodConfig().getRequiredFieldConfigs();
        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.SingleObject).fieldConfigMap(FieldConfig.toFieldConfigMap(fieldConfigs)).valueGenerator(valueGenerator).build();
        testCaseViews.add(testCaseTransformer.createTestCaseView(methodContext, testNameTable, initCodeContext, getMethodType(methodContext)));
    }
    return testCaseViews;
}
Also used : MethodModel(com.google.api.codegen.config.MethodModel) GapicMethodContext(com.google.api.codegen.config.GapicMethodContext) TestCaseView(com.google.api.codegen.viewmodel.testing.TestCaseView) FieldConfig(com.google.api.codegen.config.FieldConfig) ArrayList(java.util.ArrayList) SymbolTable(com.google.api.codegen.util.SymbolTable) InitCodeContext(com.google.api.codegen.metacode.InitCodeContext)

Example 39 with FieldConfig

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

the class PhpGapicSurfaceTestTransformer method createTestCaseViews.

private List<TestCaseView> createTestCaseViews(GapicInterfaceContext context) {
    ArrayList<TestCaseView> testCaseViews = new ArrayList<>();
    SymbolTable testNameTable = new SymbolTable();
    for (MethodModel method : context.getSupportedMethods()) {
        GapicMethodContext methodContext = context.asRequestMethodContext(method);
        if (methodContext.getMethodConfig().getGrpcStreamingType() == GrpcStreamingType.ClientStreaming) {
            // Issue: https://github.com/googleapis/toolkit/issues/946
            continue;
        }
        InitCodeOutputType initCodeOutputType = InitCodeOutputType.FieldList;
        if (methodContext.getMethodConfig().getGrpcStreamingType() == GrpcStreamingType.BidiStreaming) {
            initCodeOutputType = InitCodeOutputType.SingleObject;
        }
        ClientMethodType clientMethodType = ClientMethodType.OptionalArrayMethod;
        if (methodContext.isLongRunningMethodContext()) {
            clientMethodType = ClientMethodType.LongRunningOptionalArrayMethod;
        } else if (methodContext.getMethodConfig().isPageStreaming()) {
            clientMethodType = ClientMethodType.PagedOptionalArrayMethod;
        }
        Collection<FieldConfig> fieldConfigs = methodContext.getMethodConfig().getRequiredFieldConfigs();
        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;
}
Also used : MethodModel(com.google.api.codegen.config.MethodModel) GapicMethodContext(com.google.api.codegen.config.GapicMethodContext) ClientMethodType(com.google.api.codegen.viewmodel.ClientMethodType) TestCaseView(com.google.api.codegen.viewmodel.testing.TestCaseView) FieldConfig(com.google.api.codegen.config.FieldConfig) ArrayList(java.util.ArrayList) SymbolTable(com.google.api.codegen.util.SymbolTable) InitCodeContext(com.google.api.codegen.metacode.InitCodeContext) InitCodeOutputType(com.google.api.codegen.metacode.InitCodeContext.InitCodeOutputType)

Example 40 with FieldConfig

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

the class JavaSurfaceTransformer method getIterateMethods.

private List<PagedResponseIterateMethodView> getIterateMethods(MethodContext context) {
    SurfaceNamer namer = context.getNamer();
    List<PagedResponseIterateMethodView> iterateMethods = new ArrayList<>();
    FieldConfig resourceFieldConfig = context.getMethodConfig().getPageStreaming().getResourcesFieldConfig();
    if (context.getFeatureConfig().useResourceNameFormatOption(resourceFieldConfig)) {
        String resourceTypeName = namer.getAndSaveElementResourceTypeName(context.getTypeTable(), resourceFieldConfig);
        String resourceTypeIterateMethodName = namer.getPagedResponseIterateMethod(context.getFeatureConfig(), resourceFieldConfig);
        String resourceTypeGetValuesMethodName = namer.getPageGetValuesMethod(context.getFeatureConfig(), resourceFieldConfig);
        String parseMethodName = namer.getResourceTypeParseMethodName(context.getTypeTable(), resourceFieldConfig);
        PagedResponseIterateMethodView.Builder iterateMethod = PagedResponseIterateMethodView.newBuilder().overloadResourceTypeName(resourceTypeName).overloadResourceTypeParseFunctionName(parseMethodName).overloadResourceTypeIterateMethodName(resourceTypeIterateMethodName).overloadResourceTypeGetValuesMethodName(resourceTypeGetValuesMethodName).iterateMethodName(namer.getPagedResponseIterateMethod()).getValuesMethodName(namer.getPageGetValuesMethod());
        iterateMethods.add(iterateMethod.build());
    }
    return iterateMethods;
}
Also used : FieldConfig(com.google.api.codegen.config.FieldConfig) ArrayList(java.util.ArrayList) PagedResponseIterateMethodView(com.google.api.codegen.viewmodel.PagedResponseIterateMethodView) SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer)

Aggregations

FieldConfig (com.google.api.codegen.config.FieldConfig)40 MethodModel (com.google.api.codegen.config.MethodModel)16 ArrayList (java.util.ArrayList)15 PageStreamingConfig (com.google.api.codegen.config.PageStreamingConfig)14 FieldModel (com.google.api.codegen.config.FieldModel)11 StaticLangApiMethodView (com.google.api.codegen.viewmodel.StaticLangApiMethodView)11 MethodConfig (com.google.api.codegen.config.MethodConfig)7 SurfaceNamer (com.google.api.codegen.transformer.SurfaceNamer)7 Builder (com.google.api.codegen.viewmodel.StaticLangApiMethodView.Builder)6 GapicMethodContext (com.google.api.codegen.config.GapicMethodContext)5 SingleResourceNameConfig (com.google.api.codegen.config.SingleResourceNameConfig)5 InitCodeOutputType (com.google.api.codegen.metacode.InitCodeContext.InitCodeOutputType)5 InitCodeContext (com.google.api.codegen.metacode.InitCodeContext)4 SymbolTable (com.google.api.codegen.util.SymbolTable)4 RequestObjectParamView (com.google.api.codegen.viewmodel.RequestObjectParamView)4 MethodContext (com.google.api.codegen.config.MethodContext)3 InitCodeNode (com.google.api.codegen.metacode.InitCodeNode)3 GrpcStreamingType (com.google.api.codegen.config.GrpcStreamingConfig.GrpcStreamingType)2 ResourceNameConfig (com.google.api.codegen.config.ResourceNameConfig)2 ResourceNameMessageConfigs (com.google.api.codegen.config.ResourceNameMessageConfigs)2