@@ -39,6 +39,8 @@ private static Regexp toRegexp(String pattern) {
39
39
40
40
private boolean requiresObject = true ;
41
41
42
+ private final Map <String , Schema > definitionSchemas = new HashMap <>();
43
+
42
44
private final Map <String , Schema > propertySchemas = new HashMap <>();
43
45
44
46
private boolean additionalProperties = true ;
@@ -70,6 +72,22 @@ public Builder additionalProperties(boolean additionalProperties) {
70
72
return this ;
71
73
}
72
74
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
+
73
91
/**
74
92
* Adds a property schema.
75
93
*
@@ -175,6 +193,8 @@ private static <K, V> Map<K, V> copyMap(Map<K, V> original) {
175
193
return Collections .unmodifiableMap (new HashMap <>(original ));
176
194
}
177
195
196
+ private final Map <String , Schema > definitionSchemas ;
197
+
178
198
private final Map <String , Schema > propertySchemas ;
179
199
180
200
private final boolean additionalProperties ;
@@ -207,8 +227,10 @@ private static <K, V> Map<K, V> copyMap(Map<K, V> original) {
207
227
*/
208
228
public ObjectSchema (Builder builder ) {
209
229
super (builder );
230
+ this .definitionSchemas = builder .definitionSchemas == null ? null
231
+ : Collections .unmodifiableMap (builder .definitionSchemas );
210
232
this .propertySchemas = builder .propertySchemas == null ? null
211
- : Collections .unmodifiableMap (builder .propertySchemas );
233
+ : Collections .unmodifiableMap (builder .propertySchemas );
212
234
this .additionalProperties = builder .additionalProperties ;
213
235
this .schemaOfAdditionalProperties = builder .schemaOfAdditionalProperties ;
214
236
if (!additionalProperties && schemaOfAdditionalProperties != null ) {
@@ -253,6 +275,10 @@ public Map<String, Set<String>> getPropertyDependencies() {
253
275
return propertyDependencies ;
254
276
}
255
277
278
+ public Map <String , Schema > getDefinitionSchemas () {
279
+ return definitionSchemas ;
280
+ }
281
+
256
282
public Map <String , Schema > getPropertySchemas () {
257
283
return propertySchemas ;
258
284
}
@@ -349,6 +375,7 @@ public boolean equals(Object o) {
349
375
return that .canEqual (this ) &&
350
376
additionalProperties == that .additionalProperties &&
351
377
requiresObject == that .requiresObject &&
378
+ Objects .equals (definitionSchemas , that .definitionSchemas ) &&
352
379
Objects .equals (propertySchemas , that .propertySchemas ) &&
353
380
Objects .equals (schemaOfAdditionalProperties , that .schemaOfAdditionalProperties ) &&
354
381
Objects .equals (requiredProperties , that .requiredProperties ) &&
@@ -367,7 +394,7 @@ public boolean equals(Object o) {
367
394
368
395
@ Override
369
396
public int hashCode () {
370
- return Objects .hash (super .hashCode (), propertySchemas , propertyNameSchema , additionalProperties ,
397
+ return Objects .hash (super .hashCode (), definitionSchemas , propertySchemas , propertyNameSchema , additionalProperties ,
371
398
schemaOfAdditionalProperties , requiredProperties , minProperties , maxProperties , propertyDependencies ,
372
399
schemaDependencies , requiresObject , patternProperties , oneOrMoreDefaultProperty );
373
400
}
0 commit comments