use of com.google.api.codegen.config.InterfaceContext in project toolkit by googleapis.
the class JavaApiMethodTransformer method generateLongRunningMethods.
private List<StaticLangApiMethodView> generateLongRunningMethods(MethodContext methodContext, @Nullable SampleContext sampleContext) {
List<StaticLangApiMethodView> apiMethods = new ArrayList<>();
InterfaceContext interfaceContext = methodContext.getSurfaceInterfaceContext();
interfaceContext.getImportTypeTable().saveNicknameFor("com.google.api.gax.rpc.OperationCallable");
MethodConfig methodConfig = methodContext.getMethodConfig();
if (methodConfig.isFlattening()) {
List<FlatteningConfig> flatteningConfigs = FlatteningConfig.withRepeatedResourceInSampleOnly(methodConfig.getFlatteningConfigs());
for (FlatteningConfig flatteningGroup : flatteningConfigs) {
MethodContext flattenedMethodContext = interfaceContext.asFlattenedMethodContext(methodContext, flatteningGroup).withCallingForms(Collections.singletonList(CallingForm.LongRunningFlattenedAsync));
apiMethods.add(generateAsyncOperationFlattenedMethod(flattenedMethodContext, sampleContext));
}
}
apiMethods.add(generateAsyncOperationRequestObjectMethod(methodContext.withCallingForms(Collections.singletonList(CallingForm.LongRunningRequestAsync)), sampleContext));
apiMethods.add(generateOperationCallableMethod(methodContext.withCallingForms(Collections.singletonList(CallingForm.LongRunningCallable)), sampleContext));
apiMethods.add(generateCallableMethod(methodContext.withCallingForms(Collections.singletonList(CallingForm.Callable)), sampleContext));
return apiMethods;
}
use of com.google.api.codegen.config.InterfaceContext in project toolkit by googleapis.
the class JavaApiMethodTransformer method generateUnaryMethods.
private List<StaticLangApiMethodView> generateUnaryMethods(MethodContext methodContext, @Nullable SampleContext sampleContext) {
List<StaticLangApiMethodView> apiMethods = new ArrayList<>();
InterfaceContext interfaceContext = methodContext.getSurfaceInterfaceContext();
MethodConfig methodConfig = methodContext.getMethodConfig();
if (methodConfig.isFlattening()) {
List<FlatteningConfig> flatteningConfigs = FlatteningConfig.withRepeatedResourceInSampleOnly(methodConfig.getFlatteningConfigs());
for (FlatteningConfig flatteningGroup : flatteningConfigs) {
MethodContext flattenedMethodContext = interfaceContext.asFlattenedMethodContext(methodContext, flatteningGroup);
apiMethods.add(generateFlattenedMethod(flattenedMethodContext.withCallingForms(Collections.singletonList(CallingForm.Flattened)), sampleContext));
}
}
apiMethods.add(generateRequestObjectMethod(methodContext.withCallingForms(Collections.singletonList(CallingForm.Request)), sampleContext));
apiMethods.add(generateCallableMethod(methodContext.withCallingForms(Collections.singletonList(CallingForm.Callable)), sampleContext));
return apiMethods;
}
use of com.google.api.codegen.config.InterfaceContext in project toolkit by googleapis.
the class JavaApiMethodTransformer method generatePagedStreamingMethods.
private List<StaticLangApiMethodView> generatePagedStreamingMethods(MethodContext methodContext, @Nullable SampleContext sampleContext) {
List<StaticLangApiMethodView> apiMethods = new ArrayList<>();
InterfaceContext interfaceContext = methodContext.getSurfaceInterfaceContext();
MethodConfig methodConfig = methodContext.getMethodConfig();
if (methodConfig.isFlattening()) {
List<FlatteningConfig> flatteningConfigs = FlatteningConfig.withRepeatedResourceInSampleOnly(methodConfig.getFlatteningConfigs());
for (FlatteningConfig flatteningGroup : flatteningConfigs) {
MethodContext flattenedMethodContext = interfaceContext.asFlattenedMethodContext(methodContext, flatteningGroup).withCallingForms(ImmutableList.of(CallingForm.FlattenedPaged));
apiMethods.add(generatePagedFlattenedMethod(flattenedMethodContext, sampleContext));
}
}
apiMethods.add(generatePagedRequestObjectMethod(methodContext.withCallingForms(ImmutableList.of(CallingForm.RequestPaged)), sampleContext));
apiMethods.add(generatePagedCallableMethod(methodContext.withCallingForms(ImmutableList.of(CallingForm.CallablePaged)), sampleContext));
apiMethods.add(generateUnpagedListCallableMethod(methodContext.withCallingForms(Collections.singletonList(CallingForm.CallableList)), sampleContext));
return apiMethods;
}
use of com.google.api.codegen.config.InterfaceContext in project toolkit by googleapis.
the class SampleManifestTransformer method transform.
@Override
public List<ViewModel> transform(ProtoApiModel model, GapicProductConfig productConfig) {
SurfaceNamer surfaceNamer = newSurfaceNamer.apply(productConfig);
ModelTypeTable typeTable = newTypeTable.apply(productConfig.getPackageName());
FeatureConfig featureConfig = newFeatureConfig.apply(productConfig);
ImmutableList.Builder<SampleManifestView.SampleEntry> builder = ImmutableList.builder();
List<InterfaceContext> interfaceContexts = Streams.stream(model.getInterfaces(productConfig)).filter(iface -> productConfig.hasInterfaceConfig(iface)).map(iface -> GapicInterfaceContext.create(iface, productConfig, typeTable, surfaceNamer, featureConfig)).collect(ImmutableList.toImmutableList());
List<SampleContext> sampleContexts = metadataNamer.getSampleContexts(interfaceContexts, productConfig);
for (SampleContext context : sampleContexts) {
String sample = context.uniqueSampleId();
String path = metadataNamer.getSamplePath(sample);
String regionTag = context.sampleConfig().regionTag();
String className = metadataNamer.getSampleClassName(sample);
builder.add(SampleManifestView.SampleEntry.create(sample, path, className, regionTag));
}
ImmutableList<SampleManifestView.SampleEntry> entries = builder.build();
// Only generate manifest files when samples are configured through sample config.
if (entries.isEmpty()) {
return Collections.emptyList();
}
SampleManifestView.Builder sampleManifestView = SampleManifestView.newBuilder();
sampleManifestView.environment(metadataNamer.getEnvironment());
sampleManifestView.bin(metadataNamer.getBin());
sampleManifestView.basePath(metadataNamer.getBasePath(productConfig));
sampleManifestView.packageName(metadataNamer.getPackageName(productConfig));
sampleManifestView.invocation(metadataNamer.getInvocation());
sampleManifestView.schemaVersion(MANIFEST_SCHEMA_VERSION);
sampleManifestView.sampleEntries(entries);
sampleManifestView.outputPath(getManifestOutputPath(model, productConfig));
sampleManifestView.templateFileName(TEMPLATE_NAME);
return Collections.singletonList(sampleManifestView.build());
}
use of com.google.api.codegen.config.InterfaceContext in project toolkit by googleapis.
the class RubyPackageMetadataTransformer method generateMetadataView.
private ViewModel generateMetadataView(ApiModel model, GapicProductConfig productConfig, String template, RubyPackageMetadataNamer namer, String filePrefix) {
String noLeadingRubyDir = template.startsWith(RUBY_PREFIX) ? template.substring(RUBY_PREFIX.length()) : template;
if (!Strings.isNullOrEmpty(filePrefix)) {
noLeadingRubyDir = filePrefix + noLeadingRubyDir;
}
int extensionIndex = noLeadingRubyDir.lastIndexOf(".");
String outputPath = noLeadingRubyDir.substring(0, extensionIndex);
Collection<InterfaceModel> interfaceModels = model.getInterfaces(productConfig).stream().filter(productConfig::hasInterfaceConfig).collect(ImmutableList.toImmutableList());
List<GapicInterfaceContext> contexts = interfaceModels.stream().map(i -> createContext(i, productConfig)).collect(ImmutableList.toImmutableList());
boolean hasSmokeTests = contexts.stream().map(InterfaceContext::getInterfaceConfig).map(InterfaceConfig::getSmokeTestConfig).anyMatch(Objects::nonNull);
SurfaceNamer surfaceNamer = new RubySurfaceNamer(productConfig.getPackageName());
ImportSectionView importSection = importSectionTransformer.generateRakefileAcceptanceTaskImportSection(contexts);
return metadataTransformer.generateMetadataView(namer, packageConfig, model, template, outputPath, TargetLanguage.RUBY).identifier(namer.getMetadataIdentifier()).fileHeader(fileHeaderTransformer.generateFileHeader(productConfig, importSection, surfaceNamer)).hasSmokeTests(hasSmokeTests).versionPath(surfaceNamer.getVersionIndexFileImportName()).versionNamespace(validVersionNamespace(interfaceModels, surfaceNamer)).credentialsClassName(surfaceNamer.getFullyQualifiedCredentialsClassName()).smokeTestProjectVariable(namer.getProjectVariable(true)).smokeTestKeyfileVariable(namer.getKeyfileVariable(true)).smokeTestJsonKeyVariable(namer.getJsonKeyVariable(true)).projectVariable(namer.getProjectVariable(false)).jsonKeyVariable(namer.getJsonKeyVariable(false)).build();
}
Aggregations