Search in sources :

Example 16 with FieldModel

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

the class PhpApiMethodParamTransformer method generateDefaultableParams.

private List<DynamicLangDefaultableParamView> generateDefaultableParams(GapicMethodContext context) {
    if (context.getMethodModel().getRequestStreaming()) {
        return ImmutableList.<DynamicLangDefaultableParamView>of();
    }
    ImmutableList.Builder<DynamicLangDefaultableParamView> methodParams = ImmutableList.builder();
    for (FieldModel field : context.getMethodConfig().getRequiredFields()) {
        DynamicLangDefaultableParamView param = DynamicLangDefaultableParamView.newBuilder().name(context.getNamer().getVariableName(field)).defaultValue("").build();
        methodParams.add(param);
    }
    return methodParams.build();
}
Also used : DynamicLangDefaultableParamView(com.google.api.codegen.viewmodel.DynamicLangDefaultableParamView) ImmutableList(com.google.common.collect.ImmutableList) FieldModel(com.google.api.codegen.config.FieldModel)

Example 17 with FieldModel

use of com.google.api.codegen.config.FieldModel 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 18 with FieldModel

use of com.google.api.codegen.config.FieldModel 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 19 with FieldModel

use of com.google.api.codegen.config.FieldModel 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 20 with FieldModel

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

the class TestCaseTransformerTest method testResponseOneof.

@Test
public void testResponseOneof() {
    Oneof oneof1 = Mockito.mock(Oneof.class);
    Oneof oneof2 = Mockito.mock(Oneof.class);
    FieldModel field1 = Mockito.mock(FieldModel.class);
    Mockito.when(field1.isPrimitive()).thenReturn(true);
    Mockito.when(field1.isRepeated()).thenReturn(false);
    Mockito.when(field1.getOneof()).thenReturn(oneof1);
    FieldModel field2 = Mockito.mock(FieldModel.class);
    Mockito.when(field2.isPrimitive()).thenReturn(true);
    Mockito.when(field2.isRepeated()).thenReturn(false);
    Mockito.when(field2.getOneof()).thenReturn(oneof1);
    // not equal, even if they have the same properties; otherwise "containsExactly" below doesn't work.
    assertThat(field1).isNotEqualTo(field2);
    FieldModel field3 = Mockito.mock(FieldModel.class);
    Mockito.when(field3.isPrimitive()).thenReturn(true);
    Mockito.when(field3.isRepeated()).thenReturn(false);
    Mockito.when(field3.getOneof()).thenReturn(oneof2);
    List<FieldModel> fields;
    fields = Arrays.asList(field1);
    assertThat(TestCaseTransformer.responseInitFields(fields)).containsExactly(field1);
    // field1 and field2 have the same oneof, we can only choose one. First one wins.
    fields = Arrays.asList(field1, field2);
    assertThat(TestCaseTransformer.responseInitFields(fields)).containsExactly(field1);
    fields = Arrays.asList(field2, field1);
    assertThat(TestCaseTransformer.responseInitFields(fields)).containsExactly(field2);
    // field3 has a different oneof.
    fields = Arrays.asList(field1, field3);
    assertThat(TestCaseTransformer.responseInitFields(fields)).containsExactly(field1, field3);
    fields = Arrays.asList(field1, field2, field3);
    assertThat(TestCaseTransformer.responseInitFields(fields)).containsExactly(field1, field3);
}
Also used : Oneof(com.google.api.tools.framework.model.Oneof) FieldModel(com.google.api.codegen.config.FieldModel) Test(org.junit.Test)

Aggregations

FieldModel (com.google.api.codegen.config.FieldModel)44 MethodConfig (com.google.api.codegen.config.MethodConfig)13 ArrayList (java.util.ArrayList)13 ImmutableList (com.google.common.collect.ImmutableList)11 FieldConfig (com.google.api.codegen.config.FieldConfig)9 MethodModel (com.google.api.codegen.config.MethodModel)8 SimpleParamDocView (com.google.api.codegen.viewmodel.SimpleParamDocView)7 ParamDocView (com.google.api.codegen.viewmodel.ParamDocView)6 BatchingConfig (com.google.api.codegen.config.BatchingConfig)4 PageStreamingConfig (com.google.api.codegen.config.PageStreamingConfig)4 DynamicLangDefaultableParamView (com.google.api.codegen.viewmodel.DynamicLangDefaultableParamView)4 SurfaceNamer (com.google.api.codegen.transformer.SurfaceNamer)3 Name (com.google.api.codegen.util.Name)3 DiscoveryMethodModel (com.google.api.codegen.config.DiscoveryMethodModel)2 GenericFieldSelector (com.google.api.codegen.config.GenericFieldSelector)2 Schema (com.google.api.codegen.discovery.Schema)2 SymbolTable (com.google.api.codegen.util.SymbolTable)2 TypeName (com.google.api.codegen.util.TypeName)2 RequestObjectParamView (com.google.api.codegen.viewmodel.RequestObjectParamView)2 StaticLangApiMessageView (com.google.api.codegen.viewmodel.StaticLangApiMessageView)2