@tsofist/schema-forge 2.11.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} +116 -107
- 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} +26 -19
- 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/schema-generator/shrink-definition-name.d.ts +7 -0
- package/lib/schema-generator/shrink-definition-name.d.ts.map +1 -0
- package/lib/schema-generator/shrink-definition-name.js +21 -0
- 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 +53 -79
- package/lib/types.d.ts.map +1 -0
- package/lib/types.js +0 -15
- package/package.json +7 -4
- 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
|
}
|
|
@@ -399,47 +403,52 @@ describe('generator for a3', () => {
|
|
|
399
403
|
it('generated schema should be valid', () => {
|
|
400
404
|
expect(forgeSchemaResult).toBeTruthy();
|
|
401
405
|
});
|
|
406
|
+
it('should generate root schema normally', () => {
|
|
407
|
+
const registry = (0, registry_1.createSchemaForgeRegistry)({
|
|
408
|
+
engine: { schemas: [forgeSchemaResult.schema] },
|
|
409
|
+
});
|
|
410
|
+
expect(registry.getRootSchema('')).toBeTruthy();
|
|
411
|
+
});
|
|
402
412
|
it('interface generics should works', () => {
|
|
403
|
-
const props = forgeSchemaResult.schema.definitions?.
|
|
404
|
-
.properties;
|
|
413
|
+
const props = forgeSchemaResult.schema.definitions?.InterfaceWithGeneric__APIInterface.properties;
|
|
405
414
|
expect(props).toBeTruthy();
|
|
406
415
|
expect(props.propWithGeneric).toBeTruthy();
|
|
407
416
|
expect(props.propWithGeneric.$ref).toStrictEqual('#/definitions/NonEmptyString');
|
|
408
417
|
});
|
|
409
418
|
it('optional args in API methods should works', () => {
|
|
410
419
|
{
|
|
411
|
-
const props = forgeSchemaResult.schema.definitions?.
|
|
420
|
+
const props = forgeSchemaResult.schema.definitions?.API_methodG0__APIMethodArgs;
|
|
412
421
|
expect(props).toBeTruthy();
|
|
413
422
|
expect(props.minItems).toStrictEqual(0);
|
|
414
423
|
expect(props.maxItems).toStrictEqual(1);
|
|
415
424
|
}
|
|
416
425
|
{
|
|
417
|
-
const props = forgeSchemaResult.schema.definitions?.
|
|
426
|
+
const props = forgeSchemaResult.schema.definitions?.API_methodG1__APIMethodArgs;
|
|
418
427
|
expect(props).toBeTruthy();
|
|
419
428
|
expect(props.minItems).toStrictEqual(0);
|
|
420
429
|
expect(props.maxItems).toStrictEqual(2);
|
|
421
430
|
}
|
|
422
431
|
{
|
|
423
|
-
const props = forgeSchemaResult.schema.definitions?.
|
|
432
|
+
const props = forgeSchemaResult.schema.definitions?.API_methodG2__APIMethodArgs;
|
|
424
433
|
expect(props).toBeTruthy();
|
|
425
434
|
expect(props.minItems).toStrictEqual(1);
|
|
426
435
|
expect(props.maxItems).toStrictEqual(2);
|
|
427
436
|
}
|
|
428
437
|
// {
|
|
429
|
-
// const props = forgeSchemaResult!.schema.definitions?.
|
|
438
|
+
// const props = forgeSchemaResult!.schema.definitions?.API_methodG3__APIMethodArgs;
|
|
430
439
|
// expect(props).toBeTruthy();
|
|
431
440
|
// expect(props.minItems).toStrictEqual(0);
|
|
432
441
|
// expect(props.maxItems).toBeUndefined();
|
|
433
442
|
// }
|
|
434
443
|
// {
|
|
435
|
-
// const props = forgeSchemaResult!.schema.definitions?.
|
|
444
|
+
// const props = forgeSchemaResult!.schema.definitions?.API_methodG4__APIMethodArgs;
|
|
436
445
|
// expect(props).toBeTruthy();
|
|
437
446
|
// expect(props.minItems).toStrictEqual(1);
|
|
438
447
|
// expect(props.maxItems).toBeUndefined();
|
|
439
448
|
// }
|
|
440
449
|
});
|
|
441
450
|
it('extends should works', () => {
|
|
442
|
-
const props = forgeSchemaResult.schema.definitions?.
|
|
451
|
+
const props = forgeSchemaResult.schema.definitions?.BAPI__APIInterface.properties;
|
|
443
452
|
expect(props).toBeTruthy();
|
|
444
453
|
expect(Object.keys(props)).toStrictEqual([
|
|
445
454
|
'propertyA',
|
|
@@ -464,7 +473,7 @@ describe('generator for a2', () => {
|
|
|
464
473
|
const outputSchemaMetadataFile = './a2.generated.definitions.tmp.json';
|
|
465
474
|
let forgeSchemaResult;
|
|
466
475
|
beforeAll(async () => {
|
|
467
|
-
forgeSchemaResult = await (0,
|
|
476
|
+
forgeSchemaResult = await (0, forge_1.forgeSchema)({
|
|
468
477
|
tsconfigFrom: './tsconfig.build-test.json',
|
|
469
478
|
sourcesDirectoryPattern: 'test-sources/a2',
|
|
470
479
|
sourcesFilesPattern: 'service-api.ts',
|
|
@@ -473,7 +482,7 @@ describe('generator for a2', () => {
|
|
|
473
482
|
});
|
|
474
483
|
});
|
|
475
484
|
afterAll(async () => {
|
|
476
|
-
if (!
|
|
485
|
+
if (!artefacts_policy_1.KEEP_SPEC_ARTEFACTS) {
|
|
477
486
|
await (0, promises_1.unlink)(outputSchemaFile).catch(noop_1.noop);
|
|
478
487
|
await (0, promises_1.unlink)(outputSchemaMetadataFile).catch(noop_1.noop);
|
|
479
488
|
}
|
|
@@ -489,7 +498,7 @@ describe('generator for a1', () => {
|
|
|
489
498
|
let forgeSchemaResult;
|
|
490
499
|
let validator;
|
|
491
500
|
beforeAll(async () => {
|
|
492
|
-
forgeSchemaResult = await (0,
|
|
501
|
+
forgeSchemaResult = await (0, forge_1.forgeSchema)({
|
|
493
502
|
allowUseFallbackDescription: false,
|
|
494
503
|
explicitPublic: true,
|
|
495
504
|
schemaId,
|
|
@@ -499,12 +508,12 @@ describe('generator for a1', () => {
|
|
|
499
508
|
outputSchemaFile,
|
|
500
509
|
outputSchemaMetadataFile,
|
|
501
510
|
});
|
|
502
|
-
validator = (0,
|
|
503
|
-
const schema = await (0,
|
|
511
|
+
validator = (0, registry_1.createSchemaForgeRegistry)();
|
|
512
|
+
const schema = await (0, loader_1.loadJSONSchema)([outputSchemaFile]);
|
|
504
513
|
validator.addSchema(schema);
|
|
505
514
|
}, 10_000);
|
|
506
515
|
afterAll(async () => {
|
|
507
|
-
if (!
|
|
516
|
+
if (!artefacts_policy_1.KEEP_SPEC_ARTEFACTS) {
|
|
508
517
|
await (0, promises_1.unlink)(outputSchemaFile).catch(noop_1.noop);
|
|
509
518
|
await (0, promises_1.unlink)(outputSchemaMetadataFile).catch(noop_1.noop);
|
|
510
519
|
}
|
|
@@ -535,16 +544,16 @@ describe('generator for a1', () => {
|
|
|
535
544
|
});
|
|
536
545
|
});
|
|
537
546
|
it('hasSchema', () => {
|
|
538
|
-
expect(validator.
|
|
539
|
-
expect(validator.
|
|
540
|
-
expect(validator.
|
|
541
|
-
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);
|
|
542
551
|
});
|
|
543
552
|
it('checkBySchema', () => {
|
|
544
|
-
expect(() => validator.checkBySchema('test#/definitions/
|
|
553
|
+
expect(() => validator.checkBySchema('test#/definitions/ExportedInterfaceB__APIInterface', {})).toThrow(efc_1.SchemaForgeErrors.msg('EC_SF_VALIDATION_FAILED'));
|
|
545
554
|
expect(validator.checkBySchema('test#/definitions/PositiveInt', 1)).toStrictEqual(true);
|
|
546
|
-
expect(() => validator.checkBySchema('test#/definitions/PositiveInt', 1.1)).toThrow(
|
|
547
|
-
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'));
|
|
548
557
|
{
|
|
549
558
|
const schema = '!test#/definitions/Int';
|
|
550
559
|
try {
|
|
@@ -553,8 +562,8 @@ describe('generator for a1', () => {
|
|
|
553
562
|
catch (e) {
|
|
554
563
|
const context = (0, error_1.readErrorContext)(e);
|
|
555
564
|
const code = (0, error_1.readErrorCode)(e);
|
|
556
|
-
expect(e.message).toStrictEqual(
|
|
557
|
-
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');
|
|
558
567
|
expect(context).toBeTruthy();
|
|
559
568
|
expect(context.schema).toStrictEqual(schema);
|
|
560
569
|
expect(context.errorMessage).toStrictEqual(undefined);
|
|
@@ -569,8 +578,8 @@ describe('generator for a1', () => {
|
|
|
569
578
|
catch (e) {
|
|
570
579
|
const context = (0, error_1.readErrorContext)(e);
|
|
571
580
|
const code = (0, error_1.readErrorCode)(e);
|
|
572
|
-
expect(
|
|
573
|
-
expect(
|
|
581
|
+
expect(code).toStrictEqual('EC_SF_VALIDATION_FAILED');
|
|
582
|
+
expect(e.message).toStrictEqual(efc_1.SchemaForgeErrors.msg(code));
|
|
574
583
|
expect(context).toBeTruthy();
|
|
575
584
|
expect(context.schema).toStrictEqual(schema);
|
|
576
585
|
expect(context.errorMessage).toStrictEqual(message);
|
|
@@ -581,63 +590,63 @@ describe('generator for a1', () => {
|
|
|
581
590
|
it('listDefinitions', () => {
|
|
582
591
|
const defs = [
|
|
583
592
|
{
|
|
584
|
-
ref: 'test#/definitions/
|
|
593
|
+
ref: 'test#/definitions/ExportedInterfaceB__APIInterface',
|
|
585
594
|
kind: 1,
|
|
586
|
-
name: '
|
|
595
|
+
name: 'ExportedInterfaceB__APIInterface',
|
|
587
596
|
schemaId: 'test',
|
|
588
597
|
interface: 'ExportedInterfaceB',
|
|
589
598
|
},
|
|
590
599
|
{
|
|
591
|
-
ref: 'test#/definitions/
|
|
600
|
+
ref: 'test#/definitions/ExportedInterfaceB_methodA__APIMethodArgs',
|
|
592
601
|
kind: 3,
|
|
593
|
-
name: '
|
|
602
|
+
name: 'ExportedInterfaceB_methodA__APIMethodArgs',
|
|
594
603
|
schemaId: 'test',
|
|
595
604
|
interface: 'ExportedInterfaceB',
|
|
596
605
|
method: 'methodA',
|
|
597
606
|
},
|
|
598
607
|
{
|
|
599
|
-
ref: 'test#/definitions/
|
|
608
|
+
ref: 'test#/definitions/ExportedInterfaceB_methodA__APIMethodResult',
|
|
600
609
|
kind: 2,
|
|
601
|
-
name: '
|
|
610
|
+
name: 'ExportedInterfaceB_methodA__APIMethodResult',
|
|
602
611
|
schemaId: 'test',
|
|
603
612
|
interface: 'ExportedInterfaceB',
|
|
604
613
|
method: 'methodA',
|
|
605
614
|
},
|
|
606
615
|
{
|
|
607
|
-
ref: 'test#/definitions/
|
|
616
|
+
ref: 'test#/definitions/ExportedInterfaceB_methodB__APIMethodArgs',
|
|
608
617
|
kind: 3,
|
|
609
|
-
name: '
|
|
618
|
+
name: 'ExportedInterfaceB_methodB__APIMethodArgs',
|
|
610
619
|
schemaId: 'test',
|
|
611
620
|
interface: 'ExportedInterfaceB',
|
|
612
621
|
method: 'methodB',
|
|
613
622
|
},
|
|
614
623
|
{
|
|
615
|
-
ref: 'test#/definitions/
|
|
624
|
+
ref: 'test#/definitions/ExportedInterfaceB_methodB__APIMethodResult',
|
|
616
625
|
kind: 2,
|
|
617
|
-
name: '
|
|
626
|
+
name: 'ExportedInterfaceB_methodB__APIMethodResult',
|
|
618
627
|
schemaId: 'test',
|
|
619
628
|
interface: 'ExportedInterfaceB',
|
|
620
629
|
method: 'methodB',
|
|
621
630
|
},
|
|
622
631
|
{
|
|
623
|
-
ref: 'test#/definitions/
|
|
632
|
+
ref: 'test#/definitions/NonExportedInterfaceD__APIInterface',
|
|
624
633
|
kind: 1,
|
|
625
|
-
name: '
|
|
634
|
+
name: 'NonExportedInterfaceD__APIInterface',
|
|
626
635
|
schemaId: 'test',
|
|
627
636
|
interface: 'NonExportedInterfaceD',
|
|
628
637
|
},
|
|
629
638
|
{
|
|
630
|
-
ref: 'test#/definitions/
|
|
639
|
+
ref: 'test#/definitions/NonExportedInterfaceD_methodA__APIMethodArgs',
|
|
631
640
|
kind: 3,
|
|
632
|
-
name: '
|
|
641
|
+
name: 'NonExportedInterfaceD_methodA__APIMethodArgs',
|
|
633
642
|
schemaId: 'test',
|
|
634
643
|
interface: 'NonExportedInterfaceD',
|
|
635
644
|
method: 'methodA',
|
|
636
645
|
},
|
|
637
646
|
{
|
|
638
|
-
ref: 'test#/definitions/
|
|
647
|
+
ref: 'test#/definitions/NonExportedInterfaceD_methodA__APIMethodResult',
|
|
639
648
|
kind: 2,
|
|
640
|
-
name: '
|
|
649
|
+
name: 'NonExportedInterfaceD_methodA__APIMethodResult',
|
|
641
650
|
schemaId: 'test',
|
|
642
651
|
interface: 'NonExportedInterfaceD',
|
|
643
652
|
method: 'methodA',
|
|
@@ -669,24 +678,24 @@ describe('generator for a1', () => {
|
|
|
669
678
|
defsByName[def.name] = def;
|
|
670
679
|
}
|
|
671
680
|
expect(validator.listDefinitions()).toStrictEqual(defs);
|
|
672
|
-
expect(validator.listDefinitions((info) => info.kind === types_1.
|
|
673
|
-
expect(validator.listDefinitions((info) => info.kind === types_1.
|
|
674
|
-
defsByName['
|
|
675
|
-
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'],
|
|
676
685
|
]);
|
|
677
|
-
expect(validator.listDefinitions((info) => info.kind === types_1.
|
|
678
|
-
defsByName['
|
|
679
|
-
defsByName['
|
|
680
|
-
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'],
|
|
681
690
|
]);
|
|
682
|
-
expect(validator.listDefinitions((info) => info.kind === types_1.
|
|
683
|
-
defsByName['
|
|
684
|
-
defsByName['
|
|
685
|
-
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'],
|
|
686
695
|
]);
|
|
687
696
|
});
|
|
688
697
|
it('should be valid descriptions', () => {
|
|
689
|
-
const schema = validator.getSchema('test#/definitions/
|
|
698
|
+
const schema = validator.getSchema('test#/definitions/ExportedInterfaceB__APIInterface');
|
|
690
699
|
expect(schema).toBeTruthy();
|
|
691
700
|
expect(schema.description).toStrictEqual('TAG: Description for ExportedInterfaceB');
|
|
692
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"}
|