@@ -39,6 +39,8 @@ private static 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 ;
@@ -70,6 +72,22 @@ public Builder additionalProperties(boolean additionalProperties) {
7072 return this ;
7173 }
7274
75+ /**
76+ * Adds a definition schema.
77+ *
78+ * @param definitionName
79+ * the name of the definition
80+ * @param schema
81+ * the definition of the {@code schema}
82+ * @return {@code this}
83+ */
84+ public Builder addDefinitionSchema (String definitionName , Schema schema ) {
85+ requireNonNull (definitionName , "definitionName cannot be null" );
86+ requireNonNull (schema , "schema cannot be null" );
87+ definitionSchemas .put (definitionName , schema );
88+ return this ;
89+ }
90+
7391 /**
7492 * Adds a property schema.
7593 *
@@ -175,6 +193,8 @@ private static <K, V> Map<K, V> copyMap(Map<K, V> original) {
175193 return Collections .unmodifiableMap (new HashMap <>(original ));
176194 }
177195
196+ private final Map <String , Schema > definitionSchemas ;
197+
178198 private final Map <String , Schema > propertySchemas ;
179199
180200 private final boolean additionalProperties ;
@@ -207,8 +227,10 @@ private static <K, V> Map<K, V> copyMap(Map<K, V> original) {
207227 */
208228 public ObjectSchema (Builder builder ) {
209229 super (builder );
230+ this .definitionSchemas = builder .definitionSchemas == null ? null
231+ : Collections .unmodifiableMap (builder .definitionSchemas );
210232 this .propertySchemas = builder .propertySchemas == null ? null
211- : Collections .unmodifiableMap (builder .propertySchemas );
233+ : Collections .unmodifiableMap (builder .propertySchemas );
212234 this .additionalProperties = builder .additionalProperties ;
213235 this .schemaOfAdditionalProperties = builder .schemaOfAdditionalProperties ;
214236 if (!additionalProperties && schemaOfAdditionalProperties != null ) {
@@ -253,6 +275,10 @@ public Map<String, Set<String>> getPropertyDependencies() {
253275 return propertyDependencies ;
254276 }
255277
278+ public Map <String , Schema > getDefinitionSchemas () {
279+ return definitionSchemas ;
280+ }
281+
256282 public Map <String , Schema > getPropertySchemas () {
257283 return propertySchemas ;
258284 }
@@ -349,6 +375,7 @@ public boolean equals(Object o) {
349375 return that .canEqual (this ) &&
350376 additionalProperties == that .additionalProperties &&
351377 requiresObject == that .requiresObject &&
378+ Objects .equals (definitionSchemas , that .definitionSchemas ) &&
352379 Objects .equals (propertySchemas , that .propertySchemas ) &&
353380 Objects .equals (schemaOfAdditionalProperties , that .schemaOfAdditionalProperties ) &&
354381 Objects .equals (requiredProperties , that .requiredProperties ) &&
@@ -367,7 +394,7 @@ public boolean equals(Object o) {
367394
368395 @ Override
369396 public int hashCode () {
370- return Objects .hash (super .hashCode (), propertySchemas , propertyNameSchema , additionalProperties ,
397+ return Objects .hash (super .hashCode (), definitionSchemas , propertySchemas , propertyNameSchema , additionalProperties ,
371398 schemaOfAdditionalProperties , requiredProperties , minProperties , maxProperties , propertyDependencies ,
372399 schemaDependencies , requiresObject , patternProperties , oneOrMoreDefaultProperty );
373400 }
0 commit comments