Search in sources :

Example 21 with ConjureDefinition

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

the class DialogueServiceGeneratorTests method generateEteServices.

@Test
public void generateEteServices() throws IOException {
    ConjureDefinition def = Conjure.parse(ImmutableList.of(new File("src/test/resources/cookie-service.yml"), 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 DialogueServiceGenerator(Options.builder().apiVersion("1.2.3").build()))).emit(def, folder);
    validateGeneratorOutput(files, Paths.get("src/integrationInput/java/com/palantir/product"));
}
Also used : Path(java.nio.file.Path) ConjureDefinition(com.palantir.conjure.spec.ConjureDefinition) File(java.io.File) DialogueServiceGenerator(com.palantir.conjure.java.services.dialogue.DialogueServiceGenerator) Test(org.junit.jupiter.api.Test)

Example 22 with ConjureDefinition

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

the class ConjureParserUtils method parseConjureDef.

static ConjureDefinition parseConjureDef(Map<String, AnnotatedConjureSourceFile> annotatedParsedDefs) {
    ImmutableList.Builder<ServiceDefinition> servicesBuilder = ImmutableList.builder();
    ImmutableList.Builder<ErrorDefinition> errorsBuilder = ImmutableList.builder();
    ImmutableList.Builder<TypeDefinition> typesBuilder = ImmutableList.builder();
    annotatedParsedDefs.values().forEach(annotatedParsed -> {
        ConjureSourceFile parsed = annotatedParsed.conjureSourceFile();
        try {
            ConjureTypeParserVisitor.ReferenceTypeResolver typeResolver = new ConjureTypeParserVisitor.ByParsedRepresentationTypeNameResolver(parsed.types(), annotatedParsed.importProviders(), annotatedParsedDefs);
            // Resolve objects first, so we can use them in service validations
            Map<TypeName, TypeDefinition> objects = parseObjects(parsed.types(), typeResolver);
            Map<TypeName, TypeDefinition> importedObjects = parseImportObjects(parsed.types().conjureImports(), annotatedParsedDefs);
            Map<TypeName, TypeDefinition> allObjects = new HashMap<>();
            allObjects.putAll(objects);
            allObjects.putAll(importedObjects);
            DealiasingTypeVisitor dealiasingVisitor = new DealiasingTypeVisitor(allObjects);
            parsed.services().forEach((serviceName, service) -> {
                servicesBuilder.add(parseService(service, TypeName.of(serviceName.name(), parseConjurePackage(service.conjurePackage())), typeResolver, dealiasingVisitor));
            });
            typesBuilder.addAll(objects.values());
            errorsBuilder.addAll(parseErrors(parsed.types().definitions(), typeResolver));
        } catch (RuntimeException e) {
            throw new ConjureRuntimeException(String.format("Encountered error trying to parse file '%s'", annotatedParsed.sourceFile()), e);
        }
    });
    ConjureDefinition definition = ConjureDefinition.builder().version(Conjure.SUPPORTED_IR_VERSION).types(typesBuilder.build()).errors(errorsBuilder.build()).services(servicesBuilder.build()).build();
    ConjureDefinitionValidator.validateAll(definition);
    return definition;
}
Also used : ErrorDefinition(com.palantir.conjure.spec.ErrorDefinition) AnnotatedConjureSourceFile(com.palantir.conjure.parser.AnnotatedConjureSourceFile) ConjureSourceFile(com.palantir.conjure.parser.ConjureSourceFile) TypeName(com.palantir.conjure.spec.TypeName) ReferenceTypeResolver(com.palantir.conjure.defs.ConjureTypeParserVisitor.ReferenceTypeResolver) HashMap(java.util.HashMap) ImmutableList(com.google.common.collect.ImmutableList) ConjureRuntimeException(com.palantir.conjure.exceptions.ConjureRuntimeException) DealiasingTypeVisitor(com.palantir.conjure.visitor.DealiasingTypeVisitor) TypeDefinition(com.palantir.conjure.spec.TypeDefinition) ConjureRuntimeException(com.palantir.conjure.exceptions.ConjureRuntimeException) ConjureDefinition(com.palantir.conjure.spec.ConjureDefinition) ServiceDefinition(com.palantir.conjure.spec.ServiceDefinition)

Example 23 with ConjureDefinition

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

the class ConjureSourceFileValidatorTest method testTypeMissingRequiredSafetyInformation.

@Test
public void testTypeMissingRequiredSafetyInformation() {
    ConjureDefinition conjureDef = ConjureDefinition.builder().version(1).types(TypeDefinition.object(ObjectDefinition.builder().typeName(FOO).fields(FieldDefinition.builder().fieldName(FieldName.of("bad")).type(Type.primitive(PrimitiveType.STRING)).docs(DOCS).build()).build())).build();
    assertThatThrownBy(() -> ConjureDefinitionValidator.validateAll(conjureDef, SafetyDeclarationRequirements.REQUIRED)).isInstanceOf(ConjureIllegalStateException.class).hasMessageContaining("package.Foo::bad must declare log safety");
}
Also used : ConjureIllegalStateException(com.palantir.conjure.exceptions.ConjureIllegalStateException) ConjureDefinition(com.palantir.conjure.spec.ConjureDefinition) Test(org.junit.jupiter.api.Test)

Example 24 with ConjureDefinition

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

the class ConjureSourceFileValidatorTest method testNoIllegalMapKeys_field.

@Test
public void testNoIllegalMapKeys_field() {
    ConjureDefinition conjureDef = ConjureDefinition.builder().version(1).types(TypeDefinition.object(ObjectDefinition.builder().typeName(FOO).fields(FieldDefinition.builder().fieldName(FieldName.of("bad")).type(Type.map(MapType.of(Type.list(ListType.of(Type.primitive(PrimitiveType.STRING))), Type.primitive(PrimitiveType.STRING)))).docs(DOCS).build()).build())).build();
    assertThatThrownBy(() -> ConjureDefinitionValidator.ILLEGAL_MAP_KEYS.validate(conjureDef)).isInstanceOf(IllegalStateException.class).hasMessageStartingWith("Illegal map key found in object Foo");
}
Also used : ConjureIllegalStateException(com.palantir.conjure.exceptions.ConjureIllegalStateException) ConjureDefinition(com.palantir.conjure.spec.ConjureDefinition) Test(org.junit.jupiter.api.Test)

Example 25 with ConjureDefinition

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

the class ConjureSourceFileValidatorTest method testNoSelfRecursiveType.

@Test
public void testNoSelfRecursiveType() {
    ConjureDefinition conjureDef = ConjureDefinition.builder().version(1).types(ImmutableList.of(TypeDefinition.object(ObjectDefinition.builder().typeName(FOO).fields(FieldDefinition.builder().fieldName(FieldName.of("self")).type(Type.reference(FOO)).docs(DOCS).build()).build()))).build();
    assertThatThrownBy(() -> ConjureDefinitionValidator.NO_RECURSIVE_TYPES.validate(conjureDef)).isInstanceOf(IllegalStateException.class).hasMessage("Illegal recursive data type: Foo -> Foo");
}
Also used : ConjureIllegalStateException(com.palantir.conjure.exceptions.ConjureIllegalStateException) ConjureDefinition(com.palantir.conjure.spec.ConjureDefinition) 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