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