@@ -39,6 +39,8 @@ private static final Regexp toRegexp(String pattern) {
3939
4040 private boolean requiresObject = true ;
4141
42+ private final Map <String , Schema > definitionSchemas = new HashMap <>();
43+
4244 private final Map <String , Schema > propertySchemas = new HashMap <>();
4345
4446 private boolean additionalProperties = true ;
@@ -64,6 +66,22 @@ public Builder additionalProperties(boolean additionalProperties) {
6466 return this ;
6567 }
6668
69+ /**
70+ * Adds a definition schema.
71+ *
72+ * @param definitionName
73+ * the name of the definition
74+ * @param schema
75+ * the definition of the {@code schema}
76+ * @return {@code this}
77+ */
78+ public Builder addDefinitionSchema (String definitionName , Schema schema ) {
79+ requireNonNull (definitionName , "definitionName cannot be null" );
80+ requireNonNull (schema , "schema cannot be null" );
81+ definitionSchemas .put (definitionName , schema );
82+ return this ;
83+ }
84+
6785 /**
6886 * Adds a property schema.
6987 *
@@ -170,6 +188,8 @@ private static <K, V> Map<K, V> copyMap(Map<K, V> original) {
170188 return Collections .unmodifiableMap (new HashMap <>(original ));
171189 }
172190
191+ private final Map <String , Schema > definitionSchemas ;
192+
173193 private final Map <String , Schema > propertySchemas ;
174194
175195 private final boolean additionalProperties ;
@@ -202,8 +222,10 @@ private static <K, V> Map<K, V> copyMap(Map<K, V> original) {
202222 */
203223 public ObjectSchema (Builder builder ) {
204224 super (builder );
225+ this .definitionSchemas = builder .definitionSchemas == null ? null
226+ : Collections .unmodifiableMap (builder .definitionSchemas );
205227 this .propertySchemas = builder .propertySchemas == null ? null
206- : Collections .unmodifiableMap (builder .propertySchemas );
228+ : Collections .unmodifiableMap (builder .propertySchemas );
207229 this .additionalProperties = builder .additionalProperties ;
208230 this .schemaOfAdditionalProperties = builder .schemaOfAdditionalProperties ;
209231 if (!additionalProperties && schemaOfAdditionalProperties != null ) {
@@ -248,6 +270,10 @@ public Map<String, Set<String>> getPropertyDependencies() {
248270 return propertyDependencies ;
249271 }
250272
273+ public Map <String , Schema > getDefinitionSchemas () {
274+ return definitionSchemas ;
275+ }
276+
251277 public Map <String , Schema > getPropertySchemas () {
252278 return propertySchemas ;
253279 }
@@ -344,6 +370,7 @@ public boolean equals(Object o) {
344370 return that .canEqual (this ) &&
345371 additionalProperties == that .additionalProperties &&
346372 requiresObject == that .requiresObject &&
373+ Objects .equals (definitionSchemas , that .definitionSchemas ) &&
347374 Objects .equals (propertySchemas , that .propertySchemas ) &&
348375 Objects .equals (schemaOfAdditionalProperties , that .schemaOfAdditionalProperties ) &&
349376 Objects .equals (requiredProperties , that .requiredProperties ) &&
@@ -362,7 +389,7 @@ public boolean equals(Object o) {
362389
363390 @ Override
364391 public int hashCode () {
365- return Objects .hash (super .hashCode (), propertySchemas , propertyNameSchema , additionalProperties ,
392+ return Objects .hash (super .hashCode (), definitionSchemas , propertySchemas , propertyNameSchema , additionalProperties ,
366393 schemaOfAdditionalProperties , requiredProperties , minProperties , maxProperties , propertyDependencies ,
367394 schemaDependencies , requiresObject , patternProperties , oneOrMoreDefaultProperty );
368395 }
0 commit comments