use of com.google.api.codegen.viewmodel.metadata.VersionIndexRequireView 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.metadata.VersionIndexRequireView in project toolkit by googleapis.
the class PythonGapicSurfaceTransformer method versionedInitRequireViews.
private List<VersionIndexRequireView> versionedInitRequireViews(Model model, GapicProductConfig productConfig, SurfaceNamer namer) {
ImmutableList.Builder<VersionIndexRequireView> views = ImmutableList.builder();
Iterable<Interface> apiInterfaces = new InterfaceView().getElementIterable(model);
for (Interface apiInterface : apiInterfaces) {
views.add(VersionIndexRequireView.newBuilder().clientName(namer.getApiWrapperClassName(productConfig.getInterfaceConfig(apiInterface))).localName(namer.getApiWrapperVariableName(productConfig.getInterfaceConfig(apiInterface))).fileName(namer.getNotImplementedString("VersionIndexRequireView.fileName")).build());
}
return views.build();
}
use of com.google.api.codegen.viewmodel.metadata.VersionIndexRequireView in project toolkit by googleapis.
the class RubyGapicSurfaceTransformer method generateVersionIndexView.
private ViewModel generateVersionIndexView(ApiModel model, GapicProductConfig productConfig) {
SurfaceNamer namer = new RubySurfaceNamer(productConfig.getPackageName());
ImmutableList.Builder<VersionIndexRequireView> requireViews = ImmutableList.builder();
Iterable<? extends InterfaceModel> interfaces = model.getInterfaces();
for (InterfaceModel apiInterface : interfaces) {
GapicInterfaceContext context = createContext(apiInterface, productConfig);
InterfaceConfig interfaceConfig = productConfig.getInterfaceConfig(apiInterface);
requireViews.add(VersionIndexRequireView.newBuilder().clientName(namer.getFullyQualifiedApiWrapperClassName(interfaceConfig)).fileName(namer.getServiceFileName(interfaceConfig)).serviceName(namer.getPackageServiceName(context.getInterfaceConfig())).doc(serviceTransformer.generateServiceDoc(context, generateApiMethods(context).get(0), productConfig)).build());
}
// append any additional types
Set<String> requireTypes = new HashSet<>();
for (TypeModel type : model.getAdditionalTypes()) {
if (type instanceof ProtoTypeRef) {
ProtoTypeRef t = (ProtoTypeRef) type;
String name = namer.getVersionIndexFileImportName() + "/" + namer.getProtoFileImportName(t.getProtoType().getMessageType().getFile().getSimpleName());
requireTypes.add(name);
}
}
return VersionIndexView.newBuilder().apiVersion(packageConfig.apiVersion()).requireViews(requireViews.build()).requireTypes(ImmutableList.copyOf(requireTypes)).templateFileName(VERSION_INDEX_TEMPLATE_FILE).packageVersion(packageConfig.generatedPackageVersionBound(TargetLanguage.RUBY).lower()).fileHeader(fileHeaderTransformer.generateFileHeader(productConfig, ImportSectionView.newBuilder().build(), namer)).outputPath("lib" + File.separator + versionPackagePath(namer) + ".rb").modules(generateModuleViews(model, productConfig, true)).type(VersionIndexType.VersionIndex).toolkitVersion(GeneratorVersionProvider.getGeneratorVersion()).build();
}
use of com.google.api.codegen.viewmodel.metadata.VersionIndexRequireView in project toolkit by googleapis.
the class PythonGapicSurfaceTransformer method generateTypesView.
private ViewModel generateTypesView(Model model, GapicProductConfig productConfig) {
SurfaceNamer namer = new PythonSurfaceNamer(productConfig.getPackageName());
ImportSectionView imports = importSectionTransformer.generateTypesImportSection(model, productConfig);
return VersionIndexView.newBuilder().templateFileName(TYPES_TEMPLEATE_FILENAME).outputPath(typesOutputFile(namer)).requireViews(ImmutableList.<VersionIndexRequireView>of()).apiVersion(namer.getApiWrapperModuleVersion()).namespace(namer.getVersionedDirectoryNamespace()).packageVersion(packageConfig.generatedPackageVersionBound(TargetLanguage.PYTHON).lower()).fileHeader(fileHeaderTransformer.generateFileHeader(productConfig, imports, namer)).build();
}
use of com.google.api.codegen.viewmodel.metadata.VersionIndexRequireView in project toolkit by googleapis.
the class PythonGapicSurfaceTransformer method topLevelRequireViews.
private List<VersionIndexRequireView> topLevelRequireViews(Model model, GapicProductConfig productConfig, SurfaceNamer namer) {
ImmutableList.Builder<VersionIndexRequireView> views = ImmutableList.builder();
Iterable<Interface> apiInterfaces = new InterfaceView().getElementIterable(model);
for (Interface apiInterface : apiInterfaces) {
views.add(VersionIndexRequireView.newBuilder().clientName(namer.getApiWrapperClassName(productConfig.getInterfaceConfig(apiInterface))).localName(namer.getApiWrapperVariableName(productConfig.getInterfaceConfig(apiInterface))).fileName(namer.getNotImplementedString("VersionIndexRequireView.fileName")).build());
}
return views.build();
}
Aggregations