Search in sources :

Example 31 with MethodConfig

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

the class RubySurfaceNamer method getReturnDocLines.

@Override
public List<String> getReturnDocLines(TransformationContext context, MethodContext methodContext, Synchronicity synchronicity) {
    MethodModel method = methodContext.getMethodModel();
    MethodConfig methodConfig = methodContext.getMethodConfig();
    if (method.getResponseStreaming()) {
        String classInfo = method.getOutputTypeName(methodContext.getTypeTable()).getFullName();
        return ImmutableList.of("An enumerable of " + classInfo + " instances.", "");
    }
    if (methodConfig.isPageStreaming()) {
        String resourceTypeName = getTypeFormatter().getFullNameForElementType(methodConfig.getPageStreaming().getResourcesField());
        return ImmutableList.of("An enumerable of " + resourceTypeName + " instances.", "See Google::Gax::PagedEnumerable documentation for other", "operations such as per-page iteration or access to the response", "object.");
    }
    return ImmutableList.<String>of();
}
Also used : MethodConfig(com.google.api.codegen.config.MethodConfig) MethodModel(com.google.api.codegen.config.MethodModel)

Example 32 with MethodConfig

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

the class JavaDiscoGapicResourceNameToViewTransformer method transform.

@Override
public List<ViewModel> transform(DiscoApiModel apiModel, GapicProductConfig productConfig) {
    List<ViewModel> surfaceRequests = new ArrayList<>();
    String packageName = productConfig.getPackageName();
    SurfaceNamer surfaceNamer = new JavaSurfaceNamer(packageName, packageName, nameFormatter);
    DiscoGapicInterfaceContext context = DiscoGapicInterfaceContext.createWithoutInterface(apiModel, productConfig, createTypeTable(productConfig.getPackageName(), surfaceNamer), surfaceNamer, JavaFeatureConfig.newBuilder().enableStringFormatFunctions(true).build());
    // Keep track of which name patterns have been generated to avoid duplicate classes.
    Set<String> namePatterns = new HashSet<>();
    for (String interfaceName : productConfig.getInterfaceConfigMap().keySet()) {
        SchemaTransformationContext requestContext = SchemaTransformationContext.create(interfaceName, context.getSchemaTypeTable(), context);
        // Maps a canonical resource name pattern to any method that uses that pattern.
        Map<String, Method> namePatternsToMethod = new HashMap<>();
        for (MethodConfig methodConfig : productConfig.getInterfaceConfigMap().get(interfaceName).getMethodConfigs()) {
            Method method = ((DiscoveryMethodModel) methodConfig.getMethodModel()).getDiscoMethod();
            namePatternsToMethod.put(DiscoGapicParser.getCanonicalPath(method), method);
        }
        for (SingleResourceNameConfig nameConfig : productConfig.getInterfaceConfigMap().get(interfaceName).getSingleResourceNameConfigs()) {
            String namePattern = nameConfig.getNamePattern();
            if (namePatterns.contains(namePattern)) {
                continue;
            }
            Method method = namePatternsToMethod.get(namePattern);
            StaticLangApiResourceNameView resourceNameView = generateResourceNameClass(requestContext, method, nameConfig);
            surfaceRequests.add(generateResourceNameFile(requestContext, resourceNameView));
            namePatterns.add(nameConfig.getNamePattern());
        }
    }
    Collections.sort(surfaceRequests, new Comparator<ViewModel>() {

        @Override
        public int compare(ViewModel o1, ViewModel o2) {
            return String.CASE_INSENSITIVE_ORDER.compare(o1.outputPath(), o2.outputPath());
        }
    });
    return surfaceRequests;
}
Also used : SchemaTransformationContext(com.google.api.codegen.discogapic.SchemaTransformationContext) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ViewModel(com.google.api.codegen.viewmodel.ViewModel) Method(com.google.api.codegen.discovery.Method) DiscoveryMethodModel(com.google.api.codegen.config.DiscoveryMethodModel) JavaSurfaceNamer(com.google.api.codegen.transformer.java.JavaSurfaceNamer) StaticLangApiResourceNameView(com.google.api.codegen.viewmodel.StaticLangApiResourceNameView) SingleResourceNameConfig(com.google.api.codegen.config.SingleResourceNameConfig) MethodConfig(com.google.api.codegen.config.MethodConfig) JavaSurfaceNamer(com.google.api.codegen.transformer.java.JavaSurfaceNamer) SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer) DiscoGapicInterfaceContext(com.google.api.codegen.transformer.DiscoGapicInterfaceContext) HashSet(java.util.HashSet)

