Search in sources :

Example 6 with InterfaceConfig

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

the class PathTemplateTransformer method getSingleResourceNameConfigsUsedByInterface.

private List<SingleResourceNameConfig> getSingleResourceNameConfigsUsedByInterface(InterfaceContext context) {
    InterfaceConfig interfaceConfig = context.getInterfaceConfig();
    Set<String> foundSet = new HashSet<>();
    ImmutableList.Builder<SingleResourceNameConfig> resourceNameConfigsBuilder = ImmutableList.builder();
    for (SingleResourceNameConfig config : interfaceConfig.getSingleResourceNameConfigs()) {
        resourceNameConfigsBuilder.add(config);
        foundSet.add(config.getEntityId());
    }
    for (MethodConfig methodConfig : interfaceConfig.getMethodConfigs()) {
        MethodContext methodContext = context.asRequestMethodContext(methodConfig.getMethodModel());
        for (String fieldNamePattern : methodConfig.getFieldNamePatterns().values()) {
            SingleResourceNameConfig resourceNameConfig = methodContext.getSingleResourceNameConfig(fieldNamePattern);
            if (resourceNameConfig != null && !foundSet.contains(resourceNameConfig.getEntityId())) {
                resourceNameConfigsBuilder.add(resourceNameConfig);
                foundSet.add(resourceNameConfig.getEntityId());
            }
        }
    }
    return resourceNameConfigsBuilder.build();
}
Also used : MethodConfig(com.google.api.codegen.config.MethodConfig) InterfaceConfig(com.google.api.codegen.config.InterfaceConfig) ImmutableList(com.google.common.collect.ImmutableList) SingleResourceNameConfig(com.google.api.codegen.config.SingleResourceNameConfig) HashSet(java.util.HashSet)

Example 7 with InterfaceConfig

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

the class StaticLangApiMethodTransformer method setCommonFields.

private void setCommonFields(MethodContext context, StaticLangApiMethodView.Builder methodViewBuilder) {
    MethodModel method = context.getMethodModel();
    SurfaceNamer namer = context.getNamer();
    InterfaceConfig interfaceConfig = context.getInterfaceConfig();
    String requestTypeName = method.getAndSaveRequestTypeName(context.getTypeTable(), context.getNamer());
    methodViewBuilder.serviceRequestTypeName(requestTypeName);
    methodViewBuilder.serviceRequestTypeConstructor(namer.getTypeConstructor(requestTypeName));
    methodViewBuilder.serviceConstructorName(namer.getApiWrapperClassConstructorName(context.getInterfaceConfig()));
    setServiceResponseTypeName(context, methodViewBuilder);
    methodViewBuilder.apiClassName(namer.getApiWrapperClassName(interfaceConfig));
    methodViewBuilder.apiVariableName(namer.getApiWrapperVariableName(interfaceConfig));
    methodViewBuilder.stubName(namer.getStubName(context.getTargetInterface()));
    methodViewBuilder.settingsGetterName(namer.getSettingsFunctionName(method));
    methodViewBuilder.callableName(context.getNamer().getCallableName(method));
    methodViewBuilder.modifyMethodName(namer.getModifyMethodName(context));
    methodViewBuilder.grpcStreamingType(context.getMethodConfig().getGrpcStreamingType());
    methodViewBuilder.visibility(namer.getVisiblityKeyword(context.getMethodConfig().getVisibility()));
    methodViewBuilder.releaseLevelAnnotation(namer.getReleaseAnnotation(context.getMethodConfig().getReleaseLevel()));
    ServiceMessages messages = new ServiceMessages();
    if (context.getMethodConfig().isLongRunningOperation()) {
        methodViewBuilder.hasReturnValue(!context.getMethodConfig().getLongRunningConfig().getReturnType().isEmptyType());
    } else {
        methodViewBuilder.hasReturnValue(!method.isOutputTypeEmpty());
    }
    methodViewBuilder.headerRequestParams(headerRequestParamTransformer.generateHeaderRequestParams(context));
}
Also used : MethodModel(com.google.api.codegen.config.MethodModel) InterfaceConfig(com.google.api.codegen.config.InterfaceConfig) ServiceMessages(com.google.api.codegen.ServiceMessages)

Example 8 with InterfaceConfig

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

the class CSharpGapicClientTransformer method generateSettingsClass.

