use of com.google.api.codegen.viewmodel.PageStreamingDescriptorClassView in project toolkit by googleapis.
the class GoGapicSurfaceTransformer method generate.
private StaticLangClientFileView generate(GapicInterfaceContext context) {
StaticLangClientFileView.Builder view = StaticLangClientFileView.newBuilder();
SurfaceNamer namer = context.getNamer();
ApiModel model = context.getApiModel();
ProtoInterfaceModel apiInterface = context.getInterfaceModel();
GapicProductConfig productConfig = context.getProductConfig();
GapicInterfaceConfig interfaceConfig = context.getInterfaceConfig();
view.templateFileName(API_TEMPLATE_FILENAME);
view.serviceDoc(serviceTransformer.generateServiceDoc(context, null, productConfig));
view.domainLayerLocation(productConfig.getDomainLayerLocation());
view.clientTypeName(namer.getApiWrapperClassName(context.getInterfaceConfig()));
view.clientConstructorName(namer.getApiWrapperClassConstructorName(interfaceConfig));
view.defaultClientOptionFunctionName(namer.getDefaultApiSettingsFunctionName(interfaceConfig));
view.defaultCallOptionFunctionName(namer.getDefaultCallSettingsFunctionName(interfaceConfig));
view.callOptionsTypeName(namer.getCallSettingsTypeName(interfaceConfig));
view.serviceOriginalName(model.getTitle());
view.servicePhraseName(namer.getServicePhraseName(interfaceConfig));
String outputPath = pathMapper.getOutputPath(apiInterface.getFullName(), productConfig);
String fileName = namer.getServiceFileName(context.getInterfaceConfig());
view.outputPath(outputPath + File.separator + fileName);
List<RetryConfigDefinitionView> retryDef = generateRetryConfigDefinitions(context, context.getSupportedMethods());
view.retryPairDefinitions(retryDef);
view.callSettings(apiCallableTransformer.generateCallSettings(context));
List<StaticLangApiMethodView> apiMethods = generateApiMethods(context, context.getSupportedMethods());
view.apiMethods(apiMethods);
// "net/url" is needed for `url.QueryEscape`.
if (apiMethods.stream().anyMatch(m -> !m.headerRequestParams().isEmpty())) {
context.getImportTypeTable().saveNicknameFor("fmt;;;");
context.getImportTypeTable().saveNicknameFor("net/url;;;");
}
// In Go, multiple methods share the same iterator type, one iterator type per resource type.
// We have to dedupe the iterators.
Map<String, PageStreamingDescriptorClassView> iterators = new TreeMap<>();
for (PageStreamingDescriptorClassView desc : pageStreamingTransformer.generateDescriptorClasses(context)) {
iterators.put(desc.typeName(), desc);
}
view.pageStreamingDescriptorClasses(new ArrayList<>(iterators.values()));
// Same with long running operations.
Map<String, LongRunningOperationDetailView> lros = new TreeMap<>();
for (StaticLangApiMethodView apiMethod : apiMethods) {
LongRunningOperationDetailView lro = apiMethod.operationMethod();
if (lro != null) {
lros.put(lro.clientReturnTypeName(), lro);
}
}
view.lroDetailViews(new ArrayList<>(lros.values()));
view.serviceHostname(productServiceConfig.getServiceHostname(context.getServiceAddress()));
view.servicePort(productServiceConfig.getServicePort(context.getServiceAddress()));
view.stubs(grpcStubTransformer.generateGrpcStubs(context));
addXApiImports(context, context.getSupportedMethods());
view.fileHeader(fileHeaderTransformer.generateFileHeader(context));
return view.build();
}
use of com.google.api.codegen.viewmodel.PageStreamingDescriptorClassView in project toolkit by googleapis.
the class PageStreamingTransformer method generateDescriptorClass.
private PageStreamingDescriptorClassView generateDescriptorClass(MethodContext context) {
SurfaceNamer namer = context.getNamer();
ImportTypeTable typeTable = context.getTypeTable();
MethodModel method = context.getMethodModel();
PageStreamingConfig pageStreaming = context.getMethodConfig().getPageStreaming();
PageStreamingDescriptorClassView.Builder desc = PageStreamingDescriptorClassView.newBuilder();
FieldModel resourceField = pageStreaming.getResourcesField();
FieldConfig resourceFieldConfig = pageStreaming.getResourcesFieldConfig();
desc.name(namer.getPageStreamingDescriptorConstName(method));
desc.typeName(namer.getAndSavePagedResponseTypeName(context, resourceFieldConfig));
desc.requestTypeName(method.getAndSaveRequestTypeName(typeTable, namer));
desc.responseTypeName(method.getAndSaveResponseTypeName(typeTable, namer));
desc.resourceTypeName(typeTable.getAndSaveNicknameForElementType(resourceField));
desc.defaultTokenValue(typeTable.getSnippetZeroValueAndSaveNicknameFor(pageStreaming.getResponseTokenField()));
desc.requestTokenSetFunction(namer.getFieldSetFunctionName(pageStreaming.getRequestTokenField()));
if (pageStreaming.hasPageSizeField()) {
desc.requestPageSizeSetFunction(namer.getFieldSetFunctionName(pageStreaming.getPageSizeField()));
desc.requestPageSizeGetFunction(namer.getFieldGetFunctionName(pageStreaming.getPageSizeField()));
}
desc.responseTokenGetFunction(namer.getFieldGetFunctionName(pageStreaming.getResponseTokenField()));
desc.resourcesFieldGetFunction(namer.getFieldGetFunctionName(resourceField));
desc.resourcesFieldIsMap(resourceField.isMap());
return desc.build();
}
Aggregations