use of com.google.api.tools.framework.model.Interface in project toolkit by googleapis.
the class PythonImportSectionTransformer method generateVersionedInitAppImports.
private List<ImportFileView> generateVersionedInitAppImports(Model model, GapicProductConfig productConfig, SurfaceNamer namer, boolean packageHasEnums) {
Set<ImportFileView> imports = new TreeSet<>(importFileViewComparator());
for (Interface apiInterface : new InterfaceView().getElementIterable(model)) {
imports.add(createImport(productConfig.getPackageName(), namer.getApiWrapperVariableName(productConfig.getInterfaceConfig(apiInterface))));
}
if (packageHasEnums) {
imports.add(createImport(productConfig.getPackageName(), "enums"));
}
imports.add(createImport(namer.getVersionedDirectoryNamespace(), "types"));
return ImmutableList.<ImportFileView>builder().addAll(imports).build();
}
use of com.google.api.tools.framework.model.Interface in project toolkit by googleapis.
the class RubyImportSectionTransformer method generateImportFilenames.
private Set<String> generateImportFilenames(GapicInterfaceContext context) {
Set<String> filenames = new TreeSet<>();
filenames.add(context.getInterface().getFile().getSimpleName());
for (MethodModel method : context.getSupportedMethods()) {
Interface targetInterface = context.asRequestMethodContext(method).getTargetInterface().getInterface();
filenames.add(targetInterface.getFile().getSimpleName());
}
return filenames;
}
use of com.google.api.tools.framework.model.Interface in project toolkit by googleapis.
the class GoGapicSurfaceTransformerTest method setupClass.
@BeforeClass
public static void setupClass() {
TestDataLocator locator = TestDataLocator.create(GoGapicSurfaceTransformerTest.class);
model = CodegenTestUtil.readModel(locator, tempDir, new String[] { "myproto.proto", "singleservice.proto" }, new String[] { "myproto.yaml" });
for (Interface apiInterface : model.getSymbolTable().getInterfaces()) {
if (apiInterface.getSimpleName().equals("Gopher")) {
GoGapicSurfaceTransformerTest.apiInterface = apiInterface;
break;
}
}
ConfigProto configProto = CodegenTestUtil.readConfig(model.getDiagCollector(), locator, new String[] { "myproto_gapic.yaml" });
productConfig = GapicProductConfig.create(model, configProto);
if (model.getDiagCollector().hasErrors()) {
throw new IllegalStateException(model.getDiagCollector().getDiags().toString());
}
}
use of com.google.api.tools.framework.model.Interface in project toolkit by googleapis.
the class MainGapicProviderFactory method defaultCreate.
/**
* Create the GapicProviders based on the given id
*/
public static List<GapicProvider> defaultCreate(Model 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(CLIENT_CONFIG)) {
GapicProvider provider = CommonGapicProvider.<Interface>newBuilder().setModel(model).setView(new InterfaceView()).setContext(new ClientConfigGapicContext(model, productConfig)).setSnippetSetRunner(new ClientConfigSnippetSetRunner<>(SnippetSetRunner.SNIPPET_RESOURCE_ROOT)).setSnippetFileNames(Arrays.asList("clientconfig/json.snip")).setCodePathMapper(CommonGapicCodePathMapper.defaultInstance()).build();
providers.add(provider);
} else if (id.equals(CSHARP)) {
String packageName = productConfig.getPackageName();
if (generatorConfig.enableSurfaceGenerator()) {
GapicCodePathMapper pathMapper = CommonGapicCodePathMapper.newBuilder().setPrefix(packageName + File.separator + packageName).setPackageFilePathNameFormatter(new CSharpNameFormatter()).build();
GapicProvider mainProvider = ViewModelGapicProvider.newBuilder().setModel(model).setProductConfig(productConfig).setSnippetSetRunner(new CommonSnippetSetRunner(new CSharpRenderingUtil())).setModelToViewTransformer(new CSharpGapicClientTransformer(pathMapper, packageConfig)).build();
providers.add(mainProvider);
GapicCodePathMapper snippetPathMapper = CommonGapicCodePathMapper.newBuilder().setPrefix(packageName + File.separator + packageName + ".Snippets").setPackageFilePathNameFormatter(new CSharpNameFormatter()).build();
GapicProvider snippetProvider = ViewModelGapicProvider.newBuilder().setModel(model).setProductConfig(productConfig).setSnippetSetRunner(new CommonSnippetSetRunner(new CSharpRenderingUtil())).setModelToViewTransformer(new CSharpGapicSnippetsTransformer(snippetPathMapper)).build();
providers.add(snippetProvider);
}
if (generatorConfig.enableTestGenerator()) {
GapicCodePathMapper smokeTestPathMapper = CommonGapicCodePathMapper.newBuilder().setPrefix(packageName + File.separator + packageName + ".SmokeTests").setPackageFilePathNameFormatter(new CSharpNameFormatter()).build();
GapicProvider smokeTestProvider = ViewModelGapicProvider.newBuilder().setModel(model).setProductConfig(productConfig).setSnippetSetRunner(new CommonSnippetSetRunner(new CSharpRenderingUtil())).setModelToViewTransformer(new CSharpGapicSmokeTestTransformer(smokeTestPathMapper)).build();
providers.add(smokeTestProvider);
GapicCodePathMapper unitTestPathMapper = CommonGapicCodePathMapper.newBuilder().setPrefix(packageName + File.separator + packageName + ".Tests").setPackageFilePathNameFormatter(new CSharpNameFormatter()).build();
GapicProvider unitTestProvider = ViewModelGapicProvider.newBuilder().setModel(model).setProductConfig(productConfig).setSnippetSetRunner(new CommonSnippetSetRunner(new CSharpRenderingUtil())).setModelToViewTransformer(new CSharpGapicUnitTestTransformer(unitTestPathMapper)).build();
providers.add(unitTestProvider);
}
} else if (id.equals(GO)) {
if (generatorConfig.enableSurfaceGenerator()) {
GapicProvider provider = ViewModelGapicProvider.newBuilder().setModel(model).setProductConfig(productConfig).setSnippetSetRunner(new CommonSnippetSetRunner(new CommonRenderingUtil())).setModelToViewTransformer(new GoGapicSurfaceTransformer(new PackageNameCodePathMapper())).build();
providers.add(provider);
}
if (generatorConfig.enableTestGenerator()) {
GapicProvider testProvider = ViewModelGapicProvider.newBuilder().setModel(model).setProductConfig(productConfig).setSnippetSetRunner(new CommonSnippetSetRunner(new CommonRenderingUtil())).setModelToViewTransformer(new GoGapicSurfaceTestTransformer()).build();
providers.add(testProvider);
}
} else if (id.equals(JAVA)) {
if (generatorConfig.enableSurfaceGenerator()) {
GapicCodePathMapper javaPathMapper = CommonGapicCodePathMapper.newBuilder().setPrefix("src/main/java").setShouldAppendPackage(true).build();
GapicProvider mainProvider = ViewModelGapicProvider.newBuilder().setModel(model).setProductConfig(productConfig).setSnippetSetRunner(new CommonSnippetSetRunner(new JavaRenderingUtil())).setModelToViewTransformer(new JavaGapicSurfaceTransformer(javaPathMapper, packageConfig)).build();
providers.add(mainProvider);
GapicProvider metadataProvider = ViewModelGapicProvider.newBuilder().setModel(model).setProductConfig(productConfig).setSnippetSetRunner(new CommonSnippetSetRunner(new JavaRenderingUtil())).setModelToViewTransformer(new JavaGapicMetadataTransformer(packageConfig)).build();
providers.add(metadataProvider);
}
if (generatorConfig.enableTestGenerator()) {
GapicCodePathMapper javaTestPathMapper = CommonGapicCodePathMapper.newBuilder().setPrefix("src/test/java").setShouldAppendPackage(true).build();
GapicProvider testProvider = ViewModelGapicProvider.newBuilder().setModel(model).setProductConfig(productConfig).setSnippetSetRunner(new CommonSnippetSetRunner(new CommonRenderingUtil())).setModelToViewTransformer(new JavaSurfaceTestTransformer(javaTestPathMapper, new JavaGapicSurfaceTransformer(javaTestPathMapper, packageConfig), "java/grpc_test.snip")).build();
providers.add(testProvider);
}
return providers;
} else if (id.equals(NODEJS) || id.equals(NODEJS_DOC)) {
if (generatorConfig.enableSurfaceGenerator()) {
GapicCodePathMapper nodeJSPathMapper = new NodeJSCodePathMapper();
GapicProvider mainProvider = ViewModelGapicProvider.newBuilder().setModel(model).setProductConfig(productConfig).setSnippetSetRunner(new CommonSnippetSetRunner(new CommonRenderingUtil())).setModelToViewTransformer(new NodeJSGapicSurfaceTransformer(nodeJSPathMapper, packageConfig)).build();
GapicProvider metadataProvider = ViewModelGapicProvider.newBuilder().setModel(model).setProductConfig(productConfig).setSnippetSetRunner(new CommonSnippetSetRunner(new CommonRenderingUtil())).setModelToViewTransformer(new NodeJSPackageMetadataTransformer(packageConfig)).build();
GapicProvider clientConfigProvider = CommonGapicProvider.<Interface>newBuilder().setModel(model).setView(new InterfaceView()).setContext(new ClientConfigGapicContext(model, productConfig)).setSnippetSetRunner(new ClientConfigSnippetSetRunner<>(SnippetSetRunner.SNIPPET_RESOURCE_ROOT)).setSnippetFileNames(Arrays.asList("clientconfig/json.snip")).setCodePathMapper(nodeJSPathMapper).build();
providers.add(mainProvider);
providers.add(metadataProvider);
providers.add(clientConfigProvider);
if (id.equals(NODEJS_DOC)) {
GapicProvider messageProvider = ViewModelGapicProvider.newBuilder().setModel(model).setProductConfig(productConfig).setSnippetSetRunner(new CommonSnippetSetRunner(new CommonRenderingUtil())).setModelToViewTransformer(new NodeJSGapicSurfaceDocTransformer()).build();
providers.add(messageProvider);
}
}
if (generatorConfig.enableTestGenerator()) {
GapicProvider testProvider = ViewModelGapicProvider.newBuilder().setModel(model).setProductConfig(productConfig).setSnippetSetRunner(new CommonSnippetSetRunner(new CommonRenderingUtil())).setModelToViewTransformer(new NodeJSGapicSurfaceTestTransformer()).build();
providers.add(testProvider);
}
} else if (id.equals(PHP)) {
if (generatorConfig.enableSurfaceGenerator()) {
GapicCodePathMapper phpPathMapper = PhpGapicCodePathMapper.newBuilder().setPrefix("src").build();
GapicProvider provider = ViewModelGapicProvider.newBuilder().setModel(model).setProductConfig(productConfig).setSnippetSetRunner(new CommonSnippetSetRunner(new CommonRenderingUtil())).setModelToViewTransformer(new PhpGapicSurfaceTransformer(productConfig, phpPathMapper, model)).build();
GapicCodePathMapper phpClientConfigPathMapper = PhpGapicCodePathMapper.newBuilder().setPrefix("src").setSuffix("resources").build();
GapicProvider clientConfigProvider = CommonGapicProvider.<Interface>newBuilder().setModel(model).setView(new InterfaceView()).setContext(new PhpClientConfigGapicContext(model, productConfig)).setSnippetSetRunner(new ClientConfigSnippetSetRunner<>(SnippetSetRunner.SNIPPET_RESOURCE_ROOT)).setSnippetFileNames(Arrays.asList("clientconfig/json.snip")).setCodePathMapper(phpClientConfigPathMapper).build();
GapicProvider metadataProvider = ViewModelGapicProvider.newBuilder().setModel(model).setProductConfig(productConfig).setSnippetSetRunner(new CommonSnippetSetRunner(new CommonRenderingUtil())).setModelToViewTransformer(new PhpPackageMetadataTransformer(packageConfig)).build();
providers.add(provider);
providers.add(clientConfigProvider);
providers.add(metadataProvider);
}
if (generatorConfig.enableTestGenerator()) {
GapicProvider testProvider = ViewModelGapicProvider.newBuilder().setModel(model).setProductConfig(productConfig).setSnippetSetRunner(new CommonSnippetSetRunner(new CommonRenderingUtil())).setModelToViewTransformer(new PhpGapicSurfaceTestTransformer()).build();
providers.add(testProvider);
}
} else if (id.equals(PYTHON)) {
if (generatorConfig.enableSurfaceGenerator()) {
GapicCodePathMapper pythonPathMapper = CommonGapicCodePathMapper.newBuilder().setShouldAppendPackage(true).build();
GapicProvider mainProvider = ViewModelGapicProvider.newBuilder().setModel(model).setProductConfig(productConfig).setSnippetSetRunner(new CommonSnippetSetRunner(new PythonRenderingUtil())).setModelToViewTransformer(new PythonGapicSurfaceTransformer(pythonPathMapper, packageConfig)).build();
GapicProvider clientConfigProvider = CommonGapicProvider.<Interface>newBuilder().setModel(model).setView(new InterfaceView()).setContext(new ClientConfigGapicContext(model, productConfig)).setSnippetSetRunner(new ClientConfigSnippetSetRunner<>(SnippetSetRunner.SNIPPET_RESOURCE_ROOT)).setSnippetFileNames(Arrays.asList("clientconfig/python_clientconfig.snip")).setCodePathMapper(pythonPathMapper).build();
providers.add(mainProvider);
providers.add(clientConfigProvider);
GapicProvider metadataProvider = ViewModelGapicProvider.newBuilder().setModel(model).setProductConfig(productConfig).setSnippetSetRunner(new CommonSnippetSetRunner(new PythonRenderingUtil())).setModelToViewTransformer(new PythonPackageMetadataTransformer(packageConfig)).build();
providers.add(metadataProvider);
}
if (generatorConfig.enableTestGenerator()) {
GapicCodePathMapper pythonTestPathMapper = CommonGapicCodePathMapper.newBuilder().setPrefix("test").setShouldAppendPackage(true).build();
GapicProvider testProvider = ViewModelGapicProvider.newBuilder().setModel(model).setProductConfig(productConfig).setSnippetSetRunner(new CommonSnippetSetRunner(new CommonRenderingUtil())).setModelToViewTransformer(new PythonGapicSurfaceTestTransformer(pythonTestPathMapper, packageConfig)).build();
providers.add(testProvider);
}
} else if (id.equals(RUBY) || id.equals(RUBY_DOC)) {
if (generatorConfig.enableSurfaceGenerator()) {
GapicCodePathMapper rubyPathMapper = CommonGapicCodePathMapper.newBuilder().setPrefix("lib").setShouldAppendPackage(true).setPackageFilePathNameFormatter(new RubyNameFormatter()).build();
GapicProvider mainProvider = ViewModelGapicProvider.newBuilder().setModel(model).setProductConfig(productConfig).setSnippetSetRunner(new CommonSnippetSetRunner(new CommonRenderingUtil())).setModelToViewTransformer(new RubyGapicSurfaceTransformer(rubyPathMapper, packageConfig)).build();
GapicProvider clientConfigProvider = CommonGapicProvider.<Interface>newBuilder().setModel(model).setView(new InterfaceView()).setContext(new ClientConfigGapicContext(model, productConfig)).setSnippetSetRunner(new ClientConfigSnippetSetRunner<>(SnippetSetRunner.SNIPPET_RESOURCE_ROOT)).setSnippetFileNames(Arrays.asList("clientconfig/json.snip")).setCodePathMapper(rubyPathMapper).build();
GapicProvider metadataProvider = ViewModelGapicProvider.newBuilder().setModel(model).setProductConfig(productConfig).setSnippetSetRunner(new CommonSnippetSetRunner(new CommonRenderingUtil())).setModelToViewTransformer(new RubyPackageMetadataTransformer(packageConfig)).build();
providers.add(mainProvider);
providers.add(clientConfigProvider);
providers.add(metadataProvider);
if (id.equals(RUBY_DOC)) {
GapicProvider messageProvider = ViewModelGapicProvider.newBuilder().setModel(model).setProductConfig(productConfig).setSnippetSetRunner(new CommonSnippetSetRunner(new CommonRenderingUtil())).setModelToViewTransformer(new RubyGapicSurfaceDocTransformer(rubyPathMapper, packageConfig)).build();
providers.add(messageProvider);
}
}
if (generatorConfig.enableTestGenerator()) {
CommonGapicCodePathMapper.Builder rubyTestPathMapperBuilder = CommonGapicCodePathMapper.newBuilder().setShouldAppendPackage(true).setPackageFilePathNameFormatter(new RubyNameFormatter());
GapicProvider testProvider = ViewModelGapicProvider.newBuilder().setModel(model).setProductConfig(productConfig).setSnippetSetRunner(new CommonSnippetSetRunner(new CommonRenderingUtil())).setModelToViewTransformer(new RubyGapicSurfaceTestTransformer(rubyTestPathMapperBuilder.setPrefix("test").build(), rubyTestPathMapperBuilder.setPrefix("acceptance").build(), packageConfig)).build();
providers.add(testProvider);
}
} else {
throw new NotImplementedException("GapicProviderFactory: invalid id \"" + id + "\"");
}
if (providers.isEmpty()) {
throw new IllegalArgumentException("No artifacts are enabled.");
}
return providers;
}
use of com.google.api.tools.framework.model.Interface in project toolkit by googleapis.
the class ProtoApiModel method getInterfaces.
@Override
public Iterable<ProtoInterfaceModel> getInterfaces() {
if (interfaceModels != null) {
return interfaceModels;
}
Iterable<Interface> interfaces = new InterfaceView().getElementIterable(protoModel);
ImmutableList.Builder<ProtoInterfaceModel> intfModels = ImmutableList.builder();
for (Interface intf : interfaces) {
intfModels.add(new ProtoInterfaceModel(intf));
}
interfaceModels = intfModels.build();
return interfaceModels;
}
Aggregations