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