use of com.google.api.codegen.config.InterfaceModel 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.config.InterfaceModel in project toolkit by googleapis.
the class GoGapicSurfaceTransformer method generateExample.
private StaticLangClientExampleFileView generateExample(InterfaceContext context) {
StaticLangClientExampleFileView.Builder view = StaticLangClientExampleFileView.newBuilder();
SurfaceNamer namer = context.getNamer();
InterfaceModel apiInterface = context.getInterfaceModel();
ProductConfig productConfig = context.getProductConfig();
InterfaceConfig interfaceConfig = context.getInterfaceConfig();
view.templateFileName(SAMPLE_TEMPLATE_FILENAME);
String outputPath = pathMapper.getOutputPath(apiInterface.getFullName(), productConfig);
String fileName = namer.getExampleFileName(context.getInterfaceConfig());
view.outputPath(outputPath + File.separator + fileName);
view.clientTypeName(namer.getApiWrapperClassName(context.getInterfaceConfig()));
view.clientConstructorName(namer.getApiWrapperClassConstructorName(interfaceConfig));
view.clientConstructorExampleName(namer.getApiWrapperClassConstructorExampleName(interfaceConfig));
view.apiMethods(generateApiMethods(context, context.getPublicMethods()));
view.iamResources(iamResourceTransformer.generateIamResources(context));
// Examples are different from the API. In particular, we use short declaration
// and so we omit most type names. We only need
// - Context, to initialize the client
// - The VKit generated library, that's what the sample is for
// - The input types of the methods, to initialize the requests
// So, we clear all imports; addXExampleImports will add back the ones we want.
context.getImportTypeTable().getImports().clear();
addXExampleImports(context, context.getPublicMethods());
view.fileHeader(fileHeaderTransformer.generateFileHeader(context));
return view.build();
}
use of com.google.api.codegen.config.InterfaceModel 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.config.InterfaceModel in project toolkit by googleapis.
the class JavaSurfaceTransformer method generatePackageInfo.
private PackageInfoView generatePackageInfo(ApiModel model, GapicProductConfig productConfig, SurfaceNamer namer, List<ServiceDocView> serviceDocs) {
PackageInfoView.Builder packageInfo = PackageInfoView.newBuilder();
packageInfo.templateFileName(PACKAGE_INFO_TEMPLATE_FILENAME);
packageInfo.serviceTitle(model.getTitle());
packageInfo.serviceDocs(serviceDocs);
packageInfo.domainLayerLocation(productConfig.getDomainLayerLocation());
packageInfo.authScopes(model.getAuthScopes());
packageInfo.fileHeader(fileHeaderTransformer.generateFileHeader(productConfig, ImportSectionView.newBuilder().build(), namer));
InterfaceModel firstInterface = model.getInterfaces().iterator().next();
String outputPath = pathMapper.getOutputPath(firstInterface.getFullName(), productConfig);
packageInfo.outputPath(outputPath + File.separator + "package-info.java");
packageInfo.releaseLevel(productConfig.getReleaseLevel());
return packageInfo.build();
}
use of com.google.api.codegen.config.InterfaceModel 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;
}
Aggregations