Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
71dd75a
Use JsonPointer syntax
usku01 Jun 17, 2026
ba7e78a
Merge branch 'main' into feature/#344-use-json-pointer-syntax
usku01 Jun 17, 2026
279287b
Use JsonPointer syntax part 2
usku01 Jun 19, 2026
1ac1c9c
fix pattern for backtracking issue
usku01 Jun 19, 2026
27952fe
also allow hyphens (for headers)
usku01 Jun 19, 2026
091aac2
fix method call
usku01 Jun 19, 2026
be6d5ba
some refactoring
usku01 Jun 22, 2026
18d37f0
allow dots in name
usku01 Jun 23, 2026
9398157
Use jsonPointer only for body
usku01 Jun 23, 2026
0384049
Merge branch 'main' into feature/#344-use-json-pointer-syntax
usku01 Jun 23, 2026
ca900f4
Add auto-conversion for name of issue + add warning when applied
usku01 Jun 26, 2026
ff348d5
Merge branch 'main' into feature/#344-use-json-pointer-syntax
usku01 Jun 26, 2026
36485a2
Merge branch 'main' into feature/#344-use-json-pointer-syntax
jpraet Jul 28, 2026
1153871
Extract JsonPointerUtil class
jpraet Jul 29, 2026
842bcbb
Move JSON Pointer auto-conversion back to InputValidationIssue class
jpraet Jul 29, 2026
4197aa3
Remove check which prevented JSON Pointer with top-level or nested array
jpraet Jul 29, 2026
e7bfbfa
Remove obsolete setName call
jpraet Jul 29, 2026
f3f3610
Update documentation
jpraet Jul 29, 2026
056a9cd
Use a precompiled cached pattern for array index regex
jpraet Jul 30, 2026
337124e
review remarks
usku01 Jul 30, 2026
154c47e
Merge branch 'main' into feature/#344-use-json-pointer-syntax
jpraet Aug 7, 2026
341b74f
Handle some review comments
jpraet Aug 7, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ void retryAfterProblem() throws IOException {
@Test
void badRequestProblemReplacedSsin() throws IOException {
BadRequestProblem problem = new BadRequestProblem(
InputValidationIssues.replacedSsin(InEnum.BODY, "parent[1].ssin", "12345678901", "23456789012"));
InputValidationIssues.replacedSsin(InEnum.BODY, "/parent/1/ssin", "12345678901", "23456789012"));
assertSerializationRoundtrip(problem);
}

