@tsofist/schema-forge 2.8.0 → 2.10.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} +157 -103
- 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 -2
- 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} +46 -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 +9 -6
- 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 -64
- 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 -385
- /package/lib/{util/tsc.js → schema-generator/helpers-tsc.js} +0 -0
|
@@ -4,12 +4,59 @@ 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 */
|
|
15
|
+
describe('generator for a8', () => {
|
|
16
|
+
const outputSchemaFile = './a8.generated.schema.tmp.json';
|
|
17
|
+
const outputSchemaMetadataFile = './a8.generated.definitions.tmp.json';
|
|
18
|
+
const schemaMetadata = {
|
|
19
|
+
title: 'Generator TEST',
|
|
20
|
+
version: '1.0.0',
|
|
21
|
+
$comment: 'WARN: This is a test schema.',
|
|
22
|
+
};
|
|
23
|
+
let forgeSchemaResult;
|
|
24
|
+
let validator;
|
|
25
|
+
let loadedSchema;
|
|
26
|
+
beforeAll(async () => {
|
|
27
|
+
forgeSchemaResult = await (0, forge_1.forgeSchema)({
|
|
28
|
+
schemaId: 'test',
|
|
29
|
+
allowUseFallbackDescription: true,
|
|
30
|
+
tsconfigFrom: './tsconfig.build-test.json',
|
|
31
|
+
sourcesDirectoryPattern: 'test-sources/a8',
|
|
32
|
+
sourcesFilesPattern: ['service-api.ts', 'types.ts'],
|
|
33
|
+
outputSchemaFile,
|
|
34
|
+
outputSchemaMetadataFile,
|
|
35
|
+
expose: 'all',
|
|
36
|
+
explicitPublic: true,
|
|
37
|
+
schemaMetadata,
|
|
38
|
+
});
|
|
39
|
+
validator = (0, registry_1.createSchemaForgeRegistry)();
|
|
40
|
+
loadedSchema = await (0, loader_1.loadJSONSchema)([outputSchemaFile]);
|
|
41
|
+
validator.addSchema(loadedSchema);
|
|
42
|
+
});
|
|
43
|
+
afterAll(async () => {
|
|
44
|
+
if (!artefacts_policy_1.KEEP_SPEC_ARTEFACTS) {
|
|
45
|
+
await (0, promises_1.unlink)(outputSchemaFile).catch(noop_1.noop);
|
|
46
|
+
await (0, promises_1.unlink)(outputSchemaMetadataFile).catch(noop_1.noop);
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
it('generated schema should have correct metadata', () => {
|
|
50
|
+
expect(forgeSchemaResult).toBeTruthy();
|
|
51
|
+
const schema = forgeSchemaResult.schema;
|
|
52
|
+
expect((0, pick_1.pickProps)(schema, Object.keys(schemaMetadata))).toStrictEqual(schemaMetadata);
|
|
53
|
+
});
|
|
54
|
+
it('generated schema should be valid', () => {
|
|
55
|
+
expect(forgeSchemaResult).toBeTruthy();
|
|
56
|
+
const schema = validator.getSchema('test#/definitions/TypeFromJSON');
|
|
57
|
+
expect(schema).toBeTruthy();
|
|
58
|
+
});
|
|
59
|
+
});
|
|
13
60
|
describe('generator for a7', () => {
|
|
14
61
|
const outputSchemaFile = './a7.generated.schema.tmp.json';
|
|
15
62
|
const outputSchemaMetadataFile = './a7.generated.definitions.tmp.json';
|
|
@@ -19,10 +66,10 @@ describe('generator for a7', () => {
|
|
|
19
66
|
$comment: 'WARN: This is a test schema.',
|
|
20
67
|
};
|
|
21
68
|
let forgeSchemaResult;
|
|
22
|
-
let
|
|
69
|
+
let registry;
|
|
23
70
|
let loadedSchema;
|
|
24
71
|
beforeAll(async () => {
|
|
25
|
-
forgeSchemaResult = await (0,
|
|
72
|
+
forgeSchemaResult = await (0, forge_1.forgeSchema)({
|
|
26
73
|
schemaId: 'test',
|
|
27
74
|
allowUseFallbackDescription: true,
|
|
28
75
|
tsconfigFrom: './tsconfig.build-test.json',
|
|
@@ -34,12 +81,12 @@ describe('generator for a7', () => {
|
|
|
34
81
|
explicitPublic: true,
|
|
35
82
|
schemaMetadata,
|
|
36
83
|
});
|
|
37
|
-
|
|
38
|
-
loadedSchema = await (0,
|
|
39
|
-
|
|
84
|
+
registry = (0, registry_1.createSchemaForgeRegistry)();
|
|
85
|
+
loadedSchema = await (0, loader_1.loadJSONSchema)([outputSchemaFile]);
|
|
86
|
+
registry.addSchema(loadedSchema);
|
|
40
87
|
});
|
|
41
88
|
afterAll(async () => {
|
|
42
|
-
if (!
|
|
89
|
+
if (!artefacts_policy_1.KEEP_SPEC_ARTEFACTS) {
|
|
43
90
|
await (0, promises_1.unlink)(outputSchemaFile).catch(noop_1.noop);
|
|
44
91
|
await (0, promises_1.unlink)(outputSchemaMetadataFile).catch(noop_1.noop);
|
|
45
92
|
}
|
|
@@ -51,7 +98,7 @@ describe('generator for a7', () => {
|
|
|
51
98
|
});
|
|
52
99
|
it('generated schema should be valid', () => {
|
|
53
100
|
expect(forgeSchemaResult).toBeTruthy();
|
|
54
|
-
const schema =
|
|
101
|
+
const schema = registry.getSchema('test#/definitions/SomeAPI_doSomeWithUser__APIMethodArgs');
|
|
55
102
|
expect(schema).toBeTruthy();
|
|
56
103
|
expect(schema.items).toStrictEqual([
|
|
57
104
|
{ $ref: '#/definitions/User', title: 'user', description: 'Target user' },
|
|
@@ -66,10 +113,10 @@ describe('generator for a7', () => {
|
|
|
66
113
|
describe('validator for a7', () => {
|
|
67
114
|
const outputSchemaFile = './a7.generated.schema.tmp.json';
|
|
68
115
|
const outputSchemaMetadataFile = './a7.generated.definitions.tmp.json';
|
|
69
|
-
let
|
|
116
|
+
let registry;
|
|
70
117
|
let loadedSchema;
|
|
71
118
|
beforeAll(async () => {
|
|
72
|
-
await (0,
|
|
119
|
+
await (0, forge_1.forgeSchema)({
|
|
73
120
|
schemaId: 'test',
|
|
74
121
|
allowUseFallbackDescription: true,
|
|
75
122
|
tsconfigFrom: './tsconfig.build-test.json',
|
|
@@ -80,38 +127,38 @@ describe('validator for a7', () => {
|
|
|
80
127
|
expose: 'all',
|
|
81
128
|
explicitPublic: true,
|
|
82
129
|
});
|
|
83
|
-
|
|
84
|
-
loadedSchema = await (0,
|
|
85
|
-
|
|
130
|
+
registry = (0, registry_1.createSchemaForgeRegistry)();
|
|
131
|
+
loadedSchema = await (0, loader_1.loadJSONSchema)([outputSchemaFile]);
|
|
132
|
+
registry.addSchema(loadedSchema);
|
|
86
133
|
});
|
|
87
134
|
afterAll(async () => {
|
|
88
|
-
if (!
|
|
135
|
+
if (!artefacts_policy_1.KEEP_SPEC_ARTEFACTS) {
|
|
89
136
|
await (0, promises_1.unlink)(outputSchemaFile).catch(noop_1.noop);
|
|
90
137
|
await (0, promises_1.unlink)(outputSchemaMetadataFile).catch(noop_1.noop);
|
|
91
138
|
}
|
|
92
139
|
});
|
|
93
140
|
it('should be able to warm-up cache', async () => {
|
|
94
|
-
const initial =
|
|
141
|
+
const initial = registry.compilationArtifactCount;
|
|
95
142
|
expect(initial).toStrictEqual(2);
|
|
96
|
-
|
|
97
|
-
const warmed =
|
|
143
|
+
registry.warmupCacheSync();
|
|
144
|
+
const warmed = registry.compilationArtifactCount;
|
|
98
145
|
expect(warmed).toStrictEqual(9);
|
|
99
|
-
|
|
100
|
-
const cleared =
|
|
146
|
+
registry.clear();
|
|
147
|
+
const cleared = registry.compilationArtifactCount;
|
|
101
148
|
expect(cleared).toStrictEqual(1);
|
|
102
|
-
|
|
103
|
-
expect(
|
|
104
|
-
await
|
|
105
|
-
expect(
|
|
149
|
+
registry.addSchema(loadedSchema);
|
|
150
|
+
expect(registry.compilationArtifactCount).toStrictEqual(initial);
|
|
151
|
+
await registry.warmupCache();
|
|
152
|
+
expect(registry.compilationArtifactCount).toStrictEqual(warmed);
|
|
106
153
|
});
|
|
107
154
|
});
|
|
108
155
|
describe('generator for a6', () => {
|
|
109
156
|
const outputSchemaFile = './a6.generated.schema.tmp.json';
|
|
110
157
|
const outputSchemaMetadataFile = './a6.generated.definitions.tmp.json';
|
|
111
158
|
let forgeSchemaResult;
|
|
112
|
-
let
|
|
159
|
+
let registry;
|
|
113
160
|
beforeAll(async () => {
|
|
114
|
-
forgeSchemaResult = await (0,
|
|
161
|
+
forgeSchemaResult = await (0, forge_1.forgeSchema)({
|
|
115
162
|
schemaId: 'test',
|
|
116
163
|
tsconfigFrom: './tsconfig.build-test.json',
|
|
117
164
|
sourcesDirectoryPattern: 'test-sources/a6',
|
|
@@ -121,12 +168,12 @@ describe('generator for a6', () => {
|
|
|
121
168
|
expose: 'all',
|
|
122
169
|
explicitPublic: true,
|
|
123
170
|
});
|
|
124
|
-
|
|
125
|
-
const schema = await (0,
|
|
126
|
-
|
|
171
|
+
registry = (0, registry_1.createSchemaForgeRegistry)();
|
|
172
|
+
const schema = await (0, loader_1.loadJSONSchema)([outputSchemaFile]);
|
|
173
|
+
registry.addSchema(schema);
|
|
127
174
|
});
|
|
128
175
|
afterAll(async () => {
|
|
129
|
-
if (!
|
|
176
|
+
if (!artefacts_policy_1.KEEP_SPEC_ARTEFACTS) {
|
|
130
177
|
await (0, promises_1.unlink)(outputSchemaFile).catch(noop_1.noop);
|
|
131
178
|
await (0, promises_1.unlink)(outputSchemaMetadataFile).catch(noop_1.noop);
|
|
132
179
|
}
|
|
@@ -135,24 +182,24 @@ describe('generator for a6', () => {
|
|
|
135
182
|
expect(forgeSchemaResult).toBeTruthy();
|
|
136
183
|
const defs = forgeSchemaResult?.schema?.definitions;
|
|
137
184
|
expect(defs).toBeTruthy();
|
|
138
|
-
expect(
|
|
185
|
+
expect(registry.getValidator('test#/definitions/CollectionItemID1').schema).toStrictEqual({
|
|
139
186
|
$ref: '#/definitions/UUID',
|
|
140
187
|
format: 'uuid',
|
|
141
188
|
description: 'This is Collection item ID (inherits from UUID)',
|
|
142
189
|
});
|
|
143
|
-
expect(
|
|
190
|
+
expect(registry.getValidator('test#/definitions/CollectionItemID2').schema).toStrictEqual({
|
|
144
191
|
format: 'uuid',
|
|
145
192
|
type: 'string',
|
|
146
193
|
});
|
|
147
194
|
{
|
|
148
|
-
const rec =
|
|
195
|
+
const rec = registry.getValidator('test#/definitions/PRec<CollectionItem,UUID>').schema;
|
|
149
196
|
expect(rec).toBeTruthy();
|
|
150
197
|
expect(rec.propertyNames).toStrictEqual({
|
|
151
198
|
format: 'uuid',
|
|
152
199
|
});
|
|
153
200
|
}
|
|
154
201
|
{
|
|
155
|
-
const rec =
|
|
202
|
+
const rec = registry.getValidator('test#/definitions/PRec<CollectionItem,CollectionItemID1>').schema;
|
|
156
203
|
expect(rec).toBeTruthy();
|
|
157
204
|
expect(rec.propertyNames).toStrictEqual({
|
|
158
205
|
format: 'uuid',
|
|
@@ -165,9 +212,9 @@ describe('generator for a5', () => {
|
|
|
165
212
|
const outputSchemaFile = './a5.generated.schema.tmp.json';
|
|
166
213
|
const outputSchemaMetadataFile = './a5.generated.definitions.tmp.json';
|
|
167
214
|
let forgeSchemaResult;
|
|
168
|
-
let
|
|
215
|
+
let registry;
|
|
169
216
|
beforeAll(async () => {
|
|
170
|
-
forgeSchemaResult = await (0,
|
|
217
|
+
forgeSchemaResult = await (0, forge_1.forgeSchema)({
|
|
171
218
|
schemaId: 'test',
|
|
172
219
|
tsconfigFrom: './tsconfig.build-test.json',
|
|
173
220
|
sourcesDirectoryPattern: 'test-sources/a5',
|
|
@@ -182,12 +229,12 @@ describe('generator for a5', () => {
|
|
|
182
229
|
return undefined;
|
|
183
230
|
},
|
|
184
231
|
});
|
|
185
|
-
|
|
186
|
-
const schema = await (0,
|
|
187
|
-
|
|
232
|
+
registry = (0, registry_1.createSchemaForgeRegistry)();
|
|
233
|
+
const schema = await (0, loader_1.loadJSONSchema)([outputSchemaFile]);
|
|
234
|
+
registry.addSchema(schema);
|
|
188
235
|
});
|
|
189
236
|
afterAll(async () => {
|
|
190
|
-
if (!
|
|
237
|
+
if (!artefacts_policy_1.KEEP_SPEC_ARTEFACTS) {
|
|
191
238
|
await (0, promises_1.unlink)(outputSchemaFile).catch(noop_1.noop);
|
|
192
239
|
await (0, promises_1.unlink)(outputSchemaMetadataFile).catch(noop_1.noop);
|
|
193
240
|
}
|
|
@@ -210,12 +257,14 @@ describe('generator for a5', () => {
|
|
|
210
257
|
'VariadicList',
|
|
211
258
|
'VariadicList1',
|
|
212
259
|
]);
|
|
213
|
-
expect(
|
|
260
|
+
expect(registry.getValidator('test#/definitions/NT').schema).toStrictEqual({
|
|
214
261
|
type: 'string',
|
|
215
262
|
enum: ['v:name1', 'v:name2'],
|
|
216
263
|
});
|
|
217
|
-
expect(
|
|
218
|
-
|
|
264
|
+
expect(registry.getValidator('test#/definitions/NamesTypeAbnormal').schema).toStrictEqual({
|
|
265
|
+
type: 'string',
|
|
266
|
+
});
|
|
267
|
+
expect(registry.getValidator('test#/definitions/Some').schema).toStrictEqual({
|
|
219
268
|
type: 'object',
|
|
220
269
|
properties: {
|
|
221
270
|
vals: {
|
|
@@ -308,7 +357,7 @@ describe('generator for a4', () => {
|
|
|
308
357
|
const outputSchemaMetadataFile = './a4.generated.definitions.tmp.json';
|
|
309
358
|
let forgeSchemaResult;
|
|
310
359
|
beforeAll(async () => {
|
|
311
|
-
forgeSchemaResult = await (0,
|
|
360
|
+
forgeSchemaResult = await (0, forge_1.forgeSchema)({
|
|
312
361
|
tsconfigFrom: './tsconfig.build-test.json',
|
|
313
362
|
sourcesDirectoryPattern: 'test-sources/a4',
|
|
314
363
|
sourcesFilesPattern: 'service-api.ts',
|
|
@@ -319,7 +368,7 @@ describe('generator for a4', () => {
|
|
|
319
368
|
});
|
|
320
369
|
});
|
|
321
370
|
afterAll(async () => {
|
|
322
|
-
if (!
|
|
371
|
+
if (!artefacts_policy_1.KEEP_SPEC_ARTEFACTS) {
|
|
323
372
|
await (0, promises_1.unlink)(outputSchemaFile).catch(noop_1.noop);
|
|
324
373
|
await (0, promises_1.unlink)(outputSchemaMetadataFile).catch(noop_1.noop);
|
|
325
374
|
}
|
|
@@ -336,7 +385,7 @@ describe('generator for a3', () => {
|
|
|
336
385
|
const outputSchemaMetadataFile = './a3.generated.definitions.tmp.json';
|
|
337
386
|
let forgeSchemaResult;
|
|
338
387
|
beforeAll(async () => {
|
|
339
|
-
forgeSchemaResult = await (0,
|
|
388
|
+
forgeSchemaResult = await (0, forge_1.forgeSchema)({
|
|
340
389
|
tsconfigFrom: './tsconfig.build-test.json',
|
|
341
390
|
sourcesDirectoryPattern: 'test-sources/a3',
|
|
342
391
|
sourcesFilesPattern: 'service-api.ts',
|
|
@@ -346,7 +395,7 @@ describe('generator for a3', () => {
|
|
|
346
395
|
});
|
|
347
396
|
});
|
|
348
397
|
afterAll(async () => {
|
|
349
|
-
if (!
|
|
398
|
+
if (!artefacts_policy_1.KEEP_SPEC_ARTEFACTS) {
|
|
350
399
|
await (0, promises_1.unlink)(outputSchemaFile).catch(noop_1.noop);
|
|
351
400
|
await (0, promises_1.unlink)(outputSchemaMetadataFile).catch(noop_1.noop);
|
|
352
401
|
}
|
|
@@ -354,47 +403,52 @@ describe('generator for a3', () => {
|
|
|
354
403
|
it('generated schema should be valid', () => {
|
|
355
404
|
expect(forgeSchemaResult).toBeTruthy();
|
|
356
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
|
+
});
|
|
357
412
|
it('interface generics should works', () => {
|
|
358
|
-
const props = forgeSchemaResult.schema.definitions?.
|
|
359
|
-
.properties;
|
|
413
|
+
const props = forgeSchemaResult.schema.definitions?.InterfaceWithGeneric__APIInterface.properties;
|
|
360
414
|
expect(props).toBeTruthy();
|
|
361
415
|
expect(props.propWithGeneric).toBeTruthy();
|
|
362
416
|
expect(props.propWithGeneric.$ref).toStrictEqual('#/definitions/NonEmptyString');
|
|
363
417
|
});
|
|
364
418
|
it('optional args in API methods should works', () => {
|
|
365
419
|
{
|
|
366
|
-
const props = forgeSchemaResult.schema.definitions?.
|
|
420
|
+
const props = forgeSchemaResult.schema.definitions?.API_methodG0__APIMethodArgs;
|
|
367
421
|
expect(props).toBeTruthy();
|
|
368
422
|
expect(props.minItems).toStrictEqual(0);
|
|
369
423
|
expect(props.maxItems).toStrictEqual(1);
|
|
370
424
|
}
|
|
371
425
|
{
|
|
372
|
-
const props = forgeSchemaResult.schema.definitions?.
|
|
426
|
+
const props = forgeSchemaResult.schema.definitions?.API_methodG1__APIMethodArgs;
|
|
373
427
|
expect(props).toBeTruthy();
|
|
374
428
|
expect(props.minItems).toStrictEqual(0);
|
|
375
429
|
expect(props.maxItems).toStrictEqual(2);
|
|
376
430
|
}
|
|
377
431
|
{
|
|
378
|
-
const props = forgeSchemaResult.schema.definitions?.
|
|
432
|
+
const props = forgeSchemaResult.schema.definitions?.API_methodG2__APIMethodArgs;
|
|
379
433
|
expect(props).toBeTruthy();
|
|
380
434
|
expect(props.minItems).toStrictEqual(1);
|
|
381
435
|
expect(props.maxItems).toStrictEqual(2);
|
|
382
436
|
}
|
|
383
437
|
// {
|
|
384
|
-
// const props = forgeSchemaResult!.schema.definitions?.
|
|
438
|
+
// const props = forgeSchemaResult!.schema.definitions?.API_methodG3__APIMethodArgs;
|
|
385
439
|
// expect(props).toBeTruthy();
|
|
386
440
|
// expect(props.minItems).toStrictEqual(0);
|
|
387
441
|
// expect(props.maxItems).toBeUndefined();
|
|
388
442
|
// }
|
|
389
443
|
// {
|
|
390
|
-
// const props = forgeSchemaResult!.schema.definitions?.
|
|
444
|
+
// const props = forgeSchemaResult!.schema.definitions?.API_methodG4__APIMethodArgs;
|
|
391
445
|
// expect(props).toBeTruthy();
|
|
392
446
|
// expect(props.minItems).toStrictEqual(1);
|
|
393
447
|
// expect(props.maxItems).toBeUndefined();
|
|
394
448
|
// }
|
|
395
449
|
});
|
|
396
450
|
it('extends should works', () => {
|
|
397
|
-
const props = forgeSchemaResult.schema.definitions?.
|
|
451
|
+
const props = forgeSchemaResult.schema.definitions?.BAPI__APIInterface.properties;
|
|
398
452
|
expect(props).toBeTruthy();
|
|
399
453
|
expect(Object.keys(props)).toStrictEqual([
|
|
400
454
|
'propertyA',
|
|
@@ -419,7 +473,7 @@ describe('generator for a2', () => {
|
|
|
419
473
|
const outputSchemaMetadataFile = './a2.generated.definitions.tmp.json';
|
|
420
474
|
let forgeSchemaResult;
|
|
421
475
|
beforeAll(async () => {
|
|
422
|
-
forgeSchemaResult = await (0,
|
|
476
|
+
forgeSchemaResult = await (0, forge_1.forgeSchema)({
|
|
423
477
|
tsconfigFrom: './tsconfig.build-test.json',
|
|
424
478
|
sourcesDirectoryPattern: 'test-sources/a2',
|
|
425
479
|
sourcesFilesPattern: 'service-api.ts',
|
|
@@ -428,7 +482,7 @@ describe('generator for a2', () => {
|
|
|
428
482
|
});
|
|
429
483
|
});
|
|
430
484
|
afterAll(async () => {
|
|
431
|
-
if (!
|
|
485
|
+
if (!artefacts_policy_1.KEEP_SPEC_ARTEFACTS) {
|
|
432
486
|
await (0, promises_1.unlink)(outputSchemaFile).catch(noop_1.noop);
|
|
433
487
|
await (0, promises_1.unlink)(outputSchemaMetadataFile).catch(noop_1.noop);
|
|
434
488
|
}
|
|
@@ -444,7 +498,7 @@ describe('generator for a1', () => {
|
|
|
444
498
|
let forgeSchemaResult;
|
|
445
499
|
let validator;
|
|
446
500
|
beforeAll(async () => {
|
|
447
|
-
forgeSchemaResult = await (0,
|
|
501
|
+
forgeSchemaResult = await (0, forge_1.forgeSchema)({
|
|
448
502
|
allowUseFallbackDescription: false,
|
|
449
503
|
explicitPublic: true,
|
|
450
504
|
schemaId,
|
|
@@ -454,12 +508,12 @@ describe('generator for a1', () => {
|
|
|
454
508
|
outputSchemaFile,
|
|
455
509
|
outputSchemaMetadataFile,
|
|
456
510
|
});
|
|
457
|
-
validator = (0,
|
|
458
|
-
const schema = await (0,
|
|
511
|
+
validator = (0, registry_1.createSchemaForgeRegistry)();
|
|
512
|
+
const schema = await (0, loader_1.loadJSONSchema)([outputSchemaFile]);
|
|
459
513
|
validator.addSchema(schema);
|
|
460
514
|
}, 10_000);
|
|
461
515
|
afterAll(async () => {
|
|
462
|
-
if (!
|
|
516
|
+
if (!artefacts_policy_1.KEEP_SPEC_ARTEFACTS) {
|
|
463
517
|
await (0, promises_1.unlink)(outputSchemaFile).catch(noop_1.noop);
|
|
464
518
|
await (0, promises_1.unlink)(outputSchemaMetadataFile).catch(noop_1.noop);
|
|
465
519
|
}
|
|
@@ -490,16 +544,16 @@ describe('generator for a1', () => {
|
|
|
490
544
|
});
|
|
491
545
|
});
|
|
492
546
|
it('hasSchema', () => {
|
|
493
|
-
expect(validator.
|
|
494
|
-
expect(validator.
|
|
495
|
-
expect(validator.
|
|
496
|
-
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);
|
|
497
551
|
});
|
|
498
552
|
it('checkBySchema', () => {
|
|
499
|
-
expect(() => validator.checkBySchema('test#/definitions/
|
|
553
|
+
expect(() => validator.checkBySchema('test#/definitions/ExportedInterfaceB__APIInterface', {})).toThrow(efc_1.SchemaForgeErrors.msg('EC_SF_VALIDATION_FAILED'));
|
|
500
554
|
expect(validator.checkBySchema('test#/definitions/PositiveInt', 1)).toStrictEqual(true);
|
|
501
|
-
expect(() => validator.checkBySchema('test#/definitions/PositiveInt', 1.1)).toThrow(
|
|
502
|
-
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'));
|
|
503
557
|
{
|
|
504
558
|
const schema = '!test#/definitions/Int';
|
|
505
559
|
try {
|
|
@@ -508,8 +562,8 @@ describe('generator for a1', () => {
|
|
|
508
562
|
catch (e) {
|
|
509
563
|
const context = (0, error_1.readErrorContext)(e);
|
|
510
564
|
const code = (0, error_1.readErrorCode)(e);
|
|
511
|
-
expect(e.message).toStrictEqual(
|
|
512
|
-
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');
|
|
513
567
|
expect(context).toBeTruthy();
|
|
514
568
|
expect(context.schema).toStrictEqual(schema);
|
|
515
569
|
expect(context.errorMessage).toStrictEqual(undefined);
|
|
@@ -524,8 +578,8 @@ describe('generator for a1', () => {
|
|
|
524
578
|
catch (e) {
|
|
525
579
|
const context = (0, error_1.readErrorContext)(e);
|
|
526
580
|
const code = (0, error_1.readErrorCode)(e);
|
|
527
|
-
expect(
|
|
528
|
-
expect(
|
|
581
|
+
expect(code).toStrictEqual('EC_SF_VALIDATION_FAILED');
|
|
582
|
+
expect(e.message).toStrictEqual(efc_1.SchemaForgeErrors.msg(code));
|
|
529
583
|
expect(context).toBeTruthy();
|
|
530
584
|
expect(context.schema).toStrictEqual(schema);
|
|
531
585
|
expect(context.errorMessage).toStrictEqual(message);
|
|
@@ -536,63 +590,63 @@ describe('generator for a1', () => {
|
|
|
536
590
|
it('listDefinitions', () => {
|
|
537
591
|
const defs = [
|
|
538
592
|
{
|
|
539
|
-
ref: 'test#/definitions/
|
|
593
|
+
ref: 'test#/definitions/ExportedInterfaceB__APIInterface',
|
|
540
594
|
kind: 1,
|
|
541
|
-
name: '
|
|
595
|
+
name: 'ExportedInterfaceB__APIInterface',
|
|
542
596
|
schemaId: 'test',
|
|
543
597
|
interface: 'ExportedInterfaceB',
|
|
544
598
|
},
|
|
545
599
|
{
|
|
546
|
-
ref: 'test#/definitions/
|
|
600
|
+
ref: 'test#/definitions/ExportedInterfaceB_methodA__APIMethodArgs',
|
|
547
601
|
kind: 3,
|
|
548
|
-
name: '
|
|
602
|
+
name: 'ExportedInterfaceB_methodA__APIMethodArgs',
|
|
549
603
|
schemaId: 'test',
|
|
550
604
|
interface: 'ExportedInterfaceB',
|
|
551
605
|
method: 'methodA',
|
|
552
606
|
},
|
|
553
607
|
{
|
|
554
|
-
ref: 'test#/definitions/
|
|
608
|
+
ref: 'test#/definitions/ExportedInterfaceB_methodA__APIMethodResult',
|
|
555
609
|
kind: 2,
|
|
556
|
-
name: '
|
|
610
|
+
name: 'ExportedInterfaceB_methodA__APIMethodResult',
|
|
557
611
|
schemaId: 'test',
|
|
558
612
|
interface: 'ExportedInterfaceB',
|
|
559
613
|
method: 'methodA',
|
|
560
614
|
},
|
|
561
615
|
{
|
|
562
|
-
ref: 'test#/definitions/
|
|
616
|
+
ref: 'test#/definitions/ExportedInterfaceB_methodB__APIMethodArgs',
|
|
563
617
|
kind: 3,
|
|
564
|
-
name: '
|
|
618
|
+
name: 'ExportedInterfaceB_methodB__APIMethodArgs',
|
|
565
619
|
schemaId: 'test',
|
|
566
620
|
interface: 'ExportedInterfaceB',
|
|
567
621
|
method: 'methodB',
|
|
568
622
|
},
|
|
569
623
|
{
|
|
570
|
-
ref: 'test#/definitions/
|
|
624
|
+
ref: 'test#/definitions/ExportedInterfaceB_methodB__APIMethodResult',
|
|
571
625
|
kind: 2,
|
|
572
|
-
name: '
|
|
626
|
+
name: 'ExportedInterfaceB_methodB__APIMethodResult',
|
|
573
627
|
schemaId: 'test',
|
|
574
628
|
interface: 'ExportedInterfaceB',
|
|
575
629
|
method: 'methodB',
|
|
576
630
|
},
|
|
577
631
|
{
|
|
578
|
-
ref: 'test#/definitions/
|
|
632
|
+
ref: 'test#/definitions/NonExportedInterfaceD__APIInterface',
|
|
579
633
|
kind: 1,
|
|
580
|
-
name: '
|
|
634
|
+
name: 'NonExportedInterfaceD__APIInterface',
|
|
581
635
|
schemaId: 'test',
|
|
582
636
|
interface: 'NonExportedInterfaceD',
|
|
583
637
|
},
|
|
584
638
|
{
|
|
585
|
-
ref: 'test#/definitions/
|
|
639
|
+
ref: 'test#/definitions/NonExportedInterfaceD_methodA__APIMethodArgs',
|
|
586
640
|
kind: 3,
|
|
587
|
-
name: '
|
|
641
|
+
name: 'NonExportedInterfaceD_methodA__APIMethodArgs',
|
|
588
642
|
schemaId: 'test',
|
|
589
643
|
interface: 'NonExportedInterfaceD',
|
|
590
644
|
method: 'methodA',
|
|
591
645
|
},
|
|
592
646
|
{
|
|
593
|
-
ref: 'test#/definitions/
|
|
647
|
+
ref: 'test#/definitions/NonExportedInterfaceD_methodA__APIMethodResult',
|
|
594
648
|
kind: 2,
|
|
595
|
-
name: '
|
|
649
|
+
name: 'NonExportedInterfaceD_methodA__APIMethodResult',
|
|
596
650
|
schemaId: 'test',
|
|
597
651
|
interface: 'NonExportedInterfaceD',
|
|
598
652
|
method: 'methodA',
|
|
@@ -624,24 +678,24 @@ describe('generator for a1', () => {
|
|
|
624
678
|
defsByName[def.name] = def;
|
|
625
679
|
}
|
|
626
680
|
expect(validator.listDefinitions()).toStrictEqual(defs);
|
|
627
|
-
expect(validator.listDefinitions((info) => info.kind === types_1.
|
|
628
|
-
expect(validator.listDefinitions((info) => info.kind === types_1.
|
|
629
|
-
defsByName['
|
|
630
|
-
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'],
|
|
631
685
|
]);
|
|
632
|
-
expect(validator.listDefinitions((info) => info.kind === types_1.
|
|
633
|
-
defsByName['
|
|
634
|
-
defsByName['
|
|
635
|
-
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'],
|
|
636
690
|
]);
|
|
637
|
-
expect(validator.listDefinitions((info) => info.kind === types_1.
|
|
638
|
-
defsByName['
|
|
639
|
-
defsByName['
|
|
640
|
-
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'],
|
|
641
695
|
]);
|
|
642
696
|
});
|
|
643
697
|
it('should be valid descriptions', () => {
|
|
644
|
-
const schema = validator.getSchema('test#/definitions/
|
|
698
|
+
const schema = validator.getSchema('test#/definitions/ExportedInterfaceB__APIInterface');
|
|
645
699
|
expect(schema).toBeTruthy();
|
|
646
700
|
expect(schema.description).toStrictEqual('TAG: Description for ExportedInterfaceB');
|
|
647
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,10 +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-argument,@typescript-eslint/no-unsafe-member-access
|
|
8
9
|
return (0, typescript_1.formatDiagnostics)(error.diagnostic.relatedInformation || [], {
|
|
9
10
|
getCanonicalFileName: (fileName) => fileName,
|
|
10
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"}
|