@tsofist/schema-forge 3.6.0 → 3.7.0

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;
@@ -4,14 +4,13 @@ const error_1 = require("@tsofist/stem/lib/error");
4
4
  const is_empty_1 = require("@tsofist/stem/lib/object/is-empty");
5
5
  const ts_json_schema_generator_1 = require("ts-json-schema-generator");
6
6
  const typescript_1 = require("typescript");
7
- const helpers_tsc_1 = require("./helpers-tsc");
8
7
  {
9
8
  // Support for @inheritDoc tag to enforce inheritance of annotations
9
+ // todo rework
10
10
  // eslint-disable-next-line @typescript-eslint/unbound-method
11
11
  const getAnnotations = ts_json_schema_generator_1.ExtendedAnnotationsReader.prototype.getAnnotations;
12
12
  ts_json_schema_generator_1.ExtendedAnnotationsReader.prototype.getAnnotations = function getAnnotationsWithInheritance(node) {
13
- if (!(0, helpers_tsc_1.hasJSDocTag)(node, 'inheritDoc'))
14
- return getAnnotations.call(this, node);
13
+ // if (!hasJSDocTag(node, 'inheritDoc')) return getAnnotations.call(this, node);
15
14
  // @ts-expect-error access to private property
16
15
  const checker = this.typeChecker || (0, error_1.raise)('TypeChecker is not available');
17
16
  const result = {};
@@ -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");
@@ -189,8 +190,9 @@ describe('generator for a6', () => {
189
190
  description: 'This is Collection item ID (inherits from UUID)',
190
191
  });
191
192
  expect(registry.getValidator('test#/definitions/CollectionItemID2').schema).toStrictEqual({
193
+ $ref: '#/definitions/UUID',
192
194
  format: 'uuid',
193
- type: 'string',
195
+ description: 'This is Collection item ID (non-inherits from UUID)',
194
196
  });
195
197
  {
196
198
  const rec = registry.getValidator('test#/definitions/PRec<CollectionItem,UUID>').schema;
@@ -248,11 +250,13 @@ describe('generator for a5', () => {
248
250
  'DomainNum',
249
251
  'DomainValue',
250
252
  'DomainValuesType',
253
+ 'FKColumn',
251
254
  'NT', // 'NamesType',
252
255
  'NamesTypeAbnormal',
253
256
  'NumN',
254
257
  'Nums',
255
258
  'Some',
259
+ 'UUID',
256
260
  'Variadic',
257
261
  'Variadic1',
258
262
  'VariadicList',
@@ -265,6 +269,12 @@ describe('generator for a5', () => {
265
269
  expect(registry.getValidator('test#/definitions/NamesTypeAbnormal').schema).toStrictEqual({
266
270
  type: 'string',
267
271
  });
272
+ expect(registry.getValidator('test#/definitions/FKColumn').schema).toStrictEqual({
273
+ $ref: '#/definitions/UUID',
274
+ dbFK: true,
275
+ description: 'Foreign Key Column Type.',
276
+ format: 'uuid',
277
+ });
268
278
  expect(registry.getValidator('test#/definitions/Some').schema).toStrictEqual({
269
279
  type: 'object',
270
280
  properties: {
@@ -333,6 +343,18 @@ describe('generator for a5', () => {
333
343
  ],
334
344
  type: 'number',
335
345
  },
346
+ ref0: {
347
+ $ref: '#/definitions/UUID',
348
+ dbFK: true,
349
+ description: 'Inline Foreign Key',
350
+ },
351
+ ref1: {
352
+ $ref: '#/definitions/FKColumn',
353
+ },
354
+ ref2: {
355
+ $ref: '#/definitions/FKColumn',
356
+ description: 'Inline Foreign Key (2)',
357
+ },
336
358
  },
337
359
  required: [
338
360
  'vals',
@@ -349,11 +371,35 @@ describe('generator for a5', () => {
349
371
  'indexedField2',
350
372
  'indexedField3',
351
373
  'indexedField4',
374
+ 'ref0',
375
+ 'ref1',
376
+ 'ref2',
352
377
  ],
353
378
  additionalProperties: false,
354
379
  dbEntity: 'cmn.some',
355
380
  });
356
381
  });
382
+ it('should works with dereferenced schema', () => {
383
+ const v = (0, dereference_1.dereferenceSchema)(registry.getRootSchema('test')).definitions['Some'];
384
+ expect(v.properties.ref0).toStrictEqual({
385
+ type: 'string',
386
+ format: 'uuid',
387
+ description: 'Inline Foreign Key',
388
+ dbFK: true,
389
+ });
390
+ expect(v.properties.ref1).toStrictEqual({
391
+ type: 'string',
392
+ format: 'uuid',
393
+ description: 'Foreign Key Column Type.',
394
+ dbFK: true,
395
+ });
396
+ expect(v.properties.ref2).toStrictEqual({
397
+ type: 'string',
398
+ format: 'uuid',
399
+ description: 'Inline Foreign Key (2)',
400
+ dbFK: true,
401
+ });
402
+ });
357
403
  });
358
404
  describe('generator for a4', () => {
359
405
  const outputSchemaFile = './a4.generated.schema.tmp.json';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tsofist/schema-forge",
3
- "version": "3.6.0",
3
+ "version": "3.7.0",
4
4
  "description": "Generate JSON schema from TypeScript types",
5
5
  "author": "Andrew Berdnikov <tsofistgudmen@gmail.com>",
6
6
  "license": "LGPL-3.0",