use of com.palantir.conjure.python.poet.PythonSnippet in project conjure-python by palantir.
the class ClientGenerator method generateClient.
public PythonSnippet generateClient(ServiceDefinition serviceDef) {
ImportTypeVisitor importTypeVisitor = new ImportTypeVisitor(serviceDef.getServiceName(), implTypeNameProcessor, implPackageNameProcessor);
ImmutableSet.Builder<Type> referencedTypesBuilder = ImmutableSet.builder();
List<PythonEndpointDefinition> endpoints = serviceDef.getEndpoints().stream().map(endpointDef -> generateEndpoint(endpointDef, referencedTypesBuilder)).collect(Collectors.toList());
List<PythonImport> imports = referencedTypesBuilder.build().stream().flatMap(entry -> entry.accept(importTypeVisitor).stream()).collect(Collectors.toList());
return PythonService.builder().pythonPackage(PythonPackage.of(implPackageNameProcessor.process(serviceDef.getServiceName().getPackage()))).className(implTypeNameProcessor.process(serviceDef.getServiceName())).definitionPackage(PythonPackage.of(definitionPackageNameProcessor.process(serviceDef.getServiceName().getPackage()))).definitionName(definitionTypeNameProcessor.process(serviceDef.getServiceName())).addAllImports(PythonService.CONJURE_IMPORTS).addAllImports(imports).docs(serviceDef.getDocs()).addAllEndpointDefinitions(endpoints).build();
}
use of com.palantir.conjure.python.poet.PythonSnippet in project conjure-python by palantir.
the class ConjurePythonGenerator method getInitFiles.
private List<PythonFile> getInitFiles(ConjureDefinition conjureDefinition, TypeNameProcessor implTypeNameProcessor, PackageNameProcessor definitionPackageNameProcessor, TypeNameProcessor definitionTypeNameProcessor) {
String moduleSpecifier = ".._impl";
DefinitionImportTypeDefinitionVisitor definitionImportTypeDefinitionVisitor = new DefinitionImportTypeDefinitionVisitor(moduleSpecifier, implTypeNameProcessor, definitionTypeNameProcessor);
List<PythonSnippet> snippets = new ArrayList<>();
snippets.addAll(conjureDefinition.getTypes().stream().map(typeDefinition -> {
TypeName typeName = typeDefinition.accept(TypeDefinitionVisitor.TYPE_NAME);
return EmptySnippet.builder().pythonPackage(PythonPackage.of(definitionPackageNameProcessor.process(typeName.getPackage()))).addAllImports(typeDefinition.accept(definitionImportTypeDefinitionVisitor)).build();
}).collect(Collectors.toList()));
snippets.addAll(conjureDefinition.getServices().stream().map(serviceDefinition -> EmptySnippet.builder().pythonPackage(PythonPackage.of(definitionPackageNameProcessor.process(serviceDefinition.getServiceName().getPackage()))).addImports(PythonImport.of(moduleSpecifier, NamedImport.of(implTypeNameProcessor.process(serviceDefinition.getServiceName()), definitionTypeNameProcessor.process(serviceDefinition.getServiceName())))).build()).collect(Collectors.toList()));
Map<PythonPackage, List<PythonSnippet>> snippetsByPackage = snippets.stream().collect(Collectors.groupingBy(PythonSnippet::pythonPackage));
return KeyedStream.stream(snippetsByPackage).map((pythonPackage, pythonSnippets) -> PythonFile.builder().pythonPackage(pythonPackage).fileName(INIT_PY).contents(pythonSnippets).build()).values().collect(Collectors.toList());
}
use of com.palantir.conjure.python.poet.PythonSnippet in project conjure-python by palantir.
the class ConjurePythonGenerator method getImplPythonFile.
private PythonFile getImplPythonFile(ConjureDefinition conjureDefinition, DealiasingTypeVisitor dealiasingTypeVisitor, PackageNameProcessor implPackageNameProcessor, TypeNameProcessor implTypeNameProcessor, PackageNameProcessor definitionPackageNameProcessor, TypeNameProcessor definitionTypeNameProcessor) {
PythonTypeGenerator beanGenerator = new PythonTypeGenerator(implPackageNameProcessor, implTypeNameProcessor, definitionPackageNameProcessor, definitionTypeNameProcessor, dealiasingTypeVisitor);
ClientGenerator clientGenerator = new ClientGenerator(implPackageNameProcessor, implTypeNameProcessor, definitionPackageNameProcessor, definitionTypeNameProcessor, dealiasingTypeVisitor);
List<PythonSnippet> snippets = new ArrayList<>();
snippets.addAll(conjureDefinition.getTypes().stream().map(beanGenerator::generateType).collect(Collectors.toList()));
snippets.addAll(conjureDefinition.getServices().stream().map(clientGenerator::generateClient).collect(Collectors.toList()));
Map<PythonPackage, List<PythonSnippet>> snippetsByPackage = snippets.stream().collect(Collectors.groupingBy(PythonSnippet::pythonPackage));
PythonPackage rootPackage = PythonPackage.of(implPackageNameProcessor.process(""));
List<PythonFile> pythonFiles = KeyedStream.stream(snippetsByPackage).map((_pythonPackage, pythonSnippets) -> PythonFile.builder().pythonPackage(rootPackage).fileName(IMPL_PY).contents(pythonSnippets).build()).values().collect(Collectors.toList());
return Iterables.getOnlyElement(pythonFiles);
}
Aggregations