forked from asyncapi/modelina
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CommonModel.ts
838 lines (795 loc) · 23.4 KB
/
CommonModel.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
import { Logger } from '../utils';
export interface MergingOptions {
/**
* When models are merged, should merging models constrict the `merging to` model?
* If false, `required` keyword would no longer be applied from the `merging from` model.
*/
constrictModels?: boolean;
}
export const defaultMergingOptions: MergingOptions = {
constrictModels: true
};
/**
* Common internal representation for a model.
*/
export class CommonModel {
extend?: string[];
originalInput?: any;
$id?: string;
type?: string | string[];
enum?: any[];
const?: unknown;
discriminator?: string;
items?: CommonModel | CommonModel[];
properties?: { [key: string]: CommonModel };
additionalProperties?: CommonModel;
patternProperties?: { [key: string]: CommonModel };
required?: string[];
additionalItems?: CommonModel;
union?: CommonModel[];
format?: string;
/**
* Takes a deep copy of the input object and converts it to an instance of CommonModel.
*
* @param object to transform
* @returns CommonModel instance of the object
*/
static toCommonModel(
object: Record<string, unknown> | CommonModel
): CommonModel {
const convertedSchema = CommonModel.internalToSchema(object);
if (convertedSchema instanceof CommonModel) {
return convertedSchema;
}
throw new Error('Could not convert input to expected copy of CommonModel');
}
private static internalToSchema(
object: any,
seenSchemas: Map<any, CommonModel> = new Map()
): any {
// if primitive types return as is
if (null === object || 'object' !== typeof object) {
return object;
}
if (seenSchemas.has(object)) {
return seenSchemas.get(object);
}
if (object instanceof Array) {
const copy: any = [];
for (let i = 0, len = object.length; i < len; i++) {
copy[Number(i)] = CommonModel.internalToSchema(
object[Number(i)],
seenSchemas
);
}
return copy;
}
//Nothing else left then to create an object
const schema = new CommonModel();
seenSchemas.set(object, schema);
for (const [propName, prop] of Object.entries(object)) {
let copyProp = prop;
// Ignore value properties (those with `any` type) as they should be saved as is regardless of value
if (propName !== 'originalInput' && propName !== 'enum') {
copyProp = CommonModel.internalToSchema(prop, seenSchemas);
}
(schema as any)[String(propName)] = copyProp;
}
return schema;
}
/**
* Retrieves data from originalInput by given key
*
* @param key given key
* @returns {any}
*/
getFromOriginalInput<K extends keyof any>(key: K): any {
const input = this.originalInput || {};
if (typeof input === 'boolean') {
return undefined;
}
return input[String(key)];
}
/**
* Set the types of the model
*
* @param type
*/
setType(type: string | string[] | undefined): void {
if (Array.isArray(type)) {
if (type.length === 0) {
this.type = undefined;
return;
} else if (type.length === 1) {
this.type = type[0];
return;
}
}
this.type = type;
}
/**
* Removes type(s) from model type
*
* @param types
*/
removeType(typesToRemove: string | string[]): void {
if (Array.isArray(typesToRemove)) {
for (const type of typesToRemove) {
this.removeType(type);
}
} else if (this.type !== undefined && this.type.includes(typesToRemove)) {
if (Array.isArray(this.type)) {
this.setType(
this.type.filter((el) => {
return el !== typesToRemove;
})
);
} else {
this.setType(undefined);
}
}
}
/**
* Adds types to the existing model types.
*
* Makes sure to only keep a single type incase of duplicates.
*
* @param types which types we should try and add to the existing output
*/
addTypes(types: string[] | string): void {
if (Array.isArray(types)) {
for (const type of types) {
this.addTypes(type);
}
} else if (this.type === undefined) {
this.type = types;
} else if (!Array.isArray(this.type) && this.type !== types) {
this.type = [this.type, types];
} else if (Array.isArray(this.type) && !this.type.includes(types)) {
this.type.push(types);
}
}
/**
* Checks if given property name is required in object
*
* @param propertyName given property name
* @returns {boolean}
*/
isRequired(propertyName: string): boolean {
if (this.required === undefined) {
return false;
}
return this.required.includes(propertyName);
}
/**
* Adds an item to the model.
*
* If items already exist the two are merged.
*
* @param itemModel
* @param originalInput corresponding input that got interpreted to this model
*/
addItem(itemModel: CommonModel, originalInput: any): void {
if (this.items !== undefined) {
Logger.warn(
`While trying to add item to model ${this.$id}, duplicate items found. Merging models together to form a unified item model.`,
itemModel,
originalInput,
this
);
this.items = CommonModel.mergeCommonModels(
this.items as CommonModel,
itemModel,
originalInput
);
} else {
this.items = itemModel;
}
}
/**
* Adds a tuple to the model.
*
* If a item already exist it will be merged.
*
* @param tupleModel
* @param originalInput corresponding input that got interpreted to this model
* @param index
*/
addItemTuple(
tupleModel: CommonModel,
originalInput: any,
index: number
): void {
let modelItems = this.items;
if (!Array.isArray(modelItems)) {
Logger.warn(
'Trying to add item tuple to a non-tuple item, will drop existing item model',
tupleModel,
originalInput,
index
);
modelItems = [];
}
const existingModelAtIndex = modelItems[Number(index)];
if (existingModelAtIndex !== undefined) {
Logger.warn(
'Trying to add item tuple at index ${index} but it was already occupied, merging models',
tupleModel,
originalInput,
index
);
modelItems[Number(index)] = CommonModel.mergeCommonModels(
existingModelAtIndex,
tupleModel,
originalInput
);
} else {
modelItems[Number(index)] = tupleModel;
}
this.items = modelItems;
}
/**
* Adds a union model to the model.
*
* @param unionModel
*/
addItemUnion(unionModel: CommonModel): void {
if (Array.isArray(this.union)) {
this.union.push(unionModel);
} else {
this.union = [unionModel];
}
}
/**
* Add enum value to the model.
*
* Ensures no duplicates are added.
*
* @param enumValue
*/
addEnum(enumValue: any): void {
if (this.enum === undefined) {
this.enum = [];
}
if (!this.enum.includes(enumValue)) {
this.enum.push(enumValue);
}
}
/**
* Remove enum from model.
*
* @param enumValue
*/
removeEnum(enumsToRemove: any | any[]): void {
if (this.enum === undefined || enumsToRemove === undefined) {
return;
}
if (Array.isArray(enumsToRemove)) {
for (const enumToRemove of enumsToRemove) {
this.removeEnum(enumToRemove);
}
return;
}
const filteredEnums = this.enum.filter((el) => {
return enumsToRemove !== el;
});
if (filteredEnums.length === 0) {
this.enum = undefined;
} else {
this.enum = filteredEnums;
}
}
/**
* Adds a property to the model.
* If the property already exist the two are merged.
*
* @param propertyName
* @param propertyModel
* @param originalInput corresponding input that got interpreted to this model
*/
addProperty(
propertyName: string,
propertyModel: CommonModel,
originalInput: any
): void {
if (this.properties === undefined) {
this.properties = {};
}
if (this.properties[`${propertyName}`] !== undefined) {
Logger.warn(
`While trying to add property to model, duplicate properties found. Merging models together for property ${propertyName}`,
propertyModel,
originalInput,
this
);
this.properties[String(propertyName)] = CommonModel.mergeCommonModels(
this.properties[String(propertyName)],
propertyModel,
originalInput
);
} else {
this.properties[String(propertyName)] = propertyModel;
}
}
/**
* Adds additionalProperty to the model.
* If another model already exist the two are merged.
*
* @param additionalPropertiesModel
* @param originalInput corresponding input that got interpreted to this model corresponding input that got interpreted to this model
*/
addAdditionalProperty(
additionalPropertiesModel: CommonModel,
originalInput: any
): void {
if (this.additionalProperties !== undefined) {
Logger.warn(
'While trying to add additionalProperties to model, but it is already present, merging models together',
additionalPropertiesModel,
originalInput,
this
);
this.additionalProperties = CommonModel.mergeCommonModels(
this.additionalProperties,
additionalPropertiesModel,
originalInput
);
} else {
this.additionalProperties = additionalPropertiesModel;
}
}
/**
* Adds a patternProperty to the model.
* If the pattern already exist the two models are merged.
*
* @param pattern
* @param patternModel
* @param originalInput corresponding input that got interpreted to this model
*/
addPatternProperty(
pattern: string,
patternModel: CommonModel,
originalInput: any
): void {
if (this.patternProperties === undefined) {
this.patternProperties = {};
}
if (this.patternProperties[`${pattern}`] !== undefined) {
Logger.warn(
`While trying to add patternProperty to model, duplicate patterns found. Merging pattern models together for pattern ${pattern}`,
patternModel,
originalInput,
this
);
this.patternProperties[String(pattern)] = CommonModel.mergeCommonModels(
this.patternProperties[String(pattern)],
patternModel,
originalInput
);
} else {
this.patternProperties[String(pattern)] = patternModel;
}
}
/**
* Adds additionalItems to the model.
* If another model already exist the two are merged.
*
* @param additionalItemsModel
* @param originalInput corresponding input that got interpreted to this model
*/
addAdditionalItems(
additionalItemsModel: CommonModel,
originalInput: any
): void {
if (this.additionalItems !== undefined) {
Logger.warn(
'While trying to add additionalItems to model, but it is already present, merging models together',
additionalItemsModel,
originalInput,
this
);
this.additionalItems = CommonModel.mergeCommonModels(
this.additionalItems,
additionalItemsModel,
originalInput
);
} else {
this.additionalItems = additionalItemsModel;
}
}
/**
* Adds another model this model should extend.
*
* It is only allowed to extend if the other model have $id and is not already being extended.
*
* @param extendedModel
*/
addExtendedModel(extendedModel: CommonModel): void {
if (extendedModel.$id === undefined) {
Logger.error(
'Found no $id for allOf model and cannot extend the existing model, this should never happen.',
this,
extendedModel
);
return;
}
this.extend = this.extend || [];
if (this.extend.includes(extendedModel.$id)) {
Logger.info(
`${this.$id} model already extends model ${extendedModel.$id}.`,
this,
extendedModel
);
return;
}
this.extend.push(extendedModel.$id);
}
/**
* Returns true if the $id of a CommonModel includes anonymous_schema
*
* @param commonModel
*/
private static idIncludesAnonymousSchema(commonModel: CommonModel) {
return commonModel.$id?.includes('anonymous_schema');
}
/**
* Merge two common model properties together
*
* @param mergeTo
* @param mergeFrom
* @param originalInput corresponding input that got interpreted to this model
* @param alreadyIteratedModels
*/
private static mergeProperties(
mergeTo: CommonModel,
mergeFrom: CommonModel,
originalInput: any,
alreadyIteratedModels: Map<CommonModel, CommonModel> = new Map(),
options: MergingOptions = defaultMergingOptions
) {
if (!mergeTo.properties) {
mergeTo.properties = mergeFrom.properties;
return;
}
if (!mergeFrom.properties) {
return;
}
mergeTo.properties = {
...mergeTo.properties
};
for (const [propName, propValue] of Object.entries(mergeFrom.properties)) {
if (!mergeTo.properties[String(propName)]) {
mergeTo.properties[String(propName)] = propValue;
} else {
Logger.warn(
`Found duplicate properties ${propName} for model. Model property from ${
mergeFrom.$id || 'unknown'
} merged into ${mergeTo.$id || 'unknown'}`,
mergeTo,
mergeFrom,
originalInput
);
// takes a deep copy of the mergeTo model if the id of mergeTo is anonymous to avoid carrying over properties to other models
const mergeToModel = CommonModel.idIncludesAnonymousSchema(
mergeTo.properties[String(propName)]
)
? CommonModel.toCommonModel(mergeTo.properties[String(propName)])
: mergeTo.properties[String(propName)];
const mergedModel = CommonModel.mergeCommonModels(
mergeToModel,
propValue,
originalInput,
alreadyIteratedModels,
options
);
if (propValue.const) {
mergeTo.properties[String(propName)] =
CommonModel.toCommonModel(mergedModel);
mergeTo.properties[String(propName)].const = propValue.const;
} else {
mergeTo.properties[String(propName)] = mergedModel;
}
}
}
}
/**
* Merge two common model additionalProperties together
*
* @param mergeTo
* @param mergeFrom
* @param originalInput corresponding input that got interpreted to this model
* @param alreadyIteratedModels
*/
private static mergeAdditionalProperties(
mergeTo: CommonModel,
mergeFrom: CommonModel,
originalInput: any,
alreadyIteratedModels: Map<CommonModel, CommonModel> = new Map(),
options: MergingOptions = defaultMergingOptions
) {
const mergeToAdditionalProperties = mergeTo.additionalProperties;
const mergeFromAdditionalProperties = mergeFrom.additionalProperties;
if (mergeFromAdditionalProperties !== undefined) {
if (mergeToAdditionalProperties === undefined) {
mergeTo.additionalProperties = mergeFromAdditionalProperties;
} else {
Logger.warn(
`Found duplicate additionalProperties for model. additionalProperties from ${
mergeFrom.$id || 'unknown'
} merged into ${mergeTo.$id || 'unknown'}`,
mergeTo,
mergeFrom,
originalInput
);
mergeTo.additionalProperties = CommonModel.mergeCommonModels(
mergeToAdditionalProperties,
mergeFromAdditionalProperties,
originalInput,
alreadyIteratedModels,
options
);
}
}
}
/**
* Merge two common model additionalItems together
*
* @param mergeTo
* @param mergeFrom
* @param originalInput corresponding input that got interpreted to this model
* @param alreadyIteratedModels
*/
private static mergeAdditionalItems(
mergeTo: CommonModel,
mergeFrom: CommonModel,
originalInput: any,
alreadyIteratedModels: Map<CommonModel, CommonModel> = new Map(),
options: MergingOptions = defaultMergingOptions
) {
const mergeToAdditionalItems = mergeTo.additionalItems;
const mergeFromAdditionalItems = mergeFrom.additionalItems;
if (mergeFromAdditionalItems !== undefined) {
if (mergeToAdditionalItems === undefined) {
mergeTo.additionalItems = mergeFromAdditionalItems;
} else {
Logger.warn(
`Found duplicate additionalItems for model. additionalItems from ${
mergeFrom.$id || 'unknown'
} merged into ${mergeTo.$id || 'unknown'}`,
mergeTo,
mergeFrom,
originalInput
);
mergeTo.additionalItems = CommonModel.mergeCommonModels(
mergeToAdditionalItems,
mergeFromAdditionalItems,
originalInput,
alreadyIteratedModels,
options
);
}
}
}
/**
* Merge items together, prefer tuples over simple array since it is more strict.
*
* @param mergeTo
* @param mergeFrom
* @param originalInput corresponding input that got interpreted to this model
* @param alreadyIteratedModels
*/
// eslint-disable-next-line sonarjs/cognitive-complexity
private static mergeItems(
mergeTo: CommonModel,
mergeFrom: CommonModel,
originalInput: any,
alreadyIteratedModels: Map<CommonModel, CommonModel> = new Map(),
options: MergingOptions = defaultMergingOptions
) {
if (mergeFrom.items === undefined) {
return;
}
if (Array.isArray(mergeFrom.items) && mergeFrom.items.length === 0) {
return;
}
if (mergeTo.items === undefined) {
mergeTo.items = mergeFrom.items;
return;
}
const mergeToItems = mergeTo.items;
//mergeFrom and mergeTo is not tuple
if (!Array.isArray(mergeFrom.items) && !Array.isArray(mergeToItems)) {
mergeTo.items = CommonModel.mergeCommonModels(
mergeToItems,
mergeFrom.items,
originalInput,
alreadyIteratedModels,
options
);
}
//mergeFrom and mergeTo is tuple
if (Array.isArray(mergeFrom.items) && Array.isArray(mergeToItems)) {
for (const [index, mergeFromTupleModel] of mergeFrom.items.entries()) {
(mergeTo.items as CommonModel[])[Number(index)] =
CommonModel.mergeCommonModels(
mergeToItems[Number(index)],
mergeFromTupleModel,
originalInput,
alreadyIteratedModels,
options
);
}
}
//mergeFrom is a tuple && mergeTo is not, use mergeFrom items (the tuple is prioritized)
if (Array.isArray(mergeFrom.items) && !Array.isArray(mergeToItems)) {
mergeTo.items = mergeFrom.items;
}
//mergeFrom is not tuple && mergeTo is, do nothing
}
/**
* Merge two common model pattern properties together
*
* @param mergeTo
* @param mergeFrom
* @param originalInput corresponding input that got interpreted to this model
* @param alreadyIteratedModels
*/
private static mergePatternProperties(
mergeTo: CommonModel,
mergeFrom: CommonModel,
originalInput: any,
alreadyIteratedModels: Map<CommonModel, CommonModel> = new Map(),
options: MergingOptions = defaultMergingOptions
) {
const mergeToPatternProperties = mergeTo.patternProperties;
const mergeFromPatternProperties = mergeFrom.patternProperties;
if (mergeFromPatternProperties !== undefined) {
if (mergeToPatternProperties === undefined) {
mergeTo.patternProperties = mergeFromPatternProperties;
} else {
for (const [pattern, patternModel] of Object.entries(
mergeFromPatternProperties
)) {
if (mergeToPatternProperties[String(pattern)] !== undefined) {
Logger.warn(
`Found duplicate pattern ${pattern} for model. Model pattern for ${
mergeFrom.$id || 'unknown'
} merged into ${mergeTo.$id || 'unknown'}`,
mergeTo,
mergeFrom,
originalInput
);
mergeToPatternProperties[String(pattern)] =
CommonModel.mergeCommonModels(
mergeToPatternProperties[String(pattern)],
patternModel,
originalInput,
alreadyIteratedModels,
options
);
} else {
mergeToPatternProperties[String(pattern)] = patternModel;
}
}
}
}
}
/**
* Merge types together
*
* @param mergeTo
* @param mergeFrom
*/
private static mergeTypes(mergeTo: CommonModel, mergeFrom: CommonModel) {
//Only add the types that do not already exist
const addToType = (type: string) => {
if (mergeTo.type !== undefined && !mergeTo.type.includes(type)) {
if (Array.isArray(mergeTo.type)) {
mergeTo.type.push(type);
} else {
mergeTo.type = [mergeTo.type, type];
}
}
};
if (mergeFrom.type !== undefined) {
if (mergeTo.type === undefined) {
mergeTo.type = mergeFrom.type;
} else if (Array.isArray(mergeFrom.type)) {
for (const type of mergeFrom.type) {
addToType(type);
}
} else {
addToType(mergeFrom.type);
}
}
}
/**
* Only merge if left side is undefined and right side is sat OR both sides are defined
*
* @param mergeTo
* @param mergeFrom
* @param originalInput corresponding input that got interpreted to this model
* @param alreadyIteratedModels
*/
// eslint-disable-next-line sonarjs/cognitive-complexity
static mergeCommonModels(
mergeTo: CommonModel | undefined,
mergeFrom: CommonModel,
originalInput: any,
alreadyIteratedModels: Map<CommonModel, CommonModel> = new Map(),
options: MergingOptions = defaultMergingOptions
): CommonModel {
if (mergeTo === undefined) {
return mergeFrom;
}
Logger.debug(
`Merging model ${mergeFrom.$id || 'unknown'} into ${
mergeTo.$id || 'unknown'
}`,
mergeTo,
mergeFrom,
originalInput
);
if (alreadyIteratedModels.has(mergeFrom)) {
return alreadyIteratedModels.get(mergeFrom) as CommonModel;
}
alreadyIteratedModels.set(mergeFrom, mergeTo);
CommonModel.mergeAdditionalProperties(
mergeTo,
mergeFrom,
originalInput,
alreadyIteratedModels,
options
);
CommonModel.mergePatternProperties(
mergeTo,
mergeFrom,
originalInput,
alreadyIteratedModels,
options
);
CommonModel.mergeAdditionalItems(
mergeTo,
mergeFrom,
originalInput,
alreadyIteratedModels,
options
);
CommonModel.mergeProperties(
mergeTo,
mergeFrom,
originalInput,
alreadyIteratedModels,
options
);
CommonModel.mergeItems(
mergeTo,
mergeFrom,
originalInput,
alreadyIteratedModels,
options
);
CommonModel.mergeTypes(mergeTo, mergeFrom);
if (mergeFrom.enum !== undefined) {
mergeTo.enum = [...new Set([...(mergeTo.enum || []), ...mergeFrom.enum])];
}
mergeTo.const = mergeTo.const || mergeFrom.const;
if (mergeFrom.required !== undefined && options.constrictModels === true) {
mergeTo.required = [
...new Set([...(mergeTo.required || []), ...mergeFrom.required])
];
}
mergeTo.format = mergeTo.format || mergeFrom.format;
if (
CommonModel.idIncludesAnonymousSchema(mergeTo) &&
!CommonModel.idIncludesAnonymousSchema(mergeFrom)
) {
mergeTo.$id = mergeFrom.$id;
} else {
mergeTo.$id = mergeTo.$id || mergeFrom.$id;
}
mergeTo.extend = mergeTo.extend || mergeFrom.extend;
mergeTo.originalInput = originalInput;
return mergeTo;
}
}