diff --git a/CHANGELOG.md b/CHANGELOG.md
index b1109967..5ca02817 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -5,8 +5,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [Unreleased]
-
--
+### `jsonschema-module-jakarta-validation`
+#### Added
+- populate `const`/`enum` based on `@AssertTrue`/`@AssertFalse`
## [4.35.0] - 2024-03-29
### `jsonschema-generator`
diff --git a/jsonschema-examples/pom.xml b/jsonschema-examples/pom.xml
index 530a3502..bc6e9f93 100644
--- a/jsonschema-examples/pom.xml
+++ b/jsonschema-examples/pom.xml
@@ -5,7 +5,7 @@
com.github.victools
jsonschema-generator-parent
- 4.35.1-SNAPSHOT
+ 4.36.0-SNAPSHOT
../jsonschema-generator-parent/pom.xml
jsonschema-examples
diff --git a/jsonschema-generator-bom/pom.xml b/jsonschema-generator-bom/pom.xml
index 312137c8..3b616ece 100644
--- a/jsonschema-generator-bom/pom.xml
+++ b/jsonschema-generator-bom/pom.xml
@@ -8,7 +8,7 @@
com.github.victools
jsonschema-generator-bom
- 4.35.1-SNAPSHOT
+ 4.36.0-SNAPSHOT
pom
diff --git a/jsonschema-generator-parent/pom.xml b/jsonschema-generator-parent/pom.xml
index 8c54ccde..3340bbdf 100644
--- a/jsonschema-generator-parent/pom.xml
+++ b/jsonschema-generator-parent/pom.xml
@@ -4,14 +4,14 @@
com.github.victools
jsonschema-generator-bom
- 4.35.1-SNAPSHOT
+ 4.36.0-SNAPSHOT
../jsonschema-generator-bom/pom.xml
jsonschema-generator-parent
pom
Java JSON Schema Generator (Parent)
- Java JSON Schema Generator + Modules – creating a JSON Schema from your Java classes
+ Java JSON Schema Generator + Modules - creating a JSON Schema from your Java classes
https://github.com/victools/jsonschema-generator
@@ -126,6 +126,7 @@
https://github.com/Nephery
Provided PR #435 (fixing Jackson JsonUnwrapped annotation on inherited properties)
+ Provided PR #456 (introducing support for Jakarta @AssertTrue/@AssertFalse)
diff --git a/jsonschema-generator/pom.xml b/jsonschema-generator/pom.xml
index a98f98b6..82d33498 100644
--- a/jsonschema-generator/pom.xml
+++ b/jsonschema-generator/pom.xml
@@ -5,7 +5,7 @@
com.github.victools
jsonschema-generator-parent
- 4.35.1-SNAPSHOT
+ 4.36.0-SNAPSHOT
../jsonschema-generator-parent/pom.xml
jsonschema-generator
diff --git a/jsonschema-generator/src/main/java/com/github/victools/jsonschema/generator/impl/AttributeCollector.java b/jsonschema-generator/src/main/java/com/github/victools/jsonschema/generator/impl/AttributeCollector.java
index 5f093774..22a8e803 100644
--- a/jsonschema-generator/src/main/java/com/github/victools/jsonschema/generator/impl/AttributeCollector.java
+++ b/jsonschema-generator/src/main/java/com/github/victools/jsonschema/generator/impl/AttributeCollector.java
@@ -435,6 +435,7 @@ private boolean isSupportedEnumValue(Object target) {
}
Class> targetType = target.getClass();
return targetType.isPrimitive()
+ || Boolean.class.isAssignableFrom(targetType)
|| Number.class.isAssignableFrom(targetType)
|| CharSequence.class.isAssignableFrom(targetType)
|| Enum.class.isAssignableFrom(targetType);
diff --git a/jsonschema-maven-plugin/pom.xml b/jsonschema-maven-plugin/pom.xml
index 5e2bb0e9..69f5eef1 100644
--- a/jsonschema-maven-plugin/pom.xml
+++ b/jsonschema-maven-plugin/pom.xml
@@ -6,7 +6,7 @@
com.github.victools
jsonschema-generator-parent
- 4.35.1-SNAPSHOT
+ 4.36.0-SNAPSHOT
../jsonschema-generator-parent/pom.xml
jsonschema-maven-plugin
diff --git a/jsonschema-module-jackson/pom.xml b/jsonschema-module-jackson/pom.xml
index 73952c73..861836d8 100644
--- a/jsonschema-module-jackson/pom.xml
+++ b/jsonschema-module-jackson/pom.xml
@@ -5,7 +5,7 @@
com.github.victools
jsonschema-generator-parent
- 4.35.1-SNAPSHOT
+ 4.36.0-SNAPSHOT
../jsonschema-generator-parent/pom.xml
jsonschema-module-jackson
diff --git a/jsonschema-module-jakarta-validation/README.md b/jsonschema-module-jakarta-validation/README.md
index f31acc30..cf1a0d0e 100644
--- a/jsonschema-module-jakarta-validation/README.md
+++ b/jsonschema-module-jakarta-validation/README.md
@@ -13,6 +13,7 @@ Module for the [jsonschema-generator](../jsonschema-generator) – deriving JSON
7. Populate "pattern" for strings. Based on `@Pattern`/`@Email`, when corresponding `JakartaValidationOption.INCLUDE_PATTERN_EXPRESSIONS` is being provided in constructor.
8. Populate "minimum"/"exclusiveMinimum" for numbers. Based on `@Min`/`@DecimalMin`/`@Positive`/`@PositiveOrZero`.
9. Populate "maximum"/"exclusiveMaximum" for numbers. Based on `@Max`/`@DecimalMax`/`@Negative`/`@NegativeOrZero`.
+10. Populate "enum"/"const" for booleans. Based on `@AssertTrue`/`@AssertFalse`.
Schema attributes derived from validation annotations on fields are also applied to their respective getter methods.
Schema attributes derived from validation annotations on getter methods are also applied to their associated fields.
diff --git a/jsonschema-module-jakarta-validation/pom.xml b/jsonschema-module-jakarta-validation/pom.xml
index dd5e77f4..044b5243 100644
--- a/jsonschema-module-jakarta-validation/pom.xml
+++ b/jsonschema-module-jakarta-validation/pom.xml
@@ -5,7 +5,7 @@
com.github.victools
jsonschema-generator-parent
- 4.35.1-SNAPSHOT
+ 4.36.0-SNAPSHOT
../jsonschema-generator-parent/pom.xml
jsonschema-module-jakarta-validation
diff --git a/jsonschema-module-jakarta-validation/src/main/java/com/github/victools/jsonschema/module/jakarta/validation/JakartaValidationModule.java b/jsonschema-module-jakarta-validation/src/main/java/com/github/victools/jsonschema/module/jakarta/validation/JakartaValidationModule.java
index 3bfc2574..012ccee0 100644
--- a/jsonschema-module-jakarta-validation/src/main/java/com/github/victools/jsonschema/module/jakarta/validation/JakartaValidationModule.java
+++ b/jsonschema-module-jakarta-validation/src/main/java/com/github/victools/jsonschema/module/jakarta/validation/JakartaValidationModule.java
@@ -28,6 +28,8 @@
import com.github.victools.jsonschema.generator.SchemaGeneratorConfigPart;
import com.github.victools.jsonschema.generator.SchemaKeyword;
import jakarta.validation.Constraint;
+import jakarta.validation.constraints.AssertFalse;
+import jakarta.validation.constraints.AssertTrue;
import jakarta.validation.constraints.DecimalMax;
import jakarta.validation.constraints.DecimalMin;
import jakarta.validation.constraints.Email;
@@ -45,12 +47,13 @@
import jakarta.validation.constraints.Size;
import java.lang.annotation.Annotation;
import java.math.BigDecimal;
+import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
+import java.util.List;
import java.util.Map;
import java.util.Set;
-import java.util.function.BiPredicate;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.function.ToIntBiFunction;
@@ -116,8 +119,9 @@ public void applyToConfigBuilder(SchemaGeneratorConfigBuilder builder) {
if (this.options.contains(JakartaValidationOption.NOT_NULLABLE_METHOD_IS_REQUIRED)) {
methodConfigPart.withRequiredCheck(this::isRequired);
}
- Stream.of(DecimalMax.class, DecimalMin.class, Email.class, Max.class, Min.class, Negative.class, NegativeOrZero.class,
- NotBlank.class, NotEmpty.class, Null.class, NotNull.class, Pattern.class, Positive.class, PositiveOrZero.class, Size.class)
+ Stream.of(AssertFalse.class, AssertTrue.class, DecimalMax.class, DecimalMin.class, Email.class, Max.class, Min.class,
+ Negative.class, NegativeOrZero.class, NotBlank.class, NotEmpty.class, Null.class, NotNull.class,
+ Pattern.class, Positive.class, PositiveOrZero.class, Size.class)
.forEach(annotationType -> builder.withAnnotationInclusionOverride(annotationType, AnnotationInclusion.INCLUDE_AND_INHERIT));
}
@@ -137,6 +141,7 @@ private void applyToConfigPart(SchemaGeneratorConfigPart> configPart) {
configPart.withNumberExclusiveMinimumResolver(this::resolveNumberExclusiveMinimum);
configPart.withNumberInclusiveMaximumResolver(this::resolveNumberInclusiveMaximum);
configPart.withNumberExclusiveMaximumResolver(this::resolveNumberExclusiveMaximum);
+ configPart.withEnumResolver(this::resolveEnum);
configPart.withInstanceAttributeOverride(this::overrideInstanceAttributes);
if (this.options.contains(JakartaValidationOption.INCLUDE_PATTERN_EXPRESSIONS)) {
@@ -499,6 +504,28 @@ protected BigDecimal resolveNumberExclusiveMaximum(MemberScope, ?> member) {
return null;
}
+ /**
+ * Look-up the finite list of possible values.
+ *
+ * @param member field/method to determine allowed values for
+ * @return applicable "const"/"enum" values or null
+ *
+ * @since 4.36.0
+ * @see AssertTrue
+ * @see AssertFalse
+ */
+ protected List