Search in sources :

Example 46 with SurfaceNamer

use of com.google.api.codegen.transformer.SurfaceNamer in project toolkit by googleapis.

the class PhpGapicSurfaceTransformer method buildGapicClientViewModel.

private ViewModel buildGapicClientViewModel(GapicInterfaceContext context) {
    SurfaceNamer namer = context.getNamer();
    addApiImports(context);
    List<OptionalArrayMethodView> methods = apiMethodTransformer.generateApiMethods(context);
    DynamicLangXApiView.Builder apiImplClass = DynamicLangXApiView.newBuilder();
    apiImplClass.doc(serviceTransformer.generateServiceDoc(context, methods.get(0), context.getProductConfig()));
    apiImplClass.templateFileName(API_IMPL_TEMPLATE_FILENAME);
    apiImplClass.supportsGrpcTransport(supportsGrpcTransport());
    apiImplClass.protoFilename(context.getInterface().getFile().getSimpleName());
    String implName = namer.getApiWrapperClassImplName(context.getInterfaceConfig());
    apiImplClass.name(implName);
    String serviceAddress = context.getServiceAddress();
    apiImplClass.serviceHostname(productServiceConfig.getServiceHostname(serviceAddress));
    apiImplClass.servicePort(productServiceConfig.getServicePort(serviceAddress));
    apiImplClass.serviceTitle(productServiceConfig.getTitle(context.getInterface().getModel()));
    apiImplClass.authScopes(productServiceConfig.getAuthScopes(context.getInterface().getModel()));
    apiImplClass.pathTemplates(pathTemplateTransformer.generatePathTemplates(context));
    apiImplClass.formatResourceFunctions(pathTemplateTransformer.generateFormatResourceFunctions(context));
    apiImplClass.parseResourceFunctions(pathTemplateTransformer.generateParseResourceFunctions(context));
    apiImplClass.pathTemplateGetterFunctions(pathTemplateTransformer.generatePathTemplateGetterFunctions(context));
    apiImplClass.pageStreamingDescriptors(pageStreamingTransformer.generateDescriptors(context));
    apiImplClass.hasPageStreamingMethods(context.getInterfaceConfig().hasPageStreamingMethods());
    apiImplClass.batchingDescriptors(ImmutableList.<BatchingDescriptorView>of());
    apiImplClass.hasBatchingMethods(context.getInterfaceConfig().hasBatchingMethods());
    apiImplClass.longRunningDescriptors(createLongRunningDescriptors(context));
    apiImplClass.hasLongRunningOperations(context.getInterfaceConfig().hasLongRunningOperations());
    apiImplClass.grpcStreamingDescriptors(createGrpcStreamingDescriptors(context));
    apiImplClass.clientConfigPath(namer.getClientConfigPath(context.getInterfaceConfig()));
    apiImplClass.clientConfigName(namer.getClientConfigName(context.getInterfaceConfig()));
    apiImplClass.interfaceKey(context.getInterface().getFullName());
    if (supportsGrpcTransport()) {
        // PHP generates a client that supports both gRPC and REST
        String grpcClientTypeName = namer.getAndSaveNicknameForGrpcClientTypeName(context.getImportTypeTable(), context.getInterfaceModel());
        apiImplClass.grpcClientTypeName(grpcClientTypeName);
        apiImplClass.stubs(grpcStubTransformer.generateGrpcStubs(context));
    } else {
        // PHP generates a client that only supports REST
        apiImplClass.grpcClientTypeName("");
        apiImplClass.stubs(Collections.emptyList());
    }
    apiImplClass.apiMethods(methods.stream().collect(Collectors.toList()));
    apiImplClass.hasDefaultServiceAddress(context.getInterfaceConfig().hasDefaultServiceAddress());
    apiImplClass.hasDefaultServiceScopes(context.getInterfaceConfig().hasDefaultServiceScopes());
    // must be done as the last step to catch all imports
    apiImplClass.fileHeader(fileHeaderTransformer.generateFileHeader(context));
    String outputPath = pathMapper.getOutputPath(context.getInterfaceModel().getFullName(), context.getProductConfig());
    apiImplClass.outputPath(outputPath + "/" + implName + ".php");
    return apiImplClass.build();
}
Also used : OptionalArrayMethodView(com.google.api.codegen.viewmodel.OptionalArrayMethodView) DynamicLangXApiView(com.google.api.codegen.viewmodel.DynamicLangXApiView) SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer)

