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();
}
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)));
}
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();
}
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();
}
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);
}
Aggregations