@tsofist/schema-forge 3.7.0 → 4.0.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.
Files changed (48) hide show
  1. package/lib/dbml-generator/generator.spec.js +13 -2
  2. package/lib/dbml-generator/types.d.ts +7 -1
  3. package/lib/dbml-generator/types.d.ts.map +1 -1
  4. package/lib/definition-info/guards.d.ts +7 -1
  5. package/lib/definition-info/guards.d.ts.map +1 -1
  6. package/lib/definition-info/guards.js +20 -0
  7. package/lib/definition-info/parser.d.ts +1 -1
  8. package/lib/definition-info/parser.d.ts.map +1 -1
  9. package/lib/definition-info/parser.js +10 -10
  10. package/lib/fake-generator/generator-host.d.ts.map +1 -1
  11. package/lib/fake-generator/generator-host.js +2 -1
  12. package/lib/schema-dereference/dereference.d.ts.map +1 -1
  13. package/lib/schema-dereference/dereference.js +7 -2
  14. package/lib/schema-dereference/types.d.ts +13 -0
  15. package/lib/schema-dereference/types.d.ts.map +1 -1
  16. package/lib/schema-generator/extended-annotations-reader.js +3 -1
  17. package/lib/schema-generator/forge.spec.js +96 -7
  18. package/lib/schema-generator/generate-drafts.d.ts.map +1 -1
  19. package/lib/schema-generator/generate-drafts.js +1 -0
  20. package/lib/schema-generator/generate-schema.d.ts +1 -1
  21. package/lib/schema-generator/generate-schema.d.ts.map +1 -1
  22. package/lib/schema-generator/generate-schema.js +65 -5
  23. package/lib/schema-generator/helpers-tsc.d.ts +2 -0
  24. package/lib/schema-generator/helpers-tsc.d.ts.map +1 -1
  25. package/lib/schema-generator/helpers-tsc.js +18 -1
  26. package/lib/schema-generator/patch-enum-node-parser.d.ts +12 -0
  27. package/lib/schema-generator/patch-enum-node-parser.d.ts.map +1 -0
  28. package/lib/schema-generator/patch-enum-node-parser.js +54 -0
  29. package/lib/schema-generator/shrink-definition-name.d.ts +2 -2
  30. package/lib/schema-generator/shrink-definition-name.d.ts.map +1 -1
  31. package/lib/schema-generator/shrink-definition-name.js +2 -2
  32. package/lib/schema-generator/types.d.ts +8 -7
  33. package/lib/schema-generator/types.d.ts.map +1 -1
  34. package/lib/schema-generator/types.js +31 -21
  35. package/lib/schema-registry/kw-api.d.ts.map +1 -1
  36. package/lib/schema-registry/kw-api.js +4 -4
  37. package/lib/schema-registry/kw-common.d.ts.map +1 -1
  38. package/lib/schema-registry/kw-common.js +44 -0
  39. package/lib/schema-registry/kw-dbml.d.ts +1 -1
  40. package/lib/schema-registry/kw-dbml.d.ts.map +1 -1
  41. package/lib/schema-registry/kw-dbml.js +6 -2
  42. package/lib/schema-registry/registry.d.ts.map +1 -1
  43. package/lib/schema-registry/registry.js +5 -2
  44. package/lib/schema-registry/types.d.ts +3 -3
  45. package/lib/schema-registry/types.d.ts.map +1 -1
  46. package/lib/types.d.ts +25 -15
  47. package/lib/types.d.ts.map +1 -1
  48. package/package.json +4 -4
