Search in sources :

Example 6 with ErrorDefinition

use of com.palantir.conjure.spec.ErrorDefinition 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 7 with ErrorDefinition

use of com.palantir.conjure.spec.ErrorDefinition in project conjure-java by palantir.

the class ErrorGenerator method splitErrorDefsByNamespace.

private static Map<String, Map<ErrorNamespace, List<ErrorDefinition>>> splitErrorDefsByNamespace(List<ErrorDefinition> errorTypeNameToDef) {
    Map<String, Map<ErrorNamespace, List<ErrorDefinition>>> pkgToNamespacedErrorDefs = new HashMap<>();
    errorTypeNameToDef.forEach(errorDef -> {
        String errorPkg = errorDef.getErrorName().getPackage();
        pkgToNamespacedErrorDefs.computeIfAbsent(errorPkg, key -> new HashMap<>());
        Map<ErrorNamespace, List<ErrorDefinition>> namespacedErrorDefs = pkgToNamespacedErrorDefs.get(errorPkg);
        ErrorNamespace namespace = errorDef.getNamespace();
        // TODO(rfink): Use Multimap?
        namespacedErrorDefs.computeIfAbsent(namespace, key -> new ArrayList<>());
        namespacedErrorDefs.get(namespace).add(errorDef);
    });
    return pkgToNamespacedErrorDefs;
}
Also used : ErrorDefinition(com.palantir.conjure.spec.ErrorDefinition) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) List(java.util.List) ErrorNamespace(com.palantir.conjure.spec.ErrorNamespace) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

ErrorDefinition (com.palantir.conjure.spec.ErrorDefinition)7 HashMap (java.util.HashMap)4 ImmutableList (com.google.common.collect.ImmutableList)3 ConjureDefinition (com.palantir.conjure.spec.ConjureDefinition)3 TypeDefinition (com.palantir.conjure.spec.TypeDefinition)3 TypeName (com.palantir.conjure.spec.TypeName)3 ReferenceTypeResolver (com.palantir.conjure.defs.ConjureTypeParserVisitor.ReferenceTypeResolver)2 ConjureRuntimeException (com.palantir.conjure.exceptions.ConjureRuntimeException)2 AnnotatedConjureSourceFile (com.palantir.conjure.parser.AnnotatedConjureSourceFile)2 ConjureSourceFile (com.palantir.conjure.parser.ConjureSourceFile)2 ErrorNamespace (com.palantir.conjure.spec.ErrorNamespace)2 FieldDefinition (com.palantir.conjure.spec.FieldDefinition)2 ServiceDefinition (com.palantir.conjure.spec.ServiceDefinition)2 DealiasingTypeVisitor (com.palantir.conjure.visitor.DealiasingTypeVisitor)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Map (java.util.Map)2 CaseFormat (com.google.common.base.CaseFormat)1 Streams (com.google.common.collect.Streams)1 ConjureAnnotations (com.palantir.conjure.java.ConjureAnnotations)1