Search in sources :

Example 86 with MethodModel

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

the class NodeJSSurfaceNamer method returnCallbackDocLines.

private List<String> returnCallbackDocLines(ImportTypeTable typeTable, GapicMethodConfig methodConfig) {
    String returnTypeDoc = returnTypeDoc(typeTable, methodConfig);
    Method method = methodConfig.getMethod();
    MethodModel methodModel = methodConfig.getMethodModel();
    String classInfo = getParamTypeName(typeTable, methodModel.getOutputType());
    String callbackType;
    if (isProtobufEmpty(method.getOutputMessage())) {
        callbackType = "function(?Error)";
    } else if (methodConfig.isPageStreaming()) {
        callbackType = String.format("function(?Error, ?Array, ?Object, ?%s)", classInfo);
    } else {
        callbackType = String.format("function(?Error, ?%s)", classInfo);
    }
    ImmutableList.Builder<String> callbackLines = ImmutableList.builder();
    callbackLines.add("@param {" + callbackType + "} [callback]", "  The function which will be called with the result of the API call.");
    if (!isProtobufEmpty(method.getOutputMessage())) {
        callbackLines.add("", "  The second parameter to the callback is " + returnTypeDoc + ".");
        if (methodConfig.isPageStreaming()) {
            callbackLines.add("", "  When autoPaginate: false is specified through options, it contains the result", "  in a single response. If the response indicates the next page exists, the third", "  parameter is set to be used for the next request object. The fourth parameter keeps", "  the raw response object of " + getTypeNameDoc(typeTable, methodModel.getOutputType()) + ".");
        }
    }
    return callbackLines.build();
}
Also used : MethodModel(com.google.api.codegen.config.MethodModel) ImmutableList(com.google.common.collect.ImmutableList) Method(com.google.api.tools.framework.model.Method)

Example 87 with MethodModel

use of com.google.api.codegen.config.MethodModel 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.getMethodConfig().isLongRunningOperation()) {
            clientMethodType = ClientMethodType.OperationOptionalArrayMethod;
        } else if (methodContext.getMethodConfig().isPageStreaming()) {
            clientMethodType = ClientMethodType.PagedOptionalArrayMethod;
        }
        Iterable<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.transformer.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 88 with MethodModel

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

the class MethodTransformer method generateMethods.

public List<MethodView> generateMethods(InterfaceModel apiInterface, Map<String, String> collectionNameMap) {
    ImmutableList.Builder<MethodView> methods = ImmutableList.builder();
    for (MethodModel method : apiInterface.getMethods()) {
        MethodView.Builder methodView = MethodView.newBuilder();
        methodView.name(method.getRawName());
        generateField(method, methodView);
        generatePageStreaming(method, methodView);
        generateRetry(method, methodView);
        generateFieldNamePatterns(method, methodView, collectionNameMap);
        methodView.timeoutMillis("60000");
        methods.add(methodView.build());
    }
    return methods.build();
}
Also used : MethodModel(com.google.api.codegen.config.MethodModel) ImmutableList(com.google.common.collect.ImmutableList) MethodView(com.google.api.codegen.configgen.viewmodel.MethodView)

Example 89 with MethodModel

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

the class JavaDiscoGapicRequestToViewTransformer method transform.

@Override
public List<ViewModel> transform(DiscoApiModel model, GapicProductConfig productConfig) {
    List<ViewModel> surfaceRequests = new ArrayList<>();
    String packageName = productConfig.getPackageName();
    SurfaceNamer surfaceNamer = new JavaSurfaceNamer(packageName, packageName, nameFormatter);
    for (InterfaceModel apiInterface : model.getInterfaces()) {
        boolean enableStringFormatFunctions = productConfig.getResourceNameMessageConfigs().isEmpty();
        DiscoGapicInterfaceContext context = JavaDiscoGapicSurfaceTransformer.newInterfaceContext(apiInterface, productConfig, surfaceNamer, createTypeTable(productConfig.getPackageName()), enableStringFormatFunctions);
        for (MethodModel method : context.getSupportedMethods()) {
            RequestObjectParamView params = getRequestObjectParams(context, method);
            SchemaTransformationContext requestContext = SchemaTransformationContext.create(method.getFullName(), context.getSchemaTypeTable(), context);
            StaticLangApiMessageView requestView = generateRequestClass(requestContext, method, params);
            surfaceRequests.add(generateRequestFile(requestContext, requestView));
        }
    }
    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) DiscoveryMethodModel(com.google.api.codegen.config.DiscoveryMethodModel) MethodModel(com.google.api.codegen.config.MethodModel) ArrayList(java.util.ArrayList) ViewModel(com.google.api.codegen.viewmodel.ViewModel) RequestObjectParamView(com.google.api.codegen.viewmodel.RequestObjectParamView) JavaSurfaceNamer(com.google.api.codegen.transformer.java.JavaSurfaceNamer) InterfaceModel(com.google.api.codegen.config.InterfaceModel) StaticLangApiMessageView(com.google.api.codegen.viewmodel.StaticLangApiMessageView) JavaSurfaceNamer(com.google.api.codegen.transformer.java.JavaSurfaceNamer) SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer) DiscoGapicInterfaceContext(com.google.api.codegen.transformer.DiscoGapicInterfaceContext)

