Search in sources :

Example 11 with TypeName

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());
}
Also used : PythonPackage(com.palantir.conjure.python.poet.PythonPackage) TypeName(com.palantir.conjure.spec.TypeName) PythonSnippet(com.palantir.conjure.python.poet.PythonSnippet) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) DefinitionImportTypeDefinitionVisitor(com.palantir.conjure.python.types.DefinitionImportTypeDefinitionVisitor)

Example 12 with TypeName

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)));
}
Also used : TypeMapper(com.palantir.conjure.java.types.TypeMapper) DefaultClassNameVisitor(com.palantir.conjure.java.types.DefaultClassNameVisitor) TypeName(com.palantir.conjure.spec.TypeName) SpecializeBinaryClassNameVisitor(com.palantir.conjure.java.types.SpecializeBinaryClassNameVisitor) DefaultClassNameVisitor(com.palantir.conjure.java.types.DefaultClassNameVisitor) ClassNameVisitor(com.palantir.conjure.java.types.ClassNameVisitor) SpecializeBinaryClassNameVisitor(com.palantir.conjure.java.types.SpecializeBinaryClassNameVisitor) TypeDefinition(com.palantir.conjure.spec.TypeDefinition)

Example 13 with TypeName

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();
        }
    });
}
Also used : TypeName(com.palantir.conjure.spec.TypeName) Optional(java.util.Optional) MapType(com.palantir.conjure.spec.MapType) ListType(com.palantir.conjure.spec.ListType) Type(com.palantir.conjure.spec.Type) BodyParameterType(com.palantir.conjure.spec.BodyParameterType) MapType(com.palantir.conjure.spec.MapType) OptionalType(com.palantir.conjure.spec.OptionalType) SetType(com.palantir.conjure.spec.SetType) PrimitiveType(com.palantir.conjure.spec.PrimitiveType) OptionalType(com.palantir.conjure.spec.OptionalType) ExternalReference(com.palantir.conjure.spec.ExternalReference) SetType(com.palantir.conjure.spec.SetType) ListType(com.palantir.conjure.spec.ListType) PrimitiveType(com.palantir.conjure.spec.PrimitiveType) PostmanRequest(com.palantir.conjure.postman.api.PostmanRequest)

Aggregations

TypeName (com.palantir.conjure.spec.TypeName)13 TypeDefinition (com.palantir.conjure.spec.TypeDefinition)6 ImmutableList (com.google.common.collect.ImmutableList)4 DealiasingTypeVisitor (com.palantir.conjure.visitor.DealiasingTypeVisitor)4 ReferenceTypeResolver (com.palantir.conjure.defs.ConjureTypeParserVisitor.ReferenceTypeResolver)3 AnnotatedConjureSourceFile (com.palantir.conjure.parser.AnnotatedConjureSourceFile)3 ConjureSourceFile (com.palantir.conjure.parser.ConjureSourceFile)3 ConjureDefinition (com.palantir.conjure.spec.ConjureDefinition)3 ErrorDefinition (com.palantir.conjure.spec.ErrorDefinition)3 HashMap (java.util.HashMap)3 ConjureRuntimeException (com.palantir.conjure.exceptions.ConjureRuntimeException)2 DefaultClassNameVisitor (com.palantir.conjure.java.types.DefaultClassNameVisitor)2 SpecializeBinaryClassNameVisitor (com.palantir.conjure.java.types.SpecializeBinaryClassNameVisitor)2 TypeMapper (com.palantir.conjure.java.types.TypeMapper)2 PathString (com.palantir.conjure.parser.services.PathString)2 EndpointDefinition (com.palantir.conjure.spec.EndpointDefinition)2 ExternalReference (com.palantir.conjure.spec.ExternalReference)2 FieldDefinition (com.palantir.conjure.spec.FieldDefinition)2 ObjectDefinition (com.palantir.conjure.spec.ObjectDefinition)2 TypeDefinitionVisitor (com.palantir.conjure.visitor.TypeDefinitionVisitor)2