Search in sources :

Example 1 with ConjureDefinition

use of com.palantir.conjure.spec.ConjureDefinition in project conjure-java by palantir.

the class DialogueServiceGenerator method generate.

@Override
public Stream<JavaFile> generate(ConjureDefinition conjureDefinition) {
    Map<TypeName, TypeDefinition> types = TypeFunctions.toTypesMap(conjureDefinition);
    DialogueEndpointsGenerator endpoints = new DialogueEndpointsGenerator(options);
    TypeMapper parameterTypes = new TypeMapper(types, new SpecializeBinaryClassNameVisitor(new DefaultClassNameVisitor(types.keySet(), options), types, ClassName.get(BinaryRequestBody.class)));
    TypeMapper returnTypes = new TypeMapper(types, new SpecializeBinaryClassNameVisitor(new DefaultClassNameVisitor(types.keySet(), options), types, ClassName.get(InputStream.class)));
    Map<TypeName, TypeDefinition> typeDefinitionsByName = conjureDefinition.getTypes().stream().collect(Collectors.toMap(type -> type.accept(TypeDefinitionVisitor.TYPE_NAME), Function.identity()));
    DialogueInterfaceGenerator interfaceGenerator = new DialogueInterfaceGenerator(options, new ParameterTypeMapper(parameterTypes), new ReturnTypeMapper(returnTypes));
    TypeNameResolver typeNameResolver = typeName -> Preconditions.checkNotNull(typeDefinitionsByName.get(typeName), "Referenced unknown TypeName", SafeArg.of("typeName", typeName));
    StaticFactoryMethodGenerator asyncGenerator = new DefaultStaticFactoryMethodGenerator(options, typeNameResolver, new ParameterTypeMapper(parameterTypes), new ReturnTypeMapper(returnTypes), StaticFactoryMethodType.ASYNC);
    StaticFactoryMethodGenerator blockingGenerator = new DefaultStaticFactoryMethodGenerator(options, typeNameResolver, new ParameterTypeMapper(parameterTypes), new ReturnTypeMapper(returnTypes), StaticFactoryMethodType.BLOCKING);
    return conjureDefinition.getServices().stream().flatMap(serviceDef -> Stream.of(endpoints.endpointsClass(serviceDef), interfaceGenerator.generateBlocking(serviceDef, blockingGenerator), interfaceGenerator.generateAsync(serviceDef, asyncGenerator)));
}
Also used : TypeMapper(com.palantir.conjure.java.types.TypeMapper) TypeDefinition(com.palantir.conjure.spec.TypeDefinition) SpecializeBinaryClassNameVisitor(com.palantir.conjure.java.types.SpecializeBinaryClassNameVisitor) DefaultClassNameVisitor(com.palantir.conjure.java.types.DefaultClassNameVisitor) TypeFunctions(com.palantir.conjure.java.util.TypeFunctions) ClassName(com.squareup.javapoet.ClassName) TypeMapper(com.palantir.conjure.java.types.TypeMapper) TypeDefinitionVisitor(com.palantir.conjure.visitor.TypeDefinitionVisitor) ConjureDefinition(com.palantir.conjure.spec.ConjureDefinition) BinaryRequestBody(com.palantir.dialogue.BinaryRequestBody) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) Options(com.palantir.conjure.java.Options) JavaFile(com.squareup.javapoet.JavaFile) SafeArg(com.palantir.logsafe.SafeArg) Stream(java.util.stream.Stream) Generator(com.palantir.conjure.java.Generator) TypeName(com.palantir.conjure.spec.TypeName) Map(java.util.Map) Preconditions(com.palantir.logsafe.Preconditions) InputStream(java.io.InputStream) DefaultClassNameVisitor(com.palantir.conjure.java.types.DefaultClassNameVisitor) TypeName(com.palantir.conjure.spec.TypeName) SpecializeBinaryClassNameVisitor(com.palantir.conjure.java.types.SpecializeBinaryClassNameVisitor) TypeDefinition(com.palantir.conjure.spec.TypeDefinition)

Example 2 with ConjureDefinition

use of com.palantir.conjure.spec.ConjureDefinition in project conjure-java by palantir.

the class JerseyServiceEteTest method beforeClass.

@BeforeAll
public static void beforeClass() throws IOException {
    ConjureDefinition def = Conjure.parse(ImmutableList.of(new File("src/test/resources/ete-service.yml"), new File("src/test/resources/ete-binary.yml")));
    List<Path> files = new GenerationCoordinator(MoreExecutors.directExecutor(), ImmutableSet.of(new JerseyServiceGenerator(Options.builder().requireNotNullAuthAndBodyParams(true).build()))).emit(def, folder);
    validateGeneratorOutput(files, Paths.get("src/integrationInput/java/com/palantir/product"));
}
Also used : Path(java.nio.file.Path) JerseyServiceGenerator(com.palantir.conjure.java.services.JerseyServiceGenerator) ConjureDefinition(com.palantir.conjure.spec.ConjureDefinition) File(java.io.File) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 3 with ConjureDefinition