Example 33 with MethodConfig

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

the class ApiCallableTransformer method generateMethodDescriptor.

private MethodDescriptorView generateMethodDescriptor(MethodContext context) {
    ImportTypeTable typeTable = context.getTypeTable();
    MethodModel method = context.getMethodModel();
    MethodConfig methodConfig = context.getMethodConfig();
    SurfaceNamer namer = context.getNamer();
    MethodDescriptorView.Builder methodDescriptorBuilder = MethodDescriptorView.newBuilder();
    if (methodConfig.isGrpcStreaming()) {
        methodDescriptorBuilder.grpcStreamingType(methodConfig.getGrpcStreaming().getType());
    }
    methodDescriptorBuilder.requestTypeName(method.getAndSaveRequestTypeName(typeTable, namer));
    methodDescriptorBuilder.responseTypeName(method.getAndSaveResponseTypeName(typeTable, namer));
    methodDescriptorBuilder.hasResponse(!method.isOutputTypeEmpty());
    methodDescriptorBuilder.name(namer.getMethodDescriptorName(method));
    methodDescriptorBuilder.protoMethodName(method.getSimpleName());
    methodDescriptorBuilder.fullServiceName(context.getTargetInterface().getFullName());
    methodDescriptorBuilder.transportSettingsVar(namer.getTransportSettingsVar(method));
    methodDescriptorBuilder.headerRequestParams(headerRequestParamTransformer.generateHeaderRequestParams(context));
    methodDescriptorBuilder.httpMethod(generateHttpFields(context));
    return methodDescriptorBuilder.build();
}
Also used : MethodConfig(com.google.api.codegen.config.MethodConfig) MethodModel(com.google.api.codegen.config.MethodModel) DiscoveryMethodModel(com.google.api.codegen.config.DiscoveryMethodModel) MethodDescriptorView(com.google.api.codegen.viewmodel.MethodDescriptorView)

Example 34 with MethodConfig

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

the class ApiCallableTransformer method generateMainApiCallable.

private ApiCallableView generateMainApiCallable(MethodContext context) {
    MethodConfig methodConfig = context.getMethodConfig();
    MethodModel method = context.getMethodModel();
    SurfaceNamer namer = context.getNamer();
    ApiCallableView.Builder apiCallableBuilder = ApiCallableView.newBuilder();
    apiCallableBuilder.requestTypeName(method.getAndSaveRequestTypeName(context.getTypeTable(), context.getNamer()));
    apiCallableBuilder.responseTypeName(method.getAndSaveResponseTypeName(context.getTypeTable(), context.getNamer()));
    apiCallableBuilder.name(namer.getCallableName(method));
    apiCallableBuilder.methodName(namer.getApiMethodName(method, context.getMethodConfig().getVisibility()));
    apiCallableBuilder.asyncMethodName(namer.getAsyncApiMethodName(method, VisibilityConfig.PUBLIC));
    apiCallableBuilder.memberName(namer.getSettingsMemberName(method));
    apiCallableBuilder.settingsFunctionName(namer.getSettingsFunctionName(method));
    apiCallableBuilder.grpcClientVarName(namer.getReroutedGrpcClientVarName(methodConfig));
    apiCallableBuilder.headerRequestParams(headerRequestParamTransformer.generateHeaderRequestParams(context));
    setCommonApiCallableFields(context, apiCallableBuilder);
    ApiCallableImplType callableImplType = ApiCallableImplType.SimpleApiCallable;
    if (methodConfig.isGrpcStreaming()) {
        callableImplType = ApiCallableImplType.of(methodConfig.getGrpcStreamingType());
        apiCallableBuilder.grpcStreamingType(methodConfig.getGrpcStreamingType());
    } else if (methodConfig.isBatching()) {
        callableImplType = ApiCallableImplType.BatchingApiCallable;
    }
    apiCallableBuilder.type(callableImplType);
    apiCallableBuilder.interfaceTypeName(namer.getApiCallableTypeName(callableImplType.serviceMethodType()));
    return apiCallableBuilder.build();
}
Also used : MethodConfig(com.google.api.codegen.config.MethodConfig) MethodModel(com.google.api.codegen.config.MethodModel) DiscoveryMethodModel(com.google.api.codegen.config.DiscoveryMethodModel) ApiCallableView(com.google.api.codegen.viewmodel.ApiCallableView) ApiCallableImplType(com.google.api.codegen.viewmodel.ApiCallableImplType)

