ajsc 5.0.2 → 5.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/JSONSchemaConverter.js +20 -6
- package/dist/JSONSchemaConverter.js.map +1 -1
- package/dist/JSONSchemaConverter.test.js +60 -0
- package/dist/JSONSchemaConverter.test.js.map +1 -1
- package/dist/TypescriptBaseConverter.d.ts +4 -0
- package/dist/TypescriptBaseConverter.js +43 -3
- package/dist/TypescriptBaseConverter.js.map +1 -1
- package/dist/TypescriptConverter.composites.test.js +292 -0
- package/dist/TypescriptConverter.composites.test.js.map +1 -1
- package/dist/TypescriptConverter.d.ts +36 -0
- package/dist/TypescriptConverter.js +272 -16
- package/dist/TypescriptConverter.js.map +1 -1
- package/dist/TypescriptConverter.jsdoc.test.d.ts +1 -0
- package/dist/TypescriptConverter.jsdoc.test.js +194 -0
- package/dist/TypescriptConverter.jsdoc.test.js.map +1 -0
- package/dist/types.d.ts +4 -0
- package/package.json +1 -1
|
@@ -10,4 +10,296 @@ describe("TypescriptConverter - unions and intersections", () => {
|
|
|
10
10
|
}).code).toMatch(`string & number`);
|
|
11
11
|
});
|
|
12
12
|
});
|
|
13
|
+
describe("TypescriptConverter - unions and intersections with shared ancestor type merging", () => {
|
|
14
|
+
it("should merge enum unions with same name under shared ancestor", () => {
|
|
15
|
+
expect(new TypescriptConverter({
|
|
16
|
+
type: "object",
|
|
17
|
+
properties: {
|
|
18
|
+
timeLog: {
|
|
19
|
+
type: "array",
|
|
20
|
+
items: {
|
|
21
|
+
anyOf: [
|
|
22
|
+
{
|
|
23
|
+
type: "object",
|
|
24
|
+
properties: {
|
|
25
|
+
action: {
|
|
26
|
+
type: "string",
|
|
27
|
+
enum: ["startshift", "endshift"],
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
type: "object",
|
|
33
|
+
properties: {
|
|
34
|
+
action: {
|
|
35
|
+
type: "string",
|
|
36
|
+
enum: ["startbreak", "endbreak"],
|
|
37
|
+
},
|
|
38
|
+
break: {
|
|
39
|
+
type: "object",
|
|
40
|
+
properties: {
|
|
41
|
+
durationMin: {
|
|
42
|
+
type: "number",
|
|
43
|
+
},
|
|
44
|
+
mandatory: {
|
|
45
|
+
type: "boolean",
|
|
46
|
+
},
|
|
47
|
+
paid: {
|
|
48
|
+
type: "boolean",
|
|
49
|
+
},
|
|
50
|
+
startsAfterShiftHrs: {
|
|
51
|
+
type: "number",
|
|
52
|
+
},
|
|
53
|
+
type: {
|
|
54
|
+
type: "string",
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
],
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
}, { enumStyle: "enum" }).code).toMatch(`export enum Action { Startshift = "startshift", Endshift = "endshift", Startbreak = "startbreak", Endbreak = "endbreak" }`);
|
|
65
|
+
});
|
|
66
|
+
it("should merge type unions with shared ancestor", () => {
|
|
67
|
+
expect(new TypescriptConverter({
|
|
68
|
+
type: "object",
|
|
69
|
+
properties: {
|
|
70
|
+
status: {
|
|
71
|
+
anyOf: [
|
|
72
|
+
{
|
|
73
|
+
type: "object",
|
|
74
|
+
properties: {
|
|
75
|
+
color: {
|
|
76
|
+
type: "string",
|
|
77
|
+
},
|
|
78
|
+
timeframe: {
|
|
79
|
+
type: "string",
|
|
80
|
+
enum: ["past"],
|
|
81
|
+
},
|
|
82
|
+
title: {
|
|
83
|
+
type: "string",
|
|
84
|
+
enum: ["completed", "missed"],
|
|
85
|
+
},
|
|
86
|
+
},
|
|
87
|
+
required: ["timeframe", "title"],
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
type: "object",
|
|
91
|
+
properties: {
|
|
92
|
+
color: {
|
|
93
|
+
type: "string",
|
|
94
|
+
},
|
|
95
|
+
timeframe: {
|
|
96
|
+
type: "string",
|
|
97
|
+
enum: ["current"],
|
|
98
|
+
},
|
|
99
|
+
title: {
|
|
100
|
+
type: "string",
|
|
101
|
+
enum: [
|
|
102
|
+
"ended",
|
|
103
|
+
"inprogress",
|
|
104
|
+
"notended",
|
|
105
|
+
"notstarted",
|
|
106
|
+
"onbreak",
|
|
107
|
+
],
|
|
108
|
+
},
|
|
109
|
+
},
|
|
110
|
+
required: ["timeframe", "title"],
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
type: "object",
|
|
114
|
+
properties: {
|
|
115
|
+
color: {
|
|
116
|
+
type: "string",
|
|
117
|
+
},
|
|
118
|
+
timeframe: {
|
|
119
|
+
type: "string",
|
|
120
|
+
enum: ["future"],
|
|
121
|
+
},
|
|
122
|
+
},
|
|
123
|
+
required: ["timeframe"],
|
|
124
|
+
},
|
|
125
|
+
],
|
|
126
|
+
},
|
|
127
|
+
},
|
|
128
|
+
}, { enumStyle: "enum" }).code).toContain(`export enum Timeframe { Past = "past", Current = "current", Future = "future" }\nexport enum Title { Completed = "completed", Missed = "missed", Ended = "ended", Inprogress = "inprogress", Notended = "notended", Notstarted = "notstarted", Onbreak = "onbreak" }\nexport type Status = { color?: string; timeframe: Timeframe; title?: Title; };\n\nexport type Root = { status?: Status; };\n`);
|
|
129
|
+
});
|
|
130
|
+
it("should merge enum + literal properties across union options", () => {
|
|
131
|
+
expect(new TypescriptConverter({
|
|
132
|
+
type: "object",
|
|
133
|
+
properties: {
|
|
134
|
+
item: {
|
|
135
|
+
anyOf: [
|
|
136
|
+
{
|
|
137
|
+
type: "object",
|
|
138
|
+
properties: {
|
|
139
|
+
kind: { const: "book" },
|
|
140
|
+
shared: { type: "string" },
|
|
141
|
+
},
|
|
142
|
+
},
|
|
143
|
+
{
|
|
144
|
+
type: "object",
|
|
145
|
+
properties: {
|
|
146
|
+
kind: {
|
|
147
|
+
type: "string",
|
|
148
|
+
enum: ["dvd", "cd"],
|
|
149
|
+
},
|
|
150
|
+
shared: { type: "string" },
|
|
151
|
+
},
|
|
152
|
+
},
|
|
153
|
+
],
|
|
154
|
+
},
|
|
155
|
+
},
|
|
156
|
+
}, { enumStyle: "enum" }).code).toMatch(`export enum Kind { Book = "book", Dvd = "dvd", Cd = "cd" }`);
|
|
157
|
+
});
|
|
158
|
+
it("should preserve union when options have incompatible property types", () => {
|
|
159
|
+
const code = new TypescriptConverter({
|
|
160
|
+
type: "object",
|
|
161
|
+
properties: {
|
|
162
|
+
field: {
|
|
163
|
+
anyOf: [
|
|
164
|
+
{
|
|
165
|
+
type: "object",
|
|
166
|
+
properties: {
|
|
167
|
+
value: { type: "string" },
|
|
168
|
+
name: { type: "string" },
|
|
169
|
+
},
|
|
170
|
+
},
|
|
171
|
+
{
|
|
172
|
+
type: "object",
|
|
173
|
+
properties: {
|
|
174
|
+
value: { type: "number" },
|
|
175
|
+
name: { type: "string" },
|
|
176
|
+
},
|
|
177
|
+
},
|
|
178
|
+
],
|
|
179
|
+
},
|
|
180
|
+
},
|
|
181
|
+
}, { enumStyle: "enum" }).code;
|
|
182
|
+
// Should remain as a union because "value" has incompatible types
|
|
183
|
+
expect(code).toMatch(/Field \| FieldType/);
|
|
184
|
+
});
|
|
185
|
+
it("should preserve discriminated unions as separate types", () => {
|
|
186
|
+
const code = new TypescriptConverter({
|
|
187
|
+
type: "object",
|
|
188
|
+
properties: {
|
|
189
|
+
shape: {
|
|
190
|
+
anyOf: [
|
|
191
|
+
{
|
|
192
|
+
type: "object",
|
|
193
|
+
properties: {
|
|
194
|
+
kind: { const: "circle" },
|
|
195
|
+
radius: { type: "number" },
|
|
196
|
+
},
|
|
197
|
+
},
|
|
198
|
+
{
|
|
199
|
+
type: "object",
|
|
200
|
+
properties: {
|
|
201
|
+
kind: { const: "square" },
|
|
202
|
+
side: { type: "number" },
|
|
203
|
+
},
|
|
204
|
+
},
|
|
205
|
+
],
|
|
206
|
+
},
|
|
207
|
+
},
|
|
208
|
+
}, { enumStyle: "enum" }).code;
|
|
209
|
+
// Discriminated union: "kind" has distinct const per option with
|
|
210
|
+
// option-specific properties — should NOT be merged
|
|
211
|
+
expect(code).toMatch(/Shape \| ShapeType/);
|
|
212
|
+
});
|
|
213
|
+
it("should merge with union-style enums (default enumStyle)", () => {
|
|
214
|
+
const code = new TypescriptConverter({
|
|
215
|
+
type: "object",
|
|
216
|
+
properties: {
|
|
217
|
+
event: {
|
|
218
|
+
anyOf: [
|
|
219
|
+
{
|
|
220
|
+
type: "object",
|
|
221
|
+
properties: {
|
|
222
|
+
type: {
|
|
223
|
+
type: "string",
|
|
224
|
+
enum: ["click", "hover"],
|
|
225
|
+
},
|
|
226
|
+
x: { type: "number" },
|
|
227
|
+
},
|
|
228
|
+
},
|
|
229
|
+
{
|
|
230
|
+
type: "object",
|
|
231
|
+
properties: {
|
|
232
|
+
type: {
|
|
233
|
+
type: "string",
|
|
234
|
+
enum: ["scroll", "resize"],
|
|
235
|
+
},
|
|
236
|
+
x: { type: "number" },
|
|
237
|
+
},
|
|
238
|
+
},
|
|
239
|
+
],
|
|
240
|
+
},
|
|
241
|
+
},
|
|
242
|
+
}).code;
|
|
243
|
+
// With default enumStyle ("union"), merged enums appear as string literal unions
|
|
244
|
+
expect(code).toMatch(`"click" | "hover" | "scroll" | "resize"`);
|
|
245
|
+
});
|
|
246
|
+
it("should handle nested anyOf merging (bottom-up)", () => {
|
|
247
|
+
const code = new TypescriptConverter({
|
|
248
|
+
type: "object",
|
|
249
|
+
properties: {
|
|
250
|
+
outer: {
|
|
251
|
+
type: "array",
|
|
252
|
+
items: {
|
|
253
|
+
anyOf: [
|
|
254
|
+
{
|
|
255
|
+
type: "object",
|
|
256
|
+
properties: {
|
|
257
|
+
tag: {
|
|
258
|
+
type: "string",
|
|
259
|
+
enum: ["a"],
|
|
260
|
+
},
|
|
261
|
+
inner: {
|
|
262
|
+
anyOf: [
|
|
263
|
+
{
|
|
264
|
+
type: "object",
|
|
265
|
+
properties: {
|
|
266
|
+
level: {
|
|
267
|
+
type: "string",
|
|
268
|
+
enum: ["low"],
|
|
269
|
+
},
|
|
270
|
+
},
|
|
271
|
+
},
|
|
272
|
+
{
|
|
273
|
+
type: "object",
|
|
274
|
+
properties: {
|
|
275
|
+
level: {
|
|
276
|
+
type: "string",
|
|
277
|
+
enum: ["high"],
|
|
278
|
+
},
|
|
279
|
+
},
|
|
280
|
+
},
|
|
281
|
+
],
|
|
282
|
+
},
|
|
283
|
+
},
|
|
284
|
+
},
|
|
285
|
+
{
|
|
286
|
+
type: "object",
|
|
287
|
+
properties: {
|
|
288
|
+
tag: {
|
|
289
|
+
type: "string",
|
|
290
|
+
enum: ["b"],
|
|
291
|
+
},
|
|
292
|
+
},
|
|
293
|
+
},
|
|
294
|
+
],
|
|
295
|
+
},
|
|
296
|
+
},
|
|
297
|
+
},
|
|
298
|
+
}, { enumStyle: "enum" }).code;
|
|
299
|
+
// Inner anyOf should be merged first (bottom-up), producing a merged Level enum
|
|
300
|
+
expect(code).toMatch(`export enum Level { Low = "low", High = "high" }`);
|
|
301
|
+
// Outer anyOf should also be merged (tag is shared)
|
|
302
|
+
expect(code).toMatch(`export enum Tag { A = "a", B = "b" }`);
|
|
303
|
+
});
|
|
304
|
+
});
|
|
13
305
|
//# sourceMappingURL=TypescriptConverter.composites.test.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TypescriptConverter.composites.test.js","sourceRoot":"","sources":["../src/TypescriptConverter.composites.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAE/D,QAAQ,CAAC,gDAAgD,EAAE,GAAG,EAAE;IAC9D,EAAE,CAAC,uBAAuB,EAAE,GAAG,EAAE;QAC/B,MAAM,CACJ,IAAI,mBAAmB,CAAC,EAAE,IAAI,EAAE,CAAC,QAAQ,EAAE,QAAQ,CAAC,EAAE,CAAC,CAAC,IAAI,CAC7D,CAAC,OAAO,CAAC,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,CAAC,CAAC"}
|
|
@@ -31,6 +31,11 @@ export interface TypescriptConverterOpts {
|
|
|
31
31
|
* @example ["criteria", "alumni", "corpus"]
|
|
32
32
|
*/
|
|
33
33
|
uncountableWords?: string[];
|
|
34
|
+
/**
|
|
35
|
+
* If true, emit JSDoc comments from JSON Schema `description` annotations.
|
|
36
|
+
* Only applies when `inlineTypes` is false (the default).
|
|
37
|
+
*/
|
|
38
|
+
jsdoc?: boolean;
|
|
34
39
|
}
|
|
35
40
|
/**
|
|
36
41
|
* A TypeScript language converter plugin.
|
|
@@ -47,6 +52,7 @@ export declare class TypescriptConverter extends TypescriptBaseConverter impleme
|
|
|
47
52
|
*/
|
|
48
53
|
private enumDeclarations;
|
|
49
54
|
readonly code: string;
|
|
55
|
+
private mergeCounter;
|
|
50
56
|
constructor(schema: JSONSchema7Definition, opts?: TypescriptConverterOpts);
|
|
51
57
|
protected getRefTypeNamingConfig(): RefTypeNamingConfig;
|
|
52
58
|
/**
|
|
@@ -83,4 +89,34 @@ export declare class TypescriptConverter extends TypescriptBaseConverter impleme
|
|
|
83
89
|
* Converts a string value to a valid PascalCase enum member name.
|
|
84
90
|
*/
|
|
85
91
|
private toEnumMemberName;
|
|
92
|
+
/**
|
|
93
|
+
* Recursively walks the IR tree (bottom-up) and merges anyOf unions
|
|
94
|
+
* whose options are all objects with compatible property types.
|
|
95
|
+
* Merged enums collect values from all options; properties missing
|
|
96
|
+
* from some options become optional in the merged type.
|
|
97
|
+
*/
|
|
98
|
+
private mergeCompatibleUnions;
|
|
99
|
+
/**
|
|
100
|
+
* Attempts to merge all options of an anyOf union into a single object type.
|
|
101
|
+
* Returns the merged IRNode, or null if the options are not compatible.
|
|
102
|
+
*/
|
|
103
|
+
private tryMergeObjectUnion;
|
|
104
|
+
/**
|
|
105
|
+
* Tries to merge multiple instances of the same property across union options.
|
|
106
|
+
* Returns the merged IRNode, or null if incompatible.
|
|
107
|
+
*/
|
|
108
|
+
private tryMergeProperty;
|
|
109
|
+
/**
|
|
110
|
+
* Detects discriminated union patterns where merging would lose
|
|
111
|
+
* semantic precision. A discriminated union requires:
|
|
112
|
+
* 1. A shared property with distinct const/single-value-enum per option
|
|
113
|
+
* (the "discriminator")
|
|
114
|
+
* 2. Every option has at least one property exclusive to only that option
|
|
115
|
+
* (variant-specific fields tied to the discriminator value)
|
|
116
|
+
*
|
|
117
|
+
* This distinguishes true tagged unions (circle+radius vs square+side)
|
|
118
|
+
* from schemas where single-value enums represent different values of
|
|
119
|
+
* the same field that should be merged (past/current/future → Timeframe).
|
|
120
|
+
*/
|
|
121
|
+
private isDiscriminatedUnion;
|
|
86
122
|
}
|