Skip to content
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 @@ -10,6 +10,7 @@
import jakarta.ws.rs.ext.Provider;

import io.github.belgif.rest.problem.api.InEnum;
import io.github.belgif.rest.problem.api.InputValidationIssue;
import io.github.belgif.rest.problem.ee.server.jaxrs.AbstractInputParamConverterProvider;

@Provider
Expand All @@ -31,7 +32,9 @@ protected LocalDate fromString(InEnum in, String name, String value) {
try {
return LocalDate.parse(value, LOCAL_DATE_FORMATTER);
} catch (DateTimeParseException e) {
throw new BadRequestProblem(schemaViolation(in, name, value, "date has invalid format"));
throw new BadRequestProblem(
schemaViolation(in, InputValidationIssue.transformName(in, name), value,
"date has invalid format"));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import javax.ws.rs.ext.Provider;

import io.github.belgif.rest.problem.api.InEnum;
import io.github.belgif.rest.problem.api.InputValidationIssue;
import io.github.belgif.rest.problem.ee.server.jaxrs.AbstractInputParamConverterProvider;

@Provider
Expand All @@ -31,7 +32,9 @@ protected LocalDate fromString(InEnum in, String name, String value) {
try {
return LocalDate.parse(value, LOCAL_DATE_FORMATTER);
} catch (DateTimeParseException e) {
throw new BadRequestProblem(schemaViolation(in, name, value, "date has invalid format"));
throw new BadRequestProblem(
schemaViolation(in, InputValidationIssue.transformName(in, name), value,
"date has invalid format"));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import io.github.belgif.rest.problem.BadRequestProblem;
import io.github.belgif.rest.problem.api.InEnum;
import io.github.belgif.rest.problem.api.InputValidationIssue;
import io.github.belgif.rest.problem.ee.server.jaxrs.AbstractInputParamConverterProvider;

@Provider
Expand All @@ -32,7 +33,9 @@ protected LocalDate fromString(InEnum in, String name, String value) {
try {
return LocalDate.parse(value, LOCAL_DATE_FORMATTER);
} catch (DateTimeParseException e) {
throw new BadRequestProblem(schemaViolation(in, name, value, "date has invalid format"));
throw new BadRequestProblem(
schemaViolation(in, InputValidationIssue.transformName(in, name), value,
"date has invalid format"));
}
}

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
Loading
Loading