Search in sources :

Example 1 with EnumTypeDefinition

use of com.palantir.conjure.parser.types.complex.EnumTypeDefinition in project conjure by palantir.

the class ConjureParserTest method testConjureEnumValueDeprecation.

@Test
public void testConjureEnumValueDeprecation() {
    ConjureSourceFile conjure = ConjureParser.parse(new File("src/test/resources/example-deprecation.yml"));
    EnumTypeDefinition enumType = conjure.types().definitions().objects().get(TypeName.of("EnumWithDeprecatedValues")).visit(new TypeDefinitionVisitor<EnumTypeDefinition>() {

        @Override
        public EnumTypeDefinition visit(AliasTypeDefinition _def) {
            throw new SafeIllegalArgumentException("Expected EnumTypeDefinition");
        }

        @Override
        public EnumTypeDefinition visit(EnumTypeDefinition def) {
            return def;
        }

        @Override
        public EnumTypeDefinition visit(ObjectTypeDefinition _def) {
            throw new SafeIllegalArgumentException("Expected EnumTypeDefinition");
        }

        @Override
        public EnumTypeDefinition visit(UnionTypeDefinition _def) {
            throw new SafeIllegalArgumentException("Expected EnumTypeDefinition");
        }
    });
    EnumValueDefinition one = enumType.values().get(0);
    EnumValueDefinition two = enumType.values().get(1);
    assertThat(one.value()).isEqualTo("ONE");
    assertThat(one.deprecated()).isNotPresent();
    assertThat(two.value()).isEqualTo("TWO");
    assertThat(two.deprecated()).hasValue("Prefer ONE.");
}
Also used : ObjectTypeDefinition(com.palantir.conjure.parser.types.complex.ObjectTypeDefinition) EnumTypeDefinition(com.palantir.conjure.parser.types.complex.EnumTypeDefinition) EnumValueDefinition(com.palantir.conjure.parser.types.complex.EnumValueDefinition) UnionTypeDefinition(com.palantir.conjure.parser.types.complex.UnionTypeDefinition) File(java.io.File) SafeIllegalArgumentException(com.palantir.logsafe.exceptions.SafeIllegalArgumentException) AliasTypeDefinition(com.palantir.conjure.parser.types.reference.AliasTypeDefinition) Test(org.junit.jupiter.api.Test)

Example 2 with EnumTypeDefinition

use of com.palantir.conjure.parser.types.complex.EnumTypeDefinition in project conjure by palantir.

the class ConjureParserTest method testConjureFieldDeprecation.

@Test
public void testConjureFieldDeprecation() {
    ConjureSourceFile conjure = ConjureParser.parse(new File("src/test/resources/example-deprecation.yml"));
    ObjectTypeDefinition object = conjure.types().definitions().objects().get(TypeName.of("BeanWithDeprecatedField")).visit(new TypeDefinitionVisitor<ObjectTypeDefinition>() {

        @Override
        public ObjectTypeDefinition visit(AliasTypeDefinition _def) {
            throw new SafeIllegalArgumentException("Expected ObjectTypeDefinition");
        }

        @Override
        public ObjectTypeDefinition visit(EnumTypeDefinition _def) {
            throw new SafeIllegalArgumentException("Expected ObjectTypeDefinition");
        }

        @Override
        public ObjectTypeDefinition visit(ObjectTypeDefinition def) {
            return def;
        }

        @Override
        public ObjectTypeDefinition visit(UnionTypeDefinition _def) {
            throw new SafeIllegalArgumentException("Expected ObjectTypeDefinition");
        }
    });
    assertThat(object.fields().get(FieldName.of("old")).deprecated()).hasValue("Test deprecated.");
}
Also used : ObjectTypeDefinition(com.palantir.conjure.parser.types.complex.ObjectTypeDefinition) EnumTypeDefinition(com.palantir.conjure.parser.types.complex.EnumTypeDefinition) UnionTypeDefinition(com.palantir.conjure.parser.types.complex.UnionTypeDefinition) File(java.io.File) SafeIllegalArgumentException(com.palantir.logsafe.exceptions.SafeIllegalArgumentException) AliasTypeDefinition(com.palantir.conjure.parser.types.reference.AliasTypeDefinition) Test(org.junit.jupiter.api.Test)

Example 3 with EnumTypeDefinition

use of com.palantir.conjure.parser.types.complex.EnumTypeDefinition in project conjure by palantir.

the class ConjureParserTest method testConjureUnionTypeDeprecation.

@Test
public void testConjureUnionTypeDeprecation() {
    ConjureSourceFile conjure = ConjureParser.parse(new File("src/test/resources/example-deprecation.yml"));
    UnionTypeDefinition union = conjure.types().definitions().objects().get(TypeName.of("UnionWithDeprecatedTypes")).visit(new TypeDefinitionVisitor<UnionTypeDefinition>() {

        @Override
        public UnionTypeDefinition visit(AliasTypeDefinition _def) {
            throw new SafeIllegalArgumentException("Expected EnumTypeDefinition");
        }

        @Override
        public UnionTypeDefinition visit(EnumTypeDefinition _def) {
            throw new SafeIllegalArgumentException("Expected EnumTypeDefinition");
        }

        @Override
        public UnionTypeDefinition visit(ObjectTypeDefinition _def) {
            throw new SafeIllegalArgumentException("Expected EnumTypeDefinition");
        }

        @Override
        public UnionTypeDefinition visit(UnionTypeDefinition def) {
            return def;
        }
    });
    assertThat(union.union().get(FieldName.of("first")).deprecated()).isNotPresent();
    assertThat(union.union().get(FieldName.of("second")).deprecated()).hasValue("Use 'first'.");
}
Also used : ObjectTypeDefinition(com.palantir.conjure.parser.types.complex.ObjectTypeDefinition) EnumTypeDefinition(com.palantir.conjure.parser.types.complex.EnumTypeDefinition) UnionTypeDefinition(com.palantir.conjure.parser.types.complex.UnionTypeDefinition) File(java.io.File) SafeIllegalArgumentException(com.palantir.logsafe.exceptions.SafeIllegalArgumentException) AliasTypeDefinition(com.palantir.conjure.parser.types.reference.AliasTypeDefinition) Test(org.junit.jupiter.api.Test)

Aggregations

EnumTypeDefinition (com.palantir.conjure.parser.types.complex.EnumTypeDefinition)3 ObjectTypeDefinition (com.palantir.conjure.parser.types.complex.ObjectTypeDefinition)3 UnionTypeDefinition (com.palantir.conjure.parser.types.complex.UnionTypeDefinition)3 AliasTypeDefinition (com.palantir.conjure.parser.types.reference.AliasTypeDefinition)3 SafeIllegalArgumentException (com.palantir.logsafe.exceptions.SafeIllegalArgumentException)3 File (java.io.File)3 Test (org.junit.jupiter.api.Test)3 EnumValueDefinition (com.palantir.conjure.parser.types.complex.EnumValueDefinition)1