use of com.google.api.codegen.config.GapicProductConfig in project toolkit by googleapis.
the class StaticLangGapicSamplesTransformer method transform.
@Override
public List<ViewModel> transform(ProtoApiModel apiModel, GapicProductConfig productConfig) {
String packageName = productConfig.getPackageName();
SurfaceNamer namer = newSurfaceNamer.apply(productConfig);
ModelTypeTable typeTable = newTypeTable.apply(packageName);
FeatureConfig featureConfig = newFeatureConfig.apply(productConfig);
List<InterfaceContext> interfaceContexts = Streams.stream(apiModel.getInterfaces(productConfig)).filter(iface -> productConfig.hasInterfaceConfig(iface)).map(iface -> GapicInterfaceContext.create(iface, productConfig, typeTable, namer, featureConfig)).collect(ImmutableList.toImmutableList());
ImmutableTable<String, String, ImmutableList<SampleConfig>> sampleConfigTable = productConfig.getSampleConfigTable();
List<ViewModel> sampleFiles;
if (sampleConfigTable.isEmpty()) {
// We don't have sample configs. Continue to use gapic config.
sampleFiles = generateSamplesFromGapicConfigs(interfaceContexts, productConfig, namer);
} else {
// Generate samples using sample configs.
sampleFiles = generateSamplesFromSampleConfigs(interfaceContexts, productConfig);
}
if (!interfaceContexts.isEmpty() && !sampleFiles.isEmpty()) {
ViewModel entryPoint = generateSampleEntryPoint(interfaceContexts.get(0));
if (entryPoint != null) {
sampleFiles.add(entryPoint);
}
}
return ImmutableList.copyOf(sampleFiles);
}
use of com.google.api.codegen.config.GapicProductConfig in project toolkit by googleapis.
the class CSharpBasicPackageTransformer method generateCsproj.
private SimpleInitFileView generateCsproj(GapicInterfaceContext context) {
GapicProductConfig productConfig = context.getProductConfig();
String outputPath = pathMapper.getOutputPath(context.getInterface().getFullName(), productConfig);
return SimpleInitFileView.create(templateFilename, outputPath + File.separator + productConfig.getPackageName() + fileBaseSuffix, fileHeaderTransformer.generateFileHeader(context));
}
use of com.google.api.codegen.config.GapicProductConfig in project toolkit by googleapis.
the class DynamicLangGapicSamplesTransformer method generateSamplesFromGapicConfigs.
private List<ViewModel> generateSamplesFromGapicConfigs(List<InterfaceContext> interfaceContexts, GapicProductConfig productConfig, SurfaceNamer namer) {
List<MethodSampleView> allSamples = interfaceContexts.stream().flatMap(c -> apiMethodTransformer.generateApiMethods(c).stream()).flatMap(m -> m.samples().stream()).collect(ImmutableList.toImmutableList());
SampleFileRegistry registry = new SampleFileRegistry(namer, allSamples);
ImmutableList.Builder<ViewModel> sampleFileViews = ImmutableList.builder();
for (InterfaceContext context : interfaceContexts) {
List<OptionalArrayMethodView> methods = apiMethodTransformer.generateApiMethods(context);
for (OptionalArrayMethodView method : methods) {
for (MethodSampleView sample : method.samples()) {
sampleFileViews.add(newSampleFileView(productConfig, context, registry.getSampleFileName(sample, method.name()), method, sample));
}
}
}
return sampleFileViews.build();
}
use of com.google.api.codegen.config.GapicProductConfig in project toolkit by googleapis.
the class NodeJSSamplePackageMetadataTransformer method transform.
@Override
public List<ViewModel> transform(ProtoApiModel model, GapicProductConfig productConfig) {
boolean shouldGenerateSamplePackages = productConfig.getInterfaceConfigMap().values().stream().flatMap(config -> config.getMethodConfigs().stream()).anyMatch(config -> config.getSampleSpec().isConfigured());
if (!shouldGenerateSamplePackages) {
return Collections.emptyList();
}
NodeJSPackageMetadataNamer gapicPackageNamer = new NodeJSPackageMetadataNamer(productConfig.getPackageName(), productConfig.getDomainLayerLocation());
String outputPath = "samples/package.json";
ViewModel metadataView = metadataTransformer.generateMetadataView(gapicPackageNamer, packageConfig, model, TEMPLATE_FILE, outputPath, TargetLanguage.NODEJS).identifier(samplePackageIdentifier(productConfig)).hasMultipleServices(model.hasMultipleServices()).additionalDependencies(additionalDependencies(gapicPackageNamer)).build();
return Collections.singletonList(metadataView);
}
Aggregations