private StaticLangSettingsView generateSettingsClass(GapicInterfaceContext context) {
    StaticLangSettingsView.Builder settingsClass = StaticLangSettingsView.newBuilder();
    settingsClass.doc(generateSettingsDoc(context));
    String name = context.getNamer().getApiSettingsClassName(context.getInterfaceConfig());
    settingsClass.name(name);
    ApiModel model = context.getApiModel();
    settingsClass.serviceAddress(model.getServiceAddress());
    settingsClass.servicePort(model.getServicePort());
    settingsClass.authScopes(model.getAuthScopes());
    settingsClass.callSettings(generateCallSettings(context));
    settingsClass.pageStreamingDescriptors(pageStreamingTransformer.generateDescriptorClasses(context));
    settingsClass.pagedListResponseFactories(pageStreamingTransformer.generateFactoryClasses(context));
    settingsClass.batchingDescriptors(batchingTransformer.generateDescriptorClasses(context));
    settingsClass.retryCodesDefinitions(retryDefinitionsTransformer.generateRetryCodesDefinitions(context));
    settingsClass.retryParamsDefinitions(retryDefinitionsTransformer.generateRetryParamsDefinitions(context));
    InterfaceConfig interfaceConfig = context.getInterfaceConfig();
    settingsClass.hasDefaultServiceAddress(interfaceConfig.hasDefaultServiceAddress());
    settingsClass.hasDefaultServiceScopes(interfaceConfig.hasDefaultServiceScopes());
    settingsClass.hasDefaultInstance(interfaceConfig.hasDefaultInstance());
    return settingsClass.build();
}
Also used : InterfaceConfig(com.google.api.codegen.config.InterfaceConfig) StaticLangSettingsView(com.google.api.codegen.viewmodel.StaticLangSettingsView) ApiModel(com.google.api.codegen.config.ApiModel)

Example 9 with InterfaceConfig

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

the class GoGapicSurfaceTransformer method generateExample.

private StaticLangClientExampleFileView generateExample(InterfaceContext context) {
    StaticLangClientExampleFileView.Builder view = StaticLangClientExampleFileView.newBuilder();
    SurfaceNamer namer = context.getNamer();
    InterfaceModel apiInterface = context.getInterfaceModel();
    ProductConfig productConfig = context.getProductConfig();
    InterfaceConfig interfaceConfig = context.getInterfaceConfig();
    view.templateFileName(SAMPLE_TEMPLATE_FILENAME);
    String outputPath = pathMapper.getOutputPath(apiInterface.getFullName(), productConfig);
    String fileName = namer.getExampleFileName(context.getInterfaceConfig());
    view.outputPath(outputPath + File.separator + fileName);
    view.clientTypeName(namer.getApiWrapperClassName(context.getInterfaceConfig()));
    view.clientConstructorName(namer.getApiWrapperClassConstructorName(interfaceConfig));
    view.clientConstructorExampleName(namer.getApiWrapperClassConstructorExampleName(interfaceConfig));
    view.apiMethods(generateApiMethods(context, context.getPublicMethods()));
    view.iamResources(iamResourceTransformer.generateIamResources(context));
    // Examples are different from the API. In particular, we use short declaration
    // and so we omit most type names. We only need
    // - Context, to initialize the client
    // - The VKit generated library, that's what the sample is for
    // - The input types of the methods, to initialize the requests
    // So, we clear all imports; addXExampleImports will add back the ones we want.
    context.getImportTypeTable().getImports().clear();
    addXExampleImports(context, context.getPublicMethods());
    view.fileHeader(fileHeaderTransformer.generateFileHeader(context));
    return view.build();
}
Also used : GapicInterfaceConfig(com.google.api.codegen.config.GapicInterfaceConfig) InterfaceConfig(com.google.api.codegen.config.InterfaceConfig) InterfaceModel(com.google.api.codegen.config.InterfaceModel) ProtoInterfaceModel(com.google.api.codegen.config.ProtoInterfaceModel) StaticLangClientExampleFileView(com.google.api.codegen.viewmodel.StaticLangClientExampleFileView) ProductConfig(com.google.api.codegen.config.ProductConfig) GapicProductConfig(com.google.api.codegen.config.GapicProductConfig) SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer)

Example 10 with InterfaceConfig

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

the class JavaSurfaceTransformer method generateSettingsClass.

