@tsofist/schema-forge 2.12.0 → 3.0.0-next.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.
- package/lib/artefacts-policy.d.ts +3 -0
- package/lib/artefacts-policy.d.ts.map +1 -0
- package/lib/artefacts-policy.js +7 -0
- package/lib/dbml-generator/converter.d.ts +5 -0
- package/lib/dbml-generator/converter.d.ts.map +1 -0
- package/lib/dbml-generator/converter.js +15 -0
- package/lib/dbml-generator/generator.d.ts +4 -0
- package/lib/dbml-generator/generator.d.ts.map +1 -0
- package/lib/dbml-generator/generator.js +423 -0
- package/lib/dbml-generator/generator.spec.d.ts +2 -0
- package/lib/dbml-generator/generator.spec.d.ts.map +1 -0
- package/lib/dbml-generator/generator.spec.js +94 -0
- package/lib/dbml-generator/types.d.ts +144 -0
- package/lib/dbml-generator/types.d.ts.map +1 -0
- package/lib/dbml-generator/types.js +53 -0
- package/lib/definition-info/api-signature.d.ts +18 -0
- package/lib/definition-info/api-signature.d.ts.map +1 -0
- package/lib/definition-info/api-signature.js +31 -0
- package/lib/definition-info/parser.d.ts +3 -0
- package/lib/definition-info/parser.d.ts.map +1 -0
- package/lib/definition-info/parser.js +44 -0
- package/lib/definition-info/ref.d.ts +3 -0
- package/lib/definition-info/ref.d.ts.map +1 -0
- package/lib/definition-info/ref.js +6 -0
- package/lib/definition-info/types.d.ts +48 -0
- package/lib/definition-info/types.d.ts.map +1 -0
- package/lib/definition-info/types.js +20 -0
- package/lib/efc.d.ts +27 -0
- package/lib/efc.d.ts.map +1 -0
- package/lib/efc.js +9 -0
- package/lib/fake-generator/generator-host.d.ts +4 -0
- package/lib/fake-generator/generator-host.d.ts.map +1 -0
- package/lib/fake-generator/generator-host.js +57 -0
- package/lib/fake-generator/generator.d.ts +6 -0
- package/lib/fake-generator/generator.d.ts.map +1 -0
- package/lib/fake-generator/generator.js +64 -0
- package/lib/fake-generator/generator.spec.d.ts +2 -0
- package/lib/fake-generator/generator.spec.d.ts.map +1 -0
- package/lib/{fake-generator.spec.js → fake-generator/generator.spec.js} +21 -19
- package/lib/fake-generator/modules.d.ts +3 -0
- package/lib/fake-generator/modules.d.ts.map +1 -0
- package/lib/fake-generator/modules.js +44 -0
- package/lib/fake-generator/types.d.ts +18 -0
- package/lib/fake-generator/types.d.ts.map +1 -0
- package/lib/fake-generator/types.js +2 -0
- package/lib/schema-generator/extended-annotations-reader.d.ts +2 -0
- package/lib/schema-generator/extended-annotations-reader.d.ts.map +1 -0
- package/lib/{util/patch.extended-annotations-reader.js → schema-generator/extended-annotations-reader.js} +2 -2
- package/lib/schema-generator/forge.d.ts +3 -0
- package/lib/schema-generator/forge.d.ts.map +1 -0
- package/lib/{generator.js → schema-generator/forge.js} +13 -33
- package/lib/schema-generator/forge.spec.d.ts +2 -0
- package/lib/schema-generator/forge.spec.d.ts.map +1 -0
- package/lib/{generator.spec.js → schema-generator/forge.spec.js} +113 -108
- package/lib/schema-generator/format-error.d.ts +2 -0
- package/lib/schema-generator/format-error.d.ts.map +1 -0
- package/lib/{util/format.error.js → schema-generator/format-error.js} +3 -3
- package/lib/schema-generator/generate-drafts.d.ts +17 -0
- package/lib/schema-generator/generate-drafts.d.ts.map +1 -0
- package/lib/{generator/types-generator.js → schema-generator/generate-drafts.js} +140 -120
- package/lib/schema-generator/generate-schema.d.ts +15 -0
- package/lib/schema-generator/generate-schema.d.ts.map +1 -0
- package/lib/{generator/schema-generator.js → schema-generator/generate-schema.js} +21 -20
- package/lib/{util/tsc.d.ts → schema-generator/helpers-tsc.d.ts} +2 -1
- package/lib/schema-generator/helpers-tsc.d.ts.map +1 -0
- package/lib/{shrink-names.d.ts → schema-generator/shrink-definition-name.d.ts} +2 -1
- package/lib/schema-generator/shrink-definition-name.d.ts.map +1 -0
- package/lib/{shrink-names.js → schema-generator/shrink-definition-name.js} +5 -5
- package/lib/schema-generator/sort-properties.d.ts +3 -0
- package/lib/schema-generator/sort-properties.d.ts.map +1 -0
- package/lib/{util → schema-generator}/sort-properties.js +2 -2
- package/lib/schema-generator/types.d.ts +18 -0
- package/lib/schema-generator/types.d.ts.map +1 -0
- package/lib/{generator → schema-generator}/types.js +20 -8
- package/lib/schema-registry/kw-api.d.ts +3 -0
- package/lib/schema-registry/kw-api.d.ts.map +1 -0
- package/lib/schema-registry/kw-api.js +25 -0
- package/lib/schema-registry/kw-common.d.ts +3 -0
- package/lib/schema-registry/kw-common.d.ts.map +1 -0
- package/lib/schema-registry/kw-common.js +47 -0
- package/lib/schema-registry/kw-dbml.d.ts +3 -0
- package/lib/schema-registry/kw-dbml.d.ts.map +1 -0
- package/lib/schema-registry/kw-dbml.js +79 -0
- package/lib/schema-registry/loader.d.ts +10 -0
- package/lib/schema-registry/loader.d.ts.map +1 -0
- package/lib/schema-registry/loader.js +24 -0
- package/lib/schema-registry/registry.d.ts +25 -0
- package/lib/schema-registry/registry.d.ts.map +1 -0
- package/lib/schema-registry/registry.js +230 -0
- package/lib/schema-registry/types.d.ts +78 -0
- package/lib/schema-registry/types.d.ts.map +1 -0
- package/lib/schema-registry/types.js +2 -0
- package/lib/types.d.ts +51 -78
- package/lib/types.d.ts.map +1 -0
- package/lib/types.js +0 -15
- package/package.json +6 -3
- package/lib/fake-generator.d.ts +0 -21
- package/lib/fake-generator.js +0 -158
- package/lib/fake-generator.spec.d.ts +0 -1
- package/lib/generator/schema-generator.d.ts +0 -20
- package/lib/generator/types-generator.d.ts +0 -13
- package/lib/generator/types.d.ts +0 -40
- package/lib/generator.d.ts +0 -5
- package/lib/generator.spec.d.ts +0 -1
- package/lib/index.d.ts +0 -7
- package/lib/index.js +0 -64
- package/lib/types/db.types.d.ts +0 -96
- package/lib/types/db.types.js +0 -17
- package/lib/util/format.error.d.ts +0 -1
- package/lib/util/patch.extended-annotations-reader.d.ts +0 -1
- package/lib/util/sort-properties.d.ts +0 -2
- package/lib/validator.d.ts +0 -47
- package/lib/validator.js +0 -396
- /package/lib/{util/tsc.js → schema-generator/helpers-tsc.js} +0 -0
|
@@ -4,10 +4,12 @@ const promises_1 = require("node:fs/promises");
|
|
|
4
4
|
const error_1 = require("@tsofist/stem/lib/error");
|
|
5
5
|
const noop_1 = require("@tsofist/stem/lib/noop");
|
|
6
6
|
const pick_1 = require("@tsofist/stem/lib/object/pick");
|
|
7
|
-
const
|
|
8
|
-
const types_1 = require("
|
|
9
|
-
const
|
|
10
|
-
const
|
|
7
|
+
const artefacts_policy_1 = require("../artefacts-policy");
|
|
8
|
+
const types_1 = require("../definition-info/types");
|
|
9
|
+
const efc_1 = require("../efc");
|
|
10
|
+
const loader_1 = require("../schema-registry/loader");
|
|
11
|
+
const registry_1 = require("../schema-registry/registry");
|
|
12
|
+
const forge_1 = require("./forge");
|
|
11
13
|
/* eslint-disable @typescript-eslint/no-unsafe-argument */
|
|
12
14
|
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
|
|
13
15
|
describe('generator for a8', () => {
|
|
@@ -22,7 +24,7 @@ describe('generator for a8', () => {
|
|
|
22
24
|
let validator;
|
|
23
25
|
let loadedSchema;
|
|
24
26
|
beforeAll(async () => {
|
|
25
|
-
forgeSchemaResult = await (0,
|
|
27
|
+
forgeSchemaResult = await (0, forge_1.forgeSchema)({
|
|
26
28
|
schemaId: 'test',
|
|
27
29
|
allowUseFallbackDescription: true,
|
|
28
30
|
tsconfigFrom: './tsconfig.build-test.json',
|
|
@@ -34,12 +36,12 @@ describe('generator for a8', () => {
|
|
|
34
36
|
explicitPublic: true,
|
|
35
37
|
schemaMetadata,
|
|
36
38
|
});
|
|
37
|
-
validator = (0,
|
|
38
|
-
loadedSchema = await (0,
|
|
39
|
+
validator = (0, registry_1.createSchemaForgeRegistry)();
|
|
40
|
+
loadedSchema = await (0, loader_1.loadJSONSchema)([outputSchemaFile]);
|
|
39
41
|
validator.addSchema(loadedSchema);
|
|
40
42
|
});
|
|
41
43
|
afterAll(async () => {
|
|
42
|
-
if (!
|
|
44
|
+
if (!artefacts_policy_1.KEEP_SPEC_ARTEFACTS) {
|
|
43
45
|
await (0, promises_1.unlink)(outputSchemaFile).catch(noop_1.noop);
|
|
44
46
|
await (0, promises_1.unlink)(outputSchemaMetadataFile).catch(noop_1.noop);
|
|
45
47
|
}
|
|
@@ -64,10 +66,10 @@ describe('generator for a7', () => {
|
|
|
64
66
|
$comment: 'WARN: This is a test schema.',
|
|
65
67
|
};
|
|
66
68
|
let forgeSchemaResult;
|
|
67
|
-
let
|
|
69
|
+
let registry;
|
|
68
70
|
let loadedSchema;
|
|
69
71
|
beforeAll(async () => {
|
|
70
|
-
forgeSchemaResult = await (0,
|
|
72
|
+
forgeSchemaResult = await (0, forge_1.forgeSchema)({
|
|
71
73
|
schemaId: 'test',
|
|
72
74
|
allowUseFallbackDescription: true,
|
|
73
75
|
tsconfigFrom: './tsconfig.build-test.json',
|
|
@@ -79,12 +81,12 @@ describe('generator for a7', () => {
|
|
|
79
81
|
explicitPublic: true,
|
|
80
82
|
schemaMetadata,
|
|
81
83
|
});
|
|
82
|
-
|
|
83
|
-
loadedSchema = await (0,
|
|
84
|
-
|
|
84
|
+
registry = (0, registry_1.createSchemaForgeRegistry)();
|
|
85
|
+
loadedSchema = await (0, loader_1.loadJSONSchema)([outputSchemaFile]);
|
|
86
|
+
registry.addSchema(loadedSchema);
|
|
85
87
|
});
|
|
86
88
|
afterAll(async () => {
|
|
87
|
-
if (!
|
|
89
|
+
if (!artefacts_policy_1.KEEP_SPEC_ARTEFACTS) {
|
|
88
90
|
await (0, promises_1.unlink)(outputSchemaFile).catch(noop_1.noop);
|
|
89
91
|
await (0, promises_1.unlink)(outputSchemaMetadataFile).catch(noop_1.noop);
|
|
90
92
|
}
|
|
@@ -96,7 +98,7 @@ describe('generator for a7', () => {
|
|
|
96
98
|
});
|
|
97
99
|
it('generated schema should be valid', () => {
|
|
98
100
|
expect(forgeSchemaResult).toBeTruthy();
|
|
99
|
-
const schema =
|
|
101
|
+
const schema = registry.getSchema('test#/definitions/SomeAPI_doSomeWithUser__APIMethodArgs');
|
|
100
102
|
expect(schema).toBeTruthy();
|
|
101
103
|
expect(schema.items).toStrictEqual([
|
|
102
104
|
{ $ref: '#/definitions/User', title: 'user', description: 'Target user' },
|
|
@@ -111,10 +113,10 @@ describe('generator for a7', () => {
|
|
|
111
113
|
describe('validator for a7', () => {
|
|
112
114
|
const outputSchemaFile = './a7.generated.schema.tmp.json';
|
|
113
115
|
const outputSchemaMetadataFile = './a7.generated.definitions.tmp.json';
|
|
114
|
-
let
|
|
116
|
+
let registry;
|
|
115
117
|
let loadedSchema;
|
|
116
118
|
beforeAll(async () => {
|
|
117
|
-
await (0,
|
|
119
|
+
await (0, forge_1.forgeSchema)({
|
|
118
120
|
schemaId: 'test',
|
|
119
121
|
allowUseFallbackDescription: true,
|
|
120
122
|
tsconfigFrom: './tsconfig.build-test.json',
|
|
@@ -125,38 +127,38 @@ describe('validator for a7', () => {
|
|
|
125
127
|
expose: 'all',
|
|
126
128
|
explicitPublic: true,
|
|
127
129
|
});
|
|
128
|
-
|
|
129
|
-
loadedSchema = await (0,
|
|
130
|
-
|
|
130
|
+
registry = (0, registry_1.createSchemaForgeRegistry)();
|
|
131
|
+
loadedSchema = await (0, loader_1.loadJSONSchema)([outputSchemaFile]);
|
|
132
|
+
registry.addSchema(loadedSchema);
|
|
131
133
|
});
|
|
132
134
|
afterAll(async () => {
|
|
133
|
-
if (!
|
|
135
|
+
if (!artefacts_policy_1.KEEP_SPEC_ARTEFACTS) {
|
|
134
136
|
await (0, promises_1.unlink)(outputSchemaFile).catch(noop_1.noop);
|
|
135
137
|
await (0, promises_1.unlink)(outputSchemaMetadataFile).catch(noop_1.noop);
|
|
136
138
|
}
|
|
137
139
|
});
|
|
138
140
|
it('should be able to warm-up cache', async () => {
|
|
139
|
-
const initial =
|
|
141
|
+
const initial = registry.compilationArtifactCount;
|
|
140
142
|
expect(initial).toStrictEqual(2);
|
|
141
|
-
|
|
142
|
-
const warmed =
|
|
143
|
+
registry.warmupCacheSync();
|
|
144
|
+
const warmed = registry.compilationArtifactCount;
|
|
143
145
|
expect(warmed).toStrictEqual(9);
|
|
144
|
-
|
|
145
|
-
const cleared =
|
|
146
|
+
registry.clear();
|
|
147
|
+
const cleared = registry.compilationArtifactCount;
|
|
146
148
|
expect(cleared).toStrictEqual(1);
|
|
147
|
-
|
|
148
|
-
expect(
|
|
149
|
-
await
|
|
150
|
-
expect(
|
|
149
|
+
registry.addSchema(loadedSchema);
|
|
150
|
+
expect(registry.compilationArtifactCount).toStrictEqual(initial);
|
|
151
|
+
await registry.warmupCache();
|
|
152
|
+
expect(registry.compilationArtifactCount).toStrictEqual(warmed);
|
|
151
153
|
});
|
|
152
154
|
});
|
|
153
155
|
describe('generator for a6', () => {
|
|
154
156
|
const outputSchemaFile = './a6.generated.schema.tmp.json';
|
|
155
157
|
const outputSchemaMetadataFile = './a6.generated.definitions.tmp.json';
|
|
156
158
|
let forgeSchemaResult;
|
|
157
|
-
let
|
|
159
|
+
let registry;
|
|
158
160
|
beforeAll(async () => {
|
|
159
|
-
forgeSchemaResult = await (0,
|
|
161
|
+
forgeSchemaResult = await (0, forge_1.forgeSchema)({
|
|
160
162
|
schemaId: 'test',
|
|
161
163
|
tsconfigFrom: './tsconfig.build-test.json',
|
|
162
164
|
sourcesDirectoryPattern: 'test-sources/a6',
|
|
@@ -166,12 +168,12 @@ describe('generator for a6', () => {
|
|
|
166
168
|
expose: 'all',
|
|
167
169
|
explicitPublic: true,
|
|
168
170
|
});
|
|
169
|
-
|
|
170
|
-
const schema = await (0,
|
|
171
|
-
|
|
171
|
+
registry = (0, registry_1.createSchemaForgeRegistry)();
|
|
172
|
+
const schema = await (0, loader_1.loadJSONSchema)([outputSchemaFile]);
|
|
173
|
+
registry.addSchema(schema);
|
|
172
174
|
});
|
|
173
175
|
afterAll(async () => {
|
|
174
|
-
if (!
|
|
176
|
+
if (!artefacts_policy_1.KEEP_SPEC_ARTEFACTS) {
|
|
175
177
|
await (0, promises_1.unlink)(outputSchemaFile).catch(noop_1.noop);
|
|
176
178
|
await (0, promises_1.unlink)(outputSchemaMetadataFile).catch(noop_1.noop);
|
|
177
179
|
}
|
|
@@ -180,24 +182,24 @@ describe('generator for a6', () => {
|
|
|
180
182
|
expect(forgeSchemaResult).toBeTruthy();
|
|
181
183
|
const defs = forgeSchemaResult?.schema?.definitions;
|
|
182
184
|
expect(defs).toBeTruthy();
|
|
183
|
-
expect(
|
|
185
|
+
expect(registry.getValidator('test#/definitions/CollectionItemID1').schema).toStrictEqual({
|
|
184
186
|
$ref: '#/definitions/UUID',
|
|
185
187
|
format: 'uuid',
|
|
186
188
|
description: 'This is Collection item ID (inherits from UUID)',
|
|
187
189
|
});
|
|
188
|
-
expect(
|
|
190
|
+
expect(registry.getValidator('test#/definitions/CollectionItemID2').schema).toStrictEqual({
|
|
189
191
|
format: 'uuid',
|
|
190
192
|
type: 'string',
|
|
191
193
|
});
|
|
192
194
|
{
|
|
193
|
-
const rec =
|
|
195
|
+
const rec = registry.getValidator('test#/definitions/PRec<CollectionItem,UUID>').schema;
|
|
194
196
|
expect(rec).toBeTruthy();
|
|
195
197
|
expect(rec.propertyNames).toStrictEqual({
|
|
196
198
|
format: 'uuid',
|
|
197
199
|
});
|
|
198
200
|
}
|
|
199
201
|
{
|
|
200
|
-
const rec =
|
|
202
|
+
const rec = registry.getValidator('test#/definitions/PRec<CollectionItem,CollectionItemID1>').schema;
|
|
201
203
|
expect(rec).toBeTruthy();
|
|
202
204
|
expect(rec.propertyNames).toStrictEqual({
|
|
203
205
|
format: 'uuid',
|
|
@@ -210,9 +212,9 @@ describe('generator for a5', () => {
|
|
|
210
212
|
const outputSchemaFile = './a5.generated.schema.tmp.json';
|
|
211
213
|
const outputSchemaMetadataFile = './a5.generated.definitions.tmp.json';
|
|
212
214
|
let forgeSchemaResult;
|
|
213
|
-
let
|
|
215
|
+
let registry;
|
|
214
216
|
beforeAll(async () => {
|
|
215
|
-
forgeSchemaResult = await (0,
|
|
217
|
+
forgeSchemaResult = await (0, forge_1.forgeSchema)({
|
|
216
218
|
schemaId: 'test',
|
|
217
219
|
tsconfigFrom: './tsconfig.build-test.json',
|
|
218
220
|
sourcesDirectoryPattern: 'test-sources/a5',
|
|
@@ -227,12 +229,12 @@ describe('generator for a5', () => {
|
|
|
227
229
|
return undefined;
|
|
228
230
|
},
|
|
229
231
|
});
|
|
230
|
-
|
|
231
|
-
const schema = await (0,
|
|
232
|
-
|
|
232
|
+
registry = (0, registry_1.createSchemaForgeRegistry)();
|
|
233
|
+
const schema = await (0, loader_1.loadJSONSchema)([outputSchemaFile]);
|
|
234
|
+
registry.addSchema(schema);
|
|
233
235
|
});
|
|
234
236
|
afterAll(async () => {
|
|
235
|
-
if (!
|
|
237
|
+
if (!artefacts_policy_1.KEEP_SPEC_ARTEFACTS) {
|
|
236
238
|
await (0, promises_1.unlink)(outputSchemaFile).catch(noop_1.noop);
|
|
237
239
|
await (0, promises_1.unlink)(outputSchemaMetadataFile).catch(noop_1.noop);
|
|
238
240
|
}
|
|
@@ -255,12 +257,14 @@ describe('generator for a5', () => {
|
|
|
255
257
|
'VariadicList',
|
|
256
258
|
'VariadicList1',
|
|
257
259
|
]);
|
|
258
|
-
expect(
|
|
260
|
+
expect(registry.getValidator('test#/definitions/NT').schema).toStrictEqual({
|
|
259
261
|
type: 'string',
|
|
260
262
|
enum: ['v:name1', 'v:name2'],
|
|
261
263
|
});
|
|
262
|
-
expect(
|
|
263
|
-
|
|
264
|
+
expect(registry.getValidator('test#/definitions/NamesTypeAbnormal').schema).toStrictEqual({
|
|
265
|
+
type: 'string',
|
|
266
|
+
});
|
|
267
|
+
expect(registry.getValidator('test#/definitions/Some').schema).toStrictEqual({
|
|
264
268
|
type: 'object',
|
|
265
269
|
properties: {
|
|
266
270
|
vals: {
|
|
@@ -353,7 +357,7 @@ describe('generator for a4', () => {
|
|
|
353
357
|
const outputSchemaMetadataFile = './a4.generated.definitions.tmp.json';
|
|
354
358
|
let forgeSchemaResult;
|
|
355
359
|
beforeAll(async () => {
|
|
356
|
-
forgeSchemaResult = await (0,
|
|
360
|
+
forgeSchemaResult = await (0, forge_1.forgeSchema)({
|
|
357
361
|
tsconfigFrom: './tsconfig.build-test.json',
|
|
358
362
|
sourcesDirectoryPattern: 'test-sources/a4',
|
|
359
363
|
sourcesFilesPattern: 'service-api.ts',
|
|
@@ -364,7 +368,7 @@ describe('generator for a4', () => {
|
|
|
364
368
|
});
|
|
365
369
|
});
|
|
366
370
|
afterAll(async () => {
|
|
367
|
-
if (!
|
|
371
|
+
if (!artefacts_policy_1.KEEP_SPEC_ARTEFACTS) {
|
|
368
372
|
await (0, promises_1.unlink)(outputSchemaFile).catch(noop_1.noop);
|
|
369
373
|
await (0, promises_1.unlink)(outputSchemaMetadataFile).catch(noop_1.noop);
|
|
370
374
|
}
|
|
@@ -381,7 +385,7 @@ describe('generator for a3', () => {
|
|
|
381
385
|
const outputSchemaMetadataFile = './a3.generated.definitions.tmp.json';
|
|
382
386
|
let forgeSchemaResult;
|
|
383
387
|
beforeAll(async () => {
|
|
384
|
-
forgeSchemaResult = await (0,
|
|
388
|
+
forgeSchemaResult = await (0, forge_1.forgeSchema)({
|
|
385
389
|
tsconfigFrom: './tsconfig.build-test.json',
|
|
386
390
|
sourcesDirectoryPattern: 'test-sources/a3',
|
|
387
391
|
sourcesFilesPattern: 'service-api.ts',
|
|
@@ -391,7 +395,7 @@ describe('generator for a3', () => {
|
|
|
391
395
|
});
|
|
392
396
|
});
|
|
393
397
|
afterAll(async () => {
|
|
394
|
-
if (!
|
|
398
|
+
if (!artefacts_policy_1.KEEP_SPEC_ARTEFACTS) {
|
|
395
399
|
await (0, promises_1.unlink)(outputSchemaFile).catch(noop_1.noop);
|
|
396
400
|
await (0, promises_1.unlink)(outputSchemaMetadataFile).catch(noop_1.noop);
|
|
397
401
|
}
|
|
@@ -400,50 +404,51 @@ describe('generator for a3', () => {
|
|
|
400
404
|
expect(forgeSchemaResult).toBeTruthy();
|
|
401
405
|
});
|
|
402
406
|
it('should generate root schema normally', () => {
|
|
403
|
-
const registry = (0,
|
|
407
|
+
const registry = (0, registry_1.createSchemaForgeRegistry)({
|
|
408
|
+
engine: { schemas: [forgeSchemaResult.schema] },
|
|
409
|
+
});
|
|
404
410
|
expect(registry.getRootSchema('')).toBeTruthy();
|
|
405
411
|
});
|
|
406
412
|
it('interface generics should works', () => {
|
|
407
|
-
const props = forgeSchemaResult.schema.definitions?.
|
|
408
|
-
.properties;
|
|
413
|
+
const props = forgeSchemaResult.schema.definitions?.InterfaceWithGeneric__APIInterface.properties;
|
|
409
414
|
expect(props).toBeTruthy();
|
|
410
415
|
expect(props.propWithGeneric).toBeTruthy();
|
|
411
416
|
expect(props.propWithGeneric.$ref).toStrictEqual('#/definitions/NonEmptyString');
|
|
412
417
|
});
|
|
413
418
|
it('optional args in API methods should works', () => {
|
|
414
419
|
{
|
|
415
|
-
const props = forgeSchemaResult.schema.definitions?.
|
|
420
|
+
const props = forgeSchemaResult.schema.definitions?.API_methodG0__APIMethodArgs;
|
|
416
421
|
expect(props).toBeTruthy();
|
|
417
422
|
expect(props.minItems).toStrictEqual(0);
|
|
418
423
|
expect(props.maxItems).toStrictEqual(1);
|
|
419
424
|
}
|
|
420
425
|
{
|
|
421
|
-
const props = forgeSchemaResult.schema.definitions?.
|
|
426
|
+
const props = forgeSchemaResult.schema.definitions?.API_methodG1__APIMethodArgs;
|
|
422
427
|
expect(props).toBeTruthy();
|
|
423
428
|
expect(props.minItems).toStrictEqual(0);
|
|
424
429
|
expect(props.maxItems).toStrictEqual(2);
|
|
425
430
|
}
|
|
426
431
|
{
|
|
427
|
-
const props = forgeSchemaResult.schema.definitions?.
|
|
432
|
+
const props = forgeSchemaResult.schema.definitions?.API_methodG2__APIMethodArgs;
|
|
428
433
|
expect(props).toBeTruthy();
|
|
429
434
|
expect(props.minItems).toStrictEqual(1);
|
|
430
435
|
expect(props.maxItems).toStrictEqual(2);
|
|
431
436
|
}
|
|
432
437
|
// {
|
|
433
|
-
// const props = forgeSchemaResult!.schema.definitions?.
|
|
438
|
+
// const props = forgeSchemaResult!.schema.definitions?.API_methodG3__APIMethodArgs;
|
|
434
439
|
// expect(props).toBeTruthy();
|
|
435
440
|
// expect(props.minItems).toStrictEqual(0);
|
|
436
441
|
// expect(props.maxItems).toBeUndefined();
|
|
437
442
|
// }
|
|
438
443
|
// {
|
|
439
|
-
// const props = forgeSchemaResult!.schema.definitions?.
|
|
444
|
+
// const props = forgeSchemaResult!.schema.definitions?.API_methodG4__APIMethodArgs;
|
|
440
445
|
// expect(props).toBeTruthy();
|
|
441
446
|
// expect(props.minItems).toStrictEqual(1);
|
|
442
447
|
// expect(props.maxItems).toBeUndefined();
|
|
443
448
|
// }
|
|
444
449
|
});
|
|
445
450
|
it('extends should works', () => {
|
|
446
|
-
const props = forgeSchemaResult.schema.definitions?.
|
|
451
|
+
const props = forgeSchemaResult.schema.definitions?.BAPI__APIInterface.properties;
|
|
447
452
|
expect(props).toBeTruthy();
|
|
448
453
|
expect(Object.keys(props)).toStrictEqual([
|
|
449
454
|
'propertyA',
|
|
@@ -468,7 +473,7 @@ describe('generator for a2', () => {
|
|
|
468
473
|
const outputSchemaMetadataFile = './a2.generated.definitions.tmp.json';
|
|
469
474
|
let forgeSchemaResult;
|
|
470
475
|
beforeAll(async () => {
|
|
471
|
-
forgeSchemaResult = await (0,
|
|
476
|
+
forgeSchemaResult = await (0, forge_1.forgeSchema)({
|
|
472
477
|
tsconfigFrom: './tsconfig.build-test.json',
|
|
473
478
|
sourcesDirectoryPattern: 'test-sources/a2',
|
|
474
479
|
sourcesFilesPattern: 'service-api.ts',
|
|
@@ -477,7 +482,7 @@ describe('generator for a2', () => {
|
|
|
477
482
|
});
|
|
478
483
|
});
|
|
479
484
|
afterAll(async () => {
|
|
480
|
-
if (!
|
|
485
|
+
if (!artefacts_policy_1.KEEP_SPEC_ARTEFACTS) {
|
|
481
486
|
await (0, promises_1.unlink)(outputSchemaFile).catch(noop_1.noop);
|
|
482
487
|
await (0, promises_1.unlink)(outputSchemaMetadataFile).catch(noop_1.noop);
|
|
483
488
|
}
|
|
@@ -493,7 +498,7 @@ describe('generator for a1', () => {
|
|
|
493
498
|
let forgeSchemaResult;
|
|
494
499
|
let validator;
|
|
495
500
|
beforeAll(async () => {
|
|
496
|
-
forgeSchemaResult = await (0,
|
|
501
|
+
forgeSchemaResult = await (0, forge_1.forgeSchema)({
|
|
497
502
|
allowUseFallbackDescription: false,
|
|
498
503
|
explicitPublic: true,
|
|
499
504
|
schemaId,
|
|
@@ -503,12 +508,12 @@ describe('generator for a1', () => {
|
|
|
503
508
|
outputSchemaFile,
|
|
504
509
|
outputSchemaMetadataFile,
|
|
505
510
|
});
|
|
506
|
-
validator = (0,
|
|
507
|
-
const schema = await (0,
|
|
511
|
+
validator = (0, registry_1.createSchemaForgeRegistry)();
|
|
512
|
+
const schema = await (0, loader_1.loadJSONSchema)([outputSchemaFile]);
|
|
508
513
|
validator.addSchema(schema);
|
|
509
514
|
}, 10_000);
|
|
510
515
|
afterAll(async () => {
|
|
511
|
-
if (!
|
|
516
|
+
if (!artefacts_policy_1.KEEP_SPEC_ARTEFACTS) {
|
|
512
517
|
await (0, promises_1.unlink)(outputSchemaFile).catch(noop_1.noop);
|
|
513
518
|
await (0, promises_1.unlink)(outputSchemaMetadataFile).catch(noop_1.noop);
|
|
514
519
|
}
|
|
@@ -539,16 +544,16 @@ describe('generator for a1', () => {
|
|
|
539
544
|
});
|
|
540
545
|
});
|
|
541
546
|
it('hasSchema', () => {
|
|
542
|
-
expect(validator.
|
|
543
|
-
expect(validator.
|
|
544
|
-
expect(validator.
|
|
545
|
-
expect(validator.
|
|
547
|
+
expect(validator.hasSchema('test#/definitions/SomeType1')).toStrictEqual(true);
|
|
548
|
+
expect(validator.hasSchema('test#/definitions/PositiveInt')).toStrictEqual(true);
|
|
549
|
+
expect(validator.hasSchema('test#/definitions/Int')).toStrictEqual(false);
|
|
550
|
+
expect(validator.hasSchema('test#/definitions/!Int')).toStrictEqual(false);
|
|
546
551
|
});
|
|
547
552
|
it('checkBySchema', () => {
|
|
548
|
-
expect(() => validator.checkBySchema('test#/definitions/
|
|
553
|
+
expect(() => validator.checkBySchema('test#/definitions/ExportedInterfaceB__APIInterface', {})).toThrow(efc_1.SchemaForgeErrors.msg('EC_SF_VALIDATION_FAILED'));
|
|
549
554
|
expect(validator.checkBySchema('test#/definitions/PositiveInt', 1)).toStrictEqual(true);
|
|
550
|
-
expect(() => validator.checkBySchema('test#/definitions/PositiveInt', 1.1)).toThrow(
|
|
551
|
-
expect(() => validator.checkBySchema('!test#/definitions/PositiveInt', 1)).toThrow(
|
|
555
|
+
expect(() => validator.checkBySchema('test#/definitions/PositiveInt', 1.1)).toThrow(efc_1.SchemaForgeErrors.msg('EC_SF_VALIDATION_FAILED'));
|
|
556
|
+
expect(() => validator.checkBySchema('!test#/definitions/PositiveInt', 1)).toThrow(efc_1.SchemaForgeErrors.msg('EC_SF_SCHEMA_NOT_FOUND'));
|
|
552
557
|
{
|
|
553
558
|
const schema = '!test#/definitions/Int';
|
|
554
559
|
try {
|
|
@@ -557,8 +562,8 @@ describe('generator for a1', () => {
|
|
|
557
562
|
catch (e) {
|
|
558
563
|
const context = (0, error_1.readErrorContext)(e);
|
|
559
564
|
const code = (0, error_1.readErrorCode)(e);
|
|
560
|
-
expect(e.message).toStrictEqual(
|
|
561
|
-
expect(code).toStrictEqual(
|
|
565
|
+
expect(e.message).toStrictEqual(efc_1.SchemaForgeErrors.msg('EC_SF_SCHEMA_NOT_FOUND'));
|
|
566
|
+
expect(code).toStrictEqual('EC_SF_SCHEMA_NOT_FOUND');
|
|
562
567
|
expect(context).toBeTruthy();
|
|
563
568
|
expect(context.schema).toStrictEqual(schema);
|
|
564
569
|
expect(context.errorMessage).toStrictEqual(undefined);
|
|
@@ -573,8 +578,8 @@ describe('generator for a1', () => {
|
|
|
573
578
|
catch (e) {
|
|
574
579
|
const context = (0, error_1.readErrorContext)(e);
|
|
575
580
|
const code = (0, error_1.readErrorCode)(e);
|
|
576
|
-
expect(
|
|
577
|
-
expect(
|
|
581
|
+
expect(code).toStrictEqual('EC_SF_VALIDATION_FAILED');
|
|
582
|
+
expect(e.message).toStrictEqual(efc_1.SchemaForgeErrors.msg(code));
|
|
578
583
|
expect(context).toBeTruthy();
|
|
579
584
|
expect(context.schema).toStrictEqual(schema);
|
|
580
585
|
expect(context.errorMessage).toStrictEqual(message);
|
|
@@ -585,63 +590,63 @@ describe('generator for a1', () => {
|
|
|
585
590
|
it('listDefinitions', () => {
|
|
586
591
|
const defs = [
|
|
587
592
|
{
|
|
588
|
-
ref: 'test#/definitions/
|
|
593
|
+
ref: 'test#/definitions/ExportedInterfaceB__APIInterface',
|
|
589
594
|
kind: 1,
|
|
590
|
-
name: '
|
|
595
|
+
name: 'ExportedInterfaceB__APIInterface',
|
|
591
596
|
schemaId: 'test',
|
|
592
597
|
interface: 'ExportedInterfaceB',
|
|
593
598
|
},
|
|
594
599
|
{
|
|
595
|
-
ref: 'test#/definitions/
|
|
600
|
+
ref: 'test#/definitions/ExportedInterfaceB_methodA__APIMethodArgs',
|
|
596
601
|
kind: 3,
|
|
597
|
-
name: '
|
|
602
|
+
name: 'ExportedInterfaceB_methodA__APIMethodArgs',
|
|
598
603
|
schemaId: 'test',
|
|
599
604
|
interface: 'ExportedInterfaceB',
|
|
600
605
|
method: 'methodA',
|
|
601
606
|
},
|
|
602
607
|
{
|
|
603
|
-
ref: 'test#/definitions/
|
|
608
|
+
ref: 'test#/definitions/ExportedInterfaceB_methodA__APIMethodResult',
|
|
604
609
|
kind: 2,
|
|
605
|
-
name: '
|
|
610
|
+
name: 'ExportedInterfaceB_methodA__APIMethodResult',
|
|
606
611
|
schemaId: 'test',
|
|
607
612
|
interface: 'ExportedInterfaceB',
|
|
608
613
|
method: 'methodA',
|
|
609
614
|
},
|
|
610
615
|
{
|
|
611
|
-
ref: 'test#/definitions/
|
|
616
|
+
ref: 'test#/definitions/ExportedInterfaceB_methodB__APIMethodArgs',
|
|
612
617
|
kind: 3,
|
|
613
|
-
name: '
|
|
618
|
+
name: 'ExportedInterfaceB_methodB__APIMethodArgs',
|
|
614
619
|
schemaId: 'test',
|
|
615
620
|
interface: 'ExportedInterfaceB',
|
|
616
621
|
method: 'methodB',
|
|
617
622
|
},
|
|
618
623
|
{
|
|
619
|
-
ref: 'test#/definitions/
|
|
624
|
+
ref: 'test#/definitions/ExportedInterfaceB_methodB__APIMethodResult',
|
|
620
625
|
kind: 2,
|
|
621
|
-
name: '
|
|
626
|
+
name: 'ExportedInterfaceB_methodB__APIMethodResult',
|
|
622
627
|
schemaId: 'test',
|
|
623
628
|
interface: 'ExportedInterfaceB',
|
|
624
629
|
method: 'methodB',
|
|
625
630
|
},
|
|
626
631
|
{
|
|
627
|
-
ref: 'test#/definitions/
|
|
632
|
+
ref: 'test#/definitions/NonExportedInterfaceD__APIInterface',
|
|
628
633
|
kind: 1,
|
|
629
|
-
name: '
|
|
634
|
+
name: 'NonExportedInterfaceD__APIInterface',
|
|
630
635
|
schemaId: 'test',
|
|
631
636
|
interface: 'NonExportedInterfaceD',
|
|
632
637
|
},
|
|
633
638
|
{
|
|
634
|
-
ref: 'test#/definitions/
|
|
639
|
+
ref: 'test#/definitions/NonExportedInterfaceD_methodA__APIMethodArgs',
|
|
635
640
|
kind: 3,
|
|
636
|
-
name: '
|
|
641
|
+
name: 'NonExportedInterfaceD_methodA__APIMethodArgs',
|
|
637
642
|
schemaId: 'test',
|
|
638
643
|
interface: 'NonExportedInterfaceD',
|
|
639
644
|
method: 'methodA',
|
|
640
645
|
},
|
|
641
646
|
{
|
|
642
|
-
ref: 'test#/definitions/
|
|
647
|
+
ref: 'test#/definitions/NonExportedInterfaceD_methodA__APIMethodResult',
|
|
643
648
|
kind: 2,
|
|
644
|
-
name: '
|
|
649
|
+
name: 'NonExportedInterfaceD_methodA__APIMethodResult',
|
|
645
650
|
schemaId: 'test',
|
|
646
651
|
interface: 'NonExportedInterfaceD',
|
|
647
652
|
method: 'methodA',
|
|
@@ -673,24 +678,24 @@ describe('generator for a1', () => {
|
|
|
673
678
|
defsByName[def.name] = def;
|
|
674
679
|
}
|
|
675
680
|
expect(validator.listDefinitions()).toStrictEqual(defs);
|
|
676
|
-
expect(validator.listDefinitions((info) => info.kind === types_1.
|
|
677
|
-
expect(validator.listDefinitions((info) => info.kind === types_1.
|
|
678
|
-
defsByName['
|
|
679
|
-
defsByName['
|
|
681
|
+
expect(validator.listDefinitions((info) => info.kind === types_1.SchemaDefinitionInfoKind.Type && !info.name.startsWith('Some'))).toStrictEqual([defsByName['PositiveInt']]);
|
|
682
|
+
expect(validator.listDefinitions((info) => info.kind === types_1.SchemaDefinitionInfoKind.API)).toStrictEqual([
|
|
683
|
+
defsByName['ExportedInterfaceB__APIInterface'],
|
|
684
|
+
defsByName['NonExportedInterfaceD__APIInterface'],
|
|
680
685
|
]);
|
|
681
|
-
expect(validator.listDefinitions((info) => info.kind === types_1.
|
|
682
|
-
defsByName['
|
|
683
|
-
defsByName['
|
|
684
|
-
defsByName['
|
|
686
|
+
expect(validator.listDefinitions((info) => info.kind === types_1.SchemaDefinitionInfoKind.APIMethodResult)).toStrictEqual([
|
|
687
|
+
defsByName['ExportedInterfaceB_methodA__APIMethodResult'],
|
|
688
|
+
defsByName['ExportedInterfaceB_methodB__APIMethodResult'],
|
|
689
|
+
defsByName['NonExportedInterfaceD_methodA__APIMethodResult'],
|
|
685
690
|
]);
|
|
686
|
-
expect(validator.listDefinitions((info) => info.kind === types_1.
|
|
687
|
-
defsByName['
|
|
688
|
-
defsByName['
|
|
689
|
-
defsByName['
|
|
691
|
+
expect(validator.listDefinitions((info) => info.kind === types_1.SchemaDefinitionInfoKind.APIMethodArguments)).toStrictEqual([
|
|
692
|
+
defsByName['ExportedInterfaceB_methodA__APIMethodArgs'],
|
|
693
|
+
defsByName['ExportedInterfaceB_methodB__APIMethodArgs'],
|
|
694
|
+
defsByName['NonExportedInterfaceD_methodA__APIMethodArgs'],
|
|
690
695
|
]);
|
|
691
696
|
});
|
|
692
697
|
it('should be valid descriptions', () => {
|
|
693
|
-
const schema = validator.getSchema('test#/definitions/
|
|
698
|
+
const schema = validator.getSchema('test#/definitions/ExportedInterfaceB__APIInterface');
|
|
694
699
|
expect(schema).toBeTruthy();
|
|
695
700
|
expect(schema.description).toStrictEqual('TAG: Description for ExportedInterfaceB');
|
|
696
701
|
expect(schema.properties.propertyA.description).toStrictEqual('Description for propertyA');
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format-error.d.ts","sourceRoot":"","sources":["../../src/schema-generator/format-error.ts"],"names":[],"mappings":"AAGA,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,KAAK,EAAE,GAAG,SAAK,UAU5D"}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.formatForgeSchemaError = formatForgeSchemaError;
|
|
4
4
|
const ts_json_schema_generator_1 = require("ts-json-schema-generator");
|
|
5
5
|
const typescript_1 = require("typescript");
|
|
6
|
-
function
|
|
6
|
+
function formatForgeSchemaError(error, dir = '') {
|
|
7
7
|
if (error instanceof ts_json_schema_generator_1.BaseError) {
|
|
8
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-
|
|
8
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument,@typescript-eslint/no-unsafe-member-access
|
|
9
9
|
return (0, typescript_1.formatDiagnostics)(error.diagnostic.relatedInformation || [], {
|
|
10
10
|
getCanonicalFileName: (fileName) => fileName,
|
|
11
11
|
getCurrentDirectory: () => dir,
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type CompletedConfig } from 'ts-json-schema-generator/dist/src/Config';
|
|
2
|
+
import { ForgeSchemaOptions } from '../types';
|
|
3
|
+
/**
|
|
4
|
+
* @internal
|
|
5
|
+
*/
|
|
6
|
+
export declare function generateDraftTypeFiles(options: SFDTGOptions): Promise<{
|
|
7
|
+
files: string[];
|
|
8
|
+
definitions: string[];
|
|
9
|
+
sourcesTypesGeneratorConfig: CompletedConfig;
|
|
10
|
+
namesBySourceFile: Map<string, Set<string>>;
|
|
11
|
+
}>;
|
|
12
|
+
interface SFDTGOptions extends ForgeSchemaOptions {
|
|
13
|
+
tsconfig: string;
|
|
14
|
+
sourcesPattern: string[];
|
|
15
|
+
}
|
|
16
|
+
export {};
|
|
17
|
+
//# sourceMappingURL=generate-drafts.d.ts.map
|
|
@@ -0,0 +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;AA2WD,UAAU,YAAa,SAAQ,kBAAkB;IAC7C,QAAQ,EAAE,MAAM,CAAC;IACjB,cAAc,EAAE,MAAM,EAAE,CAAC;CAC5B"}
|