Example 90 with MethodModel

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

the class PhpGapicSurfaceTransformer method createLongRunningDescriptors.

private List<LongRunningOperationDetailView> createLongRunningDescriptors(GapicInterfaceContext context) {
    List<LongRunningOperationDetailView> result = new ArrayList<>();
    for (MethodModel method : context.getLongRunningMethods()) {
        GapicMethodContext methodContext = context.asDynamicMethodContext(method);
        LongRunningConfig lroConfig = methodContext.getMethodConfig().getLongRunningConfig();
        TypeModel returnType = lroConfig.getReturnType();
        TypeModel metadataType = lroConfig.getMetadataType();
        result.add(LongRunningOperationDetailView.newBuilder().methodName(context.getNamer().getApiMethodName(method, VisibilityConfig.PUBLIC)).transportMethodName(context.getNamer().getGrpcMethodName(method)).constructorName("").clientReturnTypeName("").operationPayloadTypeName(context.getImportTypeTable().getFullNameFor(returnType)).isEmptyOperation(lroConfig.getReturnType().isEmptyType()).metadataTypeName(context.getImportTypeTable().getFullNameFor(metadataType)).implementsCancel(true).implementsDelete(true).initialPollDelay(lroConfig.getInitialPollDelay().toMillis()).pollDelayMultiplier(lroConfig.getPollDelayMultiplier()).maxPollDelay(lroConfig.getMaxPollDelay().toMillis()).totalPollTimeout(lroConfig.getTotalPollTimeout().toMillis()).build());
    }
    return result;
}
Also used : LongRunningOperationDetailView(com.google.api.codegen.viewmodel.LongRunningOperationDetailView) MethodModel(com.google.api.codegen.config.MethodModel) GapicMethodContext(com.google.api.codegen.transformer.GapicMethodContext) LongRunningConfig(com.google.api.codegen.config.LongRunningConfig) ArrayList(java.util.ArrayList) TypeModel(com.google.api.codegen.config.TypeModel)

Aggregations

MethodModel (com.google.api.codegen.config.MethodModel)95 ArrayList (java.util.ArrayList)30 MethodConfig (com.google.api.codegen.config.MethodConfig)29 StaticLangApiMethodView (com.google.api.codegen.viewmodel.StaticLangApiMethodView)23 GapicMethodContext (com.google.api.codegen.transformer.GapicMethodContext)20 ImmutableList (com.google.common.collect.ImmutableList)16 FlatteningConfig (com.google.api.codegen.config.FlatteningConfig)14 Builder (com.google.api.codegen.viewmodel.StaticLangApiMethodView.Builder)14 SurfaceNamer (com.google.api.codegen.transformer.SurfaceNamer)12 DiscoveryMethodModel (com.google.api.codegen.config.DiscoveryMethodModel)11 FieldConfig (com.google.api.codegen.config.FieldConfig)11 ProtoMethodModel (com.google.api.codegen.config.ProtoMethodModel)9 Test (org.junit.Test)9 FieldModel (com.google.api.codegen.config.FieldModel)8 MethodContext (com.google.api.codegen.transformer.MethodContext)8 SymbolTable (com.google.api.codegen.util.SymbolTable)8 TypeModel (com.google.api.codegen.config.TypeModel)7 TestCaseView (com.google.api.codegen.viewmodel.testing.TestCaseView)7 InterfaceModel (com.google.api.codegen.config.InterfaceModel)6 PageStreamingConfig (com.google.api.codegen.config.PageStreamingConfig)6