Example 47 with SurfaceNamer

use of com.google.api.codegen.transformer.SurfaceNamer in project toolkit by googleapis.

the class PhpGapicSurfaceTransformer method generateRestInterfaceConfigViews.

private List<RestInterfaceConfigView> generateRestInterfaceConfigViews(GapicInterfaceContext context) {
    List<RestInterfaceConfigView> configViews = new ArrayList<>();
    GapicInterfaceConfig interfaceConfig = context.getInterfaceConfig();
    SurfaceNamer namer = context.getNamer();
    Map<String, List<HttpRule>> interfaces = new TreeMap<>();
    Service serviceConfig = serviceModel.getServiceConfig();
    for (MethodModel methodModel : context.getSupportedMethods()) {
        GapicMethodContext methodContext = context.asRequestMethodContext(methodModel);
        MethodConfig methodConfig = methodContext.getMethodConfig();
        Method method = methodContext.getMethod();
        // REST does not support streaming methods
        if (methodConfig.isGrpcStreaming()) {
            continue;
        }
        String interfaceName = methodConfig.getRerouteToGrpcInterface() == null ? context.getInterface().getFullName() : methodConfig.getRerouteToGrpcInterface();
        HttpRule httpRule = getHttpRule(method.getOptionFields()).toBuilder().setSelector(String.format("%s.%s", interfaceName, method.getSimpleName())).build();
        addHttpRuleToMap(interfaces, interfaceName, httpRule);
    }
    for (HttpRule httpRule : serviceConfig.getHttp().getRulesList()) {
        String selector = httpRule.getSelector();
        String interfaceName = selector.substring(0, selector.lastIndexOf("."));
        addHttpRuleToMap(interfaces, interfaceName, httpRule);
    }
    for (Map.Entry<String, List<HttpRule>> entry : interfaces.entrySet()) {
        configViews.add(generateRestInterfaceConfigView(entry.getKey(), entry.getValue(), namer));
    }
    return configViews;
}
Also used : MethodModel(com.google.api.codegen.config.MethodModel) RestInterfaceConfigView(com.google.api.codegen.viewmodel.RestInterfaceConfigView) ArrayList(java.util.ArrayList) GapicInterfaceConfig(com.google.api.codegen.config.GapicInterfaceConfig) Service(com.google.api.Service) Method(com.google.api.tools.framework.model.Method) TreeMap(java.util.TreeMap) HttpRule(com.google.api.HttpRule) MethodConfig(com.google.api.codegen.config.MethodConfig) GapicMethodContext(com.google.api.codegen.config.GapicMethodContext) List(java.util.List) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) Map(java.util.Map) TreeMap(java.util.TreeMap) SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer)

Example 48 with SurfaceNamer

use of com.google.api.codegen.transformer.SurfaceNamer in project toolkit by googleapis.

the class RubyApiMethodParamTransformer method generateMethodParamDocs.

