mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
refactor(common): share map value constraint messages (#9242)
Adds Violations.mapValues beside mapKeys and builds the map value constraint messages of AgentCore, SES v2, Firehose and Lambda with it. The Bedrock tag rules drop the unreachable null branch, and AgentCore keeps its null-key error at its own boundary. The messages are unchanged. Closes #9241
This commit is contained in:
1 parent
806b822576
commit
bf68a01fc2
8 files changed
+68
-26
No files matched your search
@@ -21,24 +21,12 @@ public final class BedrockTagKeyValueRules {
|
||||
}
|
||||
|
||||
public static String keyViolation(String key) {
|
||||
return stringViolation("tags.key", "Map keys", key, 1, KEY_MAX);
|
||||
return validKey(key) ? null : SmithyValidationErrors.Violations.WITHOUT_VALUES.mapKeys("tags", key,
|
||||
SmithyValidationErrors.constraintSet(1, KEY_MAX, TAG_PATTERN.pattern(), null));
|
||||
}
|
||||
|
||||
public static String valueViolation(String value) {
|
||||
return stringViolation("tags.value", "Map value", value, 0, VALUE_MAX);
|
||||
}
|
||||
|
||||
private static String stringViolation(String path, String mapConstraint, String value,
|
||||
int minLength, int maxLength) {
|
||||
if (value == null) {
|
||||
return SmithyValidationErrors.notNull(path);
|
||||
}
|
||||
if (SmithyValidationErrors.lengthOutOfRange(path, value, minLength, maxLength) == null
|
||||
&& TAG_PATTERN.matcher(value).matches()) {
|
||||
return null;
|
||||
}
|
||||
return SmithyValidationErrors.Violations.WITHOUT_VALUES.constraint("tags", value,
|
||||
mapConstraint + " must satisfy constraint: "
|
||||
+ SmithyValidationErrors.constraintSet(minLength, maxLength, TAG_PATTERN.pattern(), null));
|
||||
return validValue(value) ? null : SmithyValidationErrors.Violations.WITHOUT_VALUES.mapValues("tags", value,
|
||||
SmithyValidationErrors.constraintSet(0, VALUE_MAX, TAG_PATTERN.pattern(), null));
|
||||
}
|
||||
}
|
||||
@@ -267,6 +267,10 @@ public final class SmithyValidationErrors {
|
||||
return constraint(path, value, "Map keys must satisfy constraint: " + rules);
|
||||
}
|
||||
|
||||
public String mapValues(String path, String value, List<String> rules) {
|
||||
return constraint(path, value, "Map value must satisfy constraint: " + rules);
|
||||
}
|
||||
|
||||
/** The violation for a value outside its enum, the values in the model's order. */
|
||||
public String notInEnum(String value, String path, List<String> allowed) {
|
||||
return constraint(path, value, "Member must satisfy enum value set: " + allowed);
|
||||
|
||||
+3
@@ -53,6 +53,9 @@ final class BedrockAgentCoreTagValidation {
|
||||
}
|
||||
|
||||
private static void validateKey(String key) {
|
||||
if (key == null) {
|
||||
throw SmithyValidationErrors.validationException(SmithyValidationErrors.notNull("tags.key"));
|
||||
}
|
||||
String violation = BedrockTagKeyValueRules.keyViolation(key);
|
||||
if (violation != null) {
|
||||
throw SmithyValidationErrors.validationException(violation);
|
||||
|
||||
@@ -232,8 +232,8 @@ public final class S3DestinationValidator {
|
||||
"Map keys must satisfy constraint: " + constraintSet(NO_WHITESPACE_PATTERN)));
|
||||
}
|
||||
if (valueViolation) {
|
||||
violations.add(violation(shapeName, member,
|
||||
"Map value must satisfy constraint: " + constraintSet(NOT_BLANK_PATTERN)));
|
||||
violations.add(SmithyValidationErrors.Violations.WITHOUT_VALUES.mapValues(shapeName + "." + member,
|
||||
null, SmithyValidationErrors.constraintSet(1, MAPPING_MAX_LENGTH, NOT_BLANK_PATTERN, null)));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -99,9 +99,9 @@ final class LambdaWebValidation {
|
||||
boolean bad = map.values().stream()
|
||||
.anyMatch(v -> v == null || v.length() < min || v.length() > max || !pattern.matcher(v).matches());
|
||||
if (bad) {
|
||||
errors.add(valueAt(map, path) + "Map value must satisfy constraint: ["
|
||||
+ lengthConstraints(min, max) + ", Member must satisfy regular expression pattern: "
|
||||
+ pattern.pattern() + "]");
|
||||
errors.add(SmithyValidationErrors.Violations.QUOTED.mapValues(path, map.toString(),
|
||||
List.of(lengthConstraints(min, max),
|
||||
"Member must satisfy regular expression pattern: " + pattern.pattern())));
|
||||
}
|
||||
return this;
|
||||
}
|
||||
@@ -120,8 +120,8 @@ final class LambdaWebValidation {
|
||||
LambdaWebValidation sensitiveMapValues(String path, Map<String, String> map, int min) {
|
||||
boolean bad = map.values().stream().anyMatch(v -> v.length() < min);
|
||||
if (bad) {
|
||||
errors.add("Value at '" + path + "' failed to satisfy constraint: Map value must satisfy constraint: ["
|
||||
+ "Member must have length greater than or equal to " + min + "]");
|
||||
errors.add(SmithyValidationErrors.Violations.WITHOUT_VALUES.mapValues(path, null,
|
||||
List.of("Member must have length greater than or equal to " + min)));
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -240,9 +240,8 @@ final class SesV2Json {
|
||||
+ "[Member must satisfy enum value set: [" + String.join(", ", keys) + "]]");
|
||||
}
|
||||
if (filter.values().stream().anyMatch(v -> v != null && invalidValue.test(v))) {
|
||||
throw SmithyValidationErrors.badRequest( "Value at 'filter' "
|
||||
+ "failed to satisfy constraint: Map value must satisfy constraint: "
|
||||
+ "[" + valueConstraint + "]");
|
||||
throw SmithyValidationErrors.badRequest(SmithyValidationErrors.Violations.WITHOUT_VALUES
|
||||
.mapValues("filter", null, List.of(valueConstraint)));
|
||||
}
|
||||
Map<String, String> values = new LinkedHashMap<>();
|
||||
filter.forEach((key, value) -> {
|
||||
|
||||
Reference in new issue
Block a user