@@ -146,10 +146,12 @@ private void mergeAllOf(Object value, String[] paths, URI currentFileURL) {
146
146
// visited.add(value);
147
147
if (paths .length > 0 && "allOf" .equals (paths [paths .length -1 ])) {
148
148
List allOf = (List ) value ;
149
- // List<String> required = new ArrayList<>();
150
- // Map<String, Object> properties = new LinkedHashMap<>();
151
- // Map<String, Object> mergedAllOfObject = new LinkedHashMap<>();
149
+ String [] jsonPaths = Arrays .copyOf (paths , paths .length -1 );
150
+ String jsonPath = jsonPath (jsonPaths );
151
+ Map <String , Object > originalAllOfRoot = refs .jsonContext .read (jsonPath );
152
+
152
153
AllOfObject allOfObject = new AllOfObject ();
154
+ merge (allOfObject , originalAllOfRoot );
153
155
for (int i = 0 ; i < allOf .size (); i ++) {
154
156
if (allOf .get (i ) instanceof Map ) {
155
157
Map <String , Object > item = (Map <String , Object >) allOf .get (i );
@@ -158,14 +160,7 @@ private void mergeAllOf(Object value, String[] paths, URI currentFileURL) {
158
160
throw new RuntimeException ("Could not understand allOf: " + allOf .get (i ));
159
161
}
160
162
}
161
- // if(!required.isEmpty()) {
162
- // mergedAllOfObject.put("required", required);
163
- // }
164
- // if(!properties.isEmpty()) {
165
- // mergedAllOfObject.put("properties", properties);
166
- // }
167
- String [] jsonPaths = Arrays .copyOf (paths , paths .length -1 );
168
- String jsonPath = jsonPath (jsonPaths );
163
+
169
164
try {
170
165
var mergedAllOfObject = allOfObject .buildAllOfObject ();
171
166
refs .jsonContext .set (jsonPath , mergedAllOfObject );
@@ -199,7 +194,13 @@ private void merge(AllOfObject allOfObject, Map<String, Object> item) {
199
194
List <Map <String , Object >> items = (List ) item .get ("allOf" );
200
195
merge (allOfObject , items );
201
196
} else {
202
- allOfObject .allOf .putAll (item );
197
+ for (Map .Entry <String , Object > entry : item .entrySet ()) {
198
+ if (entry .getKey ().equals ("allOf" )) {
199
+ merge (allOfObject , (List ) item .get ("allOf" ));
200
+ } else {
201
+ allOfObject .allOf .put (entry .getKey (), entry .getValue ());
202
+ }
203
+ }
203
204
if (item .containsKey ("properties" )) {
204
205
allOfObject .properties .putAll ((Map ) item .get ("properties" ));
205
206
}
@@ -214,6 +215,7 @@ private static class AllOfObject {
214
215
Map <String , Object > properties = new HashMap <>();
215
216
List <String > required = new ArrayList <>();
216
217
218
+
217
219
Map <String , Object > buildAllOfObject () {
218
220
Map <String , Object > allOfObject = new LinkedHashMap <>(allOf );
219
221
if (!required .isEmpty ()) {
0 commit comments