use of com.palantir.conjure.spec.ConjureDefinition in project conjure-java by palantir.

the class JerseyServiceGeneratorTests method testServiceGeneration_exampleService_requireNotNullAuthHeadersAndRequestBodies.

@Test
public void testServiceGeneration_exampleService_requireNotNullAuthHeadersAndRequestBodies() throws IOException {
    ConjureDefinition def = Conjure.parse(ImmutableList.of(new File("src/test/resources/example-service.yml")));
    List<Path> files = new GenerationCoordinator(MoreExecutors.directExecutor(), ImmutableSet.of(new JerseyServiceGenerator(Options.builder().requireNotNullAuthAndBodyParams(true).build()))).emit(def, folder);
    validateGeneratorOutput(files, Paths.get("src/test/resources/test/api"), ".jersey_require_not_null");
}
Also used : Path(java.nio.file.Path) JerseyServiceGenerator(com.palantir.conjure.java.services.JerseyServiceGenerator) ConjureDefinition(com.palantir.conjure.spec.ConjureDefinition) File(java.io.File) Test(org.junit.jupiter.api.Test)

Example 4 with ConjureDefinition

use of com.palantir.conjure.spec.ConjureDefinition in project conjure-java by palantir.

the class JerseyServiceGeneratorTests method testPrefixedServices.

@Test
void testPrefixedServices() throws IOException {
    ConjureDefinition def = Conjure.parse(ImmutableList.of(new File("src/test/resources/example-service.yml")));
    List<Path> files = new GenerationCoordinator(MoreExecutors.directExecutor(), ImmutableSet.of(new JerseyServiceGenerator(Options.builder().packagePrefix("test.prefix").build()))).emit(def, folder);
    validateGeneratorOutput(files, Paths.get("src/test/resources/test/api"), ".jersey.prefix");
}
Also used : Path(java.nio.file.Path) JerseyServiceGenerator(com.palantir.conjure.java.services.JerseyServiceGenerator) ConjureDefinition(com.palantir.conjure.spec.ConjureDefinition) File(java.io.File) Test(org.junit.jupiter.api.Test)

Example 5 with ConjureDefinition

use of com.palantir.conjure.spec.ConjureDefinition in project conjure-java by palantir.

the class JerseyServiceGeneratorTests method testConjureImports.

@Test
public void testConjureImports() throws IOException {
    ConjureDefinition conjure = Conjure.parse(ImmutableList.of(new File("src/test/resources/example-conjure-imports.yml"), new File("src/test/resources/example-types.yml"), new File("src/test/resources/example-service.yml")));
    File src = Files.createDirectory(folder.toPath().resolve("src")).toFile();
    new GenerationCoordinator(MoreExecutors.directExecutor(), ImmutableSet.of(new JerseyServiceGenerator(Options.empty()))).emit(conjure, src);
    // Generated files contain imports
    assertThat(compiledFileContent(src, "test/api/with/imports/ImportService.java")).contains("import com.palantir.product.StringExample;");
}
Also used : JerseyServiceGenerator(com.palantir.conjure.java.services.JerseyServiceGenerator) ConjureDefinition(com.palantir.conjure.spec.ConjureDefinition) File(java.io.File) Test(org.junit.jupiter.api.Test)

Aggregations

ConjureDefinition (com.palantir.conjure.spec.ConjureDefinition)65 Test (org.junit.jupiter.api.Test)49 File (java.io.File)40 Path (java.nio.file.Path)30 ConjureIllegalStateException (com.palantir.conjure.exceptions.ConjureIllegalStateException)13 JerseyServiceGenerator (com.palantir.conjure.java.services.JerseyServiceGenerator)9 UndertowServiceGenerator (com.palantir.conjure.java.services.UndertowServiceGenerator)9 GenerationCoordinator (com.palantir.conjure.java.GenerationCoordinator)8 Retrofit2ServiceGenerator (com.palantir.conjure.java.services.Retrofit2ServiceGenerator)4 DialogueServiceGenerator (com.palantir.conjure.java.services.dialogue.DialogueServiceGenerator)4 AnnotatedConjureSourceFile (com.palantir.conjure.parser.AnnotatedConjureSourceFile)4 TypeDefinition (com.palantir.conjure.spec.TypeDefinition)4 BeforeAll (org.junit.jupiter.api.BeforeAll)4 TypeName (com.palantir.conjure.spec.TypeName)3 ImmutableList (com.google.common.collect.ImmutableList)2 ReferenceTypeResolver (com.palantir.conjure.defs.ConjureTypeParserVisitor.ReferenceTypeResolver)2 ConjureRuntimeException (com.palantir.conjure.exceptions.ConjureRuntimeException)2 ConjureSourceFile (com.palantir.conjure.parser.ConjureSourceFile)2 DefaultPostmanCollectionFileWriter (com.palantir.conjure.postman.writer.DefaultPostmanCollectionFileWriter)2 PostmanCollectionFileWriter (com.palantir.conjure.postman.writer.PostmanCollectionFileWriter)2