use of com.google.api.codegen.config.GapicInterfaceContext in project toolkit by googleapis.
the class PythonPackageMetadataTransformer method generateExampleMethods.
// Generates methods used as examples for the README.md file.
// This currently generates a list of methods that have smoke test configuration. In the future,
// the example methods may be configured separately.
private List<ApiMethodView> generateExampleMethods(ApiModel model, GapicProductConfig productConfig) {
ImmutableList.Builder<ApiMethodView> exampleMethods = ImmutableList.builder();
for (InterfaceModel apiInterface : model.getInterfaces(productConfig)) {
InterfaceConfig interfaceConfig = productConfig.getInterfaceConfig(apiInterface);
if (interfaceConfig == null || interfaceConfig.getSmokeTestConfig() == null) {
continue;
}
GapicInterfaceContext context = createContext(apiInterface, productConfig);
MethodModel method = interfaceConfig.getSmokeTestConfig().getMethod();
GapicMethodContext methodContext = context.asRequestMethodContext(method);
FlatteningConfig flatteningGroup = testCaseTransformer.getSmokeTestFlatteningGroup(context.getMethodConfig(method));
GapicMethodContext flattenedMethodContext = context.asFlattenedMethodContext(methodContext, flatteningGroup);
exampleMethods.add(createExampleApiMethodView(flattenedMethodContext));
}
return exampleMethods.build();
}
use of com.google.api.codegen.config.GapicInterfaceContext 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 = !Strings.isNullOrEmpty(version);
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 = apiMethodTransformer.generateApiMethods(context).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)).fileHeader(fileHeaderTransformer.generateFileHeader(productConfig, ImportSectionView.newBuilder().build(), namer)).packageName(packageMetadataNamer.getMetadataIdentifier());
if (hasVersion) {
indexViewbuilder.apiVersion(version);
}
indexViews.add(indexViewbuilder.build());
String webpackConfigOutputPath = "webpack.config.js";
VersionIndexView.Builder webpackConfigViewBuilder = VersionIndexView.newBuilder().templateFileName(WEBPACK_CONFIG_TEMPLATE_FILENAME).outputPath(webpackConfigOutputPath).requireViews(requireViews).namespace(packageMetadataNamer.getServiceName()).fileHeader(fileHeaderTransformer.generateFileHeader(productConfig, ImportSectionView.newBuilder().build(), namer));
indexViews.add(webpackConfigViewBuilder.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)).fileHeader(fileHeaderTransformer.generateFileHeader(productConfig, ImportSectionView.newBuilder().build(), namer)).packageName(packageMetadataNamer.getMetadataIdentifier()).namespace(packageMetadataNamer.getServiceName());
indexViews.add(versionIndexViewBuilder.build());
String versionBrowserOutputPath = "src/browser.js";
VersionIndexView.Builder versionBrowserViewBuilder = VersionIndexView.newBuilder().templateFileName(VERSION_BROWSER_TEMPLATE_FILE).outputPath(versionBrowserOutputPath).requireViews(requireViews).primaryService(requireViews.get(0)).apiVersion(version).stubs(versionIndexStubs(apiInterfaces, productConfig)).fileHeader(fileHeaderTransformer.generateFileHeader(productConfig, ImportSectionView.newBuilder().build(), namer)).packageName(packageMetadataNamer.getMetadataIdentifier()).namespace(packageMetadataNamer.getServiceName());
indexViews.add(versionBrowserViewBuilder.build());
}
return indexViews;
}
use of com.google.api.codegen.config.GapicInterfaceContext in project toolkit by googleapis.
the class NodeJSGapicSurfaceTransformer method generateApiClasses.
private List<ViewModel> generateApiClasses(Collection<? extends InterfaceModel> apiInterfaces, GapicProductConfig productConfig) {
ImmutableList.Builder<ViewModel> models = ImmutableList.builder();
for (InterfaceModel apiInterface : apiInterfaces) {
GapicInterfaceContext context = createContext(apiInterface, productConfig);
models.add(generateApiClass(context));
models.add(generateProtoList(context));
}
return models.build();
}
use of com.google.api.codegen.config.GapicInterfaceContext in project toolkit by googleapis.
the class NodeJSPackageMetadataTransformer method generateExampleMethods.
// Generates methods used as examples for the README.md file.
// Note: This is based on sample gen method calls. In the future, the example
// methods may be configured separately.
private List<ApiMethodView> generateExampleMethods(ApiModel model, GapicProductConfig productConfig) {
ImmutableList.Builder<ApiMethodView> exampleMethods = ImmutableList.builder();
for (InterfaceModel apiInterface : model.getInterfaces(productConfig)) {
InterfaceConfig interfaceConfig = productConfig.getInterfaceConfig(apiInterface);
if (interfaceConfig == null || interfaceConfig.getSmokeTestConfig() == null) {
continue;
}
GapicInterfaceContext context = createContext(apiInterface, productConfig);
MethodModel method = interfaceConfig.getSmokeTestConfig().getMethod();
FlatteningConfig flatteningGroup = testCaseTransformer.getSmokeTestFlatteningGroup(context.getMethodConfig(method));
GapicMethodContext defaultMethodContext = context.asRequestMethodContext(method);
GapicMethodContext flattenedMethodContext = context.asFlattenedMethodContext(defaultMethodContext, flatteningGroup);
exampleMethods.add(createExampleApiMethodView(flattenedMethodContext, model.hasMultipleServices()));
}
return exampleMethods.build();
}
use of com.google.api.codegen.config.GapicInterfaceContext in project toolkit by googleapis.
the class RubyImportSectionTransformer method generateRakefileAcceptanceTaskImportSection.
public ImportSectionView generateRakefileAcceptanceTaskImportSection(List<GapicInterfaceContext> contexts) {
List<ImportFileView> none = ImmutableList.of();
ImportSectionView.Builder importSection = ImportSectionView.newBuilder();
importSection.standardImports(none);
importSection.externalImports(none);
Set<ImportFileView> credentialsImports = new HashSet<>();
for (GapicInterfaceContext context : contexts) {
credentialsImports.add(createImport(context.getNamer().getCredentialsClassImportName()));
}
importSection.appImports(ImmutableList.copyOf(credentialsImports));
importSection.serviceImports(none);
return importSection.build();
}
Aggregations