@tsed/mongoose 8.0.1 → 8.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (77) hide show
  1. package/package.json +15 -14
  2. package/src/MongooseModule.ts +32 -0
  3. package/src/constants/constants.ts +20 -0
  4. package/src/decorators/auto.spec.ts +30 -0
  5. package/src/decorators/auto.ts +24 -0
  6. package/src/decorators/discriminatorKey.ts +1 -0
  7. package/src/decorators/dynamicRef.spec.ts +46 -0
  8. package/src/decorators/dynamicRef.ts +76 -0
  9. package/src/decorators/excludeIndexes.spec.ts +30 -0
  10. package/src/decorators/excludeIndexes.ts +24 -0
  11. package/src/decorators/expires.spec.ts +18 -0
  12. package/src/decorators/expires.ts +24 -0
  13. package/src/decorators/immutable.spec.ts +30 -0
  14. package/src/decorators/immutable.ts +26 -0
  15. package/src/decorators/indexed.spec.ts +19 -0
  16. package/src/decorators/indexed.ts +24 -0
  17. package/src/decorators/lowercase.spec.ts +30 -0
  18. package/src/decorators/lowercase.ts +24 -0
  19. package/src/decorators/model.ts +69 -0
  20. package/src/decorators/mongooseIndex.spec.ts +26 -0
  21. package/src/decorators/mongooseIndex.ts +35 -0
  22. package/src/decorators/mongooseIndexes.spec.ts +35 -0
  23. package/src/decorators/mongooseIndexes.ts +35 -0
  24. package/src/decorators/mongoosePlugin.spec.ts +25 -0
  25. package/src/decorators/mongoosePlugin.ts +20 -0
  26. package/src/decorators/numberDecimal.spec.ts +266 -0
  27. package/src/decorators/numberDecimal.ts +84 -0
  28. package/src/decorators/objectID.spec.ts +24 -0
  29. package/src/decorators/objectID.ts +39 -0
  30. package/src/decorators/postHook.spec.ts +44 -0
  31. package/src/decorators/postHook.ts +72 -0
  32. package/src/decorators/preHook.spec.ts +75 -0
  33. package/src/decorators/preHook.ts +70 -0
  34. package/src/decorators/ref.spec.ts +361 -0
  35. package/src/decorators/ref.ts +111 -0
  36. package/src/decorators/schema.ts +79 -0
  37. package/src/decorators/schemaIgnore.spec.ts +18 -0
  38. package/src/decorators/schemaIgnore.ts +24 -0
  39. package/src/decorators/select.spec.ts +18 -0
  40. package/src/decorators/select.ts +24 -0
  41. package/src/decorators/sparse.spec.ts +30 -0
  42. package/src/decorators/sparse.ts +26 -0
  43. package/src/decorators/text.spec.ts +30 -0
  44. package/src/decorators/text.ts +25 -0
  45. package/src/decorators/trim.spec.ts +18 -0
  46. package/src/decorators/trim.ts +23 -0
  47. package/src/decorators/unique.spec.ts +18 -0
  48. package/src/decorators/unique.ts +23 -0
  49. package/src/decorators/uppercase.spec.ts +30 -0
  50. package/src/decorators/uppercase.ts +24 -0
  51. package/src/decorators/versionKey.spec.ts +19 -0
  52. package/src/decorators/versionKey.ts +9 -0
  53. package/src/decorators/virtualRef.spec.ts +383 -0
  54. package/src/decorators/virtualRef.ts +73 -0
  55. package/src/index.ts +47 -0
  56. package/src/interfaces/MongooseConnectionOptions.ts +10 -0
  57. package/src/interfaces/MongooseDocument.ts +3 -0
  58. package/src/interfaces/MongooseModel.ts +10 -0
  59. package/src/interfaces/MongooseModelOptions.ts +8 -0
  60. package/src/interfaces/MongooseSchemaOptions.ts +51 -0
  61. package/src/interfaces/MongooseSchemaTypes.ts +5 -0
  62. package/src/interfaces/MongooseVirtualRefOptions.ts +10 -0
  63. package/src/interfaces/interfaces.ts +9 -0
  64. package/src/registries/MongooseModels.ts +3 -0
  65. package/src/services/MongooseConnection.spec.ts +70 -0
  66. package/src/services/MongooseConnections.ts +58 -0
  67. package/src/services/MongooseService.spec.ts +73 -0
  68. package/src/services/MongooseService.ts +77 -0
  69. package/src/utils/buildMongooseSchema.spec.ts +67 -0
  70. package/src/utils/createModel.spec.ts +49 -0
  71. package/src/utils/createModel.ts +54 -0
  72. package/src/utils/createSchema.spec.ts +771 -0
  73. package/src/utils/createSchema.ts +198 -0
  74. package/src/utils/resolveRefType.spec.ts +30 -0
  75. package/src/utils/resolveRefType.ts +18 -0
  76. package/src/utils/schemaOptions.spec.ts +68 -0
  77. package/src/utils/schemaOptions.ts +74 -0
