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");
}
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");
}
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: ");
}
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);
}
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");
}
Aggregations