@tsofist/schema-forge 3.6.0 → 3.7.1
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.
|
@@ -38,19 +38,23 @@ function dereferenceSchema(raw, options = {}) {
|
|
|
38
38
|
}
|
|
39
39
|
return replacement;
|
|
40
40
|
}
|
|
41
|
-
if (seen.has(resolvedSchema))
|
|
42
|
-
return seen.get(resolvedSchema);
|
|
41
|
+
// if (seen.has(resolvedSchema)) return seen.get(resolvedSchema); // todo?
|
|
43
42
|
if (Array.isArray(resolvedSchema)) {
|
|
43
|
+
if (seen.has(resolvedSchema))
|
|
44
|
+
return seen.get(resolvedSchema);
|
|
44
45
|
const resolvedArray = resolve(resolvedSchema, current.$ref);
|
|
45
46
|
seen.set(resolvedSchema, resolvedArray);
|
|
46
47
|
return resolvedArray;
|
|
47
48
|
}
|
|
49
|
+
const { $ref, ...additionalProps } = current;
|
|
48
50
|
const placeholder = {};
|
|
49
51
|
seen.set(current, placeholder);
|
|
50
52
|
const result = {
|
|
51
53
|
...resolvedSchema,
|
|
52
54
|
...resolve(resolvedSchema, current.$ref),
|
|
55
|
+
...additionalProps,
|
|
53
56
|
};
|
|
57
|
+
delete result.$ref; // !
|
|
54
58
|
Object.assign(placeholder, result);
|
|
55
59
|
seen.set(resolvedSchema, result);
|
|
56
60
|
return result;
|
|
@@ -7,6 +7,7 @@ const typescript_1 = require("typescript");
|
|
|
7
7
|
const helpers_tsc_1 = require("./helpers-tsc");
|
|
8
8
|
{
|
|
9
9
|
// Support for @inheritDoc tag to enforce inheritance of annotations
|
|
10
|
+
// todo rework
|
|
10
11
|
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
11
12
|
const getAnnotations = ts_json_schema_generator_1.ExtendedAnnotationsReader.prototype.getAnnotations;
|
|
12
13
|
ts_json_schema_generator_1.ExtendedAnnotationsReader.prototype.getAnnotations = function getAnnotationsWithInheritance(node) {
|
|
@@ -8,6 +8,7 @@ const pick_1 = require("@tsofist/stem/lib/object/pick");
|
|
|
8
8
|
const artefacts_policy_1 = require("../artefacts-policy");
|
|
9
9
|
const types_1 = require("../definition-info/types");
|
|
10
10
|
const efc_1 = require("../efc");
|
|
11
|
+
const dereference_1 = require("../schema-dereference/dereference");
|
|
11
12
|
const loader_1 = require("../schema-registry/loader");
|
|
12
13
|
const registry_1 = require("../schema-registry/registry");
|
|
13
14
|
const forge_1 = require("./forge");
|
|
@@ -188,7 +189,32 @@ describe('generator for a6', () => {
|
|
|
188
189
|
format: 'uuid',
|
|
189
190
|
description: 'This is Collection item ID (inherits from UUID)',
|
|
190
191
|
});
|
|
191
|
-
expect(registry.
|
|
192
|
+
expect(registry.getSchema('test#/definitions/CollectionItemID2')).toStrictEqual({
|
|
193
|
+
$ref: '#/definitions/UUID',
|
|
194
|
+
description: 'This is Collection item ID (non-inherits from UUID)',
|
|
195
|
+
$comment: 'This is a comment for CollectionItemID2',
|
|
196
|
+
});
|
|
197
|
+
expect(registry.getSchema('test#/definitions/CollectionItemID3')).toStrictEqual({
|
|
198
|
+
format: 'uuid',
|
|
199
|
+
type: 'string',
|
|
200
|
+
});
|
|
201
|
+
expect(registry.getSchema('test#/definitions/CollectionItemID4')).toStrictEqual({
|
|
202
|
+
$ref: '#/definitions/UUID',
|
|
203
|
+
description: 'This is Collection item ID (non-inherits from UUID)',
|
|
204
|
+
format: 'uuid',
|
|
205
|
+
});
|
|
206
|
+
expect(registry.getSchema('test#/definitions/CollectionItemID6')).toStrictEqual({
|
|
207
|
+
$ref: '#/definitions/UUID',
|
|
208
|
+
description: 'This is Collection item ID (non-inherits from UUID)',
|
|
209
|
+
dbFK: true,
|
|
210
|
+
});
|
|
211
|
+
expect(registry.getSchema('test#/definitions/CollectionItemID7')).toStrictEqual({
|
|
212
|
+
$ref: '#/definitions/UUID',
|
|
213
|
+
description: 'This is Collection item ID (non-inherits from UUID)',
|
|
214
|
+
dbFK: true,
|
|
215
|
+
format: 'uuid',
|
|
216
|
+
});
|
|
217
|
+
expect(registry.getSchema('test#/definitions/CollectionItemID5')).toStrictEqual({
|
|
192
218
|
format: 'uuid',
|
|
193
219
|
type: 'string',
|
|
194
220
|
});
|
|
@@ -207,6 +233,31 @@ describe('generator for a6', () => {
|
|
|
207
233
|
description: 'This is Collection item ID (inherits from UUID)',
|
|
208
234
|
});
|
|
209
235
|
}
|
|
236
|
+
{
|
|
237
|
+
const rec = registry.getValidator('test#/definitions/Rec<number,CollectionItemID4>').schema;
|
|
238
|
+
expect(rec).toBeTruthy();
|
|
239
|
+
expect(rec.propertyNames).toStrictEqual({
|
|
240
|
+
format: 'uuid',
|
|
241
|
+
description: 'This is Collection item ID (non-inherits from UUID)',
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
{
|
|
245
|
+
const rec = registry.getValidator('test#/definitions/Rec<number,CollectionItemID6>').schema;
|
|
246
|
+
expect(rec).toBeTruthy();
|
|
247
|
+
expect(rec.propertyNames).toStrictEqual({
|
|
248
|
+
dbFK: true,
|
|
249
|
+
description: 'This is Collection item ID (non-inherits from UUID)',
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
{
|
|
253
|
+
const rec = registry.getValidator('test#/definitions/Rec<number,CollectionItemID7>').schema;
|
|
254
|
+
expect(rec).toBeTruthy();
|
|
255
|
+
expect(rec.propertyNames).toStrictEqual({
|
|
256
|
+
dbFK: true,
|
|
257
|
+
format: 'uuid',
|
|
258
|
+
description: 'This is Collection item ID (non-inherits from UUID)',
|
|
259
|
+
});
|
|
260
|
+
}
|
|
210
261
|
});
|
|
211
262
|
});
|
|
212
263
|
describe('generator for a5', () => {
|
|
@@ -248,11 +299,13 @@ describe('generator for a5', () => {
|
|
|
248
299
|
'DomainNum',
|
|
249
300
|
'DomainValue',
|
|
250
301
|
'DomainValuesType',
|
|
302
|
+
'FKColumn',
|
|
251
303
|
'NT', // 'NamesType',
|
|
252
304
|
'NamesTypeAbnormal',
|
|
253
305
|
'NumN',
|
|
254
306
|
'Nums',
|
|
255
307
|
'Some',
|
|
308
|
+
'UUID',
|
|
256
309
|
'Variadic',
|
|
257
310
|
'Variadic1',
|
|
258
311
|
'VariadicList',
|
|
@@ -265,6 +318,12 @@ describe('generator for a5', () => {
|
|
|
265
318
|
expect(registry.getValidator('test#/definitions/NamesTypeAbnormal').schema).toStrictEqual({
|
|
266
319
|
type: 'string',
|
|
267
320
|
});
|
|
321
|
+
expect(registry.getValidator('test#/definitions/FKColumn').schema).toStrictEqual({
|
|
322
|
+
$ref: '#/definitions/UUID',
|
|
323
|
+
dbFK: true,
|
|
324
|
+
description: 'Foreign Key Column Type.',
|
|
325
|
+
// format: 'uuid',
|
|
326
|
+
});
|
|
268
327
|
expect(registry.getValidator('test#/definitions/Some').schema).toStrictEqual({
|
|
269
328
|
type: 'object',
|
|
270
329
|
properties: {
|
|
@@ -333,6 +392,18 @@ describe('generator for a5', () => {
|
|
|
333
392
|
],
|
|
334
393
|
type: 'number',
|
|
335
394
|
},
|
|
395
|
+
ref0: {
|
|
396
|
+
$ref: '#/definitions/UUID',
|
|
397
|
+
dbFK: true,
|
|
398
|
+
description: 'Inline Foreign Key',
|
|
399
|
+
},
|
|
400
|
+
ref1: {
|
|
401
|
+
$ref: '#/definitions/FKColumn',
|
|
402
|
+
},
|
|
403
|
+
ref2: {
|
|
404
|
+
$ref: '#/definitions/FKColumn',
|
|
405
|
+
description: 'Inline Foreign Key (2)',
|
|
406
|
+
},
|
|
336
407
|
},
|
|
337
408
|
required: [
|
|
338
409
|
'vals',
|
|
@@ -349,11 +420,35 @@ describe('generator for a5', () => {
|
|
|
349
420
|
'indexedField2',
|
|
350
421
|
'indexedField3',
|
|
351
422
|
'indexedField4',
|
|
423
|
+
'ref0',
|
|
424
|
+
'ref1',
|
|
425
|
+
'ref2',
|
|
352
426
|
],
|
|
353
427
|
additionalProperties: false,
|
|
354
428
|
dbEntity: 'cmn.some',
|
|
355
429
|
});
|
|
356
430
|
});
|
|
431
|
+
it('should works with dereferenced schema', () => {
|
|
432
|
+
const v = (0, dereference_1.dereferenceSchema)(registry.getRootSchema('test')).definitions['Some'];
|
|
433
|
+
expect(v.properties.ref0).toStrictEqual({
|
|
434
|
+
type: 'string',
|
|
435
|
+
format: 'uuid',
|
|
436
|
+
description: 'Inline Foreign Key',
|
|
437
|
+
dbFK: true,
|
|
438
|
+
});
|
|
439
|
+
expect(v.properties.ref1).toStrictEqual({
|
|
440
|
+
type: 'string',
|
|
441
|
+
format: 'uuid',
|
|
442
|
+
description: 'Foreign Key Column Type.',
|
|
443
|
+
dbFK: true,
|
|
444
|
+
});
|
|
445
|
+
expect(v.properties.ref2).toStrictEqual({
|
|
446
|
+
type: 'string',
|
|
447
|
+
format: 'uuid',
|
|
448
|
+
description: 'Inline Foreign Key (2)',
|
|
449
|
+
dbFK: true,
|
|
450
|
+
});
|
|
451
|
+
});
|
|
357
452
|
});
|
|
358
453
|
describe('generator for a4', () => {
|
|
359
454
|
const outputSchemaFile = './a4.generated.schema.tmp.json';
|