use of com.palantir.conjure.spec.TypeName 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.spec.TypeName in project conjure-java by palantir.
the class UndertowServiceGenerator method generate.
@Override
public Stream<JavaFile> generate(ConjureDefinition conjureDefinition) {
Map<TypeName, TypeDefinition> types = TypeFunctions.toTypesMap(conjureDefinition);
ClassNameVisitor defaultVisitor = new DefaultClassNameVisitor(types.keySet(), options);
TypeMapper typeMapper = new TypeMapper(types, new SpecializeBinaryClassNameVisitor(defaultVisitor, types, ClassName.get(InputStream.class)));
TypeMapper returnTypeMapper = new TypeMapper(types, new SpecializeBinaryClassNameVisitor(defaultVisitor, types, ClassName.get(BinaryResponseBody.class)));
UndertowServiceInterfaceGenerator interfaceGenerator = new UndertowServiceInterfaceGenerator(options);
UndertowServiceHandlerGenerator handlerGenerator = new UndertowServiceHandlerGenerator(options);
return conjureDefinition.getServices().stream().flatMap(serviceDef -> Stream.of(interfaceGenerator.generateServiceInterface(serviceDef, typeMapper, returnTypeMapper), handlerGenerator.generateServiceHandler(serviceDef, types, typeMapper, returnTypeMapper)));
}
use of com.palantir.conjure.spec.TypeName in project conjure-postman by palantir.
the class BodyParameterTypeVisitor method visitBody.
@Override
public Optional<PostmanRequest.Body> visitBody(BodyParameterType _value) {
TemplateTypeVisitor visitor = new TemplateTypeVisitor(types);
Type type = argumentDefinition.getType();
return type.accept(new Type.Visitor<Optional<PostmanRequest.Body>>() {
@Override
public Optional<PostmanRequest.Body> visitPrimitive(PrimitiveType value) {
switch(value.get()) {
case BINARY:
return Optional.of(PostmanRequest.FileBody.builder().build());
default:
return rawBody(visitor.visitPrimitive(value));
}
}
@Override
public Optional<PostmanRequest.Body> visitOptional(OptionalType value) {
return rawBody(visitor.visitOptional(value));
}
@Override
public Optional<PostmanRequest.Body> visitList(ListType value) {
return rawBody(visitor.visitList(value));
}
@Override
public Optional<PostmanRequest.Body> visitSet(SetType value) {
return rawBody(visitor.visitSet(value));
}
@Override
public Optional<PostmanRequest.Body> visitMap(MapType value) {
return rawBody(visitor.visitMap(value));
}
@Override
public Optional<PostmanRequest.Body> visitReference(TypeName value) {
return rawBody(visitor.visitReference(value));
}
@Override
public Optional<PostmanRequest.Body> visitExternal(ExternalReference value) {
return rawBody(visitor.visitExternal(value));
}
@Override
public Optional<PostmanRequest.Body> visitUnknown(String _unknownType) {
return Optional.empty();
}
});
}
Aggregations