Search in sources :

Example 6 with FieldDefinition

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

the class UnionDefinitionValidatorTest method testUnionMemberKeyMustNotHaveTrailingUnderscore.

@Test
public void testUnionMemberKeyMustNotHaveTrailingUnderscore() {
    FieldDefinition fieldDefinition = FieldDefinition.builder().fieldName(FieldName.of("foo_")).type(Type.primitive(PrimitiveType.STRING)).build();
    assertThatThrownBy(() -> UnionDefinitionValidator.validateAll(UnionDefinition.builder().union(fieldDefinition).typeName(TypeName.of("string", "")).build())).isInstanceOf(IllegalArgumentException.class).hasMessageStartingWith("Union member key must not end with an underscore: foo_");
}
Also used : FieldDefinition(com.palantir.conjure.spec.FieldDefinition) Test(org.junit.jupiter.api.Test)

Example 7 with FieldDefinition

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

the class UnionDefinitionValidatorTest method testUnionMemberKeyMustNotBeEmpty.

@Test
public void testUnionMemberKeyMustNotBeEmpty() {
    FieldDefinition fieldDefinition = FieldDefinition.builder().fieldName(FieldName.of("")).type(Type.primitive(PrimitiveType.STRING)).build();
    assertThatThrownBy(() -> UnionDefinitionValidator.validateAll(UnionDefinition.builder().union(fieldDefinition).typeName(TypeName.of("string", "")).build())).isInstanceOf(IllegalArgumentException.class).hasMessageStartingWith("Union member key must not be empty");
}
Also used : FieldDefinition(com.palantir.conjure.spec.FieldDefinition) Test(org.junit.jupiter.api.Test)

Example 8 with FieldDefinition

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

the class UnionDefinitionValidatorTest method testUnionMemberKeyMustNotBeIllegalJavaIdentifier.

@Test
public void testUnionMemberKeyMustNotBeIllegalJavaIdentifier() {
    ImmutableList.of("%foo", "foo@").forEach(key -> {
        FieldDefinition fieldDefinition = FieldDefinition.builder().fieldName(FieldName.of(key)).type(Type.primitive(PrimitiveType.STRING)).build();
        assertThatThrownBy(() -> UnionDefinitionValidator.validateAll(UnionDefinition.builder().union(fieldDefinition).typeName(TypeName.of("string", "")).build())).isInstanceOf(IllegalArgumentException.class).hasMessageStartingWith(String.format("Union member key must be a valid Java identifier: %s", key));
    });
}
Also used : FieldDefinition(com.palantir.conjure.spec.FieldDefinition) Test(org.junit.jupiter.api.Test)

Example 9 with FieldDefinition

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

the class ErrorDefinitionValidatorTest method testUniqueArgNamesValidator.

@Test
public void testUniqueArgNamesValidator() {
    FieldDefinition safeArg1 = FieldDefinition.builder().fieldName(FieldName.of("fooBar")).type(Type.primitive(PrimitiveType.STRING)).build();
    FieldDefinition unsafeArg1 = FieldDefinition.builder().fieldName(FieldName.of("foo-bar")).type(Type.primitive(PrimitiveType.STRING)).build();
    ErrorDefinition definition1 = ErrorDefinition.builder().errorName(TypeName.of("Foo", "package")).namespace(ErrorNamespace.of("Test")).code(ErrorCode.INVALID_ARGUMENT).safeArgs(safeArg1).unsafeArgs(unsafeArg1).build();
    assertThatThrownBy(() -> ErrorDefinitionValidator.validate(definition1)).isInstanceOf(IllegalArgumentException.class).hasMessage("ErrorDefinition must not contain duplicate field names (modulo case normalization): " + "foo-bar vs fooBar");
    FieldDefinition safeArg2 = FieldDefinition.builder().fieldName(FieldName.of("foo-bar")).type(Type.primitive(PrimitiveType.STRING)).build();
    FieldDefinition unsafeArg2 = FieldDefinition.builder().fieldName(FieldName.of("foo_bar")).type(Type.primitive(PrimitiveType.STRING)).build();
    ErrorDefinition definition2 = ErrorDefinition.builder().errorName(TypeName.of("Foo", "package")).namespace(ErrorNamespace.of("Test")).code(ErrorCode.INVALID_ARGUMENT).safeArgs(safeArg2).unsafeArgs(unsafeArg2).build();
    assertThatThrownBy(() -> ErrorDefinitionValidator.validate(definition2)).isInstanceOf(IllegalArgumentException.class).hasMessage("ErrorDefinition must not contain duplicate field names (modulo case normalization): " + "foo-bar vs foo_bar");
}
Also used : ErrorDefinition(com.palantir.conjure.spec.ErrorDefinition) FieldDefinition(com.palantir.conjure.spec.FieldDefinition) Test(org.junit.jupiter.api.Test)

Example 10 with FieldDefinition

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

the class FieldDefinitionValidatorTest method testNoComplexKeysInMaps.

@Test
public void testNoComplexKeysInMaps() {
    String illegalFieldName = "asdf";
    Type complexKeyType = Type.list(ListType.of(Type.primitive(PrimitiveType.STRING)));
    FieldDefinition fieldDefinition = FieldDefinition.builder().fieldName(FieldName.of(illegalFieldName)).type(Type.map(MapType.of(complexKeyType, Type.primitive(PrimitiveType.STRING)))).docs(Documentation.of("docs")).build();
    assertThatThrownBy(() -> FieldDefinitionValidator.validate(fieldDefinition)).isInstanceOf(IllegalStateException.class).hasMessageContaining(illegalFieldName).hasMessageContaining(complexKeyType.toString());
}
Also used : ListType(com.palantir.conjure.spec.ListType) MapType(com.palantir.conjure.spec.MapType) Type(com.palantir.conjure.spec.Type) PrimitiveType(com.palantir.conjure.spec.PrimitiveType) FieldDefinition(com.palantir.conjure.spec.FieldDefinition) Test(org.junit.jupiter.api.Test)

Aggregations

FieldDefinition (com.palantir.conjure.spec.FieldDefinition)14 Type (com.palantir.conjure.spec.Type)8 FieldName (com.palantir.conjure.spec.FieldName)5 MapType (com.palantir.conjure.spec.MapType)5 PrimitiveType (com.palantir.conjure.spec.PrimitiveType)5 TypeDefinition (com.palantir.conjure.spec.TypeDefinition)5 FieldSpec (com.squareup.javapoet.FieldSpec)5 List (java.util.List)5 Map (java.util.Map)5 Collectors (java.util.stream.Collectors)5 Test (org.junit.jupiter.api.Test)5 JsonIgnoreProperties (com.fasterxml.jackson.annotation.JsonIgnoreProperties)4 ImmutableList (com.google.common.collect.ImmutableList)4 ConjureAnnotations (com.palantir.conjure.java.ConjureAnnotations)4 Options (com.palantir.conjure.java.Options)4 JavaNameSanitizer (com.palantir.conjure.java.util.JavaNameSanitizer)4 TypeFunctions (com.palantir.conjure.java.util.TypeFunctions)4 ListType (com.palantir.conjure.spec.ListType)4 ObjectDefinition (com.palantir.conjure.spec.ObjectDefinition)4 OptionalType (com.palantir.conjure.spec.OptionalType)4