private List<ParamDocView> generateMethodParamDocs(GapicMethodContext context, Iterable<FieldModel> fields) {
    SurfaceNamer namer = context.getNamer();
    MethodConfig methodConfig = context.getMethodConfig();
    ImmutableList.Builder<ParamDocView> docs = ImmutableList.builder();
    for (FieldModel field : fields) {
        if (isRequestTokenParam(methodConfig, field)) {
            continue;
        }
        SimpleParamDocView.Builder paramDoc = SimpleParamDocView.newBuilder();
        paramDoc.paramName(namer.getVariableName(field));
        paramDoc.typeName(namer.getParamTypeName(context.getTypeTable(), field.getType()));
        ImmutableList.Builder<String> docLines = ImmutableList.builder();
        if (isPageSizeParam(methodConfig, field)) {
            docLines.add("The maximum number of resources contained in the underlying API", "response. If page streaming is performed per-resource, this", "parameter does not affect the return value. If page streaming is", "performed per-page, this determines the maximum number of", "resources in a page.");
        } else {
            docLines.addAll(namer.getDocLines(field));
            boolean isMessageField = field.isMessage() && !field.isMap();
            boolean isMapContainingMessage = field.isMap() && field.getType().getMapValueType().isMessage();
            if (isMessageField || isMapContainingMessage) {
                String messageType;
                if (isMapContainingMessage) {
                    messageType = context.getTypeTable().getFullNameForElementType(field.getType().getMapValueType());
                } else {
                    messageType = context.getTypeTable().getFullNameForElementType(field);
                }
                docLines.add(String.format("A hash of the same form as `%s`", messageType));
                docLines.add("can also be provided.");
            }
        }
        paramDoc.lines(docLines.build());
        docs.add(paramDoc.build());
    }
    return docs.build();
}
Also used : MethodConfig(com.google.api.codegen.config.MethodConfig) SimpleParamDocView(com.google.api.codegen.viewmodel.SimpleParamDocView) ImmutableList(com.google.common.collect.ImmutableList) SimpleParamDocView(com.google.api.codegen.viewmodel.SimpleParamDocView) ParamDocView(com.google.api.codegen.viewmodel.ParamDocView) FieldModel(com.google.api.codegen.config.FieldModel) SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer)

Example 49 with SurfaceNamer

use of com.google.api.codegen.transformer.SurfaceNamer in project toolkit by googleapis.

the class RubyGapicSurfaceTestTransformer method createSmokeTestClassView.

private SmokeTestClassView createSmokeTestClassView(GapicInterfaceContext context) {
    boolean packageHasMultipleServices = context.getApiModel().hasMultipleServices();
    String outputPath = smokeTestPathMapper.getOutputPath(context.getInterfaceModel().getFullName(), context.getProductConfig());
    SurfaceNamer namer = context.getNamer();
    RubyPackageMetadataNamer metadataNamer = new RubyPackageMetadataNamer(context.getNamer().getPackageName());
    String name = namer.getSmokeTestClassName(context.getInterfaceConfig());
    MethodModel method = context.getInterfaceConfig().getSmokeTestConfig().getMethod();
    MethodContext methodContext = context.asRequestMethodContext(method);
    TestCaseTransformer testCaseTransformer = new TestCaseTransformer(valueProducer, packageHasMultipleServices);
    FlatteningConfig flatteningGroup = testCaseTransformer.getSmokeTestFlatteningGroup(methodContext.getMethodConfig());
    GapicMethodContext flattenedMethodContext = context.asFlattenedMethodContext(methodContext, flatteningGroup);
    SmokeTestClassView.Builder testClass = SmokeTestClassView.newBuilder();
    OptionalArrayMethodView apiMethodView = createSmokeTestCaseApiMethodView(flattenedMethodContext, packageHasMultipleServices);
    testClass.apiSettingsClassName(namer.getApiSettingsClassName(context.getInterfaceConfig()));
    testClass.apiClassName(namer.getApiWrapperClassName(context.getInterfaceConfig()));
    testClass.name(name);
    testClass.outputPath(namer.getSourceFilePath(outputPath, name));
    testClass.templateFileName(SMOKE_TEST_TEMPLATE_FILE);
    testClass.apiMethod(apiMethodView);
    testClass.requireProjectId(testCaseTransformer.requireProjectIdInSmokeTest(apiMethodView.initCode(), context.getNamer()));
    testClass.projectIdVariableName(metadataNamer.getProjectVariable(true));
    testClass.apiVersion(packageConfig.apiVersion());
    FileHeaderView fileHeader = fileHeaderTransformer.generateFileHeader(context.getProductConfig(), importSectionTransformer.generateSmokeTestImportSection(context), namer);
    testClass.fileHeader(fileHeader);
    return testClass.build();
}
Also used : MethodModel(com.google.api.codegen.config.MethodModel) GapicMethodContext(com.google.api.codegen.config.GapicMethodContext) MethodContext(com.google.api.codegen.config.MethodContext) FileHeaderView(com.google.api.codegen.viewmodel.FileHeaderView) GapicMethodContext(com.google.api.codegen.config.GapicMethodContext) OptionalArrayMethodView(com.google.api.codegen.viewmodel.OptionalArrayMethodView) TestCaseTransformer(com.google.api.codegen.transformer.TestCaseTransformer) SmokeTestClassView(com.google.api.codegen.viewmodel.testing.SmokeTestClassView) FlatteningConfig(com.google.api.codegen.config.FlatteningConfig) SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer)