Expand Down Expand Up @@ -182,7 +182,7 @@ void legacyInvalidParamProblem() throws IOException {
+ " \"detail\": \"The input message is incorrect\",\n"
+ " \"invalidParams\": [ {\n"
+ " \"in\": \"body\",\n"
+ " \"name\": \"sector\",\n"
+ " \"name\": \"/sector\",\n"
+ " \"reason\": \"must be less than or equal to 999\",\n"
+ " \"value\": 9999,\n"
+ " \"issueType\": \"schemaViolation\"\n"
Expand Down Expand Up @@ -239,7 +239,7 @@ void issueWithStatusAndInstance() throws IOException {
@Test
void issueWithNullValue() throws IOException {
BadRequestProblem problem = new BadRequestProblem(
new InputValidationIssue(InEnum.BODY, "id", null));
new InputValidationIssue(InEnum.BODY, "/id", null));
String json = writeProblem(problem);
assertThat(json).doesNotContain("null");
assertSerializationRoundtrip(problem);
Expand All @@ -249,7 +249,7 @@ void issueWithNullValue() throws IOException {
void issueWithNullInputValue() throws IOException {
ProblemConfig.setExtInputsArrayEnabled(true);
BadRequestProblem problem = new BadRequestProblem(new InputValidationIssue()
.inputs(Input.body("a", null), Input.body("b", null)));
.inputs(Input.body("/a", null), Input.body("/b", null)));
String json = writeProblem(problem);
assertThat(json).doesNotContain("null");
assertSerializationRoundtrip(problem);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -332,11 +332,11 @@ public void constraintViolationBody() {
.statusCode(400)
.body("type", equalTo("urn:problem-type:belgif:badRequest"))
.body("issues[0].in", equalTo("body"))
.body("issues[0].name", equalTo("email"))
.body("issues[0].name", equalTo("/email"))
.body("issues[0].value", equalTo("mymail.com"))
.body("issues[0].detail", equalTo("must be a well-formed email address"))
.body("issues[1].in", equalTo("body"))
.body("issues[1].name", equalTo("name"))
.body("issues[1].name", equalTo("/name"))
.body("issues[1].value", nullValue())
.body("issues[1].detail", equalTo("must not be blank"));
}
Expand All @@ -352,11 +352,11 @@ public void constraintViolationBodyNested() {
.statusCode(400)
.body("type", equalTo("urn:problem-type:belgif:badRequest"))
.body("issues[0].in", equalTo("body"))
.body("issues[0].name", equalTo("nested.email"))
.body("issues[0].name", equalTo("/nested/email"))
.body("issues[0].value", equalTo("mymail.com"))
.body("issues[0].detail", equalTo("must be a well-formed email address"))
.body("issues[1].in", equalTo("body"))
.body("issues[1].name", equalTo("nested.name"))
.body("issues[1].name", equalTo("/nested/name"))
.body("issues[1].value", nullValue())
.body("issues[1].detail", equalTo("must not be blank"));
}
Expand All @@ -372,11 +372,11 @@ public void constraintViolationBodyInheritance() {
.statusCode(400)
.body("type", equalTo("urn:problem-type:belgif:badRequest"))
.body("issues[0].in", equalTo("body"))
.body("issues[0].name", equalTo("email"))
.body("issues[0].name", equalTo("/email"))
.body("issues[0].value", equalTo("mymail.com"))
.body("issues[0].detail", equalTo("must be a well-formed email address"))
.body("issues[1].in", equalTo("body"))
.body("issues[1].name", equalTo("name"))
.body("issues[1].name", equalTo("/name"))
.body("issues[1].value", nullValue())
.body("issues[1].detail", equalTo("must not be blank"));
}
Expand All @@ -389,7 +389,7 @@ public void jacksonMismatchedInputException() {
.statusCode(400)
.body("type", equalTo("urn:problem-type:belgif:badRequest"))
.body("issues[0].in", equalTo("body"))
.body("issues[0].name", equalTo("id"))
.body("issues[0].name", equalTo("/id"))
.body("issues[0].detail", equalTo("must not be null"));
}

Expand Down Expand Up @@ -542,7 +542,7 @@ public void invalidJsonNested() {
.body("issues[0].title", equalTo("Input value is invalid with respect to the schema"))
.body("issues[0].detail", equalTo("JSON syntax error"))
.body("issues[0].in", equalTo("body"))
.body("issues[0].name", equalTo("nested"));
.body("issues[0].name", equalTo("/nested"));
}

@Test
Expand All @@ -558,7 +558,7 @@ public void invalidJsonType() {
.body("issues[0].title", equalTo("Input value is invalid with respect to the schema"))
.body("issues[0].detail", equalTo("not a valid `int` value"))
.body("issues[0].in", equalTo("body"))
.body("issues[0].name", equalTo("age"))
.body("issues[0].name", equalTo("/age"))
.body("issues[0].value", equalTo("twenty-two"));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@
<version>2.17.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>2.0.18</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@
<version>${version.jackson.minimal}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>2.0.18</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@
<version>${version.jackson3.minimal}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>2.0.18</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public void contextInitialized(ServletContextEvent sce) {
setBooleanConfig(sce, ProblemConfig.PROPERTY_STACK_TRACE_ENABLED, ProblemConfig::setStackTraceEnabled);
setBooleanConfig(sce, ProblemConfig.PROPERTY_EXT_ISSUE_TYPES_ENABLED, ProblemConfig::setExtIssueTypesEnabled);
setBooleanConfig(sce, ProblemConfig.PROPERTY_EXT_INPUTS_ARRAY_ENABLED, ProblemConfig::setExtInputsArrayEnabled);
setBooleanConfig(sce, ProblemConfig.PROPERTY_JSON_POINTER_ENABLED, ProblemConfig::setJsonPointerEnabled);
}

private void setBooleanConfig(ServletContextEvent sce, String key, Consumer<Boolean> configSetter) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,18 @@ void notConfigured() {
boolean stackTraceEnabledBefore = ProblemConfig.isStackTraceEnabled();
boolean extIssueTypesEnabledBefore = ProblemConfig.isExtIssueTypesEnabled();
boolean extInputsArrayEnabledBefore = ProblemConfig.isExtInputsArrayEnabled();
boolean jsonPointerEnabledBefore = ProblemConfig.isJsonPointerEnabled();
when(servletContext.getInitParameter(ProblemConfig.PROPERTY_I18N_ENABLED)).thenReturn(null);
when(servletContext.getInitParameter(ProblemConfig.PROPERTY_STACK_TRACE_ENABLED)).thenReturn(null);
when(servletContext.getInitParameter(ProblemConfig.PROPERTY_EXT_ISSUE_TYPES_ENABLED)).thenReturn(null);
when(servletContext.getInitParameter(ProblemConfig.PROPERTY_EXT_INPUTS_ARRAY_ENABLED)).thenReturn(null);
when(servletContext.getInitParameter(ProblemConfig.PROPERTY_JSON_POINTER_ENABLED)).thenReturn(null);
configurator.contextInitialized(new ServletContextEvent(servletContext));
assertThat(ProblemConfig.isI18nEnabled()).isEqualTo(i18nEnabledBefore);
assertThat(ProblemConfig.isStackTraceEnabled()).isEqualTo(stackTraceEnabledBefore);
assertThat(ProblemConfig.isExtIssueTypesEnabled()).isEqualTo(extIssueTypesEnabledBefore);
assertThat(ProblemConfig.isExtInputsArrayEnabled()).isEqualTo(extInputsArrayEnabledBefore);
assertThat(ProblemConfig.isJsonPointerEnabled()).isEqualTo(jsonPointerEnabledBefore);
}

@Test
Expand All @@ -54,11 +57,13 @@ void enabledViaInitParam() {
when(servletContext.getInitParameter(ProblemConfig.PROPERTY_STACK_TRACE_ENABLED)).thenReturn("true");
when(servletContext.getInitParameter(ProblemConfig.PROPERTY_EXT_ISSUE_TYPES_ENABLED)).thenReturn("true");
when(servletContext.getInitParameter(ProblemConfig.PROPERTY_EXT_INPUTS_ARRAY_ENABLED)).thenReturn("true");
when(servletContext.getInitParameter(ProblemConfig.PROPERTY_JSON_POINTER_ENABLED)).thenReturn("true");
configurator.contextInitialized(new ServletContextEvent(servletContext));
assertThat(ProblemConfig.isI18nEnabled()).isTrue();
assertThat(ProblemConfig.isStackTraceEnabled()).isTrue();
assertThat(ProblemConfig.isExtIssueTypesEnabled()).isTrue();
assertThat(ProblemConfig.isExtInputsArrayEnabled()).isTrue();
assertThat(ProblemConfig.isJsonPointerEnabled()).isTrue();
}

@Test
Expand All @@ -67,24 +72,28 @@ void disabledViaInitParam() {
when(servletContext.getInitParameter(ProblemConfig.PROPERTY_STACK_TRACE_ENABLED)).thenReturn("false");
when(servletContext.getInitParameter(ProblemConfig.PROPERTY_EXT_ISSUE_TYPES_ENABLED)).thenReturn("false");
when(servletContext.getInitParameter(ProblemConfig.PROPERTY_EXT_INPUTS_ARRAY_ENABLED)).thenReturn("false");
when(servletContext.getInitParameter(ProblemConfig.PROPERTY_JSON_POINTER_ENABLED)).thenReturn("false");
configurator.contextInitialized(new ServletContextEvent(servletContext));
assertThat(ProblemConfig.isI18nEnabled()).isFalse();
assertThat(ProblemConfig.isStackTraceEnabled()).isFalse();
assertThat(ProblemConfig.isExtIssueTypesEnabled()).isFalse();
assertThat(ProblemConfig.isExtInputsArrayEnabled()).isFalse();
assertThat(ProblemConfig.isJsonPointerEnabled()).isFalse();
}

@Test
@SetSystemProperty(key = ProblemConfig.PROPERTY_I18N_ENABLED, value = "true")
@SetSystemProperty(key = ProblemConfig.PROPERTY_STACK_TRACE_ENABLED, value = "true")
@SetSystemProperty(key = ProblemConfig.PROPERTY_EXT_ISSUE_TYPES_ENABLED, value = "true")
@SetSystemProperty(key = ProblemConfig.PROPERTY_EXT_INPUTS_ARRAY_ENABLED, value = "true")
@SetSystemProperty(key = ProblemConfig.PROPERTY_JSON_POINTER_ENABLED, value = "true")
void enabledViaSystemProperties() {
configurator.contextInitialized(new ServletContextEvent(servletContext));
assertThat(ProblemConfig.isI18nEnabled()).isTrue();
assertThat(ProblemConfig.isStackTraceEnabled()).isTrue();
assertThat(ProblemConfig.isExtIssueTypesEnabled()).isTrue();
assertThat(ProblemConfig.isExtInputsArrayEnabled()).isTrue();
assertThat(ProblemConfig.isJsonPointerEnabled()).isTrue();
verifyNoInteractions(servletContext);
}

Expand All @@ -93,12 +102,14 @@ void enabledViaSystemProperties() {
@SetSystemProperty(key = ProblemConfig.PROPERTY_STACK_TRACE_ENABLED, value = "false")
@SetSystemProperty(key = ProblemConfig.PROPERTY_EXT_ISSUE_TYPES_ENABLED, value = "false")
@SetSystemProperty(key = ProblemConfig.PROPERTY_EXT_INPUTS_ARRAY_ENABLED, value = "false")
@SetSystemProperty(key = ProblemConfig.PROPERTY_JSON_POINTER_ENABLED, value = "false")
void disabledViaSystemProperty() {
configurator.contextInitialized(new ServletContextEvent(servletContext));
assertThat(ProblemConfig.isI18nEnabled()).isFalse();
assertThat(ProblemConfig.isStackTraceEnabled()).isFalse();
assertThat(ProblemConfig.isExtIssueTypesEnabled()).isFalse();
assertThat(ProblemConfig.isExtInputsArrayEnabled()).isFalse();
assertThat(ProblemConfig.isJsonPointerEnabled()).isFalse();
verifyNoInteractions(servletContext);
}

Expand All @@ -107,12 +118,14 @@ void disabledViaSystemProperty() {
@SetEnvironmentVariable(key = ProblemConfig.PROPERTY_STACK_TRACE_ENABLED, value = "true")
@SetEnvironmentVariable(key = ProblemConfig.PROPERTY_EXT_ISSUE_TYPES_ENABLED, value = "true")
@SetEnvironmentVariable(key = ProblemConfig.PROPERTY_EXT_INPUTS_ARRAY_ENABLED, value = "true")
@SetEnvironmentVariable(key = ProblemConfig.PROPERTY_JSON_POINTER_ENABLED, value = "true")
void enabledViaEnvironmentVariable() {
configurator.contextInitialized(new ServletContextEvent(servletContext));
assertThat(ProblemConfig.isI18nEnabled()).isTrue();
assertThat(ProblemConfig.isStackTraceEnabled()).isTrue();
assertThat(ProblemConfig.isExtIssueTypesEnabled()).isTrue();
assertThat(ProblemConfig.isExtInputsArrayEnabled()).isTrue();
assertThat(ProblemConfig.isJsonPointerEnabled()).isTrue();
verifyNoInteractions(servletContext);
}

Expand All @@ -121,12 +134,14 @@ void enabledViaEnvironmentVariable() {
@SetEnvironmentVariable(key = ProblemConfig.PROPERTY_STACK_TRACE_ENABLED, value = "false")
@SetEnvironmentVariable(key = ProblemConfig.PROPERTY_EXT_ISSUE_TYPES_ENABLED, value = "false")
@SetEnvironmentVariable(key = ProblemConfig.PROPERTY_EXT_INPUTS_ARRAY_ENABLED, value = "false")
@SetEnvironmentVariable(key = ProblemConfig.PROPERTY_JSON_POINTER_ENABLED, value = "false")
void disabledViaEnvironmentVariable() {
configurator.contextInitialized(new ServletContextEvent(servletContext));
assertThat(ProblemConfig.isI18nEnabled()).isFalse();
assertThat(ProblemConfig.isStackTraceEnabled()).isFalse();
assertThat(ProblemConfig.isExtIssueTypesEnabled()).isFalse();
assertThat(ProblemConfig.isExtInputsArrayEnabled()).isFalse();
assertThat(ProblemConfig.isJsonPointerEnabled()).isFalse();
verifyNoInteractions(servletContext);
}

Expand All @@ -135,16 +150,19 @@ void disabledViaEnvironmentVariable() {
@SetEnvironmentVariable(key = ProblemConfig.PROPERTY_STACK_TRACE_ENABLED, value = "false")
@SetEnvironmentVariable(key = ProblemConfig.PROPERTY_EXT_ISSUE_TYPES_ENABLED, value = "false")
@SetEnvironmentVariable(key = ProblemConfig.PROPERTY_EXT_INPUTS_ARRAY_ENABLED, value = "false")
@SetEnvironmentVariable(key = ProblemConfig.PROPERTY_JSON_POINTER_ENABLED, value = "false")
@SetSystemProperty(key = ProblemConfig.PROPERTY_I18N_ENABLED, value = "true")
@SetSystemProperty(key = ProblemConfig.PROPERTY_STACK_TRACE_ENABLED, value = "true")
@SetSystemProperty(key = ProblemConfig.PROPERTY_EXT_ISSUE_TYPES_ENABLED, value = "true")
@SetSystemProperty(key = ProblemConfig.PROPERTY_EXT_INPUTS_ARRAY_ENABLED, value = "true")
@SetSystemProperty(key = ProblemConfig.PROPERTY_JSON_POINTER_ENABLED, value = "true")
void systemPropertyHasPrecedenceOverEnvironmentVariable() {
configurator.contextInitialized(new ServletContextEvent(servletContext));
assertThat(ProblemConfig.isI18nEnabled()).isTrue();
assertThat(ProblemConfig.isStackTraceEnabled()).isTrue();
assertThat(ProblemConfig.isExtIssueTypesEnabled()).isTrue();
assertThat(ProblemConfig.isExtInputsArrayEnabled()).isTrue();
assertThat(ProblemConfig.isJsonPointerEnabled()).isTrue();
verifyNoInteractions(servletContext);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import io.github.belgif.rest.problem.api.InputValidationIssue;
import io.github.belgif.rest.problem.api.InputValidationIssues;
import io.github.belgif.rest.problem.internal.AnnotationUtil;
import io.github.belgif.rest.problem.internal.JsonPointerUtil;

/**
* Internal utility class for converting ConstraintViolation to InputValidationIssue.
Expand Down Expand Up @@ -101,6 +102,9 @@ private static Input<Object> determineInput(ConstraintViolation<?> violation,
}
}
}

input.setName(JsonPointerUtil.transformName(input.getIn(), input.getName()));

return input;
}

Expand Down
Loading
Loading