Search in sources :

Example 26 with MethodConfig

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

the class PythonSurfaceNamer method getReturnDocLines.

@Override
public List<String> getReturnDocLines(TransformationContext context, MethodContext methodContext, Synchronicity synchronicity) {
    MethodConfig methodConfig = methodContext.getMethodConfig();
    TypeRef outputType = ((GapicMethodConfig) methodConfig).getMethod().getOutputType();
    if (ServiceMessages.s_isEmptyType(outputType)) {
        return ImmutableList.<String>of();
    }
    String returnTypeName = methodConfig.isLongRunningOperation() ? "google.gax._OperationFuture" : getModelTypeFormatter().getFullNameFor(outputType);
    String classInfo = PythonDocstringUtil.napoleonType(returnTypeName, getVersionedDirectoryNamespace());
    if (((GapicMethodConfig) methodConfig).getMethod().getResponseStreaming()) {
        return ImmutableList.of("Iterable[" + classInfo + "].");
    }
    if (methodConfig.isPageStreaming()) {
        FieldModel fieldModel = methodConfig.getPageStreaming().getResourcesField();
        return ImmutableList.of("A :class:`~google.gax.PageIterator` instance. By default, this", "is an iterable of " + annotateWithClass(getResponseTypeNameForElementType(fieldModel.getType())) + " instances.", "This object can also be configured to iterate over the pages", "of the response through the `options` parameter.");
    }
    return ImmutableList.of(String.format("A %s instance.", annotateWithClass(classInfo)));
}
Also used : GapicMethodConfig(com.google.api.codegen.config.GapicMethodConfig) MethodConfig(com.google.api.codegen.config.MethodConfig) TypeRef(com.google.api.tools.framework.model.TypeRef) FieldModel(com.google.api.codegen.config.FieldModel)

Example 27 with MethodConfig

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

the class RubyApiMethodParamTransformer method generateMethodParams.

@Override
public List<DynamicLangDefaultableParamView> generateMethodParams(GapicMethodContext context) {
    ImmutableList.Builder<DynamicLangDefaultableParamView> methodParams = ImmutableList.builder();
    if (context.getMethodModel().getRequestStreaming()) {
        DynamicLangDefaultableParamView.Builder param = DynamicLangDefaultableParamView.newBuilder();
        param.name(context.getNamer().getRequestVariableName(context.getMethodModel()));
        param.defaultValue("");
        methodParams.add(param.build());
    } else {
        MethodConfig methodConfig = context.getMethodConfig();
        for (FieldModel field : methodConfig.getRequiredFields()) {
            DynamicLangDefaultableParamView.Builder param = DynamicLangDefaultableParamView.newBuilder();
            param.name(context.getNamer().getVariableName(field));
            param.defaultValue("");
            methodParams.add(param.build());
        }
        for (FieldModel field : methodConfig.getOptionalFields()) {
            if (isRequestTokenParam(methodConfig, field)) {
                continue;
            }
            DynamicLangDefaultableParamView.Builder param = DynamicLangDefaultableParamView.newBuilder();
            param.name(context.getNamer().getVariableName(field));
            param.defaultValue("nil");
            methodParams.add(param.build());
        }
    }
    DynamicLangDefaultableParamView.Builder optionsParam = DynamicLangDefaultableParamView.newBuilder();
    optionsParam.name("options");
    optionsParam.defaultValue("nil");
    methodParams.add(optionsParam.build());
    return methodParams.build();
}
Also used : DynamicLangDefaultableParamView(com.google.api.codegen.viewmodel.DynamicLangDefaultableParamView) MethodConfig(com.google.api.codegen.config.MethodConfig) ImmutableList(com.google.common.collect.ImmutableList) FieldModel(com.google.api.codegen.config.FieldModel)

Example 28 with MethodConfig

use of com.google.api.codegen.config.MethodConfig 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.getMapValueField().isMessage();
            if (isMessageField || isMapContainingMessage) {
                String messageType;
                if (isMapContainingMessage) {
                    messageType = context.getTypeTable().getFullNameForElementType(field.getMapValueField());
                } 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 29 with MethodConfig

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

the class RubyGapicSurfaceTestTransformer method createUnitTestCaseInitCodeContext.

private InitCodeContext createUnitTestCaseInitCodeContext(GapicInterfaceContext context, MethodModel method) {
    MethodContext requestMethodContext = context.asRequestMethodContext(method);
    MethodContext dynamicMethodContext = context.asDynamicMethodContext(method);
    MethodConfig methodConfig = requestMethodContext.getMethodConfig();
    Iterable<FieldConfig> fieldConfigs = methodConfig.getRequiredFieldConfigs();
    InitCodeOutputType outputType = method.getRequestStreaming() ? InitCodeOutputType.SingleObject : InitCodeOutputType.FieldList;
    return InitCodeContext.newBuilder().initObjectType(method.getInputType()).suggestedName(Name.from("request")).initFieldConfigStrings(methodConfig.getSampleCodeInitFields()).initValueConfigMap(InitCodeTransformer.createCollectionMap(dynamicMethodContext)).initFields(FieldConfig.toFieldTypeIterable(fieldConfigs)).outputType(outputType).fieldConfigMap(FieldConfig.toFieldConfigMap(fieldConfigs)).build();
}
Also used : MethodConfig(com.google.api.codegen.config.MethodConfig) FieldConfig(com.google.api.codegen.config.FieldConfig) GapicMethodContext(com.google.api.codegen.transformer.GapicMethodContext) MethodContext(com.google.api.codegen.transformer.MethodContext) InitCodeOutputType(com.google.api.codegen.metacode.InitCodeContext.InitCodeOutputType)

Example 30 with MethodConfig

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

the class RubyGapicSurfaceTestTransformer method createUnitTestCaseViews.

private List<TestCaseView> createUnitTestCaseViews(GapicInterfaceContext context, boolean packageHasMultipleServices) {
    ImmutableList.Builder<TestCaseView> testCases = ImmutableList.builder();
    for (MethodModel method : context.getSupportedMethods()) {
        GapicMethodContext requestMethodContext = context.withNewTypeTable().asRequestMethodContext(method);
        MethodConfig methodConfig = requestMethodContext.getMethodConfig();
        TestCaseTransformer testCaseTransformer = new TestCaseTransformer(valueProducer, packageHasMultipleServices);
        TestCaseView testCase = testCaseTransformer.createTestCaseView(requestMethodContext, new SymbolTable(), createUnitTestCaseInitCodeContext(context, method), getMethodType(methodConfig));
        testCases.add(testCase);
    }
    return testCases.build();
}
Also used : MethodConfig(com.google.api.codegen.config.MethodConfig) MethodModel(com.google.api.codegen.config.MethodModel) GapicMethodContext(com.google.api.codegen.transformer.GapicMethodContext) TestCaseView(com.google.api.codegen.viewmodel.testing.TestCaseView) ImmutableList(com.google.common.collect.ImmutableList) TestCaseTransformer(com.google.api.codegen.transformer.TestCaseTransformer) SymbolTable(com.google.api.codegen.util.SymbolTable)

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