use of com.google.api.codegen.config.FieldModel in project toolkit by googleapis.
the class MethodTransformer method generatePageStreamingRequest.
private PageStreamingRequestView generatePageStreamingRequest(MethodModel method) {
PageStreamingRequestView.Builder requestBuilder = PageStreamingRequestView.newBuilder();
for (FieldModel field : method.getInputFields()) {
String fieldName = field.getSimpleName();
if (fieldName.equals(helperTransformer.getPagingParameters().getNameForPageToken())) {
requestBuilder.tokenField(fieldName);
} else if (fieldName.equals(helperTransformer.getPagingParameters().getNameForPageSize())) {
requestBuilder.pageSizeField(fieldName);
}
}
PageStreamingRequestView request = requestBuilder.build();
return request.tokenField() == null && request.pageSizeField() == null ? null : request;
}
use of com.google.api.codegen.config.FieldModel in project toolkit by googleapis.
the class MethodTransformer method generateField.
private void generateField(MethodModel method, MethodView.Builder methodView) {
List<String> parameterList = new ArrayList<>();
List<FieldModel> fieldList = new ArrayList<>();
Iterable<? extends FieldModel> inputFields = method.getInputFields();
for (FieldModel field : inputFields) {
String fieldName = field.getSimpleName();
if (field.getOneof() == null && !helperTransformer.getPagingParameters().getIgnoredParameters().contains(fieldName)) {
parameterList.add(fieldName);
fieldList.add(field);
}
}
List<String> parameters = filteredInputFields(method, fieldList);
if (parameters.size() > 0 && parameters.size() <= FLATTENING_THRESHOLD) {
methodView.flattening(generateFlattening(parameters));
}
methodView.requiredFields(parameters);
// use all fields for the following check; if there are ignored fields for flattening
// purposes, the caller still needs a way to set them (by using the request object method).
methodView.requestObjectMethod((Iterators.size(inputFields.iterator()) > REQUEST_OBJECT_METHOD_THRESHOLD || Iterators.size(inputFields.iterator()) != parameterList.size()) && !method.getRequestStreaming());
methodView.resourceNameTreatment(helperTransformer.getResourceNameTreatment(method));
}
use of com.google.api.codegen.config.FieldModel in project toolkit by googleapis.
the class PythonApiMethodParamTransformer method generateMethodParams.
@Override
public List<DynamicLangDefaultableParamView> generateMethodParams(GapicMethodContext context) {
ImmutableList.Builder<DynamicLangDefaultableParamView> methodParams = ImmutableList.builder();
methodParams.add(DynamicLangDefaultableParamView.newBuilder().name("self").defaultValue("").build());
if (context.getMethod().getRequestStreaming()) {
methodParams.add(DynamicLangDefaultableParamView.newBuilder().name(context.getNamer().getRequestVariableName(context.getMethodModel())).defaultValue("").build());
} else {
for (FieldModel field : context.getMethodConfig().getRequiredFields()) {
DynamicLangDefaultableParamView.Builder param = DynamicLangDefaultableParamView.newBuilder();
param.name(context.getNamer().getVariableName(field));
param.defaultValue("");
methodParams.add(param.build());
}
for (FieldModel field : context.getMethodConfig().getOptionalFields()) {
if (isRequestTokenParam(context.getMethodConfig(), field)) {
continue;
}
DynamicLangDefaultableParamView.Builder param = DynamicLangDefaultableParamView.newBuilder();
param.name(context.getNamer().getVariableName(field));
param.defaultValue("None");
methodParams.add(param.build());
}
}
methodParams.add(DynamicLangDefaultableParamView.newBuilder().name("retry").defaultValue("google.api_core.gapic_v1.method.DEFAULT").build());
methodParams.add(DynamicLangDefaultableParamView.newBuilder().name("timeout").defaultValue("google.api_core.gapic_v1.method.DEFAULT").build());
methodParams.add(DynamicLangDefaultableParamView.newBuilder().name("metadata").defaultValue("None").build());
return methodParams.build();
}
use of com.google.api.codegen.config.FieldModel in project toolkit by googleapis.
the class PythonApiMethodParamTransformer 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("If a dict is provided, it must be of the same form as the protobuf", String.format("message :class:`%s`", PythonDocstringUtil.napoleonType(messageType, namer.getVersionedDirectoryNamespace())));
}
}
paramDoc.lines(docLines.build());
docs.add(paramDoc.build());
}
return docs.build();
}
Aggregations