Example 35 with MethodConfig

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

the class ApiCallableTransformer method generateApiCallableSettings.

public ApiCallSettingsView generateApiCallableSettings(MethodContext context, ApiCallableImplType callableImplType) {
    SurfaceNamer namer = context.getNamer();
    ImportTypeTable typeTable = context.getTypeTable();
    MethodModel method = context.getMethodModel();
    MethodConfig methodConfig = context.getMethodConfig();
    Map<String, RetryCodesDefinitionView> retryCodesByKey = new HashMap<>();
    for (RetryCodesDefinitionView retryCodes : retryDefinitionsTransformer.generateRetryCodesDefinitions(context.getSurfaceInterfaceContext())) {
        retryCodesByKey.put(retryCodes.key(), retryCodes);
    }
    Map<String, RetryParamsDefinitionView> retryParamsByKey = new HashMap<>();
    for (RetryParamsDefinitionView retryParams : retryDefinitionsTransformer.generateRetryParamsDefinitions(context.getSurfaceInterfaceContext())) {
        retryParamsByKey.put(retryParams.key(), retryParams);
    }
    ApiCallSettingsView.Builder settings = ApiCallSettingsView.newBuilder();
    settings.methodName(namer.getApiMethodName(method, VisibilityConfig.PUBLIC));
    settings.asyncMethodName(namer.getAsyncApiMethodName(method, VisibilityConfig.PUBLIC));
    settings.requestTypeName(method.getAndSaveRequestTypeName(context.getTypeTable(), context.getNamer()));
    settings.responseTypeName(method.getAndSaveResponseTypeName(context.getTypeTable(), context.getNamer()));
    settings.grpcTypeName(typeTable.getAndSaveNicknameFor(context.getGrpcContainerTypeName()));
    settings.grpcMethodConstant(namer.getGrpcMethodConstant(method));
    settings.retryCodesName(methodConfig.getRetryCodesConfigName());
    settings.retryCodesView(retryCodesByKey.get(methodConfig.getRetryCodesConfigName()));
    settings.retryParamsName(methodConfig.getRetrySettingsConfigName());
    settings.retryParamsView(retryParamsByKey.get(methodConfig.getRetrySettingsConfigName()));
    settings.visibility(namer.getVisiblityKeyword(methodConfig.getVisibility()));
    String notImplementedPrefix = "ApiCallableTransformer.generateApiCallableSettings - ";
    settings.resourceTypeName(namer.getNotImplementedString(notImplementedPrefix + "resourceTypeName"));
    settings.pagedListResponseTypeName(namer.getNotImplementedString(notImplementedPrefix + "pagedListResponseTypeName"));
    settings.pageStreamingDescriptorName(namer.getNotImplementedString(notImplementedPrefix + "pageStreamingDescriptorName"));
    settings.pagedListResponseFactoryName(namer.getNotImplementedString(notImplementedPrefix + "pagedListResponseFactoryName"));
    settings.batchingDescriptorName(namer.getNotImplementedString(notImplementedPrefix + "batchingDescriptorName"));
    settings.memberName(namer.getSettingsMemberName(method));
    settings.settingsGetFunction(namer.getSettingsFunctionName(method));
    settings.type(callableImplType);
    switch(callableImplType) {
        case BidiStreamingApiCallable:
        case ClientStreamingApiCallable:
        case ServerStreamingApiCallable:
            settings.type(ApiCallableImplType.of(methodConfig.getGrpcStreamingType()));
            if (methodConfig.getGrpcStreaming().hasResourceField()) {
                FieldModel resourceType = methodConfig.getGrpcStreaming().getResourcesField();
                settings.resourceTypeName(typeTable.getAndSaveNicknameForElementType(resourceType));
            }
            settings.grpcStreamingType(methodConfig.getGrpcStreaming().getType());
            break;
        case PagedApiCallable:
            settings.type(ApiCallableImplType.PagedApiCallable);
            FieldModel resourceField = methodConfig.getPageStreaming().getResourcesField();
            settings.resourceTypeName(typeTable.getAndSaveNicknameForElementType(resourceField));
            settings.pagedListResponseTypeName(namer.getAndSavePagedResponseTypeName(context, methodConfig.getPageStreaming().getResourcesFieldConfig()));
            settings.pageStreamingDescriptorName(namer.getPageStreamingDescriptorConstName(method));
            settings.pagedListResponseFactoryName(namer.getPagedListResponseFactoryConstName(method));
            break;
        case BatchingApiCallable:
            settings.type(ApiCallableImplType.BatchingApiCallable);
            settings.batchingDescriptorName(namer.getBatchingDescriptorConstName(method));
            settings.batchingConfig(batchingTransformer.generateBatchingConfig(context));
            break;
        case OperationApiCallable:
            settings.type(ApiCallableImplType.OperationApiCallable);
            settings.operationMethod(lroTransformer.generateDetailView(context));
            settings.memberName(namer.getOperationSettingsMemberName(method));
            settings.settingsGetFunction(namer.getOperationSettingsFunctionName(method));
            break;
        case SimpleApiCallable:
            break;
        default:
            throw new IllegalStateException("Unhandled ApiCallableImplType enum value: " + callableImplType);
    }
    return settings.build();
}
Also used : MethodModel(com.google.api.codegen.config.MethodModel) DiscoveryMethodModel(com.google.api.codegen.config.DiscoveryMethodModel) HashMap(java.util.HashMap) RetryCodesDefinitionView(com.google.api.codegen.viewmodel.RetryCodesDefinitionView) ApiCallSettingsView(com.google.api.codegen.viewmodel.ApiCallSettingsView) MethodConfig(com.google.api.codegen.config.MethodConfig) RetryParamsDefinitionView(com.google.api.codegen.viewmodel.RetryParamsDefinitionView) FieldModel(com.google.api.codegen.config.FieldModel)

