diff --git a/src/main/java/io/stargate/sgv2/jsonapi/exception/ErrorCode.java b/src/main/java/io/stargate/sgv2/jsonapi/exception/ErrorCode.java index d2a0cab5da..e637c8acf7 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/exception/ErrorCode.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/exception/ErrorCode.java @@ -79,7 +79,7 @@ public enum ErrorCode { SHRED_DOC_LIMIT_VIOLATION("Document size limitation violated"), - SHRED_DOC_KEY_NAME_VIOLATION("Document key name constraints violated"), + SHRED_DOC_KEY_NAME_VIOLATION("Document field name invalid"), SHRED_BAD_EJSON_VALUE("Bad JSON Extension value"), diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/shredding/Shredder.java b/src/main/java/io/stargate/sgv2/jsonapi/service/shredding/Shredder.java index 3307025ed4..5812b516f4 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/shredding/Shredder.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/shredding/Shredder.java @@ -389,7 +389,8 @@ private void validateObjectKey(String key, JsonNode value, int depth, int parent ; } else { throw ErrorCode.SHRED_DOC_KEY_NAME_VIOLATION.toApiException( - "property name ('%s') contains character(s) not allowed", key); + "field name ('%s') contains invalid character(s), can contain only letters (a-z/A-Z), numbers (0-9), underscores (_), and hyphens (-)", + key); } } int totalPathLength = parentPathLength + key.length(); diff --git a/src/test/java/io/stargate/sgv2/jsonapi/service/shredding/ShredderDocLimitsTest.java b/src/test/java/io/stargate/sgv2/jsonapi/service/shredding/ShredderDocLimitsTest.java index 64efeca047..4bb88c8978 100644 --- a/src/test/java/io/stargate/sgv2/jsonapi/service/shredding/ShredderDocLimitsTest.java +++ b/src/test/java/io/stargate/sgv2/jsonapi/service/shredding/ShredderDocLimitsTest.java @@ -423,7 +423,7 @@ public void catchEmptyPropertyName() { .isInstanceOf(JsonApiException.class) .hasFieldOrPropertyWithValue("errorCode", ErrorCode.SHRED_DOC_KEY_NAME_VIOLATION) .hasMessageStartingWith(ErrorCode.SHRED_DOC_KEY_NAME_VIOLATION.getMessage()) - .hasMessageEndingWith("Document key name constraints violated: empty names not allowed"); + .hasMessageEndingWith("empty names not allowed"); } @ParameterizedTest @@ -440,9 +440,9 @@ public void catchInvalidPropertyName(String invalidName) { .hasFieldOrPropertyWithValue("errorCode", ErrorCode.SHRED_DOC_KEY_NAME_VIOLATION) .hasMessageStartingWith(ErrorCode.SHRED_DOC_KEY_NAME_VIOLATION.getMessage()) .hasMessageEndingWith( - "Document key name constraints violated: property name ('" + "field name ('" + invalidName - + "') contains character(s) not allowed"); + + "') contains invalid character(s), can contain only letters (a-z/A-Z), numbers (0-9), underscores (_), and hyphens (-)"); } } diff --git a/src/test/java/io/stargate/sgv2/jsonapi/service/shredding/ShredderTest.java b/src/test/java/io/stargate/sgv2/jsonapi/service/shredding/ShredderTest.java index 06b96cfad5..7a51956de7 100644 --- a/src/test/java/io/stargate/sgv2/jsonapi/service/shredding/ShredderTest.java +++ b/src/test/java/io/stargate/sgv2/jsonapi/service/shredding/ShredderTest.java @@ -303,7 +303,7 @@ public void badEJSONUnrecognized() { assertThat(t) .isNotNull() - .hasMessageStartingWith("Document key name constraints violated") + .hasMessageStartingWith(ErrorCode.SHRED_DOC_KEY_NAME_VIOLATION.getMessage()) .hasFieldOrPropertyWithValue("errorCode", ErrorCode.SHRED_DOC_KEY_NAME_VIOLATION); } } diff --git a/src/test/java/io/stargate/sgv2/jsonapi/service/shredding/ShredderWithExtendedTypesTest.java b/src/test/java/io/stargate/sgv2/jsonapi/service/shredding/ShredderWithExtendedTypesTest.java index 69608e34b8..77643f386d 100644 --- a/src/test/java/io/stargate/sgv2/jsonapi/service/shredding/ShredderWithExtendedTypesTest.java +++ b/src/test/java/io/stargate/sgv2/jsonapi/service/shredding/ShredderWithExtendedTypesTest.java @@ -441,9 +441,7 @@ public void docUnknownEJsonAsValue() { assertThat(t) .isNotNull() .hasFieldOrPropertyWithValue("errorCode", ErrorCode.SHRED_DOC_KEY_NAME_VIOLATION) - .hasMessageStartingWith( - ErrorCode.SHRED_DOC_KEY_NAME_VIOLATION.getMessage() - + ": property name ('$unknownType') contains character(s) not allowed"); + .hasMessageStartingWith(ErrorCode.SHRED_DOC_KEY_NAME_VIOLATION.getMessage()); } }