Search in sources :

Example 46 with ConjureDefinition

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

the class ConjureSourceFileValidatorTest method testInvalidSafetyArgument_reference.

@Test
public void testInvalidSafetyArgument_reference() {
    ConjureDefinition conjureDef = ConjureDefinition.builder().version(1).types(TypeDefinition.object(ObjectDefinition.builder().typeName(FOO).build())).services(ServiceDefinition.builder().serviceName(TypeName.of("Service", "com.palantir.product")).endpoints(EndpointDefinition.builder().endpointName(EndpointName.of("end")).httpMethod(HttpMethod.PUT).httpPath(HttpPath.of("/path")).args(ArgumentDefinition.builder().argName(ArgumentName.of("arg")).type(Type.reference(FOO)).paramType(ParameterType.body(BodyParameterType.of())).safety(LogSafety.UNSAFE).build()).build()).build()).build();
    assertThatThrownBy(() -> ConjureDefinitionValidator.validateAll(conjureDef, SafetyDeclarationRequirements.ALLOWED)).isInstanceOf(IllegalStateException.class).hasMessageContaining("Service.end(arg): end cannot declare log safety. Only conjure primitives and wrappers around" + " conjure primitives may declare safety. package.Foo is not a primitive type.");
}
Also used : ConjureIllegalStateException(com.palantir.conjure.exceptions.ConjureIllegalStateException) ConjureDefinition(com.palantir.conjure.spec.ConjureDefinition) Test(org.junit.jupiter.api.Test)

Example 47 with ConjureDefinition

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

the class ConjureSourceFileValidatorTest method testNoSafetyOnComplexTypes.

@Test
public void testNoSafetyOnComplexTypes() {
    ConjureDefinition conjureDef = ConjureDefinition.builder().version(1).types(TypeDefinition.alias(AliasDefinition.builder().typeName(TypeName.of("AliasName", "package")).alias(Type.list(ListType.of(Type.primitive(PrimitiveType.STRING)))).build())).types(TypeDefinition.object(ObjectDefinition.builder().typeName(FOO).fields(FieldDefinition.builder().fieldName(FieldName.of("bad")).type(Type.reference(TypeName.of("AliasName", "package"))).safety(LogSafety.UNSAFE).docs(DOCS).build()).build())).build();
    assertThatThrownBy(() -> ConjureDefinitionValidator.validateAll(conjureDef, SafetyDeclarationRequirements.ALLOWED)).isInstanceOf(IllegalStateException.class).hasMessageContaining("Only conjure primitives and wrappers around conjure primitives may declare safety");
}
Also used : ConjureIllegalStateException(com.palantir.conjure.exceptions.ConjureIllegalStateException) ConjureDefinition(com.palantir.conjure.spec.ConjureDefinition) Test(org.junit.jupiter.api.Test)

Example 48 with ConjureDefinition

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

the class ConjureDefTest method resolvesCircularType_multiFile.

@Test
public void resolvesCircularType_multiFile() {
    ConjureDefinition conjureDefinition = ConjureParserUtils.parseConjureDef(ConjureParser.parseAnnotated(ImmutableList.of(new File("src/test/resources/example-multi-file-circular-import-a.yml"), new File("src/test/resources/example-multi-file-circular-import-b.yml"))));
    assertThat(conjureDefinition.getTypes()).hasSize(2);
}
Also used : ConjureDefinition(com.palantir.conjure.spec.ConjureDefinition) File(java.io.File) Test(org.junit.jupiter.api.Test)

Example 49 with ConjureDefinition

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

the class ConjureDefTest method resolvesCircularType_singleFile.

@Test
public void resolvesCircularType_singleFile() {
    ConjureDefinition conjureDefinition = ConjureParserUtils.parseConjureDef(ConjureParser.parseAnnotated(new File("src/test/resources/example-circular.yml")));
    assertThat(conjureDefinition.getTypes()).hasSize(2);
}
Also used : ConjureDefinition(com.palantir.conjure.spec.ConjureDefinition) File(java.io.File) Test(org.junit.jupiter.api.Test)

Example 50 with ConjureDefinition

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

the class ConjureDefTest method resolvesRecursiveImportType.

@Test
public void resolvesRecursiveImportType() {
    ConjureDefinition conjureDefinition = ConjureParserUtils.parseConjureDef(ConjureParser.parseAnnotated(new File("src/test/resources/example-recursive-imports.yml")));
    assertThat(conjureDefinition.getTypes()).hasSize(1);
}
Also used : 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