Search in sources :

Example 26 with ConjureDefinition

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

the class ConjureSourceFileValidatorTest method testNoIllegalMapKeys_returns.

@Test
public void testNoIllegalMapKeys_returns() {
    ConjureDefinition conjureDef = ConjureDefinition.builder().version(1).services(ServiceDefinition.builder().serviceName(TypeName.of("name", "package")).endpoints(EndpointDefinition.builder().endpointName(EndpointName.of("badEndpoint")).httpMethod(HttpMethod.GET).httpPath(HttpPath.of("/")).returns(Type.map(MapType.of(Type.list(ListType.of(Type.primitive(PrimitiveType.STRING))), Type.primitive(PrimitiveType.STRING)))).build()).build()).build();
    assertThatThrownBy(() -> ConjureDefinitionValidator.ILLEGAL_MAP_KEYS.validate(conjureDef)).isInstanceOf(IllegalStateException.class).hasMessageStartingWith("Illegal map key found in return type of endpoint badEndpoint");
}
Also used : ConjureIllegalStateException(com.palantir.conjure.exceptions.ConjureIllegalStateException) ConjureDefinition(com.palantir.conjure.spec.ConjureDefinition) Test(org.junit.jupiter.api.Test)

Example 27 with ConjureDefinition

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

the class ConjureSourceFileValidatorTest method testNoIllegalMapKeys_faileInvalidExternalImport.

@Test
public void testNoIllegalMapKeys_faileInvalidExternalImport() {
    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.external(ExternalReference.builder().externalReference(TypeName.of("Foo", "package")).fallback(Type.primitive(PrimitiveType.ANY)).build()), 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 28 with ConjureDefinition

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

the class ConjureSourceFileValidatorTest method testNoRecursiveCycleType.

@Test
public void testNoRecursiveCycleType() {
    ConjureDefinition conjureDef = ConjureDefinition.builder().version(1).types(ImmutableList.of(TypeDefinition.object(ObjectDefinition.builder().typeName(FOO).fields(field(FieldName.of("bar"), "Bar")).build()), TypeDefinition.object(ObjectDefinition.builder().typeName(BAR).fields(field(FieldName.of("foo"), "Foo")).build()))).build();
    assertThatThrownBy(() -> ConjureDefinitionValidator.NO_RECURSIVE_TYPES.validate(conjureDef)).isInstanceOf(IllegalStateException.class).hasMessageStartingWith("Illegal recursive data type: ");
}
Also used : ConjureIllegalStateException(com.palantir.conjure.exceptions.ConjureIllegalStateException) ConjureDefinition(com.palantir.conjure.spec.ConjureDefinition) Test(org.junit.jupiter.api.Test)

Example 29 with ConjureDefinition

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

the class ConjureSourceFileValidatorTest method testRecursiveTypeOkInReference.

@Test
public void testRecursiveTypeOkInReference() {
    Type referenceType = Type.reference(FOO);
    TypeDefinition objectDefinition = TypeDefinition.object(ObjectDefinition.builder().typeName(TypeName.of("Foo", "bar")).addAllFields(ImmutableList.of(FieldDefinition.builder().fieldName(FieldName.of("selfOptional")).type(Type.optional(OptionalType.of(Type.reference(FOO)))).docs(DOCS).build(), FieldDefinition.builder().fieldName(FieldName.of("selfMap")).type(Type.map(MapType.of(referenceType, referenceType))).docs(DOCS).build(), FieldDefinition.builder().fieldName(FieldName.of("selfSet")).type(Type.set(SetType.of(referenceType))).docs(DOCS).build(), FieldDefinition.builder().fieldName(FieldName.of("selfList")).type(Type.list(ListType.of(referenceType))).docs(DOCS).build())).build());
    ConjureDefinition conjureDef = ConjureDefinition.builder().version(1).types(ImmutableList.of(objectDefinition)).build();
    ConjureDefinitionValidator.NO_RECURSIVE_TYPES.validate(conjureDef);
}
Also used : ListType(com.palantir.conjure.spec.ListType) Type(com.palantir.conjure.spec.Type) MapType(com.palantir.conjure.spec.MapType) OptionalType(com.palantir.conjure.spec.OptionalType) SetType(com.palantir.conjure.spec.SetType) BodyParameterType(com.palantir.conjure.spec.BodyParameterType) ParameterType(com.palantir.conjure.spec.ParameterType) PrimitiveType(com.palantir.conjure.spec.PrimitiveType) ConjureDefinition(com.palantir.conjure.spec.ConjureDefinition) TypeDefinition(com.palantir.conjure.spec.TypeDefinition) Test(org.junit.jupiter.api.Test)

Example 30 with ConjureDefinition

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

the class ConjureSourceFileValidatorTest method testSafetyOnBearerToken.

@Test
public void testSafetyOnBearerToken() {
    ConjureDefinition conjureDef = ConjureDefinition.builder().version(1).types(TypeDefinition.object(ObjectDefinition.builder().typeName(FOO).fields(FieldDefinition.builder().fieldName(FieldName.of("bad")).type(Type.primitive(PrimitiveType.BEARERTOKEN)).safety(LogSafety.DO_NOT_LOG).docs(DOCS).build()).build())).build();
    assertThatThrownBy(() -> ConjureDefinitionValidator.validateAll(conjureDef, SafetyDeclarationRequirements.ALLOWED)).isInstanceOf(IllegalStateException.class).hasMessageContaining("do-not-log by default and cannot be configured");
}
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