use of com.google.api.codegen.config.ApiModel in project toolkit by googleapis.
the class NodeJSGapicSurfaceDocTransformer method transform.
@Override
public List<ViewModel> transform(ApiModel apiModel, GapicProductConfig productConfig) {
Model model = ((ProtoApiModel) apiModel).getProtoModel();
ImmutableList.Builder<ViewModel> surfaceDocs = ImmutableList.builder();
for (ProtoFile file : new ProtoFileView().getElementIterable(model)) {
surfaceDocs.add(generateDoc(file, productConfig));
}
return surfaceDocs.build();
}
use of com.google.api.codegen.config.ApiModel in project toolkit by googleapis.
the class PythonGapicSurfaceTransformer method generateApiClass.
private ViewModel generateApiClass(GapicInterfaceContext context) {
SurfaceNamer namer = context.getNamer();
String subPath = pathMapper.getOutputPath(context.getInterfaceModel().getFullName(), context.getProductConfig());
String name = namer.getApiWrapperClassName(context.getInterfaceConfig());
List<ApiMethodView> methods = generateApiMethods(context);
DynamicLangXApiView.Builder xapiClass = DynamicLangXApiView.newBuilder();
xapiClass.templateFileName(XAPI_TEMPLATE_FILENAME);
xapiClass.outputPath(namer.getSourceFilePath(subPath, name));
xapiClass.protoFilename(context.getInterface().getFile().getSimpleName());
xapiClass.servicePhraseName(namer.getServicePhraseName(context.getInterfaceConfig()));
xapiClass.name(name);
xapiClass.doc(serviceTransformer.generateServiceDoc(context, methods.get(0), context.getProductConfig()));
xapiClass.stubs(grpcStubTransformer.generateGrpcStubs(context));
ApiModel model = context.getApiModel();
xapiClass.serviceAddress(model.getServiceAddress());
xapiClass.servicePort(model.getServicePort());
xapiClass.serviceTitle(model.getTitle());
xapiClass.authScopes(model.getAuthScopes());
xapiClass.hasDefaultServiceAddress(context.getInterfaceConfig().hasDefaultServiceAddress());
xapiClass.hasDefaultServiceScopes(context.getInterfaceConfig().hasDefaultServiceScopes());
xapiClass.pageStreamingDescriptors(pageStreamingTransformer.generateDescriptors(context));
xapiClass.batchingDescriptors(ImmutableList.<BatchingDescriptorView>of());
xapiClass.longRunningDescriptors(ImmutableList.<LongRunningOperationDetailView>of());
xapiClass.grpcStreamingDescriptors(ImmutableList.<GrpcStreamingDetailView>of());
xapiClass.hasPageStreamingMethods(context.getInterfaceConfig().hasPageStreamingMethods());
xapiClass.hasBatchingMethods(context.getInterfaceConfig().hasBatchingMethods());
xapiClass.hasLongRunningOperations(context.getInterfaceConfig().hasLongRunningOperations());
xapiClass.pathTemplates(pathTemplateTransformer.generatePathTemplates(context));
xapiClass.formatResourceFunctions(pathTemplateTransformer.generateFormatResourceFunctions(context));
xapiClass.parseResourceFunctions(pathTemplateTransformer.generateParseResourceFunctions(context));
xapiClass.pathTemplateGetterFunctions(ImmutableList.<PathTemplateGetterFunctionView>of());
xapiClass.methodKeys(ImmutableList.<String>of());
xapiClass.interfaceKey(context.getInterface().getFullName());
xapiClass.clientConfigPath(namer.getClientConfigPath(context.getInterfaceConfig()));
xapiClass.clientConfigName(namer.getClientConfigName(context.getInterfaceConfig()));
xapiClass.grpcClientTypeName(namer.getAndSaveNicknameForGrpcClientTypeName(context.getImportTypeTable(), context.getInterfaceModel()));
xapiClass.apiMethods(methods);
xapiClass.toolkitVersion(GeneratorVersionProvider.getGeneratorVersion());
xapiClass.gapicPackageName(namer.getGapicPackageName(packageConfig.packageName(TargetLanguage.PYTHON)));
xapiClass.fileHeader(fileHeaderTransformer.generateFileHeader(context));
return xapiClass.build();
}
use of com.google.api.codegen.config.ApiModel in project toolkit by googleapis.
the class PythonGapicSurfaceTransformer method transform.
@Override
public List<ViewModel> transform(ApiModel apiModel, GapicProductConfig productConfig) {
// TODO(andrealin): Remove the ProtoApiModel cast.
Model model = ((ProtoApiModel) apiModel).getProtoModel();
ImmutableList.Builder<ViewModel> views = ImmutableList.builder();
views.addAll(generateServiceSurfaces(model, productConfig));
views.addAll(generateVersionedDirectoryViews(model, productConfig));
views.addAll(generateTopLevelViews(model, productConfig));
return views.build();
}
use of com.google.api.codegen.config.ApiModel in project toolkit by googleapis.
the class JavaSurfaceTransformer method generateStubSettingsClass.
private StaticLangStubSettingsView generateStubSettingsClass(InterfaceContext context, GapicProductConfig productConfig, StaticLangApiMethodView exampleApiMethod) {
addSettingsImports(context);
SurfaceNamer namer = context.getNamer();
InterfaceConfig interfaceConfig = context.getInterfaceConfig();
ApiModel model = context.getApiModel();
StaticLangStubSettingsView.Builder xsettingsClass = StaticLangStubSettingsView.newBuilder();
xsettingsClass.releaseLevelAnnotation(context.getNamer().getReleaseAnnotation(productConfig.getReleaseLevel()));
xsettingsClass.doc(generateSettingsDoc(context, exampleApiMethod, productConfig, context.getNamer().getApiStubSettingsClassName(interfaceConfig), namer.getApiStubInterfaceName(context.getInterfaceConfig())));
String name = namer.getApiStubSettingsClassName(context.getInterfaceConfig());
xsettingsClass.name(name);
xsettingsClass.serviceHostname(productServiceConfig.getServiceHostname(context.getServiceAddress()));
xsettingsClass.servicePort(productServiceConfig.getServicePort(context.getServiceAddress()));
xsettingsClass.authScopes(model.getAuthScopes(productConfig));
if (productConfig.getTransportProtocol().equals(TransportProtocol.HTTP)) {
xsettingsClass.useDefaultServicePortInEndpoint(false);
}
xsettingsClass.transportProtocol(productConfig.getTransportProtocol());
xsettingsClass.rpcTransportName(namer.getTransportClassName(productConfig.getTransportProtocol()));
xsettingsClass.transportNameGetter(namer.getTransporNameGetMethod(productConfig.getTransportProtocol()));
xsettingsClass.defaultTransportProviderBuilder(namer.getDefaultTransportProviderBuilder(productConfig.getTransportProtocol()));
xsettingsClass.transportProvider(namer.getTransportProvider(productConfig.getTransportProtocol()));
xsettingsClass.instantiatingChannelProvider(namer.getInstantiatingChannelProvider(productConfig.getTransportProtocol()));
List<ApiCallSettingsView> apiCallSettings = apiCallableTransformer.generateCallSettings(context);
xsettingsClass.callSettings(apiCallSettings);
xsettingsClass.pageStreamingDescriptors(pageStreamingTransformer.generateDescriptorClasses(context));
xsettingsClass.pagedListResponseFactories(pageStreamingTransformer.generateFactoryClasses(context));
xsettingsClass.batchingDescriptors(batchingTransformer.generateDescriptorClasses(context));
xsettingsClass.retryCodesDefinitions(retryDefinitionsTransformer.generateRetryCodesDefinitions(context));
xsettingsClass.retryParamsDefinitions(retryDefinitionsTransformer.generateRetryParamsDefinitions(context));
xsettingsClass.transportProtocol(productConfig.getTransportProtocol());
xsettingsClass.hasDefaultServiceAddress(interfaceConfig.hasDefaultServiceAddress());
xsettingsClass.hasDefaultServiceScopes(interfaceConfig.hasDefaultServiceScopes());
xsettingsClass.hasDefaultInstance(interfaceConfig.hasDefaultInstance());
xsettingsClass.stubInterfaceName(getAndSaveNicknameForStubType(context, namer.getApiStubInterfaceName(interfaceConfig)));
xsettingsClass.rpcStubClassName(getAndSaveNicknameForStubType(context, namer.getApiRpcStubClassName(interfaceConfig.getInterfaceModel(), productConfig.getTransportProtocol())));
return xsettingsClass.build();
}
use of com.google.api.codegen.config.ApiModel 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();
}
Aggregations