Search in sources :

Example 1 with ProtoInterfaceModel

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

the class JavaSurfaceNamer method getGrpcServiceClassName.

/**
 * The type name of the Grpc service class This needs to match what Grpc generates for the
 * particular language.
 */
@Override
public String getGrpcServiceClassName(InterfaceModel apiInterface) {
    String fullName = JavaModelTypeNameConverter.getGrpcTypeName(((ProtoInterfaceModel) apiInterface).getInterface()).getFullName();
    NamePath namePath = getTypeNameConverter().getNamePath(fullName);
    String grpcContainerName = publicClassName(Name.upperCamelKeepUpperAcronyms(namePath.getHead(), "Grpc"));
    String serviceClassName = publicClassName(Name.upperCamelKeepUpperAcronyms(apiInterface.getSimpleName(), "ImplBase"));
    return qualifiedName(namePath.withHead(grpcContainerName).append(serviceClassName));
}
Also used : ProtoInterfaceModel(com.google.api.codegen.config.ProtoInterfaceModel) NamePath(com.google.api.codegen.util.NamePath)

Example 2 with ProtoInterfaceModel

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

the class GoGapicSurfaceTransformer method generate.

private StaticLangClientFileView generate(GapicInterfaceContext context) {
    StaticLangClientFileView.Builder view = StaticLangClientFileView.newBuilder();
    SurfaceNamer namer = context.getNamer();
    ApiModel model = context.getApiModel();
    ProtoInterfaceModel apiInterface = context.getInterfaceModel();
    GapicProductConfig productConfig = context.getProductConfig();
    GapicInterfaceConfig interfaceConfig = context.getInterfaceConfig();
    view.templateFileName(API_TEMPLATE_FILENAME);
    view.serviceDoc(serviceTransformer.generateServiceDoc(context, null, productConfig));
    view.domainLayerLocation(productConfig.getDomainLayerLocation());
    view.clientTypeName(namer.getApiWrapperClassName(context.getInterfaceConfig()));
    view.clientConstructorName(namer.getApiWrapperClassConstructorName(interfaceConfig));
    view.defaultClientOptionFunctionName(namer.getDefaultApiSettingsFunctionName(interfaceConfig));
    view.defaultCallOptionFunctionName(namer.getDefaultCallSettingsFunctionName(interfaceConfig));
    view.callOptionsTypeName(namer.getCallSettingsTypeName(interfaceConfig));
    view.serviceOriginalName(model.getTitle());
    view.servicePhraseName(namer.getServicePhraseName(interfaceConfig));
    String outputPath = pathMapper.getOutputPath(apiInterface.getFullName(), productConfig);
    String fileName = namer.getServiceFileName(context.getInterfaceConfig());
    view.outputPath(outputPath + File.separator + fileName);
    List<RetryConfigDefinitionView> retryDef = generateRetryConfigDefinitions(context, context.getSupportedMethods());
    view.retryPairDefinitions(retryDef);
    view.callSettings(apiCallableTransformer.generateCallSettings(context));
    List<StaticLangApiMethodView> apiMethods = generateApiMethods(context, context.getSupportedMethods());
    view.apiMethods(apiMethods);
    // "net/url" is needed for `url.QueryEscape`.
    if (apiMethods.stream().anyMatch(m -> !m.headerRequestParams().isEmpty())) {
        context.getImportTypeTable().saveNicknameFor("fmt;;;");
        context.getImportTypeTable().saveNicknameFor("net/url;;;");
    }
    // In Go, multiple methods share the same iterator type, one iterator type per resource type.
    // We have to dedupe the iterators.
    Map<String, PageStreamingDescriptorClassView> iterators = new TreeMap<>();
    for (PageStreamingDescriptorClassView desc : pageStreamingTransformer.generateDescriptorClasses(context)) {
        iterators.put(desc.typeName(), desc);
    }
    view.pageStreamingDescriptorClasses(new ArrayList<>(iterators.values()));
    // Same with long running operations.
    Map<String, LongRunningOperationDetailView> lros = new TreeMap<>();
    for (StaticLangApiMethodView apiMethod : apiMethods) {
        LongRunningOperationDetailView lro = apiMethod.operationMethod();
        if (lro != null) {
            lros.put(lro.clientReturnTypeName(), lro);
        }
    }
    view.lroDetailViews(new ArrayList<>(lros.values()));
    view.serviceHostname(productServiceConfig.getServiceHostname(context.getServiceAddress()));
    view.servicePort(productServiceConfig.getServicePort(context.getServiceAddress()));
    view.stubs(grpcStubTransformer.generateGrpcStubs(context));
    addXApiImports(context, context.getSupportedMethods());
    view.fileHeader(fileHeaderTransformer.generateFileHeader(context));
    return view.build();
}
Also used : GapicProductConfig(com.google.api.codegen.config.GapicProductConfig) ProtoInterfaceModel(com.google.api.codegen.config.ProtoInterfaceModel) StaticLangApiMethodView(com.google.api.codegen.viewmodel.StaticLangApiMethodView) RetryConfigDefinitionView(com.google.api.codegen.viewmodel.RetryConfigDefinitionView) GapicInterfaceConfig(com.google.api.codegen.config.GapicInterfaceConfig) ProtoApiModel(com.google.api.codegen.config.ProtoApiModel) ApiModel(com.google.api.codegen.config.ApiModel) TreeMap(java.util.TreeMap) LongRunningOperationDetailView(com.google.api.codegen.viewmodel.LongRunningOperationDetailView) StaticLangClientFileView(com.google.api.codegen.viewmodel.StaticLangClientFileView) SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer) PageStreamingDescriptorClassView(com.google.api.codegen.viewmodel.PageStreamingDescriptorClassView)

