use of com.google.api.codegen.viewmodel.ViewModel in project toolkit by googleapis.
the class GoGapicSurfaceTransformer method transform.
@Override
public List<ViewModel> transform(ApiModel model, GapicProductConfig productConfig) {
List<ViewModel> models = new ArrayList<>();
GoSurfaceNamer namer = new GoSurfaceNamer(productConfig.getPackageName());
for (InterfaceModel apiInterface : model.getInterfaces()) {
GapicInterfaceContext context = GapicInterfaceContext.create(apiInterface, productConfig, createTypeTable(), namer, featureConfig);
models.add(generate(context));
context = GapicInterfaceContext.create(apiInterface, productConfig, createTypeTable(), namer, featureConfig);
models.add(generateExample(context));
}
models.add(generatePackageInfo(model, productConfig, namer));
return models;
}
use of com.google.api.codegen.viewmodel.ViewModel in project toolkit by googleapis.
the class JavaSurfaceTransformer method transform.
public List<ViewModel> transform(ApiModel model, GapicProductConfig productConfig) {
List<ViewModel> surfaceDocs = new ArrayList<>();
SurfaceNamer namer = surfaceTransformer.createSurfaceNamer(productConfig);
List<ServiceDocView> serviceDocs = new ArrayList<>();
for (InterfaceModel apiInterface : model.getInterfaces()) {
boolean enableStringFormatFunctions = productConfig.getResourceNameMessageConfigs().isEmpty();
ImportTypeTable typeTable = surfaceTransformer.createTypeTable(productConfig.getPackageName());
InterfaceContext context = surfaceTransformer.createInterfaceContext(apiInterface, productConfig, namer, typeTable, enableStringFormatFunctions);
StaticLangFileView<StaticLangApiView> apiFile = generateApiFile(context, productConfig);
surfaceDocs.add(apiFile);
serviceDocs.add(apiFile.classView().doc());
StaticLangApiMethodView exampleApiMethod = getExampleApiMethod(apiFile.classView().apiMethods());
context = context.withNewTypeTable(namer.getStubPackageName());
StaticLangFileView<StaticLangStubSettingsView> stubSettingsFile = generateStubSettingsFile(context, productConfig, exampleApiMethod);
context = context.withNewTypeTable(namer.getRootPackageName());
StaticLangFileView<StaticLangSettingsView> settingsFile = generateSettingsFile(context, productConfig, exampleApiMethod, stubSettingsFile.classView());
surfaceDocs.add(settingsFile);
surfaceDocs.add(stubSettingsFile);
context = context.withNewTypeTable(namer.getStubPackageName());
StaticLangFileView<StaticLangStubInterfaceView> stubInterfaceFile = generateStubInterfaceFile(context, productConfig);
surfaceDocs.add(stubInterfaceFile);
context = context.withNewTypeTable(namer.getStubPackageName());
StaticLangFileView<StaticLangRpcStubView> grpcStubFile = generateRpcStubClassFile(context, productConfig);
surfaceDocs.add(grpcStubFile);
surfaceDocs.add(generateCallableFactoryClassFile(context, productConfig));
}
PackageInfoView packageInfo = generatePackageInfo(model, productConfig, namer, serviceDocs);
surfaceDocs.add(packageInfo);
return surfaceDocs;
}
use of com.google.api.codegen.viewmodel.ViewModel 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.viewmodel.ViewModel in project toolkit by googleapis.
the class NodeJSGapicSurfaceTransformer method generateIndexViews.
private List<ViewModel> generateIndexViews(Iterable<? extends InterfaceModel> apiInterfaces, GapicProductConfig productConfig) {
NodeJSPackageMetadataNamer packageMetadataNamer = new NodeJSPackageMetadataNamer(productConfig.getPackageName(), productConfig.getDomainLayerLocation());
ArrayList<ViewModel> indexViews = new ArrayList<>();
NodeJSSurfaceNamer namer = new NodeJSSurfaceNamer(productConfig.getPackageName(), NodeJSUtils.isGcloud(productConfig));
String version = namer.getApiWrapperModuleVersion();
boolean hasVersion = version != null && !version.isEmpty();
ArrayList<VersionIndexRequireView> requireViews = new ArrayList<>();
for (InterfaceModel apiInterface : apiInterfaces) {
Name serviceName = namer.getReducedServiceName(apiInterface.getSimpleName());
String localName = hasVersion ? serviceName.join(version).toLowerCamel() : serviceName.toLowerCamel();
GapicInterfaceContext context = createContext(apiInterface, productConfig);
ApiMethodView exampleMethod = generateApiMethods(context, apiInterface.getApiModel().hasMultipleServices()).get(0);
VersionIndexRequireView require = VersionIndexRequireView.newBuilder().clientName(namer.getApiWrapperClassName(productConfig.getInterfaceConfig(apiInterface))).serviceName(namer.getPackageServiceName(context.getInterfaceConfig())).localName(localName).doc(serviceTransformer.generateServiceDoc(context, exampleMethod, productConfig)).fileName(namer.getClientFileName(context.getInterfaceConfig())).build();
requireViews.add(require);
}
String indexOutputPath = hasVersion ? "src/" + version + "/index.js" : "src/index.js";
VersionIndexView.Builder indexViewbuilder = VersionIndexView.newBuilder().templateFileName(INDEX_TEMPLATE_FILE).outputPath(indexOutputPath).requireViews(requireViews).primaryService(requireViews.get(0)).packageVersion(packageConfig.generatedPackageVersionBound(TargetLanguage.NODEJS).lower()).toolkitVersion(GeneratorVersionProvider.getGeneratorVersion()).fileHeader(fileHeaderTransformer.generateFileHeader(productConfig, ImportSectionView.newBuilder().build(), namer)).packageName(packageMetadataNamer.getMetadataIdentifier());
if (hasVersion) {
indexViewbuilder.apiVersion(version);
}
indexViews.add(indexViewbuilder.build());
if (hasVersion) {
String versionIndexOutputPath = "src/index.js";
VersionIndexView.Builder versionIndexViewBuilder = VersionIndexView.newBuilder().templateFileName(VERSION_INDEX_TEMPLATE_FILE).outputPath(versionIndexOutputPath).requireViews(requireViews).primaryService(requireViews.get(0)).apiVersion(version).stubs(versionIndexStubs(apiInterfaces, productConfig)).isGcloud(NodeJSUtils.isGcloud(productConfig)).packageVersion(packageConfig.generatedPackageVersionBound(TargetLanguage.NODEJS).lower()).toolkitVersion(GeneratorVersionProvider.getGeneratorVersion()).fileHeader(fileHeaderTransformer.generateFileHeader(productConfig, ImportSectionView.newBuilder().build(), namer)).packageName(packageMetadataNamer.getMetadataIdentifier()).namespace(packageMetadataNamer.getServiceName());
indexViews.add(versionIndexViewBuilder.build());
}
return indexViews;
}
use of com.google.api.codegen.viewmodel.ViewModel in project toolkit by googleapis.
the class PhpGapicSurfaceTransformer method transform.
public List<ViewModel> transform(GapicInterfaceContext context) {
GapicInterfaceContext gapicImplContext = context.withNewTypeTable(context.getNamer().getGapicImplNamespace());
List<ViewModel> surfaceData = new ArrayList<>();
surfaceData.add(buildGapicClientViewModel(gapicImplContext));
surfaceData.add(buildClientViewModel(context));
surfaceData.add(buildDescriptorConfigViewModel(context));
surfaceData.add(buildRestConfigViewModel(context));
return surfaceData;
}
Aggregations