Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -5,6 +5,7 @@
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
Expand Down Expand Up @@ -81,7 +82,8 @@ public ValidationAnnotationScanner(IndexView indexView) {

private ResourceBundle loadValidationMessages() {
try {
return ResourceBundle.getBundle("org.hibernate.validator.ValidationMessages");
// Always use the English base bundle, so the generated OpenAPI document does not depend on the locale of the build machine
return ResourceBundle.getBundle("org.hibernate.validator.ValidationMessages", Locale.ROOT);
} catch (MissingResourceException e) {
log.warn("Could not load ValidationMessages resource bundle", e);
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.io.InputStream;
import java.math.BigDecimal;
import java.util.LinkedHashSet;
import java.util.Locale;
import java.util.Map;
import java.util.Set;

Expand Down Expand Up @@ -184,6 +185,21 @@ public void buildDescription_notBlankConstraint() {
assertTrue(description.contains("must not be blank"));
}

@Test
public void buildDescription_isEnglishRegardlessOfDefaultLocale() {
Locale defaultLocale = Locale.getDefault();
try {
Locale.setDefault(Locale.GERMANY);
ValidationAnnotationScanner germanScanner = new ValidationAnnotationScanner(index);
ClassInfo classInfo = index.getClassByName(TestRepresentation.class);

assertTrue(germanScanner.buildDescription(classInfo, "notBlankField").contains("must not be blank"));
assertTrue(germanScanner.buildDescription(classInfo, "sizedString").contains("size must be between 5 and 100"));
} finally {
Locale.setDefault(defaultLocale);
}
}

@Test
public void buildDescription_jakartaConstraintWhenConstraintTypeNotIndexed() throws IOException {
// Mirrors OpenAPI generation: scanPackages often excludes jakarta.validation from the Jandex index
Expand Down
Loading