Example 3 with ProtoInterfaceModel

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

the class InitCodeTransformer method createInitValueView.

private InitValueView createInitValueView(MethodContext context, FieldConfig fieldConfig, SurfaceNamer namer, ImportTypeTable typeTable, InitCodeNode item, boolean convertToString) {
    SingleResourceNameConfig singleResourceNameConfig;
    switch(fieldConfig.getResourceNameType()) {
        case ANY:
            singleResourceNameConfig = Iterables.get(context.getProductConfig().getSingleResourceNameConfigs(), 0);
            InterfaceModel interfaceModel = context.getInterfaceModel();
            if (interfaceModel instanceof ProtoInterfaceModel) {
                ProtoFile protoFile = ((ProtoInterfaceModel) interfaceModel).getInterface().getFile();
                singleResourceNameConfig = singleResourceNameConfig.toBuilder().setAssignedProtoFile(protoFile).build();
            }
            FieldConfig anyResourceNameFieldConfig = fieldConfig.withResourceNameConfig(singleResourceNameConfig);
            return createResourceNameInitValueView(context, anyResourceNameFieldConfig, item).convertToString(convertToString).build();
        case FIXED:
            throw new UnsupportedOperationException("entity name invalid");
        case ONEOF:
            return createResourceNameOneofInitValueView(context, fieldConfig, item, convertToString);
        case SINGLE:
            return createResourceNameInitValueView(context, fieldConfig, item).convertToString(convertToString).build();
        case NONE:
        // Fall-through
        default:
            throw new UnsupportedOperationException("unexpected entity name type '" + fieldConfig.getResourceNameType() + "'");
    }
}
Also used : InterfaceModel(com.google.api.codegen.config.InterfaceModel) ProtoInterfaceModel(com.google.api.codegen.config.ProtoInterfaceModel) ProtoInterfaceModel(com.google.api.codegen.config.ProtoInterfaceModel) FieldConfig(com.google.api.codegen.config.FieldConfig) ProtoFile(com.google.api.tools.framework.model.ProtoFile) SingleResourceNameConfig(com.google.api.codegen.config.SingleResourceNameConfig)

Example 4 with ProtoInterfaceModel

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

the class RubyGapicSurfaceDocTransformer method generateTocModuleView.