Aggregations

MethodConfig (com.google.api.codegen.config.MethodConfig)51 MethodModel (com.google.api.codegen.config.MethodModel)29 ArrayList (java.util.ArrayList)20 ImmutableList (com.google.common.collect.ImmutableList)14 FieldModel (com.google.api.codegen.config.FieldModel)13 SurfaceNamer (com.google.api.codegen.transformer.SurfaceNamer)9 DiscoveryMethodModel (com.google.api.codegen.config.DiscoveryMethodModel)8 MethodContext (com.google.api.codegen.transformer.MethodContext)8 FieldConfig (com.google.api.codegen.config.FieldConfig)7 FlatteningConfig (com.google.api.codegen.config.FlatteningConfig)6 GapicMethodContext (com.google.api.codegen.transformer.GapicMethodContext)6 SimpleParamDocView (com.google.api.codegen.viewmodel.SimpleParamDocView)6 StaticLangApiMethodView (com.google.api.codegen.viewmodel.StaticLangApiMethodView)6 ParamDocView (com.google.api.codegen.viewmodel.ParamDocView)5 GapicMethodConfig (com.google.api.codegen.config.GapicMethodConfig)4 GapicInterfaceConfig (com.google.api.codegen.config.GapicInterfaceConfig)3 InterfaceConfig (com.google.api.codegen.config.InterfaceConfig)3 PageStreamingConfig (com.google.api.codegen.config.PageStreamingConfig)3 ParamWithSimpleDoc (com.google.api.codegen.transformer.ParamWithSimpleDoc)3 SymbolTable (com.google.api.codegen.util.SymbolTable)3