Example 50 with SurfaceNamer

use of com.google.api.codegen.transformer.SurfaceNamer in project toolkit by googleapis.

the class RubyGapicSurfaceTestTransformer method createUnitTestClassView.

private ClientTestClassView createUnitTestClassView(GapicInterfaceContext context, boolean packageHasMultipleServices) {
    SurfaceNamer namer = context.getNamer();
    String apiSettingsClassName = namer.getNotImplementedString("RubyGapicSurfaceTestTransformer.generateUnitTestClassView - apiSettingsClassName");
    String testClassName = namer.getNotImplementedString("RubyGapicSurfaceTestTransformer.generateUnitTestClassView - name");
    ImmutableList.Builder<ClientInitParamView> clientInitOptionalParams = ImmutableList.builder();
    if (RubyUtil.hasMajorVersion(context.getProductConfig().getPackageName())) {
        clientInitOptionalParams.add(ClientInitParamView.newBuilder().key("version").value(":" + packageConfig.apiVersion()).build());
    }
    return ClientTestClassView.newBuilder().apiSettingsClassName(apiSettingsClassName).apiClassName(namer.getFullyQualifiedApiWrapperClassName(context.getInterfaceConfig())).name(testClassName).testCases(createUnitTestCaseViews(context, packageHasMultipleServices)).missingDefaultServiceAddress(!context.getInterfaceConfig().hasDefaultServiceAddress()).missingDefaultServiceScopes(!context.getInterfaceConfig().hasDefaultServiceScopes()).mockCredentialsClassName(namer.getMockCredentialsClassName(context.getInterface())).fullyQualifiedCredentialsClassName(namer.getFullyQualifiedCredentialsClassName()).clientInitOptionalParams(clientInitOptionalParams.build()).mockServices(ImmutableList.<MockServiceUsageView>of()).build();
}
Also used : MockServiceUsageView(com.google.api.codegen.viewmodel.testing.MockServiceUsageView) ClientInitParamView(com.google.api.codegen.viewmodel.testing.ClientInitParamView) ImmutableList(com.google.common.collect.ImmutableList) SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer)

Aggregations

SurfaceNamer (com.google.api.codegen.transformer.SurfaceNamer)109 InterfaceModel (com.google.api.codegen.config.InterfaceModel)26 ViewModel (com.google.api.codegen.viewmodel.ViewModel)23 StaticLangApiMethodView (com.google.api.codegen.viewmodel.StaticLangApiMethodView)22 ArrayList (java.util.ArrayList)22 ImmutableList (com.google.common.collect.ImmutableList)17 GapicInterfaceContext (com.google.api.codegen.config.GapicInterfaceContext)15 MethodModel (com.google.api.codegen.config.MethodModel)14 ImportSectionView (com.google.api.codegen.viewmodel.ImportSectionView)13 SmokeTestClassView (com.google.api.codegen.viewmodel.testing.SmokeTestClassView)11 InterfaceConfig (com.google.api.codegen.config.InterfaceConfig)10 ModelTypeTable (com.google.api.codegen.transformer.ModelTypeTable)10 FileHeaderView (com.google.api.codegen.viewmodel.FileHeaderView)10 ApiModel (com.google.api.codegen.config.ApiModel)9 MethodConfig (com.google.api.codegen.config.MethodConfig)9 ProtoApiModel (com.google.api.codegen.config.ProtoApiModel)9 DynamicLangXApiView (com.google.api.codegen.viewmodel.DynamicLangXApiView)9 FieldConfig (com.google.api.codegen.config.FieldConfig)8 GapicMethodContext (com.google.api.codegen.config.GapicMethodContext)8 ImportTypeTable (com.google.api.codegen.transformer.ImportTypeTable)8