use of com.google.api.codegen.transformer.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()) {
GapicInterfaceContext context = createContext(apiInterface, productConfig);
if (context.getInterfaceConfig().getSmokeTestConfig() != null) {
MethodModel method = context.getInterfaceConfig().getSmokeTestConfig().getMethod();
FlatteningConfig flatteningGroup = testCaseTransformer.getSmokeTestFlatteningGroup(context.getMethodConfig(method), context.getInterfaceConfig().getSmokeTestConfig());
GapicMethodContext flattenedMethodContext = context.asFlattenedMethodContext(method, flatteningGroup);
exampleMethods.add(createExampleApiMethodView(flattenedMethodContext));
}
}
return exampleMethods.build();
}
use of com.google.api.codegen.transformer.GapicInterfaceContext 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.transformer.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();
}
use of com.google.api.codegen.transformer.GapicInterfaceContext in project toolkit by googleapis.
the class CSharpGapicClientTransformer method generateApiClass.
private StaticLangApiView generateApiClass(GapicInterfaceContext context) {
SurfaceNamer namer = context.getNamer();
StaticLangApiView.Builder apiClass = StaticLangApiView.newBuilder();
List<StaticLangApiMethodView> methods = generateApiMethods(context);
apiClass.doc(serviceTransformer.generateServiceDoc(context, null, context.getProductConfig()));
apiClass.name(namer.getApiWrapperClassName(context.getInterfaceConfig()));
apiClass.implName(namer.getApiWrapperClassImplName(context.getInterfaceConfig()));
apiClass.grpcServiceName(namer.getGrpcContainerTypeName(context.getInterfaceModel()));
String grpcTypeName = namer.getGrpcServiceClassName(context.getInterfaceModel());
int dotIndex = grpcTypeName.indexOf('.');
apiClass.grpcTypeNameOuter(grpcTypeName.substring(0, dotIndex));
apiClass.grpcTypeNameInner(grpcTypeName.substring(dotIndex + 1, grpcTypeName.length()));
apiClass.settingsClassName(context.getNamer().getApiSettingsClassName(context.getInterfaceConfig()));
List<ApiCallableView> callables = new ArrayList<>();
for (ApiCallableView call : apiCallableTransformer.generateStaticLangApiCallables(context)) {
if (call.type() == ApiCallableImplType.SimpleApiCallable || call.type() == ApiCallableImplType.BatchingApiCallable || call.type() == ApiCallableImplType.BidiStreamingApiCallable || call.type() == ApiCallableImplType.ServerStreamingApiCallable) {
callables.add(call);
}
}
apiClass.apiCallableMembers(callables);
apiClass.pathTemplates(pathTemplateTransformer.generatePathTemplates(context));
apiClass.formatResourceFunctions(pathTemplateTransformer.generateFormatResourceFunctions(context));
apiClass.parseResourceFunctions(pathTemplateTransformer.generateParseResourceFunctions(context));
apiClass.apiMethods(methods);
List<StaticLangApiMethodView> methodsImpl = new ArrayList<>();
for (StaticLangApiMethodView method : methods) {
if (methodTypeHasImpl(method.type())) {
methodsImpl.add(method);
}
}
apiClass.apiMethodsImpl(methodsImpl);
apiClass.hasDefaultInstance(context.getInterfaceConfig().hasDefaultInstance());
apiClass.hasLongRunningOperations(context.getInterfaceConfig().hasLongRunningOperations());
apiClass.reroutedGrpcClients(csharpCommonTransformer.generateReroutedGrpcView(context));
apiClass.modifyMethods(generateModifyMethods(context));
apiClass.apiHasUnaryMethod(methods.stream().anyMatch(m -> m.grpcStreamingType() == GrpcStreamingType.NonStreaming));
apiClass.apiHasServerStreamingMethod(methods.stream().anyMatch(m -> m.grpcStreamingType() == GrpcStreamingType.ServerStreaming));
apiClass.apiHasClientStreamingMethod(methods.stream().anyMatch(m -> m.grpcStreamingType() == GrpcStreamingType.ClientStreaming));
apiClass.apiHasBidiStreamingMethod(methods.stream().anyMatch(m -> m.grpcStreamingType() == GrpcStreamingType.BidiStreaming));
return apiClass.build();
}
use of com.google.api.codegen.transformer.GapicInterfaceContext in project toolkit by googleapis.
the class CSharpGapicClientTransformer method transform.
@Override
public List<ViewModel> transform(ApiModel model, GapicProductConfig productConfig) {
List<ViewModel> surfaceDocs = new ArrayList<>();
SurfaceNamer namer = new CSharpSurfaceNamer(productConfig.getPackageName());
CSharpFeatureConfig featureConfig = new CSharpFeatureConfig();
InterfaceModel lastApiInterface = null;
for (InterfaceModel apiInterface : model.getInterfaces()) {
GapicInterfaceContext context = GapicInterfaceContext.create(apiInterface, productConfig, createTypeTable(productConfig.getPackageName()), namer, featureConfig);
surfaceDocs.add(generateApiAndSettingsView(context));
lastApiInterface = apiInterface;
}
GapicInterfaceContext context = GapicInterfaceContext.create(lastApiInterface, productConfig, createTypeTable(productConfig.getPackageName()), namer, featureConfig);
surfaceDocs.add(generateResourceNamesView(context));
surfaceDocs.add(generateCsProjView(context));
return surfaceDocs;
}
Aggregations