use of com.google.api.codegen.config.ProtoApiModel in project toolkit by googleapis.
the class ViewModelGapicProvider method generate.
@Override
public Map<String, Doc> generate(String snippetFileName) {
// Establish required stage for generation.
model.establishStage(Merged.KEY);
if (model.getDiagCollector().getErrorCount() > 0) {
return null;
}
List<ViewModel> surfaceDocs = modelToViewTransformer.transform(new ProtoApiModel(model), productConfig);
if (model.getDiagCollector().getErrorCount() > 0) {
return null;
}
Map<String, Doc> docs = new TreeMap<>();
for (ViewModel surfaceDoc : surfaceDocs) {
if (snippetFileName != null && !surfaceDoc.templateFileName().equals(snippetFileName)) {
continue;
}
Doc doc = snippetSetRunner.generate(surfaceDoc);
if (doc == null) {
// generation failed; failures are captured in the model.
continue;
}
docs.put(surfaceDoc.outputPath(), doc);
}
return docs;
}
use of com.google.api.codegen.config.ProtoApiModel in project toolkit by googleapis.
the class JavaGrpcMetadataProvider method generate.
@Override
public Map<String, Doc> generate(Model model, PackageMetadataConfig config) {
ImmutableMap.Builder<String, Doc> docs = new ImmutableMap.Builder<>();
ProtoApiModel apiModel = new ProtoApiModel(model);
ArrayList<PackageMetadataView> metadataViews = new ArrayList<>();
metadataViews.addAll(transformer.transform(apiModel, config));
for (PackageMetadataView view : metadataViews) {
CommonSnippetSetRunner runner = new CommonSnippetSetRunner(view);
Doc result = runner.generate(view);
if (!result.isWhitespace()) {
docs.put(view.outputPath(), result);
}
}
return docs.build();
}
use of com.google.api.codegen.config.ProtoApiModel in project toolkit by googleapis.
the class NodeJSGapicSurfaceDocTransformer method transform.
@Override
public List<ViewModel> transform(ApiModel apiModel, GapicProductConfig productConfig) {
Model model = ((ProtoApiModel) apiModel).getProtoModel();
ImmutableList.Builder<ViewModel> surfaceDocs = ImmutableList.builder();
for (ProtoFile file : new ProtoFileView().getElementIterable(model)) {
surfaceDocs.add(generateDoc(file, productConfig));
}
return surfaceDocs.build();
}
use of com.google.api.codegen.config.ProtoApiModel in project toolkit by googleapis.
the class PythonGapicSurfaceTransformer method transform.
@Override
public List<ViewModel> transform(ApiModel apiModel, GapicProductConfig productConfig) {
// TODO(andrealin): Remove the ProtoApiModel cast.
Model model = ((ProtoApiModel) apiModel).getProtoModel();
ImmutableList.Builder<ViewModel> views = ImmutableList.builder();
views.addAll(generateServiceSurfaces(model, productConfig));
views.addAll(generateVersionedDirectoryViews(model, productConfig));
views.addAll(generateTopLevelViews(model, productConfig));
return views.build();
}
use of com.google.api.codegen.config.ProtoApiModel 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());
}
Aggregations