@tsofist/schema-forge 1.32.1 → 1.34.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 (58) hide show
  1. package/lib/fake-generator.d.ts +0 -1
  2. package/lib/fake-generator.js +6 -2
  3. package/lib/fake-generator.spec.d.ts +0 -1
  4. package/lib/fake-generator.spec.js +16 -18
  5. package/lib/generator/schema-generator.d.ts +0 -1
  6. package/lib/generator/schema-generator.js +61 -43
  7. package/lib/generator/types-generator.d.ts +0 -1
  8. package/lib/generator/types-generator.js +109 -98
  9. package/lib/generator/types.d.ts +0 -1
  10. package/lib/generator/types.js +0 -1
  11. package/lib/generator.d.ts +0 -1
  12. package/lib/generator.js +97 -101
  13. package/lib/generator.spec.d.ts +0 -1
  14. package/lib/generator.spec.js +94 -65
  15. package/lib/index.d.ts +0 -1
  16. package/lib/index.js +0 -1
  17. package/lib/types.d.ts +0 -1
  18. package/lib/types.js +0 -1
  19. package/lib/util/format.error.d.ts +0 -1
  20. package/lib/util/format.error.js +0 -1
  21. package/lib/util/patch.extended-annotations-reader.d.ts +0 -1
  22. package/lib/util/patch.extended-annotations-reader.js +1 -3
  23. package/lib/util/sort-properties.d.ts +0 -1
  24. package/lib/util/sort-properties.js +1 -3
  25. package/lib/util/tsc.d.ts +0 -1
  26. package/lib/util/tsc.js +4 -7
  27. package/lib/validator.d.ts +16 -2
  28. package/lib/validator.js +18 -10
  29. package/package.json +7 -7
  30. package/lib/fake-generator.d.ts.map +0 -1
  31. package/lib/fake-generator.js.map +0 -1
  32. package/lib/fake-generator.spec.d.ts.map +0 -1
  33. package/lib/fake-generator.spec.js.map +0 -1
  34. package/lib/generator/schema-generator.d.ts.map +0 -1
  35. package/lib/generator/schema-generator.js.map +0 -1
  36. package/lib/generator/types-generator.d.ts.map +0 -1
  37. package/lib/generator/types-generator.js.map +0 -1
  38. package/lib/generator/types.d.ts.map +0 -1
  39. package/lib/generator/types.js.map +0 -1
  40. package/lib/generator.d.ts.map +0 -1
  41. package/lib/generator.js.map +0 -1
  42. package/lib/generator.spec.d.ts.map +0 -1
  43. package/lib/generator.spec.js.map +0 -1
  44. package/lib/index.d.ts.map +0 -1
  45. package/lib/index.js.map +0 -1
  46. package/lib/tsconfig.build.tsbuildinfo +0 -1
  47. package/lib/types.d.ts.map +0 -1
  48. package/lib/types.js.map +0 -1
  49. package/lib/util/format.error.d.ts.map +0 -1
  50. package/lib/util/format.error.js.map +0 -1
  51. package/lib/util/patch.extended-annotations-reader.d.ts.map +0 -1
  52. package/lib/util/patch.extended-annotations-reader.js.map +0 -1
  53. package/lib/util/sort-properties.d.ts.map +0 -1
  54. package/lib/util/sort-properties.js.map +0 -1
  55. package/lib/util/tsc.d.ts.map +0 -1
  56. package/lib/util/tsc.js.map +0 -1
  57. package/lib/validator.d.ts.map +0 -1
  58. package/lib/validator.js.map +0 -1
package/lib/generator.js CHANGED
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.forgeSchema = forgeSchema;
4
4
  exports.loadJSONSchema = loadJSONSchema;
5
5
  exports.loadJSONSchemaSync = loadJSONSchemaSync;
6
- const tslib_1 = require("tslib");
7
6
  const fs_1 = require("fs");
8
7
  const promises_1 = require("fs/promises");
9
8
  const node_crypto_1 = require("node:crypto");
@@ -16,119 +15,117 @@ const random_1 = require("@tsofist/stem/lib/string/random");
16
15
  const schema_generator_1 = require("./generator/schema-generator");
17
16
  const types_generator_1 = require("./generator/types-generator");
18
17
  const KEEP_ARTEFACTS = false;
