Search in sources :

Example 41 with ConjureDefinition

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

the class ConjureSourceFileValidatorTest method testSafetyOnPrimitive.

@Test
public void testSafetyOnPrimitive() {
    ConjureDefinition conjureDef = ConjureDefinition.builder().version(1).types(TypeDefinition.object(ObjectDefinition.builder().typeName(FOO).fields(FieldDefinition.builder().fieldName(FieldName.of("bad")).type(Type.primitive(PrimitiveType.STRING)).safety(LogSafety.UNSAFE).docs(DOCS).build()).build())).build();
    ConjureDefinitionValidator.validateAll(conjureDef, SafetyDeclarationRequirements.REQUIRED);
}
Also used : ConjureDefinition(com.palantir.conjure.spec.ConjureDefinition) Test(org.junit.jupiter.api.Test)

Example 42 with ConjureDefinition

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

the class ConjureSourceFileValidatorTest method testSafetyOnMap.

@Test
public void testSafetyOnMap() {
    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.primitive(PrimitiveType.STRING), Type.primitive(PrimitiveType.STRING)))).safety(LogSafety.DO_NOT_LOG).docs(DOCS).build()).build())).build();
    assertThatThrownBy(() -> ConjureDefinitionValidator.validateAll(conjureDef, SafetyDeclarationRequirements.ALLOWED)).isInstanceOf(IllegalStateException.class).hasMessageContainingAll("Maps cannot declare log safety", "Consider using alias types");
}
Also used : ConjureIllegalStateException(com.palantir.conjure.exceptions.ConjureIllegalStateException) ConjureDefinition(com.palantir.conjure.spec.ConjureDefinition) Test(org.junit.jupiter.api.Test)

Example 43 with ConjureDefinition

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

the class ConjureSourceFileValidatorTest method testNoIllegalMapKeys_intermediateAlias.

@Test
public void testNoIllegalMapKeys_intermediateAlias() {
    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.map(MapType.of(Type.list(ListType.of(Type.primitive(PrimitiveType.STRING))), 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 44 with ConjureDefinition

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

the class ConjureSourceFileValidatorTest method testInvalidSafetyArgument_bearertoken.

@Test
public void testInvalidSafetyArgument_bearertoken() {
    ConjureDefinition conjureDef = ConjureDefinition.builder().version(1).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.primitive(PrimitiveType.BEARERTOKEN)).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): bearertoken values are 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)

Example 45 with ConjureDefinition

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

the class ConjureSourceFileValidatorTest method testValidArgumentSafety.

@Test
public void testValidArgumentSafety() {
    ConjureDefinition conjureDef = ConjureDefinition.builder().version(1).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.primitive(PrimitiveType.STRING)).paramType(ParameterType.body(BodyParameterType.of())).safety(LogSafety.UNSAFE).build()).build()).build()).build();
    ConjureDefinitionValidator.validateAll(conjureDef, SafetyDeclarationRequirements.REQUIRED);
}
Also used : 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