@@ -16,7 +16,7 @@ describe('DBML Generator', () => {
16
16
  let registry;
17
17
  beforeAll(async () => {
18
18
  forgeSchemaResult = await (0, forge_1.forgeSchema)({
19
- allowUseFallbackDescription: false,
19
+ allowUseFallbackDescription: true,
20
20
  explicitPublic: true,
21
21
  schemaId,
22
22
  tsconfigFrom: './tsconfig.build-test.json',
@@ -39,7 +39,18 @@ describe('DBML Generator', () => {
39
39
  expect(forgeSchemaResult).toBeTruthy();
40
40
  expect(forgeSchemaResult.schema.$id).toStrictEqual(schemaId);
41
41
  expect(forgeSchemaResult.generatedTemporaryFiles.length).toStrictEqual(1);
42
- expect(forgeSchemaResult.refs.length).toStrictEqual(13);
42
+ expect(forgeSchemaResult.refs.length).toStrictEqual(18);
43
+ });
44
+ describe('enums', () => {
45
+ it('should generate dbEnum definitions', () => {
46
+ const definitions = registry.listDefinitions((_info, keywords) => {
47
+ return keywords.has('dbEnum');
48
+ });
49
+ const list = definitions.map((def) => {
50
+ return registry.getSchema(def.ref);
51
+ });
52
+ expect(list).toMatchSnapshot();
53
+ });
43
54
  });
44
55
  it('basic cases', () => {
45
56
  const definitions = registry.listDefinitions((info, keywords) => {
@@ -1,4 +1,4 @@
1
- import type { ArrayMay, HexString } from '@tsofist/stem';
1
+ import type { ArrayMay, HexString, PRec } from '@tsofist/stem';
2
2
  import type { SchemaDefinitionInfoForType } from '../definition-info/types';
3
3
  /**
4
4
  * DBML Project Source
@@ -144,4 +144,10 @@ export type DBMLColumnOptions = {
144
144
  */
145
145
  type?: DBMLColumnType;
146
146
  };
147
+ export type DBMLEnumOptionsDef = boolean | string;
148
+ export type DBMLEnumAnnotationOptions = PRec<[
149
+ /** 0 */ value: string | number,
150
+ /** 1 */ note?: string,
151
+ /** 2 */ comment?: string
152
+ ]>;
147
153
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/dbml-generator/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AACzD,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,0BAA0B,CAAC;AAE5E;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC7B,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,2BAA2B,EAAE,CAAC;IAC3C,OAAO,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACjC,IAAI,CAAC,EAAE,eAAe,CAAC;IAIvB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;CAc3B;AAED;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,6DAQpB,CAAC;AAEX;;GAEG;AACH,eAAO,MAAM,kBAAkB,+ZAk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AAkB,GAAG,OAAO,GAAG,MAAM,CAAC;AAElD,MAAM,MAAM,yBAAyB,GAAG,IAAI,CACxC;IAEI,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM;IAC/B,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM;IACtB,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM;CAC5B,CACJ,CAAC"}
@@ -1,6 +1,12 @@
1
- import { APIInterfaceSDS, APIMemberSDS, APIMethodArgsSDS, APIMethodResultSDS } from './types';
1
+ import type { ForgedSchemaDefinitionShortName } from '../types';
2
+ import { APIInterfaceSDS, APIMemberSDS, APIMethodArgsSDS, APIMethodResultSDS, SchemaDefinitionInfo, SchemaDefinitionInfoForAPIInterface, SchemaDefinitionInfoForAPIMethodArguments, SchemaDefinitionInfoForAPIMethodResult, SchemaDefinitionInfoForType } from './types';
2
3
  export declare function isAPIDefinitionName(definitionName: string): definitionName is APIInterfaceSDS;
3
4
  export declare function isAPIMemberDefinitionName(definitionName: string): definitionName is APIMemberSDS;
4
5
  export declare function isAPIMethodArgsDefinitionName(definitionName: string): definitionName is APIMethodArgsSDS;
5
6
  export declare function isAPIMethodResultDefinitionName(definitionName: string): definitionName is APIMethodResultSDS;
7
+ export declare function isSchemaDefinitionForType(value: SchemaDefinitionInfo): value is SchemaDefinitionInfoForType;
8
+ export declare function isSchemaDefinitionForAPIInterface(value: SchemaDefinitionInfo): value is SchemaDefinitionInfoForAPIInterface;
9
+ export declare function isSchemaDefinitionForAPIMethodArguments(value: SchemaDefinitionInfo): value is SchemaDefinitionInfoForAPIMethodArguments;
10
+ export declare function isSchemaDefinitionForAPIMethodResult(value: SchemaDefinitionInfo): value is SchemaDefinitionInfoForAPIMethodResult;
11
+ export declare function isSchemaDefinitionShortName(name: string): name is ForgedSchemaDefinitionShortName;
6
12
  //# sourceMappingURL=guards.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"guards.d.ts","sourceRoot":"","sources":["../../src/definition-info/guards.ts"],"names":[],"mappings":"AAAA,OAAO,EAIH,eAAe,EACf,YAAY,EACZ,gBAAgB,EAChB,kBAAkB,EAKrB,MAAM,SAAS,CAAC;AAEjB,wBAAgB,mBAAmB,CAAC,cAAc,EAAE,MAAM,GAAG,cAAc,IAAI,eAAe,CAE7F;AAED,wBAAgB,yBAAyB,CAAC,cAAc,EAAE,MAAM,GAAG,cAAc,IAAI,YAAY,CAEhG;AAED,wBAAgB,6BAA6B,CACzC,cAAc,EAAE,MAAM,GACvB,cAAc,IAAI,gBAAgB,CAKpC;AAED,wBAAgB,+BAA+B,CAC3C,cAAc,EAAE,MAAM,GACvB,cAAc,IAAI,kBAAkB,CAKtC"}
1
+ {"version":3,"file":"guards.d.ts","sourceRoot":"","sources":["../../src/definition-info/guards.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,+BAA+B,EAAE,MAAM,UAAU,CAAC;AAChE,OAAO,EAIH,eAAe,EACf,YAAY,EACZ,gBAAgB,EAChB,kBAAkB,EAClB,oBAAoB,EACpB,mCAAmC,EACnC,yCAAyC,EACzC,sCAAsC,EACtC,2BAA2B,EAM9B,MAAM,SAAS,CAAC;AAEjB,wBAAgB,mBAAmB,CAAC,cAAc,EAAE,MAAM,GAAG,cAAc,IAAI,eAAe,CAE7F;AAED,wBAAgB,yBAAyB,CAAC,cAAc,EAAE,MAAM,GAAG,cAAc,IAAI,YAAY,CAEhG;AAED,wBAAgB,6BAA6B,CACzC,cAAc,EAAE,MAAM,GACvB,cAAc,IAAI,gBAAgB,CAKpC;AAED,wBAAgB,+BAA+B,CAC3C,cAAc,EAAE,MAAM,GACvB,cAAc,IAAI,kBAAkB,CAKtC;AAED,wBAAgB,yBAAyB,CACrC,KAAK,EAAE,oBAAoB,GAC5B,KAAK,IAAI,2BAA2B,CAEtC;AAED,wBAAgB,iCAAiC,CAC7C,KAAK,EAAE,oBAAoB,GAC5B,KAAK,IAAI,mCAAmC,CAE9C;AAED,wBAAgB,uCAAuC,CACnD,KAAK,EAAE,oBAAoB,GAC5B,KAAK,IAAI,yCAAyC,CAEpD;AAED,wBAAgB,oCAAoC,CAChD,KAAK,EAAE,oBAAoB,GAC5B,KAAK,IAAI,sCAAsC,CAEjD;AAED,wBAAgB,2BAA2B,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,IAAI,+BAA+B,CAEjG"}
@@ -4,6 +4,11 @@ exports.isAPIDefinitionName = isAPIDefinitionName;
4
4
  exports.isAPIMemberDefinitionName = isAPIMemberDefinitionName;
5
5
  exports.isAPIMethodArgsDefinitionName = isAPIMethodArgsDefinitionName;
6
6
  exports.isAPIMethodResultDefinitionName = isAPIMethodResultDefinitionName;
7
+ exports.isSchemaDefinitionForType = isSchemaDefinitionForType;
8
+ exports.isSchemaDefinitionForAPIInterface = isSchemaDefinitionForAPIInterface;
9
+ exports.isSchemaDefinitionForAPIMethodArguments = isSchemaDefinitionForAPIMethodArguments;
10
+ exports.isSchemaDefinitionForAPIMethodResult = isSchemaDefinitionForAPIMethodResult;
11
+ exports.isSchemaDefinitionShortName = isSchemaDefinitionShortName;
7
12
  const types_1 = require("./types");
8
13
  function isAPIDefinitionName(definitionName) {
9
14
  return definitionName.endsWith(types_1.SDS_SUFFIX_API) || definitionName.endsWith(types_1._SDS_SUFFIX_API);
@@ -19,3 +24,18 @@ function isAPIMethodResultDefinitionName(definitionName) {
19
24
  return (definitionName.endsWith(types_1.SDS_SUFFIX_METHOD_RES) ||
20
25
  definitionName.endsWith(types_1._SDS_SUFFIX_METHOD_RES));
21
26
  }
27
+ function isSchemaDefinitionForType(value) {
28
+ return value.kind === types_1.SchemaDefinitionInfoKind.Type;
29
+ }
30
+ function isSchemaDefinitionForAPIInterface(value) {
31
+ return value.kind === types_1.SchemaDefinitionInfoKind.API;
32
+ }
33
+ function isSchemaDefinitionForAPIMethodArguments(value) {
34
+ return value.kind === types_1.SchemaDefinitionInfoKind.APIMethodArguments;
35
+ }
36
+ function isSchemaDefinitionForAPIMethodResult(value) {
37
+ return value.kind === types_1.SchemaDefinitionInfoKind.APIMethodResult;
38
+ }
39
+ function isSchemaDefinitionShortName(name) {
40
+ return name.startsWith('DSN') && name.includes('_H');
41
+ }
@@ -1,3 +1,3 @@
1
1
  import { type SchemaDefinitionInfo } from './types';
2
- export declare function parseSchemaDefinitionInfo(definitionName: string, schemaId: string, legacy?: boolean): SchemaDefinitionInfo;
2
+ export declare function parseSchemaDefinitionInfo<T extends SchemaDefinitionInfo>(definitionName: string, schemaId: string, legacy?: boolean): T;
3
3
  //# sourceMappingURL=parser.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"parser.d.ts","sourceRoot":"","sources":["../../src/definition-info/parser.ts"],"names":[],"mappings":"AAOA,OAAO,EAEH,KAAK,oBAAoB,EAG5B,MAAM,SAAS,CAAC;AAEjB,wBAAgB,yBAAyB,CACrC,cAAc,EAAE,MAAM,EACtB,QAAQ,EAAE,MAAM,EAChB,MAAM,UAAQ,GACf,oBAAoB,CAsCtB"}
1
+ {"version":3,"file":"parser.d.ts","sourceRoot":"","sources":["../../src/definition-info/parser.ts"],"names":[],"mappings":"AAOA,OAAO,EAEH,KAAK,oBAAoB,EAG5B,MAAM,SAAS,CAAC;AAEjB,wBAAgB,yBAAyB,CAAC,CAAC,SAAS,oBAAoB,EACpE,cAAc,EAAE,MAAM,EACtB,QAAQ,EAAE,MAAM,EAChB,MAAM,CAAC,EAAE,OAAO,GACjB,CAAC,CAAC"}
@@ -15,31 +15,31 @@ function parseSchemaDefinitionInfo(definitionName, schemaId, legacy = false) {
15
15
  : types_1.SchemaDefinitionInfoKind.Type;
16
16
  const ref = (0, ref_1.buildSchemaDefinitionRef)(definitionName, schemaId);
17
17
  switch (kind) {
18
- case types_1.SchemaDefinitionInfoKind.API:
18
+ case types_1.SchemaDefinitionInfoKind.Type:
19
19
  return {
20
20
  ref,
21
- kind,
22
- name: definitionName,
23
21
  schemaId,
24
- interface: (0, substr_1.substr)(definitionName, 0, legacy ? types_1._SDS_SUFFIX_API : types_1.SDS_SUFFIX_API),
22
+ name: definitionName,
23
+ kind,
24
+ type: definitionName,
25
25
  };
26
26
  case types_1.SchemaDefinitionInfoKind.APIMethodArguments:
27
27
  case types_1.SchemaDefinitionInfoKind.APIMethodResult:
28
28
  return {
29
29
  ref,
30
- kind,
31
- name: definitionName,
32
30
  schemaId,
31
+ name: definitionName,
32
+ kind,
33
33
  interface: (0, substr_1.substr)(definitionName, 0, '_'),
34
34
  method: (0, substr_1.substr)(definitionName, '_', '_'),
35
35
  };
36
- case types_1.SchemaDefinitionInfoKind.Type:
36
+ case types_1.SchemaDefinitionInfoKind.API:
37
37
  return {
38
38
  ref,
39
- kind,
40
- name: definitionName,
41
39
  schemaId,
42
- type: definitionName,
40
+ name: definitionName,
41
+ kind,
42
+ interface: (0, substr_1.substr)(definitionName, 0, legacy ? types_1._SDS_SUFFIX_API : types_1.SDS_SUFFIX_API),
43
43
  };
44
44
  }
45
45
  }
@@ -1 +1 @@
1
- {"version":3,"file":"generator-host.d.ts","sourceRoot":"","sources":["../../src/fake-generator/generator-host.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAEpE,OAAO,KAAK,EAAE,iBAAiB,EAA2B,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAEhG,wBAAgB,uBAAuB,CACnC,MAAM,EAAE,mBAAmB,EAC3B,OAAO,GAAE,oBAAyB,GACnC,iBAAiB,CA4CnB"}
1
+ {"version":3,"file":"generator-host.d.ts","sourceRoot":"","sources":["../../src/fake-generator/generator-host.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAEpE,OAAO,KAAK,EAAE,iBAAiB,EAA2B,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAEhG,wBAAgB,uBAAuB,CACnC,MAAM,EAAE,mBAAmB,EAC3B,OAAO,GAAE,oBAAyB,GACnC,iBAAiB,CA4CnB"}
@@ -4,6 +4,7 @@ exports.createFakeGeneratorHost = createFakeGeneratorHost;
4
4
  const fakerModule = require("@faker-js/faker");
5
5
  const as_array_1 = require("@tsofist/stem/lib/as-array");
6
6
  const json_schema_faker_1 = require("json-schema-faker");
7
+ const types_1 = require("../schema-generator/types");
7
8
  const modules_1 = require("./modules");
8
9
  function createFakeGeneratorHost(source, options = {}) {
9
10
  const rebuild = () => {
@@ -28,7 +29,7 @@ function createFakeGeneratorHost(source, options = {}) {
28
29
  generator.option({
29
30
  alwaysFakeOptionals: true,
30
31
  refDepthMax: 1_000,
31
- pruneProperties: ['dbEntity', 'dbIndex', 'dbColumn', 'dbFK'],
32
+ pruneProperties: types_1.SFG_EXTRA_TAGS.filter((name) => name.startsWith('db')),
32
33
  ...options,
33
34
  resolveJsonPath: false,
34
35
  });
@@ -1 +1 @@
1
- {"version":3,"file":"dereference.d.ts","sourceRoot":"","sources":["../../src/schema-dereference/dereference.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE/C,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,SAAS,CAAC;AAE7D;;;;GAIG;AACH,wBAAgB,iBAAiB,CAC7B,MAAM,EAAE,WAAW,EACnB,OAAO,CAAC,EAAE,6BAA6B,GACxC,WAAW,GAAG,SAAS,CAAC"}
1
+ {"version":3,"file":"dereference.d.ts","sourceRoot":"","sources":["../../src/schema-dereference/dereference.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAG/C,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,SAAS,CAAC;AAE7D;;;;GAIG;AACH,wBAAgB,iBAAiB,CAC7B,MAAM,EAAE,WAAW,EACnB,OAAO,CAAC,EAAE,6BAA6B,GACxC,WAAW,GAAG,SAAS,CAAC"}
@@ -10,7 +10,8 @@ function dereferenceSchema(raw, options = {}) {
10
10
  return cache.main.get(raw);
11
11
  const schema = structuredClone(raw);
12
12
  const seen = new WeakMap();
13
- const { throwOnDereferenceFailure = true, onDereferenceFailure } = options;
13
+ const seenRefs = new Set();
14
+ const { throwOnDereferenceFailure = true, onDereferenceFailure, onDereferenceSuccess, definitionsSource = schema, } = options;
14
15
  function resolve(current, path) {
15
16
  if (current == undefined || typeof current !== 'object')
16
17
  return current;
@@ -25,7 +26,7 @@ function dereferenceSchema(raw, options = {}) {
25
26
  }
26
27
  // $ref
27
28
  if ('$ref' in current && typeof current.$ref === 'string') {
28
- const resolvedSchema = resolveRef(cache, schema, current.$ref);
29
+ const resolvedSchema = resolveRef(cache, definitionsSource, current.$ref);
29
30
  if (resolvedSchema == null) {
30
31
  const replacement = onDereferenceFailure && !throwOnDereferenceFailure
31
32
  ? onDereferenceFailure(current.$ref, current, schema)
@@ -57,6 +58,10 @@ function dereferenceSchema(raw, options = {}) {
57
58
  delete result.$ref; // !
58
59
  Object.assign(placeholder, result);
59
60
  seen.set(resolvedSchema, result);
61
+ if (onDereferenceSuccess != null && !seenRefs.has($ref)) {
62
+ seenRefs.add($ref);
63
+ onDereferenceSuccess($ref, result);
64
+ }
60
65
  return result;
61
66
  }
62
67
  // Objects
@@ -1,6 +1,12 @@
1
+ import type { DeepReadonly } from '@tsofist/stem';
1
2
  import type { JSONSchema7 } from 'json-schema';
3
+ import type { ForgedSchema, SchemaForgeDefinitionRef } from '../types';
2
4
  import type { SchemaDereferenceSharedCache } from './cache';
3
5
  export interface SchemaForgeDereferenceOptions {
6
+ /**
7
+ * Handler called when a reference is successfully dereferenced.
8
+ */
9
+ onDereferenceSuccess?: (resolvedRef: SchemaForgeDefinitionRef, resolvedNode: DeepReadonly<JSONSchema7>) => void;
4
10
  /**
5
11
  * Handler called when dereferencing fails.
6
12
  *
@@ -29,6 +35,13 @@ export interface SchemaForgeDereferenceOptions {
29
35
  * @default DefaultSchemaDereferenceSharedCache
30
36
  */
31
37
  sharedCacheStorage?: SchemaDereferenceSharedCache;
38
+ /**
39
+ * Source of definitions for resolving $ref references.
40
+ * If not provided, the definitions from the root schema will be used.
41
+ *
42
+ * @see ForgedSchema
43
+ */
44
+ definitionsSource?: ForgedSchema | JSONSchema7;
32
45
  }
33
46
  export type SchemaForgeDereferenceFailureHandler = (unresolvedRef: string, currentNode: JSONSchema7, resultSchema: JSONSchema7) => JSONSchema7 | undefined;
34
47
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/schema-dereference/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,SAAS,CAAC;AAE5D,MAAM,WAAW,6BAA6B;IAC1C;;;;;;OAMG;IACH,oBAAoB,CAAC,EAAE,oCAAoC,CAAC;IAC5D;;;;;;;;;OASG;IACH,yBAAyB,CAAC,EAAE,OAAO,CAAC;IACpC;;;;;;;OAOG;IACH,kBAAkB,CAAC,EAAE,4BAA4B,CAAC;CACrD;AAED,MAAM,MAAM,oCAAoC,GAAG,CAC/C,aAAa,EAAE,MAAM,EACrB,WAAW,EAAE,WAAW,EACxB,YAAY,EAAE,WAAW,KACxB,WAAW,GAAG,SAAS,CAAC"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/schema-dereference/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAClD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,KAAK,EAAE,YAAY,EAAE,wBAAwB,EAAE,MAAM,UAAU,CAAC;AACvE,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,SAAS,CAAC;AAE5D,MAAM,WAAW,6BAA6B;IAC1C;;OAEG;IACH,oBAAoB,CAAC,EAAE,CACnB,WAAW,EAAE,wBAAwB,EACrC,YAAY,EAAE,YAAY,CAAC,WAAW,CAAC,KACtC,IAAI,CAAC;IACV;;;;;;OAMG;IACH,oBAAoB,CAAC,EAAE,oCAAoC,CAAC;IAC5D;;;;;;;;;OASG;IACH,yBAAyB,CAAC,EAAE,OAAO,CAAC;IACpC;;;;;;;OAOG;IACH,kBAAkB,CAAC,EAAE,4BAA4B,CAAC;IAClD;;;;;OAKG;IACH,iBAAiB,CAAC,EAAE,YAAY,GAAG,WAAW,CAAC;CAClD;AAED,MAAM,MAAM,oCAAoC,GAAG,CAC/C,aAAa,EAAE,MAAM,EACrB,WAAW,EAAE,WAAW,EACxB,YAAY,EAAE,WAAW,KACxB,WAAW,GAAG,SAAS,CAAC"}
@@ -4,13 +4,15 @@ 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");
7
8
  {
8
9
  // Support for @inheritDoc tag to enforce inheritance of annotations
9
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) {
13
- // if (!hasJSDocTag(node, 'inheritDoc')) return getAnnotations.call(this, node);
14
+ if (!(0, helpers_tsc_1.hasJSDocTag)(node, 'inheritDoc'))
15
+ return getAnnotations.call(this, node);
14
16
  // @ts-expect-error access to private property
15
17
  const checker = this.typeChecker || (0, error_1.raise)('TypeChecker is not available');
16
18
  const result = {};
@@ -14,6 +14,38 @@ const registry_1 = require("../schema-registry/registry");
14
14
  const forge_1 = require("./forge");
15
15
  /* eslint-disable @typescript-eslint/no-unsafe-argument */
16
16
  /* eslint-disable @typescript-eslint/no-unsafe-member-access */
17
+ describe('validator for a9', () => {
18
+ const outputSchemaFile = './a9.generated.schema.tmp.json';
19
+ const outputSchemaMetadataFile = './a9.generated.definitions.tmp.json';
20
+ let registry;
21
+ let loadedSchema;
22
+ beforeAll(async () => {
23
+ await (0, forge_1.forgeSchema)({
24
+ schemaId: 'test',
25
+ allowUseFallbackDescription: true,
26
+ tsconfigFrom: './tsconfig.build-test.json',
27
+ sourcesDirectoryPattern: 'test-sources/a9',
28
+ sourcesFilesPattern: ['service-api.ts', 'types.ts'],
29
+ outputSchemaFile,
30
+ outputSchemaMetadataFile,
31
+ expose: 'export',
32
+ explicitPublic: true,
33
+ });
34
+ registry = (0, registry_1.createSchemaForgeRegistry)();
35
+ loadedSchema = await (0, loader_1.loadJSONSchema)([outputSchemaFile]);
36
+ registry.addSchema(loadedSchema);
37
+ });
38
+ afterAll(async () => {
39
+ if (!artefacts_policy_1.KEEP_SPEC_ARTEFACTS) {
40
+ await (0, promises_1.unlink)(outputSchemaFile).catch(noop_1.noop);
41
+ await (0, promises_1.unlink)(outputSchemaMetadataFile).catch(noop_1.noop);
42
+ }
43
+ });
44
+ it('schema should be generated correctly with enums', () => {
45
+ const schema = registry.getRootSchema('test');
46
+ expect(schema).toMatchSnapshot();
47
+ });
48
+ });
17
49
  describe('generator for a8', () => {
18
50
  const outputSchemaFile = './a8.generated.schema.tmp.json';
19
51
  const outputSchemaMetadataFile = './a8.generated.definitions.tmp.json';
@@ -188,17 +220,45 @@ describe('generator for a6', () => {
188
220
  $ref: '#/definitions/UUID',
189
221
  format: 'uuid',
190
222
  description: 'This is Collection item ID (inherits from UUID)',
223
+ // see: 'https://ru.wikipedia.org/wiki/UUID Wikipedia',
224
+ });
225
+ expect(registry.getSchema('test#/definitions/CollectionItemID2')).toStrictEqual({
226
+ $ref: '#/definitions/UUID',
227
+ description: 'This is Collection item ID (non-inherits from UUID)',
228
+ $comment: 'This is a comment for CollectionItemID2',
229
+ });
230
+ expect(registry.getSchema('test#/definitions/CollectionItemID3')).toStrictEqual({
231
+ format: 'uuid',
232
+ type: 'string',
233
+ // see: 'https://ru.wikipedia.org/wiki/UUID Wikipedia',
191
234
  });
192
- expect(registry.getValidator('test#/definitions/CollectionItemID2').schema).toStrictEqual({
235
+ expect(registry.getSchema('test#/definitions/CollectionItemID4')).toStrictEqual({
193
236
  $ref: '#/definitions/UUID',
237
+ description: 'This is Collection item ID (non-inherits from UUID)',
194
238
  format: 'uuid',
239
+ });
240
+ expect(registry.getSchema('test#/definitions/CollectionItemID6')).toStrictEqual({
241
+ $ref: '#/definitions/UUID',
195
242
  description: 'This is Collection item ID (non-inherits from UUID)',
243
+ dbFK: true,
244
+ });
245
+ expect(registry.getSchema('test#/definitions/CollectionItemID7')).toStrictEqual({
246
+ $ref: '#/definitions/UUID',
247
+ description: 'This is Collection item ID (non-inherits from UUID)',
248
+ dbFK: true,
249
+ format: 'uuid',
250
+ });
251
+ expect(registry.getSchema('test#/definitions/CollectionItemID5')).toStrictEqual({
252
+ format: 'uuid',
253
+ type: 'string',
254
+ // see: 'https://ru.wikipedia.org/wiki/UUID Wikipedia',
196
255
  });
197
256
  {
198
257
  const rec = registry.getValidator('test#/definitions/PRec<CollectionItem,UUID>').schema;
199
258
  expect(rec).toBeTruthy();
200
259
  expect(rec.propertyNames).toStrictEqual({
201
260
  format: 'uuid',
261
+ // see: 'https://ru.wikipedia.org/wiki/UUID Wikipedia',
202
262
  });
203
263
  }
204
264
  {
@@ -207,6 +267,32 @@ describe('generator for a6', () => {
207
267
  expect(rec.propertyNames).toStrictEqual({
208
268
  format: 'uuid',
209
269
  description: 'This is Collection item ID (inherits from UUID)',
270
+ // see: 'https://ru.wikipedia.org/wiki/UUID Wikipedia',
271
+ });
272
+ }
273
+ {
274
+ const rec = registry.getValidator('test#/definitions/Rec<number,CollectionItemID4>').schema;
275
+ expect(rec).toBeTruthy();
276
+ expect(rec.propertyNames).toStrictEqual({
277
+ format: 'uuid',
278
+ description: 'This is Collection item ID (non-inherits from UUID)',
279
+ });
280
+ }
281
+ {
282
+ const rec = registry.getValidator('test#/definitions/Rec<number,CollectionItemID6>').schema;
283
+ expect(rec).toBeTruthy();
284
+ expect(rec.propertyNames).toStrictEqual({
285
+ dbFK: true,
286
+ description: 'This is Collection item ID (non-inherits from UUID)',
287
+ });
288
+ }
289
+ {
290
+ const rec = registry.getValidator('test#/definitions/Rec<number,CollectionItemID7>').schema;
291
+ expect(rec).toBeTruthy();
292
+ expect(rec.propertyNames).toStrictEqual({
293
+ dbFK: true,
294
+ format: 'uuid',
295
+ description: 'This is Collection item ID (non-inherits from UUID)',
210
296
  });
211
297
  }
212
298
  });
@@ -228,7 +314,7 @@ describe('generator for a5', () => {
228
314
  explicitPublic: true,
229
315
  shrinkDefinitionNames: (definitionName) => {
230
316
  if (definitionName === 'NamesType')
231
- return 'NT';
317
+ return 'DSN_H';
232
318
  return undefined;
233
319
  },
234
320
  });
@@ -247,11 +333,11 @@ describe('generator for a5', () => {
247
333
  const defs = forgeSchemaResult?.schema?.definitions;
248
334
  expect(defs).toBeTruthy();
249
335
  expect((0, keys_1.keysOf)(defs)).toStrictEqual([
336
+ 'DSN_H', // 'NamesType',
250
337
  'DomainNum',
251
338
  'DomainValue',
252
339
  'DomainValuesType',
253
340
  'FKColumn',
254
- 'NT', // 'NamesType',
255
341
  'NamesTypeAbnormal',
256
342
  'NumN',
257
343
  'Nums',
@@ -262,7 +348,7 @@ describe('generator for a5', () => {
262
348
  'VariadicList',
263
349
  'VariadicList1',
264
350
  ]);
265
- expect(registry.getValidator('test#/definitions/NT').schema).toStrictEqual({
351
+ expect(registry.getValidator('test#/definitions/DSN_H').schema).toStrictEqual({
266
352
  type: 'string',
267
353
  enum: ['v:name1', 'v:name2'],
268
354
  });
@@ -273,7 +359,7 @@ describe('generator for a5', () => {
273
359
  $ref: '#/definitions/UUID',
274
360
  dbFK: true,
275
361
  description: 'Foreign Key Column Type.',
276
- format: 'uuid',
362
+ // format: 'uuid',
277
363
  });
278
364
  expect(registry.getValidator('test#/definitions/Some').schema).toStrictEqual({
279
365
  type: 'object',
@@ -282,7 +368,7 @@ describe('generator for a5', () => {
282
368
  $ref: '#/definitions/DomainValuesType',
283
369
  },
284
370
  name0: {
285
- $ref: '#/definitions/NT',
371
+ $ref: '#/definitions/DSN_H',
286
372
  },
287
373
  name1: {
288
374
  type: 'string',
@@ -384,6 +470,7 @@ describe('generator for a5', () => {
384
470
  expect(v.properties.ref0).toStrictEqual({
385
471
  type: 'string',
386
472
  format: 'uuid',
473
+ // see: 'https://ru.wikipedia.org/wiki/UUID Wikipedia',
387
474
  description: 'Inline Foreign Key',
388
475
  dbFK: true,
389
476
  });
@@ -391,6 +478,7 @@ describe('generator for a5', () => {
391
478
  type: 'string',
392
479
  format: 'uuid',
393
480
  description: 'Foreign Key Column Type.',
481
+ // see: 'https://ru.wikipedia.org/wiki/UUID Wikipedia',
394
482
  dbFK: true,
395
483
  });
396
484
  expect(v.properties.ref2).toStrictEqual({
@@ -398,6 +486,7 @@ describe('generator for a5', () => {
398
486
  format: 'uuid',
399
487
  description: 'Inline Foreign Key (2)',
400
488
  dbFK: true,
489
+ // see: 'https://ru.wikipedia.org/wiki/UUID Wikipedia',
401
490
  });
402
491
  });
403
492
  });
@@ -462,7 +551,6 @@ describe('generator for a3', () => {
462
551
  const props = forgeSchemaResult.schema.definitions?.InterfaceWithGeneric__APIInterface?.properties;
463
552
  expect(props).toBeTruthy();
464
553
  expect(props.propWithGeneric).toBeTruthy();
465
- // @ts-expect-error It's a test
466
554
  expect(props.propWithGeneric.$ref).toStrictEqual('#/definitions/NonEmptyString');
467
555
  });
468
556
  it('optional args in API methods should works', () => {
@@ -577,6 +665,7 @@ describe('generator for a1', () => {
577
665
  it('getSchema', () => {
578
666
  expect(validator.getValidator('test#/definitions/PositiveInt').schema).toStrictEqual({
579
667
  type: 'integer',
668
+ // see: 'Int',
580
669
  minimum: 1,
581
670
  maximum: 9007199254740991,
582
671
  description: 'Positive integer value.',
@@ -1 +1 @@
1
- {"version":3,"file":"generate-drafts.d.ts","sourceRoot":"","sources":["../../src/schema-generator/generate-drafts.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,KAAK,eAAe,EAAkB,MAAM,0CAA0C,CAAC;AAmChG,OAAO,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAW9C;;GAEG;AACH,wBAAsB,sBAAsB,CAAC,OAAO,EAAE,YAAY;;;;;GAiCjE;AA6WD,UAAU,YAAa,SAAQ,kBAAkB;IAC7C,QAAQ,EAAE,MAAM,CAAC;IACjB,cAAc,EAAE,MAAM,EAAE,CAAC;CAC5B"}
1
+ {"version":3,"file":"generate-drafts.d.ts","sourceRoot":"","sources":["../../src/schema-generator/generate-drafts.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,KAAK,eAAe,EAAkB,MAAM,0CAA0C,CAAC;AAmChG,OAAO,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAW9C;;GAEG;AACH,wBAAsB,sBAAsB,CAAC,OAAO,EAAE,YAAY;;;;;GAkCjE;AA6WD,UAAU,YAAa,SAAQ,kBAAkB;IAC7C,QAAQ,EAAE,MAAM,CAAC;IACjB,cAAc,EAAE,MAAM,EAAE,CAAC;CAC5B"}
@@ -21,6 +21,7 @@ async function generateDraftTypeFiles(options) {
21
21
  expose: options.expose ?? types_1.SFG_CONFIG_DEFAULTS.expose,
22
22
  path: options.sourcesPattern.length > 1 ? undefined : options.sourcesPattern[0],
23
23
  tsconfig: options.tsconfig,
24
+ skipTypeCheck: options.skipTypeCheck ?? types_1.SFG_CONFIG_DEFAULTS.skipTypeCheck,
24
25
  discriminatorType: Config_1.DEFAULT_CONFIG.discriminatorType,
25
26
  ...types_1.SFG_CONFIG_MANDATORY,
26
27
  };
@@ -1,6 +1,6 @@
1
1
  import './extended-annotations-reader';
2
2
  import { CompletedConfig } from 'ts-json-schema-generator';
3
- import type { ForgedSchema, ForgeSchemaOptions } from '../types';
3
+ import { ForgedSchema, ForgeSchemaOptions } from '../types';
4
4
  /**
5
5
  * @internal
6
6
  */
@@ -1 +1 @@
1
- {"version":3,"file":"generate-schema.d.ts","sourceRoot":"","sources":["../../src/schema-generator/generate-schema.ts"],"names":[],"mappings":"AAAA,OAAO,+BAA+B,CAAC;AAKvC,OAAO,EAGH,eAAe,EAgBlB,MAAM,0BAA0B,CAAC;AAelC,OAAO,KAAK,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAMjE;;GAEG;AACH,wBAAsB,0BAA0B,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,YAAY,CAAC,CAgGhG;AAsGD,UAAU,eAAgB,SAAQ,kBAAkB;IAChD,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,SAAS,MAAM,EAAE,CAAC;IAC/B,2BAA2B,EAAE,eAAe,CAAC;CAChD"}
1
+ {"version":3,"file":"generate-schema.d.ts","sourceRoot":"","sources":["../../src/schema-generator/generate-schema.ts"],"names":[],"mappings":"AAAA,OAAO,+BAA+B,CAAC;AAMvC,OAAO,EAIH,eAAe,EAqBlB,MAAM,0BAA0B,CAAC;AAgBlC,OAAO,EAAwB,YAAY,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAOlF;;GAEG;AACH,wBAAsB,0BAA0B,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,YAAY,CAAC,CAwGhG;AA0JD,UAAU,eAAgB,SAAQ,kBAAkB;IAChD,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,SAAS,MAAM,EAAE,CAAC;IAC/B,2BAA2B,EAAE,eAAe,CAAC;CAChD"}
@@ -3,11 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.generateSchemaByDraftTypes = generateSchemaByDraftTypes;
4
4
  require("./extended-annotations-reader");
5
5
  const error_1 = require("@tsofist/stem/lib/error");
6
+ const value_in_1 = require("@tsofist/stem/lib/value-in");
6
7
  const ajv_1 = require("ajv");
7
8
  const jsonpath_plus_1 = require("jsonpath-plus");
8
9
  const ts_json_schema_generator_1 = require("ts-json-schema-generator");
9
10
  const typescript_1 = require("typescript");
10
11
  const helpers_tsc_1 = require("./helpers-tsc");
12
+ const patch_enum_node_parser_1 = require("./patch-enum-node-parser");
11
13
  const shrink_definition_name_1 = require("./shrink-definition-name");
12
14
  const sort_properties_1 = require("./sort-properties");
13
15
  const types_1 = require("./types");
@@ -30,6 +32,7 @@ async function generateSchemaByDraftTypes(options) {
30
32
  expose: options.expose ?? types_1.SFG_CONFIG_DEFAULTS.expose,
31
33
  path: `${options.sourcesDirectoryPattern}/*${types_1.TMP_FILES_SUFFIX}.ts`,
32
34
  tsconfig: options.tsconfig,
35
+ skipTypeCheck: options.skipTypeCheck ?? types_1.SFG_CONFIG_DEFAULTS.skipTypeCheck,
33
36
  discriminatorType: options.discriminatorType ?? ts_json_schema_generator_1.DEFAULT_CONFIG.discriminatorType,
34
37
  ...types_1.SFG_CONFIG_MANDATORY,
35
38
  };
@@ -41,15 +44,19 @@ async function generateSchemaByDraftTypes(options) {
41
44
  parser.addNodeParser(new ArrayLiteralExpressionIdentifierParser(typeChecker));
42
45
  parser.addNodeParser(new TypeofNodeParserEx(typeChecker, parser));
43
46
  });
44
- const formatter = (0, ts_json_schema_generator_1.createFormatter)(options.sourcesTypesGeneratorConfig);
45
- const generator = new ts_json_schema_generator_1.SchemaGenerator(generatorProgram, parser, formatter, generatorConfig);
47
+ const enumMetadataMap = new Map();
48
+ (0, patch_enum_node_parser_1.patchEnumNodeParser)(parser, typeChecker, enumMetadataMap, allowUseFallbackDescription);
49
+ const formatter = (0, ts_json_schema_generator_1.createFormatter)(options.sourcesTypesGeneratorConfig, (formatter) => {
50
+ formatter.addTypeFormatter(new EnumTypeFormatterEx(enumMetadataMap));
51
+ });
52
+ const generator = new SchemaGeneratorEx(generatorProgram, parser, formatter, generatorConfig);
46
53
  const result = {
47
54
  $schema: 'http://json-schema.org/draft-07/schema#',
48
55
  $id: options.schemaId,
56
+ version: undefined,
49
57
  hash: '',
50
58
  title: undefined,
51
59
  description: undefined,
52
- version: undefined,
53
60
  $comment: undefined,
54
61
  };
55
62
  const defs = (result.definitions ??= {});
@@ -98,8 +105,46 @@ async function generateSchemaByDraftTypes(options) {
98
105
  }).validateSchema(result, true);
99
106
  return result;
100
107
  }
101
- function escapeDefinitionNameForJSONPath(value) {
102
- return value.replace(/\\/g, '\\\\').replace(/"/g, '\\"');
108
+ class EnumTypeFormatterEx extends ts_json_schema_generator_1.EnumTypeFormatter {
109
+ constructor(metaMap) {
110
+ super();
111
+ Object.defineProperty(this, "metaMap", {
112
+ enumerable: true,
113
+ configurable: true,
114
+ writable: true,
115
+ value: metaMap
116
+ });
117
+ }
118
+ getDefinition(type) {
119
+ const id = type.getId();
120
+ const inherited = super.getDefinition(type);
121
+ if (inherited?.enum) {
122
+ let count = 0;
123
+ const annotations = {};
124
+ for (const value of inherited.enum) {
125
+ if ((0, value_in_1.valueIn)(typeof value, ['string', 'number'])) {
126
+ const v = value;
127
+ const key = `${id}.${v}`;
128
+ const doc = this.metaMap.get(key);
129
+ if (doc) {
130
+ count++;
131
+ const ann = (annotations[doc.title] = [doc.value]);
132
+ if (doc.description)
133
+ ann.push(doc.description);
134
+ if (doc.comment)
135
+ ann.push(doc.comment);
136
+ }
137
+ }
138
+ }
139
+ if (count > 0) {
140
+ return {
141
+ ...inherited,
142
+ enumAnnotation: annotations,
143
+ };
144
+ }
145
+ }
146
+ return inherited;
147
+ }
103
148
  }
104
149
  class TypeofNodeParserEx extends ts_json_schema_generator_1.TypeofNodeParser {
105
150
  createType(node, context, reference) {
@@ -184,6 +229,18 @@ class ArrayLiteralExpressionIdentifierParser {
184
229
  }
185
230
  }
186
231
  }
232
+ class SchemaGeneratorEx extends ts_json_schema_generator_1.SchemaGenerator {
233
+ appendRootChildDefinitions(rootType, childDefinitions) {
234
+ try {
235
+ super.appendRootChildDefinitions(rootType, childDefinitions);
236
+ }
237
+ catch (e) {
238
+ if (e instanceof ts_json_schema_generator_1.MultipleDefinitionsError) {
239
+ // console.log('DUPL:', e.defA.getName()); // todo
240
+ }
241
+ }
242
+ }
243
+ }
187
244
  function getIdentifierLiteralValue(node, checker) {
188
245
  const type = checker.getTypeAtLocation(node);
189
246
  if (type.isNumberLiteral() || type.isStringLiteral()) {
@@ -191,3 +248,6 @@ function getIdentifierLiteralValue(node, checker) {
191
248
  }
192
249
  return undefined;
193
250
  }
251
+ function escapeDefinitionNameForJSONPath(value) {
252
+ return value.replace(/\\/g, '\\\\').replace(/"/g, '\\"');
253
+ }
@@ -1,7 +1,9 @@
1
1
  import { type CompilerHost, type CompilerOptions, type MethodSignature, type NamedDeclaration, type Node, type PropertySignature, type SignatureDeclarationBase } from 'typescript';
2
2
  export declare function readMemberTypeName(member: MethodSignature | PropertySignature | SignatureDeclarationBase): string | undefined;
3
+ export declare function readJSDocTagValue(node: Node, tagName: string): string | undefined;
3
4
  export declare function readJSDocDescription(node: Node, allowUseFallbackDescription: boolean | undefined, allowUseFallbackDescriptionFromParent?: boolean): string | undefined;
4
5
  export declare function readNodeName(node: NamedDeclaration): string;
6
+ export declare function readNodeName(node: Node): string | undefined;
5
7
  export declare function readInterfaceGenericText(node: NamedDeclaration): string;
6
8
  export declare function hasJSDocTag(statement: Node, tagName: string): boolean;
7
9
  export declare function resolveModuleFileName(containingFile: string, moduleName: string, compilerOptions: CompilerOptions, compilerHost: CompilerHost): string | undefined;