19
- function forgeSchema(options) {
20
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
21
- var _a, _b, _c, _d, _e, _f;
22
- const { schemaId, sourcesDirectoryPattern, outputSchemaFile } = options;
23
- const sourcesPattern = (0, as_array_1.asArray)(options.sourcesFilesPattern).map((filesPattern) => `${sourcesDirectoryPattern}/${filesPattern}`);
24
- let tsconfig = options.tsconfig;
25
- let tsconfigGenerated = false;
18
+ async function forgeSchema(options) {
19
+ const { schemaId, sourcesDirectoryPattern, outputSchemaFile } = options;
20
+ const sourcesPattern = (0, as_array_1.asArray)(options.sourcesFilesPattern).map((filesPattern) => `${sourcesDirectoryPattern}/${filesPattern}`);
21
+ let tsconfig = options.tsconfig;
22
+ let tsconfigGenerated = false;
23
+ try {
24
+ if (options.tsconfigFrom) {
25
+ tsconfigGenerated = true;
26
+ const source = await (0, promises_1.readFile)(options.tsconfigFrom, { encoding: 'utf8' });
27
+ const config = JSON.parse(source);
28
+ config.include = sourcesPattern;
29
+ config.compilerOptions.noUnusedLocals = false;
30
+ tsconfig = `./tsconfig.schema-forge-generated.${(0, random_1.randomString)(5)}.tmp.json`;
31
+ await (0, promises_1.writeFile)(tsconfig, JSON.stringify(config, null, 2), { encoding: 'utf8' });
32
+ }
33
+ if (!tsconfig)
34
+ (0, error_1.raise)('tsconfig is not specified');
35
+ const { sourcesTypesGeneratorConfig, files, definitions, namesBySourceFile } = await (0, types_generator_1.generateDraftTypeFiles)({
36
+ ...options,
37
+ tsconfig,
38
+ sourcesPattern,
39
+ });
40
+ const refs = definitions.map((item) => `${options.schemaId || ''}#/definitions/${item}`);
41
+ let schema;
26
42
  try {
27
- if (options.tsconfigFrom) {
28
- tsconfigGenerated = true;
29
- const source = yield (0, promises_1.readFile)(options.tsconfigFrom, { encoding: 'utf8' });
30
- const config = JSON.parse(source);
31
- config.include = sourcesPattern;
32
- config.compilerOptions.noUnusedLocals = false;
33
- tsconfig = `./tsconfig.schema-forge-generated.${(0, random_1.randomString)(5)}.tmp.json`;
34
- yield (0, promises_1.writeFile)(tsconfig, JSON.stringify(config, null, 2), { encoding: 'utf8' });
35
- }
36
- if (!tsconfig)
37
- (0, error_1.raise)('tsconfig is not specified');
38
- const { sourcesTypesGeneratorConfig, files, definitions, namesBySourceFile } = yield (0, types_generator_1.generateDraftTypeFiles)(Object.assign(Object.assign({}, options), { tsconfig,
39
- sourcesPattern }));
40
- const refs = definitions.map((item) => `${options.schemaId || ''}#/definitions/${item}`);
41
- let schema;
42
- try {
43
- {
44
- schema = yield (0, schema_generator_1.generateSchemaByDraftTypes)({
45
- schemaId,
46
- tsconfig,
47
- definitions,
48
- sourcesDirectoryPattern,
49
- outputSchemaFile,
50
- sourcesTypesGeneratorConfig,
51
- expose: options.expose,
52
- openAPI: options.openapiCompatible,
53
- sortObjectProperties: options.sortObjectProperties,
54
- allowUseFallbackDescription: options.allowUseFallbackDescription,
55
- });
56
- if (options.schemaMetadata) {
57
- for (const key of (0, keys_1.keysOf)(options.schemaMetadata)) {
58
- schema[key] = options.schemaMetadata[key];
59
- }
43
+ {
44
+ schema = await (0, schema_generator_1.generateSchemaByDraftTypes)({
45
+ schemaId,
46
+ tsconfig,
47
+ definitions,
48
+ sourcesDirectoryPattern,
49
+ outputSchemaFile,
50
+ sourcesTypesGeneratorConfig,
51
+ expose: options.expose,
52
+ openAPI: options.openapiCompatible,
53
+ sortObjectProperties: options.sortObjectProperties,
54
+ allowUseFallbackDescription: options.allowUseFallbackDescription,
55
+ });
56
+ if (options.schemaMetadata) {
57
+ for (const key of (0, keys_1.keysOf)(options.schemaMetadata)) {
58
+ schema[key] = options.schemaMetadata[key];
60
59
  }
61
- {
62
- const algorithm = ((_a = options.schemaMetadata) === null || _a === void 0 ? void 0 : _a.hash) == null
63
- ? 'md5'
64
- : ((_b = options.schemaMetadata) === null || _b === void 0 ? void 0 : _b.hash) === true
65
- ? 'md5'
66
- : options.schemaMetadata.hash;
67
- if (algorithm) {
68
- schema.hash = (0, node_crypto_1.createHash)(algorithm, {})
69
- .update(JSON.stringify(schema))
70
- .digest('hex');
71
- }
72
- else {
73
- delete schema.hash;
74
- }
75
- }
76
- const content = JSON.stringify(schema, null, 2);
77
- yield (0, promises_1.writeFile)(options.outputSchemaFile, content, { encoding: 'utf8' });
78
60
  }
79
- if (options.outputSchemaMetadataFile) {
80
- const map = {
81
- $id: options.schemaId || '',
82
- version: (_c = options.schemaMetadata) === null || _c === void 0 ? void 0 : _c.version,
83
- title: (_d = options.schemaMetadata) === null || _d === void 0 ? void 0 : _d.title,
84
- description: (_e = options.schemaMetadata) === null || _e === void 0 ? void 0 : _e.description,
85
- $comment: (_f = options.schemaMetadata) === null || _f === void 0 ? void 0 : _f.$comment,
86
- schemaHash: schema.hash,
87
- refs: {},
88
- names: {},
89
- serviceRefs: {},
90
- serviceNames: {},
91
- };
92
- const defs = new Set(Object.keys((schema.definitions || {})));
93
- for (const name of definitions) {
94
- const ref = `${options.schemaId || ''}#/definitions/${name}`;
95
- map.names[name] = ref;
96
- map.refs[ref] = name;
97
- defs.delete(name);
61
+ {
62
+ const algorithm = options.schemaMetadata?.hash == null
63
+ ? 'md5'
64
+ : options.schemaMetadata?.hash === true
65
+ ? 'md5'
66
+ : options.schemaMetadata.hash;
67
+ if (algorithm) {
68
+ schema.hash = (0, node_crypto_1.createHash)(algorithm, {})
69
+ .update(JSON.stringify(schema))
70
+ .digest('hex');
98
71
  }
99
- for (const name of defs) {
100
- map.serviceNames[name] = `${options.schemaId || ''}#/definitions/${name}`;
101
- map.serviceRefs[`${options.schemaId || ''}#/definitions/${name}`] = name;
72
+ else {
73
+ delete schema.hash;
102
74
  }
103
- const content = JSON.stringify(map, null, 2);
104
- yield (0, promises_1.writeFile)(options.outputSchemaMetadataFile, content, {
105
- encoding: 'utf8',
106
- });
107
75
  }
76
+ const content = JSON.stringify(schema, null, 2);
77
+ await (0, promises_1.writeFile)(options.outputSchemaFile, content, { encoding: 'utf8' });
108
78
  }
109
- finally {
110
- if (!KEEP_ARTEFACTS) {
111
- yield Promise.all(files.map((fileName) => (0, promises_2.unlink)(fileName).catch(noop_1.noop)));
79
+ if (options.outputSchemaMetadataFile) {
80
+ const map = {
81
+ $id: options.schemaId || '',
82
+ version: options.schemaMetadata?.version,
83
+ title: options.schemaMetadata?.title,
84
+ description: options.schemaMetadata?.description,
85
+ $comment: options.schemaMetadata?.$comment,
86
+ schemaHash: schema.hash,
87
+ refs: {},
88
+ names: {},
89
+ serviceRefs: {},
90
+ serviceNames: {},
91
+ };
92
+ const defs = new Set(Object.keys((schema.definitions || {})));
93
+ for (const name of definitions) {
94
+ const ref = `${options.schemaId || ''}#/definitions/${name}`;
95
+ map.names[name] = ref;
96
+ map.refs[ref] = name;
97
+ defs.delete(name);
98
+ }
99
+ for (const name of defs) {
100
+ map.serviceNames[name] = `${options.schemaId || ''}#/definitions/${name}`;
101
+ map.serviceRefs[`${options.schemaId || ''}#/definitions/${name}`] = name;
112
102
  }
103
+ const content = JSON.stringify(map, null, 2);
104
+ await (0, promises_1.writeFile)(options.outputSchemaMetadataFile, content, {
105
+ encoding: 'utf8',
106
+ });
113
107
  }
114
- return {
115
- schema,
116
- refs,
117
- generatedTemporaryFiles: files,
118
- generatedNamesBySourceFile: namesBySourceFile,
119
- };
120
108
  }
121
109
  finally {
122
- if (tsconfig && tsconfigGenerated) {
123
- yield (0, promises_2.unlink)(tsconfig).catch(noop_1.noop);
110
+ if (!KEEP_ARTEFACTS) {
111
+ await Promise.all(files.map((fileName) => (0, promises_2.unlink)(fileName).catch(noop_1.noop)));
124
112
  }
125
113
  }
126
- });
114
+ return {
115
+ schema,
116
+ refs,
117
+ generatedTemporaryFiles: files,
118
+ generatedNamesBySourceFile: namesBySourceFile,
119
+ };
120
+ }
121
+ finally {
122
+ if (tsconfig && tsconfigGenerated) {
123
+ await (0, promises_2.unlink)(tsconfig).catch(noop_1.noop);
124
+ }
125
+ }
127
126
  }
128
- function loadJSONSchema(files) {
129
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
130
- return Promise.all(files.map((fn) => (0, promises_1.readFile)(fn, { encoding: 'utf8' }).then(JSON.parse)));
131
- });
127
+ async function loadJSONSchema(files) {
128
+ return Promise.all(files.map((fn) => (0, promises_1.readFile)(fn, { encoding: 'utf8' }).then(JSON.parse)));
132
129
  }
133
130
  function loadJSONSchemaSync(files) {
134
131
  return files.map((fn) => {
@@ -136,4 +133,3 @@ function loadJSONSchemaSync(files) {
136
133
  return JSON.parse(content);
137
134
  });
138
135
  }
139
- //# sourceMappingURL=generator.js.map
@@ -1,2 +1 @@
1
1
  export {};
2
- //# sourceMappingURL=generator.spec.d.ts.map
@@ -1,6 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
3
  const promises_1 = require("node:fs/promises");
5
4
  const error_1 = require("@tsofist/stem/lib/error");
6
5
  const noop_1 = require("@tsofist/stem/lib/noop");
@@ -15,8 +14,8 @@ describe('generator for a7', () => {
15
14
  const outputSchemaMetadataFile = './a7.generated.definitions.tmp.json';
16
15
  let forgeSchemaResult;
17
16
  let validator;
18
- beforeAll(() => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
19
- forgeSchemaResult = yield (0, generator_1.forgeSchema)({
17
+ beforeAll(async () => {
18
+ forgeSchemaResult = await (0, generator_1.forgeSchema)({
20
19
  schemaId: 'test',
21
20
  allowUseFallbackDescription: true,
22
21
  tsconfigFrom: './tsconfig.build-test.json',
@@ -28,15 +27,15 @@ describe('generator for a7', () => {
28
27
  explicitPublic: true,
29
28
  });
30
29
  validator = (0, validator_1.createSchemaForgeValidator)({}, true);
31
- const schema = yield (0, generator_1.loadJSONSchema)([outputSchemaFile]);
30
+ const schema = await (0, generator_1.loadJSONSchema)([outputSchemaFile]);
32
31
  validator.addSchema(schema);
33
- }));
34
- afterAll(() => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
32
+ });
33
+ afterAll(async () => {
35
34
  if (!KEEP_ARTEFACTS) {
36
- yield (0, promises_1.unlink)(outputSchemaFile).catch(noop_1.noop);
37
- yield (0, promises_1.unlink)(outputSchemaMetadataFile).catch(noop_1.noop);
35
+ await (0, promises_1.unlink)(outputSchemaFile).catch(noop_1.noop);
36
+ await (0, promises_1.unlink)(outputSchemaMetadataFile).catch(noop_1.noop);
38
37
  }
39
- }));
38
+ });
40
39
  it('generated schema should be valid', () => {
41
40
  expect(forgeSchemaResult).toBeTruthy();
42
41
  const schema = validator.getSchema('test#/definitions/SomeAPI_doSomeWithUser_Args');
@@ -56,8 +55,8 @@ describe('generator for a6', () => {
56
55
  const outputSchemaMetadataFile = './a6.generated.definitions.tmp.json';
57
56
  let forgeSchemaResult;
58
57
  let validator;
59
- beforeAll(() => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
60
- forgeSchemaResult = yield (0, generator_1.forgeSchema)({
58
+ beforeAll(async () => {
59
+ forgeSchemaResult = await (0, generator_1.forgeSchema)({
61
60
  schemaId: 'test',
62
61
  tsconfigFrom: './tsconfig.build-test.json',
63
62
  sourcesDirectoryPattern: 'test-sources/a6',
@@ -68,19 +67,18 @@ describe('generator for a6', () => {
68
67
  explicitPublic: true,
69
68
  });
70
69
  validator = (0, validator_1.createSchemaForgeValidator)({}, true);
71
- const schema = yield (0, generator_1.loadJSONSchema)([outputSchemaFile]);
70
+ const schema = await (0, generator_1.loadJSONSchema)([outputSchemaFile]);
72
71
  validator.addSchema(schema);
73
- }));
74
- afterAll(() => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
72
+ });
73
+ afterAll(async () => {
75
74
  if (!KEEP_ARTEFACTS) {
76
- yield (0, promises_1.unlink)(outputSchemaFile).catch(noop_1.noop);
77
- yield (0, promises_1.unlink)(outputSchemaMetadataFile).catch(noop_1.noop);
75
+ await (0, promises_1.unlink)(outputSchemaFile).catch(noop_1.noop);
76
+ await (0, promises_1.unlink)(outputSchemaMetadataFile).catch(noop_1.noop);
78
77
  }
79
- }));
78
+ });
80
79
  it('generated schema should be valid', () => {
81
- var _a;
82
80
  expect(forgeSchemaResult).toBeTruthy();
83
- const defs = (_a = forgeSchemaResult === null || forgeSchemaResult === void 0 ? void 0 : forgeSchemaResult.schema) === null || _a === void 0 ? void 0 : _a.definitions;
81
+ const defs = forgeSchemaResult?.schema?.definitions;
84
82
  expect(defs).toBeTruthy();
85
83
  expect(validator.getValidator('test#/definitions/CollectionItemID1').schema).toStrictEqual({
86
84
  $ref: '#/definitions/UUID',
@@ -113,8 +111,8 @@ describe('generator for a5', () => {
113
111
  const outputSchemaMetadataFile = './a5.generated.definitions.tmp.json';
114
112
  let forgeSchemaResult;
115
113
  let validator;
116
- beforeAll(() => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
117
- forgeSchemaResult = yield (0, generator_1.forgeSchema)({
114
+ beforeAll(async () => {
115
+ forgeSchemaResult = await (0, generator_1.forgeSchema)({
118
116
  schemaId: 'test',
119
117
  tsconfigFrom: './tsconfig.build-test.json',
120
118
  sourcesDirectoryPattern: 'test-sources/a5',
@@ -125,19 +123,18 @@ describe('generator for a5', () => {
125
123
  explicitPublic: true,
126
124
  });
127
125
  validator = (0, validator_1.createSchemaForgeValidator)({}, true);
128
- const schema = yield (0, generator_1.loadJSONSchema)([outputSchemaFile]);
126
+ const schema = await (0, generator_1.loadJSONSchema)([outputSchemaFile]);
129
127
  validator.addSchema(schema);
130
- }));
131
- afterAll(() => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
128
+ });
129
+ afterAll(async () => {
132
130
  if (!KEEP_ARTEFACTS) {
133
- yield (0, promises_1.unlink)(outputSchemaFile).catch(noop_1.noop);
134
- yield (0, promises_1.unlink)(outputSchemaMetadataFile).catch(noop_1.noop);
131
+ await (0, promises_1.unlink)(outputSchemaFile).catch(noop_1.noop);
132
+ await (0, promises_1.unlink)(outputSchemaMetadataFile).catch(noop_1.noop);
135
133
  }
136
- }));
134
+ });
137
135
  it('generated schema should be valid', () => {
138
- var _a;
139
136
  expect(forgeSchemaResult).toBeTruthy();
140
- const defs = (_a = forgeSchemaResult === null || forgeSchemaResult === void 0 ? void 0 : forgeSchemaResult.schema) === null || _a === void 0 ? void 0 : _a.definitions;
137
+ const defs = forgeSchemaResult?.schema?.definitions;
141
138
  expect(defs).toBeTruthy();
142
139
  expect(Object.keys(defs)).toStrictEqual([
143
140
  'DomainNum',
@@ -225,8 +222,8 @@ describe('generator for a4', () => {
225
222
  const outputSchemaFile = './a4.generated.schema.tmp.json';
226
223
  const outputSchemaMetadataFile = './a4.generated.definitions.tmp.json';
227
224
  let forgeSchemaResult;
228
- beforeAll(() => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
229
- forgeSchemaResult = yield (0, generator_1.forgeSchema)({
225
+ beforeAll(async () => {
226
+ forgeSchemaResult = await (0, generator_1.forgeSchema)({
230
227
  tsconfigFrom: './tsconfig.build-test.json',
231
228
  sourcesDirectoryPattern: 'test-sources/a4',
232
229
  sourcesFilesPattern: 'service-api.ts',
@@ -235,17 +232,16 @@ describe('generator for a4', () => {
235
232
  expose: 'all',
236
233
  explicitPublic: false,
237
234
  });
238
- }));
239
- afterAll(() => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
235
+ });
236
+ afterAll(async () => {
240
237
  if (!KEEP_ARTEFACTS) {
241
- yield (0, promises_1.unlink)(outputSchemaFile).catch(noop_1.noop);
242
- yield (0, promises_1.unlink)(outputSchemaMetadataFile).catch(noop_1.noop);
238
+ await (0, promises_1.unlink)(outputSchemaFile).catch(noop_1.noop);
239
+ await (0, promises_1.unlink)(outputSchemaMetadataFile).catch(noop_1.noop);
243
240
  }
244
- }));
241
+ });
245
242
  it('generated schema should be valid', () => {
246
- var _a;
247
243
  expect(forgeSchemaResult).toBeTruthy();
248
- const defs = (_a = forgeSchemaResult === null || forgeSchemaResult === void 0 ? void 0 : forgeSchemaResult.schema) === null || _a === void 0 ? void 0 : _a.definitions;
244
+ const defs = forgeSchemaResult?.schema?.definitions;
249
245
  expect(defs).toBeTruthy();
250
246
  expect(Object.keys(defs)).toStrictEqual(['API', 'Enum', 'FormatMode', 'Some', 'Some2']);
251
247
  });
@@ -254,8 +250,8 @@ describe('generator for a3', () => {
254
250
  const outputSchemaFile = './a3.generated.schema.tmp.json';
255
251
  const outputSchemaMetadataFile = './a3.generated.definitions.tmp.json';
256
252
  let forgeSchemaResult;
257
- beforeAll(() => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
258
- forgeSchemaResult = yield (0, generator_1.forgeSchema)({
253
+ beforeAll(async () => {
254
+ forgeSchemaResult = await (0, generator_1.forgeSchema)({
259
255
  tsconfigFrom: './tsconfig.build-test.json',
260
256
  sourcesDirectoryPattern: 'test-sources/a3',
261
257
  sourcesFilesPattern: 'service-api.ts',
@@ -263,26 +259,57 @@ describe('generator for a3', () => {
263
259
  outputSchemaMetadataFile,
264
260
  expose: 'all',
265
261
  });
266
- }));
267
- afterAll(() => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
262
+ });
263
+ afterAll(async () => {
268
264
  if (!KEEP_ARTEFACTS) {
269
- yield (0, promises_1.unlink)(outputSchemaFile).catch(noop_1.noop);
270
- yield (0, promises_1.unlink)(outputSchemaMetadataFile).catch(noop_1.noop);
265
+ await (0, promises_1.unlink)(outputSchemaFile).catch(noop_1.noop);
266
+ await (0, promises_1.unlink)(outputSchemaMetadataFile).catch(noop_1.noop);
271
267
  }
272
- }));
268
+ });
273
269
  it('generated schema should be valid', () => {
274
270
  expect(forgeSchemaResult).toBeTruthy();
275
271
  });
276
272
  it('interface generics should works', () => {
277
- var _a;
278
- const props = (_a = forgeSchemaResult.schema.definitions) === null || _a === void 0 ? void 0 : _a.InterfaceWithGeneric_InterfaceDeclaration.properties;
273
+ const props = forgeSchemaResult.schema.definitions?.InterfaceWithGeneric_InterfaceDeclaration
274
+ .properties;
279
275
  expect(props).toBeTruthy();
280
276
  expect(props.propWithGeneric).toBeTruthy();
281
277
  expect(props.propWithGeneric.$ref).toStrictEqual('#/definitions/NonEmptyString');
282
278
  });
279
+ it('optional args in API methods should works', () => {
280
+ {
281
+ const props = forgeSchemaResult.schema.definitions?.API_methodG0_Args;
282
+ expect(props).toBeTruthy();
283
+ expect(props.minItems).toStrictEqual(0);
284
+ expect(props.maxItems).toStrictEqual(1);
285
+ }
286
+ {
287
+ const props = forgeSchemaResult.schema.definitions?.API_methodG1_Args;
288
+ expect(props).toBeTruthy();
289
+ expect(props.minItems).toStrictEqual(0);
290
+ expect(props.maxItems).toStrictEqual(2);
291
+ }
292
+ {
293
+ const props = forgeSchemaResult.schema.definitions?.API_methodG2_Args;
294
+ expect(props).toBeTruthy();
295
+ expect(props.minItems).toStrictEqual(1);
296
+ expect(props.maxItems).toStrictEqual(2);
297
+ }
298
+ // {
299
+ // const props = forgeSchemaResult!.schema.definitions?.API_methodG3_Args;
300
+ // expect(props).toBeTruthy();
301
+ // expect(props.minItems).toStrictEqual(0);
302
+ // expect(props.maxItems).toBeUndefined();
303
+ // }
304
+ // {
305
+ // const props = forgeSchemaResult!.schema.definitions?.API_methodG4_Args;
306
+ // expect(props).toBeTruthy();
307
+ // expect(props.minItems).toStrictEqual(1);
308
+ // expect(props.maxItems).toBeUndefined();
309
+ // }
310
+ });
283
311
  it('extends should works', () => {
284
- var _a;
285
- const props = (_a = forgeSchemaResult.schema.definitions) === null || _a === void 0 ? void 0 : _a.BAPI_InterfaceDeclaration.properties;
312
+ const props = forgeSchemaResult.schema.definitions?.BAPI_InterfaceDeclaration.properties;
286
313
  expect(props).toBeTruthy();
287
314
  expect(Object.keys(props)).toStrictEqual([
288
315
  'propertyA',
@@ -295,6 +322,9 @@ describe('generator for a3', () => {
295
322
  'methodE1',
296
323
  'methodE2',
297
324
  'methodF',
325
+ 'methodG0',
326
+ 'methodG1',
327
+ 'methodG2',
298
328
  'methodY',
299
329
  ]);
300
330
  });
@@ -303,21 +333,21 @@ describe('generator for a2', () => {
303
333
  const outputSchemaFile = './a2.generated.schema.tmp.json';
304
334
  const outputSchemaMetadataFile = './a2.generated.definitions.tmp.json';
305
335
  let forgeSchemaResult;
306
- beforeAll(() => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
307
- forgeSchemaResult = yield (0, generator_1.forgeSchema)({
336
+ beforeAll(async () => {
337
+ forgeSchemaResult = await (0, generator_1.forgeSchema)({
308
338
  tsconfigFrom: './tsconfig.build-test.json',
309
339
  sourcesDirectoryPattern: 'test-sources/a2',
310
340
  sourcesFilesPattern: 'service-api.ts',
311
341
  outputSchemaFile,
312
342
  outputSchemaMetadataFile,
313
343
  });
314
- }));
315
- afterAll(() => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
344
+ });
345
+ afterAll(async () => {
316
346
  if (!KEEP_ARTEFACTS) {
317
- yield (0, promises_1.unlink)(outputSchemaFile).catch(noop_1.noop);
318
- yield (0, promises_1.unlink)(outputSchemaMetadataFile).catch(noop_1.noop);
347
+ await (0, promises_1.unlink)(outputSchemaFile).catch(noop_1.noop);
348
+ await (0, promises_1.unlink)(outputSchemaMetadataFile).catch(noop_1.noop);
319
349
  }
320
- }));
350
+ });
321
351
  it('generated schema should be valid', () => {
322
352
  expect(forgeSchemaResult).toBeTruthy();
323
353
  });
@@ -328,8 +358,8 @@ describe('generator for a1', () => {
328
358
  const schemaId = 'test';
329
359
  let forgeSchemaResult;
330
360
  let validator;
331
- beforeAll(() => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
332
- forgeSchemaResult = yield (0, generator_1.forgeSchema)({
361
+ beforeAll(async () => {
362
+ forgeSchemaResult = await (0, generator_1.forgeSchema)({
333
363
  allowUseFallbackDescription: false,
334
364
  explicitPublic: true,
335
365
  schemaId,
@@ -340,15 +370,15 @@ describe('generator for a1', () => {
340
370
  outputSchemaMetadataFile,
341
371
  });
342
372
  validator = (0, validator_1.createSchemaForgeValidator)({}, true);
343
- const schema = yield (0, generator_1.loadJSONSchema)([outputSchemaFile]);
373
+ const schema = await (0, generator_1.loadJSONSchema)([outputSchemaFile]);
344
374
  validator.addSchema(schema);
345
- }), 10000);
346
- afterAll(() => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
375
+ }, 10_000);
376
+ afterAll(async () => {
347
377
  if (!KEEP_ARTEFACTS) {
348
- yield (0, promises_1.unlink)(outputSchemaFile).catch(noop_1.noop);
349
- yield (0, promises_1.unlink)(outputSchemaMetadataFile).catch(noop_1.noop);
378
+ await (0, promises_1.unlink)(outputSchemaFile).catch(noop_1.noop);
379
+ await (0, promises_1.unlink)(outputSchemaMetadataFile).catch(noop_1.noop);
350
380
  }
351
- }));
381
+ });
352
382
  it('generated schema should be valid', () => {
353
383
  expect(forgeSchemaResult).toBeTruthy();
354
384
  expect(forgeSchemaResult.schema.$id).toStrictEqual(schemaId);
@@ -535,4 +565,3 @@ describe('generator for a1', () => {
535
565
  expect(schema.properties.methodB.description).toStrictEqual('Description for methodB');
536
566
  });
537
567
  });
538
- //# sourceMappingURL=generator.spec.js.map
package/lib/index.d.ts CHANGED
@@ -4,4 +4,3 @@ export declare function buildAPIInterfaceSchemaSignature(interfaceName: string):
4
4
  export declare function buildAPIInterfaceSchemaSignature(interfaceName: string, memberName: string): string;
5
5
  export declare function buildAPIInterfaceSchemaSignature(interfaceName: string, methodName: string, suffix: SchemaForgeSignatureSuffix): string;
6
6
  export declare function parseSchemaDefinitionInfo(name: string, schemaId: string): SchemaDefinitionInfo;
7
- //# sourceMappingURL=index.d.ts.map
package/lib/index.js CHANGED
@@ -58,4 +58,3 @@ function parseSchemaDefinitionInfo(name, schemaId) {
58
58
  };
59
59
  }
60
60
  }
61
- //# sourceMappingURL=index.js.map
package/lib/types.d.ts CHANGED
@@ -156,4 +156,3 @@ export interface SchemaForgeValidationResult {
156
156
  export type SchemaForgeValidationFunction<T = unknown> = ValidateFunction<T>;
157
157
  export type SchemaForgeValidationReport = ErrorObject[];
158
158
  export {};
159
- //# sourceMappingURL=types.d.ts.map
package/lib/types.js CHANGED
@@ -15,4 +15,3 @@ var SchemaDefinitionKind;
15
15
  SchemaDefinitionKind[SchemaDefinitionKind["APIMethodResult"] = 2] = "APIMethodResult";
16
16
  SchemaDefinitionKind[SchemaDefinitionKind["APIMethodArguments"] = 3] = "APIMethodArguments";
17
17
  })(SchemaDefinitionKind || (exports.SchemaDefinitionKind = SchemaDefinitionKind = {}));
18
- //# sourceMappingURL=types.js.map
@@ -1,2 +1 @@
1
1
  export declare function formatSchemaForgeError(error: Error, dir?: string): string;
2
- //# sourceMappingURL=format.error.d.ts.map
@@ -13,4 +13,3 @@ function formatSchemaForgeError(error, dir = '') {
13
13
  }
14
14
  return error.message || String(error);
15
15
  }
16
- //# sourceMappingURL=format.error.js.map
@@ -1,2 +1 @@
1
1
  export {};
2
- //# sourceMappingURL=patch.extended-annotations-reader.d.ts.map
@@ -10,7 +10,6 @@ const tsc_1 = require("./tsc");
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
- var _a;
14
13
  if (!(0, tsc_1.hasJSDocTag)(node, 'inheritDoc'))
15
14
  return getAnnotations.call(this, node);
16
15
  // @ts-expect-error access to private property
@@ -30,7 +29,7 @@ const tsc_1 = require("./tsc");
30
29
  ? checker.getAliasedSymbol(alias)
31
30
  : undefined;
32
31
  const inheritedAnn = {};
33
- if (symbol && ((_a = symbol.declarations) === null || _a === void 0 ? void 0 : _a.length)) {
32
+ if (symbol && symbol.declarations?.length) {
34
33
  for (const declaration of symbol.declarations) {
35
34
  const ann = getAnnotations.call(this, declaration);
36
35
  if (ann)
@@ -47,4 +46,3 @@ const tsc_1 = require("./tsc");
47
46
  return (0, is_empty_1.isEmptyObject)(result) ? undefined : result;
48
47
  };
49
48
  }
50
- //# sourceMappingURL=patch.extended-annotations-reader.js.map
@@ -1,3 +1,2 @@
1
1
  import { SchemaObject } from 'ajv';
2
2
  export declare function sortProperties<T extends SchemaObject>(schema: T): T;
3
- //# sourceMappingURL=sort-properties.d.ts.map
@@ -15,7 +15,6 @@ function sortProperties(schema) {
15
15
  !(0, is_empty_1.isEmptyObject)(target.properties));
16
16
  };
17
17
  const process = (item) => {
18
- var _a;
19
18
  if (!item)
20
19
  return;
21
20
  if (Array.isArray(item)) {
@@ -24,7 +23,7 @@ function sortProperties(schema) {
24
23
  else {
25
24
  if (isTarget(item)) {
26
25
  item.properties = Object.fromEntries(Object.entries(item.properties).sort(([a], [b]) => (0, compare_1.compareStringsAsc)(a, b)));
27
- if ((_a = item.required) === null || _a === void 0 ? void 0 : _a.length)
26
+ if (item.required?.length)
28
27
  item.required.sort(compare_1.compareStringsAsc);
29
28
  }
30
29
  if (typeof item === 'object') {
@@ -38,4 +37,3 @@ function sortProperties(schema) {
38
37
  }
39
38
  return schema;
40
39
  }
41
- //# sourceMappingURL=sort-properties.js.map
package/lib/util/tsc.d.ts CHANGED
@@ -5,4 +5,3 @@ export declare function readNodeName(node: NamedDeclaration): string;
5
5
  export declare function readInterfaceGenericText(node: NamedDeclaration): string;
6
6
  export declare function hasJSDocTag(statement: Node, tagName: string): boolean;
7
7
  export declare function resolveModuleFileName(containingFile: string, moduleName: string, compilerOptions: CompilerOptions, compilerHost: CompilerHost): string | undefined;
8
- //# sourceMappingURL=tsc.d.ts.map