use of com.google.api.codegen.discogapic.transformer.DocumentToViewTransformer in project toolkit by googleapis.
the class MainDiscoGapicProviderFactory method defaultCreate.
/**
* Create the DiscoGapicProvider based on the given id
*/
public static List<GapicProvider> defaultCreate(DiscoApiModel model, GapicProductConfig productConfig, GapicGeneratorConfig generatorConfig, PackageMetadataConfig packageConfig) {
ArrayList<GapicProvider> providers = new ArrayList<>();
String id = generatorConfig.id();
// Please keep the following IDs in alphabetical order
if (id.equals(JAVA)) {
if (generatorConfig.enableSurfaceGenerator()) {
GapicCodePathMapper javaPathMapper = CommonGapicCodePathMapper.newBuilder().setPrefix("src/main/java").setShouldAppendPackage(true).build();
List<DocumentToViewTransformer> transformers = Arrays.asList(new JavaDiscoGapicResourceNameToViewTransformer(javaPathMapper, packageConfig), new JavaDiscoGapicSchemaToViewTransformer(javaPathMapper, packageConfig), new JavaDiscoGapicRequestToViewTransformer(javaPathMapper, packageConfig), new JavaDiscoGapicSurfaceTransformer(javaPathMapper, packageConfig));
DiscoGapicProvider provider = DiscoGapicProvider.newBuilder().setDiscoApiModel(model).setProductConfig(productConfig).setSnippetSetRunner(new CommonSnippetSetRunner(new JavaRenderingUtil())).setDocumentToViewTransformers(transformers).build();
providers.add(provider);
}
if (generatorConfig.enableTestGenerator()) {
GapicCodePathMapper javaTestPathMapper = CommonGapicCodePathMapper.newBuilder().setPrefix("src/test/java").setShouldAppendPackage(true).build();
GapicProvider testProvider = ViewModelDiscoGapicProvider.newBuilder().setModel(model).setProductConfig(productConfig).setSnippetSetRunner(new CommonSnippetSetRunner(new CommonRenderingUtil())).setModelToViewTransformer(new JavaSurfaceTestTransformer(javaTestPathMapper, new JavaDiscoGapicSurfaceTransformer(javaTestPathMapper, packageConfig), "java/http_test.snip")).build();
providers.add(testProvider);
}
return providers;
} else {
throw new NotImplementedException("DiscoGapicProviderFactory: invalid id \"" + id + "\"");
}
}
use of com.google.api.codegen.discogapic.transformer.DocumentToViewTransformer in project toolkit by googleapis.
the class DiscoGapicProvider method generate.
public Map<String, Doc> generate(String snippetFileName) {
Map<String, Doc> docs = new LinkedTreeMap<>();
for (DocumentToViewTransformer transformer : transformers) {
List<ViewModel> surfaceDocs = transformer.transform(model, productConfig);
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;
}
Aggregations