private StaticLangSettingsView generateSettingsClass(InterfaceContext context, GapicProductConfig productConfig, StaticLangApiMethodView exampleApiMethod, StaticLangStubSettingsView stubSettingsView) {
    addSettingsImports(context);
    SurfaceNamer namer = context.getNamer();
    InterfaceConfig interfaceConfig = context.getInterfaceConfig();
    StaticLangSettingsView.Builder xsettingsClass = StaticLangSettingsView.newBuilder();
    String name = namer.getApiSettingsClassName(context.getInterfaceConfig());
    xsettingsClass.doc(generateSettingsDoc(context, exampleApiMethod, productConfig, name, namer.getApiWrapperClassName(context.getInterfaceConfig())));
    xsettingsClass.name(name);
    xsettingsClass.releaseLevelAnnotation(stubSettingsView.releaseLevelAnnotation());
    xsettingsClass.serviceAddress(stubSettingsView.serviceAddress());
    xsettingsClass.servicePort(stubSettingsView.servicePort());
    xsettingsClass.authScopes(stubSettingsView.authScopes());
    xsettingsClass.callSettings(apiCallableTransformer.generateCallSettings(context));
    xsettingsClass.pageStreamingDescriptors(stubSettingsView.pageStreamingDescriptors());
    xsettingsClass.pagedListResponseFactories(stubSettingsView.pagedListResponseFactories());
    xsettingsClass.batchingDescriptors(stubSettingsView.batchingDescriptors());
    xsettingsClass.retryCodesDefinitions(stubSettingsView.retryCodesDefinitions());
    xsettingsClass.hasDefaultServiceAddress(stubSettingsView.hasDefaultServiceAddress());
    xsettingsClass.hasDefaultServiceScopes(stubSettingsView.hasDefaultServiceScopes());
    xsettingsClass.hasDefaultInstance(stubSettingsView.hasDefaultInstance());
    xsettingsClass.retryParamsDefinitions(stubSettingsView.retryParamsDefinitions());
    xsettingsClass.instantiatingChannelProvider(stubSettingsView.instantiatingChannelProvider());
    xsettingsClass.transportProtocol(stubSettingsView.transportProtocol());
    xsettingsClass.useDefaultServicePortInEndpoint(stubSettingsView.useDefaultServicePortInEndpoint());
    xsettingsClass.defaultTransportProviderBuilder(stubSettingsView.defaultTransportProviderBuilder());
    xsettingsClass.stubSettingsName(getAndSaveNicknameForStubType(context, namer.getApiStubSettingsClassName(interfaceConfig)));
    return xsettingsClass.build();
}
Also used : InterfaceConfig(com.google.api.codegen.config.InterfaceConfig) StaticLangSettingsView(com.google.api.codegen.viewmodel.StaticLangSettingsView) SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer)

Aggregations

InterfaceConfig (com.google.api.codegen.config.InterfaceConfig)23 SurfaceNamer (com.google.api.codegen.transformer.SurfaceNamer)7 ImmutableList (com.google.common.collect.ImmutableList)5 InterfaceModel (com.google.api.codegen.config.InterfaceModel)4 SingleResourceNameConfig (com.google.api.codegen.config.SingleResourceNameConfig)4 GapicInterfaceConfig (com.google.api.codegen.config.GapicInterfaceConfig)3 MethodConfig (com.google.api.codegen.config.MethodConfig)3 ImportTypeTable (com.google.api.codegen.transformer.ImportTypeTable)3 StaticLangApiMethodView (com.google.api.codegen.viewmodel.StaticLangApiMethodView)3 Interface (com.google.api.tools.framework.model.Interface)3 ArrayList (java.util.ArrayList)3 ApiModel (com.google.api.codegen.config.ApiModel)2 GapicMethodConfig (com.google.api.codegen.config.GapicMethodConfig)2 ProtoInterfaceModel (com.google.api.codegen.config.ProtoInterfaceModel)2 InterfaceContext (com.google.api.codegen.transformer.InterfaceContext)2 TypeAlias (com.google.api.codegen.util.TypeAlias)2 StaticLangSettingsView (com.google.api.codegen.viewmodel.StaticLangSettingsView)2 HashSet (java.util.HashSet)2 InterfaceView (com.google.api.codegen.InterfaceView)1 ServiceMessages (com.google.api.codegen.ServiceMessages)1