private TocModuleView generateTocModuleView(ApiModel model, ProtoFile file, ProductConfig productConfig, SurfaceNamer namer, String moduleName) {
    RubyPackageMetadataTransformer metadataTransformer = new RubyPackageMetadataTransformer(packageConfig);
    RubyPackageMetadataNamer packageNamer = new RubyPackageMetadataNamer(productConfig.getPackageName());
    String packageFilePath = file.getFullName().replace(".", File.separator);
    ImmutableList.Builder<TocContentView> tocContents = ImmutableList.builder();
    for (Interface apiInterface : file.getReachableInterfaces()) {
        String description = RubyUtil.getSentence(namer.getDocLines(GapicParser.getDocString(apiInterface)));
        InterfaceConfig interfaceConfig = productConfig.getInterfaceConfig(new ProtoInterfaceModel(apiInterface));
        tocContents.add(metadataTransformer.generateTocContent(description, packageNamer, packageFilePath, namer.getApiWrapperClassName(interfaceConfig)));
    }
    tocContents.add(metadataTransformer.generateTocContent("Data types for " + productConfig.getPackageName(), packageNamer, packageFilePath, "Data Types"));
    return TocModuleView.newBuilder().moduleName(moduleName).fullName(model.getTitle()).contents(tocContents.build()).build();
}
Also used : InterfaceConfig(com.google.api.codegen.config.InterfaceConfig) ProtoInterfaceModel(com.google.api.codegen.config.ProtoInterfaceModel) ImmutableList(com.google.common.collect.ImmutableList) TocContentView(com.google.api.codegen.viewmodel.metadata.TocContentView) Interface(com.google.api.tools.framework.model.Interface)

Example 5 with ProtoInterfaceModel

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

the class JavaSurfaceNamer method getGrpcContainerTypeName.

/**
 * The type name of the Grpc container class. This needs to match what Grpc generates for the
 * particular language.
 */
public String getGrpcContainerTypeName(InterfaceModel apiInterface) {
    String fullName = JavaModelTypeNameConverter.getGrpcTypeName(((ProtoInterfaceModel) apiInterface).getInterface()).getFullName();
    NamePath namePath = getTypeNameConverter().getNamePath(fullName);
    String publicClassName = publicClassName(Name.upperCamelKeepUpperAcronyms(namePath.getHead(), "Grpc"));
    return qualifiedName(namePath.withHead(publicClassName));
}
Also used : ProtoInterfaceModel(com.google.api.codegen.config.ProtoInterfaceModel) NamePath(com.google.api.codegen.util.NamePath)

Aggregations

ProtoInterfaceModel (com.google.api.codegen.config.ProtoInterfaceModel)6 NamePath (com.google.api.codegen.util.NamePath)2 Interface (com.google.api.tools.framework.model.Interface)2 TreeMap (java.util.TreeMap)2 ApiModel (com.google.api.codegen.config.ApiModel)1 FieldConfig (com.google.api.codegen.config.FieldConfig)1 GapicInterfaceConfig (com.google.api.codegen.config.GapicInterfaceConfig)1 GapicProductConfig (com.google.api.codegen.config.GapicProductConfig)1 InterfaceConfig (com.google.api.codegen.config.InterfaceConfig)1 InterfaceModel (com.google.api.codegen.config.InterfaceModel)1 ProtoApiModel (com.google.api.codegen.config.ProtoApiModel)1 SingleResourceNameConfig (com.google.api.codegen.config.SingleResourceNameConfig)1 SurfaceNamer (com.google.api.codegen.transformer.SurfaceNamer)1 LongRunningOperationDetailView (com.google.api.codegen.viewmodel.LongRunningOperationDetailView)1 PageStreamingDescriptorClassView (com.google.api.codegen.viewmodel.PageStreamingDescriptorClassView)1 RetryConfigDefinitionView (com.google.api.codegen.viewmodel.RetryConfigDefinitionView)1 StaticLangApiMethodView (com.google.api.codegen.viewmodel.StaticLangApiMethodView)1 StaticLangClientFileView (com.google.api.codegen.viewmodel.StaticLangClientFileView)1 TocContentView (com.google.api.codegen.viewmodel.metadata.TocContentView)1 Method (com.google.api.tools.framework.model.Method)1