@@ -0,0 +1,771 @@
1
+ import {
2
+ CollectionOf,
3
+ Default,
4
+ Enum,
5
+ getJsonSchema,
6
+ Maximum,
7
+ MaxLength,
8
+ Minimum,
9
+ MinLength,
10
+ Name,
11
+ Pattern,
12
+ Property,
13
+ Required
14
+ } from "@tsed/schema";
15
+ import {Schema as SchemaMongoose, Types} from "mongoose";
16
+
17
+ import {DiscriminatorKey} from "../decorators/discriminatorKey.js";
18
+ import {Model} from "../decorators/model.js";
19
+ import {ObjectID} from "../decorators/objectID.js";
20
+ import {Ref} from "../decorators/ref.js";
21
+ import {Schema} from "../decorators/schema.js";
22
+ import {SchemaIgnore} from "../decorators/schemaIgnore.js";
23
+ import {VersionKey} from "../decorators/versionKey.js";
24
+ import {VirtualRef, VirtualRefs} from "../decorators/virtualRef.js";
25
+ import {getSchema} from "./createSchema.js";
26
+
27
+ describe("createSchema", () => {
28
+ it("should create schema", () => {
29
+ enum MyEnum {
30
+ V1 = "v1",
31
+ V2 = "v2"
32
+ }
33
+
34
+ // GIVEN
35
+ @Model()
36
+ class Test {
37
+ @Name("id")
38
+ _id: string;
39
+
40
+ @Minimum(0)
41
+ @Maximum(10)
42
+ test: number;
43
+
44
+ @MinLength(0)
45
+ @MaxLength(100)
46
+ @Pattern("pattern")
47
+ @Default("defaultValue")
48
+ name: string = "defaultValue";
49
+
50
+ @Enum(MyEnum)
51
+ enum: MyEnum;
52
+ }
53
+
54
+ // WHEN
55
+ const result = getSchema(Test);
56
+
57
+ // THEN
58
+ expect(result.obj).toEqual({
59
+ _id: {
60
+ required: false,
61
+ type: String
62
+ },
63
+ enum: {
64
+ enum: ["v1", "v2"],
65
+ required: false,
66
+ type: String
67
+ },
68
+ name: {
69
+ default: "defaultValue",
70
+ match: /pattern/,
71
+ maxlength: 100,
72
+ minlength: 0,
73
+ required: false,
74
+ type: String
75
+ },
76
+ test: {
77
+ max: 10,
78
+ min: 0,
79
+ required: false,
80
+ type: Number
81
+ }
82
+ });
83
+ });
84
+ it("should create schema with buffer", () => {
85
+ // GIVEN
86
+ @Model()
87
+ class Test {
88
+ @Name("id")
89
+ _id: string;
90
+
91
+ @Property(Buffer)
92
+ image: Buffer;
93
+ }
94
+
95
+ // WHEN
96
+ const result = getSchema(Test);
97
+
98
+ // THEN
99
+ expect(result.obj).toEqual({
100
+ _id: {
101
+ required: false,
102
+ type: String
103
+ },
104
+ image: {
105
+ required: false,
106
+ type: Buffer
107
+ }
108
+ });
109
+ });
110
+ it("should create schema with required property", () => {
111
+ // GIVEN
112
+ @Model()
113
+ class Test2 {
114
+ @Required()
115
+ test: string;
116
+ }
117
+
118
+ // WHEN
119
+ const result: any = getSchema(Test2);
120
+
121
+ // THEN
122
+ expect(result.obj.test.required).toBeInstanceOf(Function);
123
+ });
124
+ it("should create schema with subdocument", () => {
125
+ // GIVEN
126
+ enum MyEnum {
127
+ V1 = "v1",
128
+ V2 = "v2"
129
+ }
130
+
131
+ @Schema()
132
+ class Children {
133
+ @Name("id")
134
+ _id: string;
135
+
136
+ @Minimum(0)
137
+ @Maximum(10)
138
+ test: number;
139
+
140
+ @MinLength(0)
141
+ @MaxLength(100)
142
+ @Pattern("pattern")
143
+ @Default("defaultValue")
144
+ name: string = "defaultValue";
145
+
146
+ @Enum(MyEnum)
147
+ enum: MyEnum;
148
+ }
149
+
150
+ @Model()
151
+ class Test3 {
152
+ @Property()
153
+ test: Children;
154
+ }
155
+
156
+ // WHEN
157
+ const testSchema = getSchema(Test3);
158
+ const childrenSchema = getSchema(Children);
159
+
160
+ // THEN
161
+ expect(testSchema.obj).toEqual({
162
+ test: {
163
+ type: childrenSchema,
164
+ required: false
165
+ }
166
+ });
167
+
168
+ expect(childrenSchema.obj).toEqual({
169
+ _id: {
170
+ required: false,
171
+ type: String
172
+ },
173
+ enum: {
174
+ enum: ["v1", "v2"],
175
+ required: false,
176
+ type: String
177
+ },
178
+ name: {
179
+ default: "defaultValue",
180
+ match: /pattern/,
181
+ maxlength: 100,
182
+ minlength: 0,
183
+ required: false,
184
+ type: String
185
+ },
186
+ test: {
187
+ max: 10,
188
+ min: 0,
189
+ required: false,
190
+ type: Number
191
+ }
192
+ });
193
+ });
194
+ it("should create schema with ref", () => {
195
+ // GIVEN
196
+ enum MyEnum {
197
+ V1 = "v1",
198
+ V2 = "v2"
199
+ }
200
+
201
+ @Model()
202
+ class Children {
203
+ @ObjectID("id")
204
+ _id: string;
205
+
206
+ @Minimum(0)
207
+ @Maximum(10)
208
+ test: number;
209
+
210
+ @MinLength(0)
211
+ @MaxLength(100)
212
+ @Pattern("pattern")
213
+ @Default("defaultValue")
214
+ name: string = "defaultValue";
215
+
216
+ @Enum(MyEnum)
217
+ enum: MyEnum;
218
+ }
219
+
220
+ @Model()
221
+ class Test4 {
222
+ @Ref(Children)
223
+ test: Ref<Children>;
224
+ }
225
+
226
+ // WHEN
227
+ const testSchema = getSchema(Test4);
228
+ const childrenSchema = getSchema(Children);
229
+
230
+ // THEN
231
+ expect(testSchema.obj).toEqual({
232
+ test: {
233
+ type: SchemaMongoose.Types.ObjectId,
234
+ ref: "Children",
235
+ required: false
236
+ }
237
+ });
238
+
239
+ expect(childrenSchema.obj).toEqual({
240
+ _id: {
241
+ auto: true,
242
+ required: false,
243
+ type: Types.ObjectId
244
+ },
245
+ enum: {
246
+ enum: ["v1", "v2"],
247
+ required: false,
248
+ type: String
249
+ },
250
+ name: {
251
+ default: "defaultValue",
252
+ match: /pattern/,
253
+ maxlength: 100,
254
+ minlength: 0,
255
+ required: false,
256
+ type: String
257
+ },
258
+ test: {
259
+ max: 10,
260
+ min: 0,
261
+ required: false,
262
+ type: Number
263
+ }
264
+ });
265
+
266
+ expect(getJsonSchema(Test4)).toEqual({
267
+ definitions: {
268
+ Children: {
269
+ properties: {
270
+ enum: {
271
+ enum: ["v1", "v2"],
272
+ type: "string"
273
+ },
274
+ id: {
275
+ description: "An ObjectID",
276
+ examples: ["5ce7ad3028890bd71749d477"],
277
+ pattern: "^[0-9a-fA-F]{24}$",
278
+ type: "string"
279
+ },
280
+ name: {
281
+ default: "defaultValue",
282
+ maxLength: 100,
283
+ minLength: 0,
284
+ pattern: "pattern",
285
+ type: "string"
286
+ },
287
+ test: {
288
+ maximum: 10,
289
+ minimum: 0,
290
+ type: "number"
291
+ }
292
+ },
293
+ type: "object"
294
+ }
295
+ },
296
+ properties: {
297
+ test: {
298
+ oneOf: [
299
+ {
300
+ description: "A reference ObjectID",
301
+ examples: ["5ce7ad3028890bd71749d477"],
302
+ type: "string"
303
+ },
304
+ {
305
+ $ref: "#/definitions/Children"
306
+ }
307
+ ]
308
+ }
309
+ },
310
+ type: "object"
311
+ });
312
+ expect(getJsonSchema(Children)).toEqual({
313
+ properties: {
314
+ enum: {
315
+ enum: ["v1", "v2"],
316
+ type: "string"
317
+ },
318
+ id: {
319
+ description: "An ObjectID",
320
+ examples: ["5ce7ad3028890bd71749d477"],
321
+ pattern: "^[0-9a-fA-F]{24}$",
322
+ type: "string"
323
+ },
324
+ name: {
325
+ default: "defaultValue",
326
+ maxLength: 100,
327
+ minLength: 0,
328
+ pattern: "pattern",
329
+ type: "string"
330
+ },
331
+ test: {
332
+ maximum: 10,
333
+ minimum: 0,
334
+ type: "number"
335
+ }
336
+ },
337
+ type: "object"
338
+ });
339
+ });
340
+ it("should create schema with virtual ref", () => {
341
+ // GIVEN
342
+ enum MyEnum {
343
+ V1 = "v1",
344
+ V2 = "v2"
345
+ }
346
+
347
+ @Model()
348
+ class Children2 {
349
+ @Name("id")
350
+ _id: string;
351
+
352
+ @Minimum(0)
353
+ @Maximum(10)
354
+ test: number;
355
+
356
+ @MinLength(0)
357
+ @MaxLength(100)
358
+ @Pattern("pattern")
359
+ @Default("defaultValue")
360
+ name: string = "defaultValue";
361
+
362
+ @Enum(MyEnum)
363
+ enum: MyEnum;
364
+ }
365
+
366
+ @Model()
367
+ class Test5 {
368
+ @VirtualRef({ref: Children2, foreignField: "foo", justOne: true})
369
+ test: VirtualRef<Children2>;
370
+ }
371
+
372
+ // WHEN
373
+ const testSchema: any = getSchema(Test5);
374
+
375
+ // THEN
376
+ expect(testSchema.obj).toEqual({});
377
+ expect(testSchema.virtuals.test.options).toMatchObject({
378
+ foreignField: "foo",
379
+ justOne: true,
380
+ localField: "_id",
381
+ options: undefined,
382
+ ref: "Children2"
383
+ });
384
+ });
385
+ it("should create schema with virtual ref (array)", () => {
386
+ // GIVEN
387
+ enum MyEnum {
388
+ V1 = "v1",
389
+ V2 = "v2"
390
+ }
391
+
392
+ @Model()
393
+ class Children2 {
394
+ @Name("id")
395
+ _id: string;
396
+
397
+ @Minimum(0)
398
+ @Maximum(10)
399
+ test: number;
400
+
401
+ @MinLength(0)
402
+ @MaxLength(100)
403
+ @Pattern("pattern")
404
+ @Default("defaultValue")
405
+ name: string = "defaultValue";
406
+
407
+ @Enum(MyEnum)
408
+ enum: MyEnum;
409
+ }
410
+
411
+ @Model()
412
+ class Test5 {
413
+ @VirtualRef({ref: Children2, justOne: false, foreignField: "foo"})
414
+ test: VirtualRefs<Children2>;
415
+ }
416
+
417
+ // WHEN
418
+ const testSchema: any = getSchema(Test5);
419
+
420
+ // THEN
421
+ expect(testSchema.obj).toEqual({});
422
+ expect(testSchema.virtuals.test.options).toMatchObject({
423
+ foreignField: "foo",
424
+ justOne: false,
425
+ localField: "_id",
426
+ options: undefined,
427
+ ref: "Children2"
428
+ });
429
+ });
430
+ it("should create schema with collection (Array of subdocument)", () => {
431
+ // GIVEN
432
+ enum MyEnum {
433
+ V1 = "v1",
434
+ V2 = "v2"
435
+ }
436
+
437
+ @Schema()
438
+ class Children {
439
+ @Name("id")
440
+ _id: string;
441
+
442
+ @Minimum(0)
443
+ @Maximum(10)
444
+ test: number;
445
+
446
+ @MinLength(0)
447
+ @MaxLength(100)
448
+ @Pattern("pattern")
449
+ @Default("defaultValue")
450
+ name: string = "defaultValue";
451
+
452
+ @Enum(MyEnum)
453
+ enum: MyEnum;
454
+ }
455
+
456
+ @Model()
457
+ class Test6 {
458
+ @CollectionOf(Children)
459
+ tests: Children[];
460
+ }
461
+
462
+ // WHEN
463
+ const testSchema = getSchema(Test6);
464
+ const childrenSchema = getSchema(Children);
465
+
466
+ // THEN
467
+ expect(testSchema.obj).toEqual({
468
+ tests: [
469
+ {
470
+ type: childrenSchema,
471
+ required: false
472
+ }
473
+ ]
474
+ });
475
+
476
+ expect(childrenSchema.obj).toEqual({
477
+ _id: {
478
+ required: false,
479
+ type: String
480
+ },
481
+ enum: {
482
+ enum: ["v1", "v2"],
483
+ required: false,
484
+ type: String
485
+ },
486
+ name: {
487
+ default: "defaultValue",
488
+ match: /pattern/,
489
+ maxlength: 100,
490
+ minlength: 0,
491
+ required: false,
492
+ type: String
493
+ },
494
+ test: {
495
+ max: 10,
496
+ min: 0,
497
+ required: false,
498
+ type: Number
499
+ }
500
+ });
501
+ });
502
+ it("should create schema with collection (Array of ref)", () => {
503
+ // GIVEN
504
+ enum MyEnum {
505
+ V1 = "v1",
506
+ V2 = "v2"
507
+ }
508
+
509
+ @Model()
510
+ class Children3 {
511
+ @Name("id")
512
+ _id: string;
513
+
514
+ @Minimum(0)
515
+ @Maximum(10)
516
+ test: number;
517
+
518
+ @MinLength(0)
519
+ @MaxLength(100)
520
+ @Pattern("pattern")
521
+ @Default("defaultValue")
522
+ name: string = "defaultValue";
523
+
524
+ @Enum(MyEnum)
525
+ enum: MyEnum;
526
+ }
527
+
528
+ @Model()
529
+ class Test7 {
530
+ @Ref(Children3)
531
+ tests: Ref<Children3>[];
532
+ }
533
+
534
+ // WHEN
535
+ const testSchema = getSchema(Test7);
536
+
537
+ // THEN
538
+ expect(testSchema.obj).toEqual({
539
+ tests: [
540
+ {
541
+ type: SchemaMongoose.Types.ObjectId,
542
+ ref: "Children3",
543
+ required: false
544
+ }
545
+ ]
546
+ });
547
+ });
548
+ it("should create schema with collection (Array of virtual ref", () => {
549
+ // GIVEN
550
+ enum MyEnum {
551
+ V1 = "v1",
552
+ V2 = "v2"
553
+ }
554
+
555
+ @Model()
556
+ class Children4 {
557
+ @Name("id")
558
+ _id: string;
559
+
560
+ @Minimum(0)
561
+ @Maximum(10)
562
+ test: number;
563
+
564
+ @MinLength(0)
565
+ @MaxLength(100)
566
+ @Pattern("pattern")
567
+ @Default("defaultValue")
568
+ name: string = "defaultValue";
569
+
570
+ @Enum(MyEnum)
571
+ enum: MyEnum;
572
+ }
573
+
574
+ @Model()
575
+ class Test8 {
576
+ @VirtualRef({ref: Children4, foreignField: "foo"})
577
+ tests: VirtualRef<Children4>[];
578
+ }
579
+
580
+ // WHEN
581
+ const testSchema = getSchema(Test8);
582
+
583
+ // THEN
584
+ expect(testSchema.obj).toEqual({});
585
+ // @ts-ignore
586
+ expect(testSchema.virtuals.tests.options).toMatchObject({
587
+ foreignField: "foo",
588
+ justOne: false,
589
+ localField: "_id",
590
+ options: undefined,
591
+ ref: "Children4"
592
+ });
593
+ });
594
+ it("should create schema with collection (Map of subdocument)", () => {
595
+ // GIVEN
596
+ enum MyEnum {
597
+ V1 = "v1",
598
+ V2 = "v2"
599
+ }
600
+
601
+ @Schema()
602
+ class Children {
603
+ @Name("id")
604
+ _id: string;
605
+
606
+ @Minimum(0)
607
+ @Maximum(10)
608
+ test: number;
609
+
610
+ @MinLength(0)
611
+ @MaxLength(100)
612
+ @Pattern("pattern")
613
+ @Default("defaultValue")
614
+ name: string = "defaultValue";
615
+
616
+ @Enum(MyEnum)
617
+ enum: MyEnum;
618
+ }
619
+
620
+ @Model()
621
+ class Test9 {
622
+ @CollectionOf(Children)
623
+ tests: Map<string, Children>;
624
+ }
625
+
626
+ // WHEN
627
+ const testSchema = getSchema(Test9);
628
+ const childrenSchema = getSchema(Children);
629
+
630
+ // THEN
631
+ expect(testSchema.obj).toEqual({
632
+ tests: {
633
+ type: Map,
634
+ of: {
635
+ type: childrenSchema,
636
+ required: false
637
+ }
638
+ }
639
+ });
640
+
641
+ expect(childrenSchema.obj).toEqual({
642
+ _id: {
643
+ required: false,
644
+ type: String
645
+ },
646
+ enum: {
647
+ enum: ["v1", "v2"],
648
+ required: false,
649
+ type: String
650
+ },
651
+ name: {
652
+ default: "defaultValue",
653
+ match: /pattern/,
654
+ maxlength: 100,
655
+ minlength: 0,
656
+ required: false,
657
+ type: String
658
+ },
659
+ test: {
660
+ max: 10,
661
+ min: 0,
662
+ required: false,
663
+ type: Number
664
+ }
665
+ });
666
+ });
667
+ it("should throw error with collection (Set of subdocument)", () => {
668
+ // GIVEN
669
+ enum MyEnum {
670
+ V1 = "v1",
671
+ V2 = "v2"
672
+ }
673
+
674
+ let actualError: any;
675
+ try {
676
+ @Schema()
677
+ class Children {
678
+ @Name("id")
679
+ _id: string;
680
+
681
+ @Minimum(0)
682
+ @Maximum(10)
683
+ test: number;
684
+
685
+ @MinLength(0)
686
+ @MaxLength(100)
687
+ @Pattern("pattern")
688
+ @Default("defaultValue")
689
+ name: string = "defaultValue";
690
+
691
+ @Enum(MyEnum)
692
+ enum: MyEnum;
693
+ }
694
+
695
+ class TestWithSet9 {
696
+ @CollectionOf(Children)
697
+ tests: Set<Children>;
698
+ }
699
+
700
+ getSchema(TestWithSet9);
701
+ } catch (er) {
702
+ actualError = er;
703
+ }
704
+
705
+ expect(actualError).toBeInstanceOf(Error);
706
+ expect(actualError.message).toBe("Invalid collection type. Set is not supported.");
707
+ });
708
+ it("should not create schema property for ignored field", () => {
709
+ @Model()
710
+ class Test10 {
711
+ @Property()
712
+ field: string;
713
+ @Property()
714
+ @SchemaIgnore()
715
+ kind: string;
716
+ }
717
+
718
+ const testSchema = getSchema(Test10);
719
+ expect(testSchema.obj).toEqual({
720
+ field: {
721
+ required: false,
722
+ type: String
723
+ }
724
+ });
725
+ });
726
+ it("should create schema with discriminator key", () => {
727
+ @Model()
728
+ class Test11 {
729
+ @DiscriminatorKey()
730
+ kind: string;
731
+ }
732
+ const testSchema = getSchema(Test11);
733
+ // @ts-ignore
734
+ const options = testSchema.options;
735
+
736
+ expect(options.discriminatorKey).toBe("kind");
737
+ });
738
+ it("should create schema with version key", () => {
739
+ @Model()
740
+ class Test12 {
741
+ @VersionKey()
742
+ version: number;
743
+ }
744
+ const testSchema = getSchema(Test12);
745
+ // @ts-ignore
746
+ const options = testSchema.options;
747
+
748
+ expect(options.versionKey).toBe("version");
749
+ });
750
+
751
+ it("should create json schema with virtual ref and count", () => {
752
+ // GIVEN
753
+ @Model()
754
+ class Children5 {
755
+ @Name("id")
756
+ _id: string;
757
+ }
758
+
759
+ @Model()
760
+ class Test13 {
761
+ @VirtualRef({ref: Children5, foreignField: "test13", count: true})
762
+ childrenCount: number;
763
+ }
764
+
765
+ // WHEN
766
+ const testSchema: any = getJsonSchema(Test13);
767
+
768
+ // THEN
769
+ expect(testSchema.properties.childrenCount.type).toEqual("number");
770
+ });
771
+ });