@kubb/plugin-ts 5.0.0-alpha.10 → 5.0.0-alpha.12
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/{components-CRu8IKY3.js → Type-CX1HRooG.js} +377 -365
- package/dist/Type-CX1HRooG.js.map +1 -0
- package/dist/Type-Cat0_htq.cjs +808 -0
- package/dist/Type-Cat0_htq.cjs.map +1 -0
- package/dist/components.cjs +3 -2
- package/dist/components.d.ts +40 -9
- package/dist/components.js +2 -2
- package/dist/generators-CLuCmfUz.js +532 -0
- package/dist/generators-CLuCmfUz.js.map +1 -0
- package/dist/generators-DWBU-MuW.cjs +536 -0
- package/dist/generators-DWBU-MuW.cjs.map +1 -0
- package/dist/generators.cjs +2 -3
- package/dist/generators.d.ts +3 -503
- package/dist/generators.js +2 -2
- package/dist/index.cjs +308 -4
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +26 -21
- package/dist/index.js +305 -2
- package/dist/index.js.map +1 -0
- package/dist/{types-mSXmB8WU.d.ts → types-BA1ZCQ5p.d.ts} +73 -57
- package/package.json +5 -5
- package/src/components/{v2/Enum.tsx → Enum.tsx} +27 -11
- package/src/components/Type.tsx +23 -141
- package/src/components/index.ts +1 -0
- package/src/generators/index.ts +0 -1
- package/src/generators/typeGenerator.tsx +189 -413
- package/src/generators/utils.ts +298 -0
- package/src/index.ts +1 -1
- package/src/plugin.ts +81 -129
- package/src/printer.ts +15 -4
- package/src/resolverTs.ts +109 -1
- package/src/types.ts +68 -52
- package/dist/components-CRu8IKY3.js.map +0 -1
- package/dist/components-DeNDKlzf.cjs +0 -982
- package/dist/components-DeNDKlzf.cjs.map +0 -1
- package/dist/plugin-BZkBwnEA.js +0 -1269
- package/dist/plugin-BZkBwnEA.js.map +0 -1
- package/dist/plugin-Bunz1oGa.cjs +0 -1322
- package/dist/plugin-Bunz1oGa.cjs.map +0 -1
- package/src/components/v2/Type.tsx +0 -59
- package/src/generators/v2/typeGenerator.tsx +0 -167
- package/src/generators/v2/utils.ts +0 -140
- package/src/parser.ts +0 -389
|
@@ -1,982 +0,0 @@
|
|
|
1
|
-
//#region \0rolldown/runtime.js
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __name = (target, value) => __defProp(target, "name", {
|
|
5
|
-
value,
|
|
6
|
-
configurable: true
|
|
7
|
-
});
|
|
8
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
9
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
10
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
11
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
14
|
-
key = keys[i];
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
16
|
-
get: ((k) => from[k]).bind(null, key),
|
|
17
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
return to;
|
|
21
|
-
};
|
|
22
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
23
|
-
value: mod,
|
|
24
|
-
enumerable: true
|
|
25
|
-
}) : target, mod));
|
|
26
|
-
//#endregion
|
|
27
|
-
let _kubb_plugin_oas = require("@kubb/plugin-oas");
|
|
28
|
-
let _kubb_fabric_core_parsers_typescript = require("@kubb/fabric-core/parsers/typescript");
|
|
29
|
-
let _kubb_react_fabric = require("@kubb/react-fabric");
|
|
30
|
-
let typescript = require("typescript");
|
|
31
|
-
typescript = __toESM(typescript);
|
|
32
|
-
let remeda = require("remeda");
|
|
33
|
-
let _kubb_react_fabric_jsx_runtime = require("@kubb/react-fabric/jsx-runtime");
|
|
34
|
-
//#region ../../internals/utils/src/casing.ts
|
|
35
|
-
/**
|
|
36
|
-
* Shared implementation for camelCase and PascalCase conversion.
|
|
37
|
-
* Splits on common word boundaries (spaces, hyphens, underscores, dots, slashes, colons)
|
|
38
|
-
* and capitalizes each word according to `pascal`.
|
|
39
|
-
*
|
|
40
|
-
* When `pascal` is `true` the first word is also capitalized (PascalCase), otherwise only subsequent words are.
|
|
41
|
-
*/
|
|
42
|
-
function toCamelOrPascal(text, pascal) {
|
|
43
|
-
return text.trim().replace(/([a-z\d])([A-Z])/g, "$1 $2").replace(/([A-Z]+)([A-Z][a-z])/g, "$1 $2").replace(/(\d)([a-z])/g, "$1 $2").split(/[\s\-_./\\:]+/).filter(Boolean).map((word, i) => {
|
|
44
|
-
if (word.length > 1 && word === word.toUpperCase()) return word;
|
|
45
|
-
if (i === 0 && !pascal) return word.charAt(0).toLowerCase() + word.slice(1);
|
|
46
|
-
return word.charAt(0).toUpperCase() + word.slice(1);
|
|
47
|
-
}).join("").replace(/[^a-zA-Z0-9]/g, "");
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Splits `text` on `.` and applies `transformPart` to each segment.
|
|
51
|
-
* The last segment receives `isLast = true`, all earlier segments receive `false`.
|
|
52
|
-
* Segments are joined with `/` to form a file path.
|
|
53
|
-
*/
|
|
54
|
-
function applyToFileParts(text, transformPart) {
|
|
55
|
-
const parts = text.split(".");
|
|
56
|
-
return parts.map((part, i) => transformPart(part, i === parts.length - 1)).join("/");
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* Converts `text` to camelCase.
|
|
60
|
-
* When `isFile` is `true`, dot-separated segments are each cased independently and joined with `/`.
|
|
61
|
-
*
|
|
62
|
-
* @example
|
|
63
|
-
* camelCase('hello-world') // 'helloWorld'
|
|
64
|
-
* camelCase('pet.petId', { isFile: true }) // 'pet/petId'
|
|
65
|
-
*/
|
|
66
|
-
function camelCase(text, { isFile, prefix = "", suffix = "" } = {}) {
|
|
67
|
-
if (isFile) return applyToFileParts(text, (part, isLast) => camelCase(part, isLast ? {
|
|
68
|
-
prefix,
|
|
69
|
-
suffix
|
|
70
|
-
} : {}));
|
|
71
|
-
return toCamelOrPascal(`${prefix} ${text} ${suffix}`, false);
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* Converts `text` to PascalCase.
|
|
75
|
-
* When `isFile` is `true`, the last dot-separated segment is PascalCased and earlier segments are camelCased.
|
|
76
|
-
*
|
|
77
|
-
* @example
|
|
78
|
-
* pascalCase('hello-world') // 'HelloWorld'
|
|
79
|
-
* pascalCase('pet.petId', { isFile: true }) // 'pet/PetId'
|
|
80
|
-
*/
|
|
81
|
-
function pascalCase(text, { isFile, prefix = "", suffix = "" } = {}) {
|
|
82
|
-
if (isFile) return applyToFileParts(text, (part, isLast) => isLast ? pascalCase(part, {
|
|
83
|
-
prefix,
|
|
84
|
-
suffix
|
|
85
|
-
}) : camelCase(part));
|
|
86
|
-
return toCamelOrPascal(`${prefix} ${text} ${suffix}`, true);
|
|
87
|
-
}
|
|
88
|
-
/**
|
|
89
|
-
* Converts `text` to snake_case.
|
|
90
|
-
*
|
|
91
|
-
* @example
|
|
92
|
-
* snakeCase('helloWorld') // 'hello_world'
|
|
93
|
-
* snakeCase('Hello-World') // 'hello_world'
|
|
94
|
-
*/
|
|
95
|
-
function snakeCase(text, { prefix = "", suffix = "" } = {}) {
|
|
96
|
-
return `${prefix} ${text} ${suffix}`.trim().replace(/([a-z])([A-Z])/g, "$1_$2").replace(/[\s\-.]+/g, "_").replace(/[^a-zA-Z0-9_]/g, "").toLowerCase().split("_").filter(Boolean).join("_");
|
|
97
|
-
}
|
|
98
|
-
/**
|
|
99
|
-
* Converts `text` to SCREAMING_SNAKE_CASE.
|
|
100
|
-
*
|
|
101
|
-
* @example
|
|
102
|
-
* screamingSnakeCase('helloWorld') // 'HELLO_WORLD'
|
|
103
|
-
*/
|
|
104
|
-
function screamingSnakeCase(text, { prefix = "", suffix = "" } = {}) {
|
|
105
|
-
return snakeCase(text, {
|
|
106
|
-
prefix,
|
|
107
|
-
suffix
|
|
108
|
-
}).toUpperCase();
|
|
109
|
-
}
|
|
110
|
-
//#endregion
|
|
111
|
-
//#region ../../internals/utils/src/string.ts
|
|
112
|
-
/**
|
|
113
|
-
* Strips a single matching pair of `"..."`, `'...'`, or `` `...` `` from both ends of `text`.
|
|
114
|
-
* Returns the string unchanged when no balanced quote pair is found.
|
|
115
|
-
*
|
|
116
|
-
* @example
|
|
117
|
-
* trimQuotes('"hello"') // 'hello'
|
|
118
|
-
* trimQuotes('hello') // 'hello'
|
|
119
|
-
*/
|
|
120
|
-
function trimQuotes(text) {
|
|
121
|
-
if (text.length >= 2) {
|
|
122
|
-
const first = text[0];
|
|
123
|
-
const last = text[text.length - 1];
|
|
124
|
-
if (first === "\"" && last === "\"" || first === "'" && last === "'" || first === "`" && last === "`") return text.slice(1, -1);
|
|
125
|
-
}
|
|
126
|
-
return text;
|
|
127
|
-
}
|
|
128
|
-
/**
|
|
129
|
-
* Escapes characters that are not allowed inside JS string literals.
|
|
130
|
-
* Handles quotes, backslashes, and Unicode line terminators (U+2028 / U+2029).
|
|
131
|
-
*
|
|
132
|
-
* @see http://www.ecma-international.org/ecma-262/5.1/#sec-7.8.4
|
|
133
|
-
*/
|
|
134
|
-
function jsStringEscape(input) {
|
|
135
|
-
return `${input}`.replace(/["'\\\n\r\u2028\u2029]/g, (character) => {
|
|
136
|
-
switch (character) {
|
|
137
|
-
case "\"":
|
|
138
|
-
case "'":
|
|
139
|
-
case "\\": return `\\${character}`;
|
|
140
|
-
case "\n": return "\\n";
|
|
141
|
-
case "\r": return "\\r";
|
|
142
|
-
case "\u2028": return "\\u2028";
|
|
143
|
-
case "\u2029": return "\\u2029";
|
|
144
|
-
default: return "";
|
|
145
|
-
}
|
|
146
|
-
});
|
|
147
|
-
}
|
|
148
|
-
//#endregion
|
|
149
|
-
//#region src/factory.ts
|
|
150
|
-
const { SyntaxKind, factory } = typescript.default;
|
|
151
|
-
const modifiers = {
|
|
152
|
-
async: factory.createModifier(typescript.default.SyntaxKind.AsyncKeyword),
|
|
153
|
-
export: factory.createModifier(typescript.default.SyntaxKind.ExportKeyword),
|
|
154
|
-
const: factory.createModifier(typescript.default.SyntaxKind.ConstKeyword),
|
|
155
|
-
static: factory.createModifier(typescript.default.SyntaxKind.StaticKeyword)
|
|
156
|
-
};
|
|
157
|
-
const syntaxKind = {
|
|
158
|
-
union: SyntaxKind.UnionType,
|
|
159
|
-
literalType: SyntaxKind.LiteralType,
|
|
160
|
-
stringLiteral: SyntaxKind.StringLiteral
|
|
161
|
-
};
|
|
162
|
-
function getUnknownType(unknownType) {
|
|
163
|
-
if (unknownType === "any") return keywordTypeNodes.any;
|
|
164
|
-
if (unknownType === "void") return keywordTypeNodes.void;
|
|
165
|
-
return keywordTypeNodes.unknown;
|
|
166
|
-
}
|
|
167
|
-
function isValidIdentifier(str) {
|
|
168
|
-
if (!str.length || str.trim() !== str) return false;
|
|
169
|
-
const node = typescript.default.parseIsolatedEntityName(str, typescript.default.ScriptTarget.Latest);
|
|
170
|
-
return !!node && node.kind === typescript.default.SyntaxKind.Identifier && typescript.default.identifierToKeywordKind(node.kind) === void 0;
|
|
171
|
-
}
|
|
172
|
-
function propertyName(name) {
|
|
173
|
-
if (typeof name === "string") return isValidIdentifier(name) ? factory.createIdentifier(name) : factory.createStringLiteral(name);
|
|
174
|
-
return name;
|
|
175
|
-
}
|
|
176
|
-
const questionToken = factory.createToken(typescript.default.SyntaxKind.QuestionToken);
|
|
177
|
-
function createQuestionToken(token) {
|
|
178
|
-
if (!token) return;
|
|
179
|
-
if (token === true) return questionToken;
|
|
180
|
-
return token;
|
|
181
|
-
}
|
|
182
|
-
function createIntersectionDeclaration({ nodes, withParentheses }) {
|
|
183
|
-
if (!nodes.length) return null;
|
|
184
|
-
if (nodes.length === 1) return nodes[0] || null;
|
|
185
|
-
const node = factory.createIntersectionTypeNode(nodes);
|
|
186
|
-
if (withParentheses) return factory.createParenthesizedType(node);
|
|
187
|
-
return node;
|
|
188
|
-
}
|
|
189
|
-
function createArrayDeclaration({ nodes, arrayType = "array" }) {
|
|
190
|
-
if (!nodes.length) return factory.createTupleTypeNode([]);
|
|
191
|
-
if (nodes.length === 1) {
|
|
192
|
-
const node = nodes[0];
|
|
193
|
-
if (!node) return null;
|
|
194
|
-
if (arrayType === "generic") return factory.createTypeReferenceNode(factory.createIdentifier("Array"), [node]);
|
|
195
|
-
return factory.createArrayTypeNode(node);
|
|
196
|
-
}
|
|
197
|
-
const unionType = factory.createUnionTypeNode(nodes);
|
|
198
|
-
if (arrayType === "generic") return factory.createTypeReferenceNode(factory.createIdentifier("Array"), [unionType]);
|
|
199
|
-
return factory.createArrayTypeNode(factory.createParenthesizedType(unionType));
|
|
200
|
-
}
|
|
201
|
-
/**
|
|
202
|
-
* Minimum nodes length of 2
|
|
203
|
-
* @example `string | number`
|
|
204
|
-
*/
|
|
205
|
-
function createUnionDeclaration({ nodes, withParentheses }) {
|
|
206
|
-
if (!nodes.length) return keywordTypeNodes.any;
|
|
207
|
-
if (nodes.length === 1) return nodes[0];
|
|
208
|
-
const node = factory.createUnionTypeNode(nodes);
|
|
209
|
-
if (withParentheses) return factory.createParenthesizedType(node);
|
|
210
|
-
return node;
|
|
211
|
-
}
|
|
212
|
-
function createPropertySignature({ readOnly, modifiers = [], name, questionToken, type }) {
|
|
213
|
-
return factory.createPropertySignature([...modifiers, readOnly ? factory.createToken(typescript.default.SyntaxKind.ReadonlyKeyword) : void 0].filter(Boolean), propertyName(name), createQuestionToken(questionToken), type);
|
|
214
|
-
}
|
|
215
|
-
function createParameterSignature(name, { modifiers, dotDotDotToken, questionToken, type, initializer }) {
|
|
216
|
-
return factory.createParameterDeclaration(modifiers, dotDotDotToken, name, createQuestionToken(questionToken), type, initializer);
|
|
217
|
-
}
|
|
218
|
-
/**
|
|
219
|
-
* @link https://github.com/microsoft/TypeScript/issues/44151
|
|
220
|
-
*/
|
|
221
|
-
function appendJSDocToNode({ node, comments }) {
|
|
222
|
-
const filteredComments = comments.filter(Boolean);
|
|
223
|
-
if (!filteredComments.length) return node;
|
|
224
|
-
const text = filteredComments.reduce((acc = "", comment = "") => {
|
|
225
|
-
return `${acc}\n * ${comment.replaceAll("*/", "*\\/")}`;
|
|
226
|
-
}, "*");
|
|
227
|
-
return typescript.default.addSyntheticLeadingComment(node, typescript.default.SyntaxKind.MultiLineCommentTrivia, `${text || "*"}\n`, true);
|
|
228
|
-
}
|
|
229
|
-
function createIndexSignature(type, { modifiers, indexName = "key", indexType = factory.createKeywordTypeNode(typescript.default.SyntaxKind.StringKeyword) } = {}) {
|
|
230
|
-
return factory.createIndexSignature(modifiers, [createParameterSignature(indexName, { type: indexType })], type);
|
|
231
|
-
}
|
|
232
|
-
function createTypeAliasDeclaration({ modifiers, name, typeParameters, type }) {
|
|
233
|
-
return factory.createTypeAliasDeclaration(modifiers, name, typeParameters, type);
|
|
234
|
-
}
|
|
235
|
-
function createInterfaceDeclaration({ modifiers, name, typeParameters, members }) {
|
|
236
|
-
return factory.createInterfaceDeclaration(modifiers, name, typeParameters, void 0, members);
|
|
237
|
-
}
|
|
238
|
-
function createTypeDeclaration({ syntax, isExportable, comments, name, type }) {
|
|
239
|
-
if (syntax === "interface" && "members" in type) return appendJSDocToNode({
|
|
240
|
-
node: createInterfaceDeclaration({
|
|
241
|
-
members: type.members,
|
|
242
|
-
modifiers: isExportable ? [modifiers.export] : [],
|
|
243
|
-
name,
|
|
244
|
-
typeParameters: void 0
|
|
245
|
-
}),
|
|
246
|
-
comments
|
|
247
|
-
});
|
|
248
|
-
return appendJSDocToNode({
|
|
249
|
-
node: createTypeAliasDeclaration({
|
|
250
|
-
type,
|
|
251
|
-
modifiers: isExportable ? [modifiers.export] : [],
|
|
252
|
-
name,
|
|
253
|
-
typeParameters: void 0
|
|
254
|
-
}),
|
|
255
|
-
comments
|
|
256
|
-
});
|
|
257
|
-
}
|
|
258
|
-
/**
|
|
259
|
-
* Apply casing transformation to enum keys
|
|
260
|
-
*/
|
|
261
|
-
function applyEnumKeyCasing(key, casing = "none") {
|
|
262
|
-
if (casing === "none") return key;
|
|
263
|
-
if (casing === "screamingSnakeCase") return screamingSnakeCase(key);
|
|
264
|
-
if (casing === "snakeCase") return snakeCase(key);
|
|
265
|
-
if (casing === "pascalCase") return pascalCase(key);
|
|
266
|
-
if (casing === "camelCase") return camelCase(key);
|
|
267
|
-
return key;
|
|
268
|
-
}
|
|
269
|
-
function createEnumDeclaration({ type = "enum", name, typeName, enums, enumKeyCasing = "none" }) {
|
|
270
|
-
if (type === "literal" || type === "inlineLiteral") return [void 0, factory.createTypeAliasDeclaration([factory.createToken(typescript.default.SyntaxKind.ExportKeyword)], factory.createIdentifier(typeName), void 0, factory.createUnionTypeNode(enums.map(([_key, value]) => {
|
|
271
|
-
if ((0, remeda.isNumber)(value)) {
|
|
272
|
-
if (value < 0) return factory.createLiteralTypeNode(factory.createPrefixUnaryExpression(typescript.default.SyntaxKind.MinusToken, factory.createNumericLiteral(Math.abs(value))));
|
|
273
|
-
return factory.createLiteralTypeNode(factory.createNumericLiteral(value?.toString()));
|
|
274
|
-
}
|
|
275
|
-
if (typeof value === "boolean") return factory.createLiteralTypeNode(value ? factory.createTrue() : factory.createFalse());
|
|
276
|
-
if (value) return factory.createLiteralTypeNode(factory.createStringLiteral(value.toString()));
|
|
277
|
-
}).filter(Boolean)))];
|
|
278
|
-
if (type === "enum" || type === "constEnum") return [void 0, factory.createEnumDeclaration([factory.createToken(typescript.default.SyntaxKind.ExportKeyword), type === "constEnum" ? factory.createToken(typescript.default.SyntaxKind.ConstKeyword) : void 0].filter(Boolean), factory.createIdentifier(typeName), enums.map(([key, value]) => {
|
|
279
|
-
let initializer = factory.createStringLiteral(value?.toString());
|
|
280
|
-
if (Number.parseInt(value.toString(), 10) === value && (0, remeda.isNumber)(Number.parseInt(value.toString(), 10))) if (value < 0) initializer = factory.createPrefixUnaryExpression(typescript.default.SyntaxKind.MinusToken, factory.createNumericLiteral(Math.abs(value)));
|
|
281
|
-
else initializer = factory.createNumericLiteral(value);
|
|
282
|
-
if (typeof value === "boolean") initializer = value ? factory.createTrue() : factory.createFalse();
|
|
283
|
-
if ((0, remeda.isNumber)(Number.parseInt(key.toString(), 10))) {
|
|
284
|
-
const casingKey = applyEnumKeyCasing(`${typeName}_${key}`, enumKeyCasing);
|
|
285
|
-
return factory.createEnumMember(propertyName(casingKey), initializer);
|
|
286
|
-
}
|
|
287
|
-
if (key) {
|
|
288
|
-
const casingKey = applyEnumKeyCasing(key.toString(), enumKeyCasing);
|
|
289
|
-
return factory.createEnumMember(propertyName(casingKey), initializer);
|
|
290
|
-
}
|
|
291
|
-
}).filter(Boolean))];
|
|
292
|
-
const identifierName = name;
|
|
293
|
-
if (enums.length === 0) return [void 0, factory.createTypeAliasDeclaration([factory.createToken(typescript.default.SyntaxKind.ExportKeyword)], factory.createIdentifier(typeName), void 0, factory.createKeywordTypeNode(typescript.default.SyntaxKind.NeverKeyword))];
|
|
294
|
-
return [factory.createVariableStatement([factory.createToken(typescript.default.SyntaxKind.ExportKeyword)], factory.createVariableDeclarationList([factory.createVariableDeclaration(factory.createIdentifier(identifierName), void 0, void 0, factory.createAsExpression(factory.createObjectLiteralExpression(enums.map(([key, value]) => {
|
|
295
|
-
let initializer = factory.createStringLiteral(value?.toString());
|
|
296
|
-
if ((0, remeda.isNumber)(value)) if (value < 0) initializer = factory.createPrefixUnaryExpression(typescript.default.SyntaxKind.MinusToken, factory.createNumericLiteral(Math.abs(value)));
|
|
297
|
-
else initializer = factory.createNumericLiteral(value);
|
|
298
|
-
if (typeof value === "boolean") initializer = value ? factory.createTrue() : factory.createFalse();
|
|
299
|
-
if (key) {
|
|
300
|
-
const casingKey = applyEnumKeyCasing(key.toString(), enumKeyCasing);
|
|
301
|
-
return factory.createPropertyAssignment(propertyName(casingKey), initializer);
|
|
302
|
-
}
|
|
303
|
-
}).filter(Boolean), true), factory.createTypeReferenceNode(factory.createIdentifier("const"), void 0)))], typescript.default.NodeFlags.Const)), factory.createTypeAliasDeclaration([factory.createToken(typescript.default.SyntaxKind.ExportKeyword)], factory.createIdentifier(typeName), void 0, factory.createIndexedAccessTypeNode(factory.createParenthesizedType(factory.createTypeQueryNode(factory.createIdentifier(identifierName), void 0)), factory.createTypeOperatorNode(typescript.default.SyntaxKind.KeyOfKeyword, factory.createTypeQueryNode(factory.createIdentifier(identifierName), void 0))))];
|
|
304
|
-
}
|
|
305
|
-
function createOmitDeclaration({ keys, type, nonNullable }) {
|
|
306
|
-
const node = nonNullable ? factory.createTypeReferenceNode(factory.createIdentifier("NonNullable"), [type]) : type;
|
|
307
|
-
if (Array.isArray(keys)) return factory.createTypeReferenceNode(factory.createIdentifier("Omit"), [node, factory.createUnionTypeNode(keys.map((key) => {
|
|
308
|
-
return factory.createLiteralTypeNode(factory.createStringLiteral(key));
|
|
309
|
-
}))]);
|
|
310
|
-
return factory.createTypeReferenceNode(factory.createIdentifier("Omit"), [node, factory.createLiteralTypeNode(factory.createStringLiteral(keys))]);
|
|
311
|
-
}
|
|
312
|
-
const keywordTypeNodes = {
|
|
313
|
-
any: factory.createKeywordTypeNode(typescript.default.SyntaxKind.AnyKeyword),
|
|
314
|
-
unknown: factory.createKeywordTypeNode(typescript.default.SyntaxKind.UnknownKeyword),
|
|
315
|
-
void: factory.createKeywordTypeNode(typescript.default.SyntaxKind.VoidKeyword),
|
|
316
|
-
number: factory.createKeywordTypeNode(typescript.default.SyntaxKind.NumberKeyword),
|
|
317
|
-
integer: factory.createKeywordTypeNode(typescript.default.SyntaxKind.NumberKeyword),
|
|
318
|
-
bigint: factory.createKeywordTypeNode(typescript.default.SyntaxKind.BigIntKeyword),
|
|
319
|
-
object: factory.createKeywordTypeNode(typescript.default.SyntaxKind.ObjectKeyword),
|
|
320
|
-
string: factory.createKeywordTypeNode(typescript.default.SyntaxKind.StringKeyword),
|
|
321
|
-
boolean: factory.createKeywordTypeNode(typescript.default.SyntaxKind.BooleanKeyword),
|
|
322
|
-
undefined: factory.createKeywordTypeNode(typescript.default.SyntaxKind.UndefinedKeyword),
|
|
323
|
-
null: factory.createLiteralTypeNode(factory.createToken(typescript.default.SyntaxKind.NullKeyword)),
|
|
324
|
-
never: factory.createKeywordTypeNode(typescript.default.SyntaxKind.NeverKeyword)
|
|
325
|
-
};
|
|
326
|
-
/**
|
|
327
|
-
* Converts a path like '/pet/{petId}/uploadImage' to a template literal type
|
|
328
|
-
* like `/pet/${string}/uploadImage`
|
|
329
|
-
*/
|
|
330
|
-
/**
|
|
331
|
-
* Converts an OAS-style path (e.g. `/pets/{petId}`) or an Express-style path
|
|
332
|
-
* (e.g. `/pets/:petId`) to a TypeScript template literal type
|
|
333
|
-
* like `` `/pets/${string}` ``.
|
|
334
|
-
*/
|
|
335
|
-
function createUrlTemplateType(path) {
|
|
336
|
-
const normalized = path.replace(/:([^/]+)/g, "{$1}");
|
|
337
|
-
if (!normalized.includes("{")) return factory.createLiteralTypeNode(factory.createStringLiteral(normalized));
|
|
338
|
-
const segments = normalized.split(/(\{[^}]+\})/);
|
|
339
|
-
const parts = [];
|
|
340
|
-
const parameterIndices = [];
|
|
341
|
-
segments.forEach((segment) => {
|
|
342
|
-
if (segment.startsWith("{") && segment.endsWith("}")) {
|
|
343
|
-
parameterIndices.push(parts.length);
|
|
344
|
-
parts.push(segment);
|
|
345
|
-
} else if (segment) parts.push(segment);
|
|
346
|
-
});
|
|
347
|
-
const head = typescript.default.factory.createTemplateHead(parts[0] || "");
|
|
348
|
-
const templateSpans = [];
|
|
349
|
-
parameterIndices.forEach((paramIndex, i) => {
|
|
350
|
-
const isLast = i === parameterIndices.length - 1;
|
|
351
|
-
const nextPart = parts[paramIndex + 1] || "";
|
|
352
|
-
const literal = isLast ? typescript.default.factory.createTemplateTail(nextPart) : typescript.default.factory.createTemplateMiddle(nextPart);
|
|
353
|
-
templateSpans.push(typescript.default.factory.createTemplateLiteralTypeSpan(keywordTypeNodes.string, literal));
|
|
354
|
-
});
|
|
355
|
-
return typescript.default.factory.createTemplateLiteralType(head, templateSpans);
|
|
356
|
-
}
|
|
357
|
-
const createTypeLiteralNode = factory.createTypeLiteralNode;
|
|
358
|
-
const createTypeReferenceNode = factory.createTypeReferenceNode;
|
|
359
|
-
const createNumericLiteral = factory.createNumericLiteral;
|
|
360
|
-
const createStringLiteral = factory.createStringLiteral;
|
|
361
|
-
const createArrayTypeNode = factory.createArrayTypeNode;
|
|
362
|
-
factory.createParenthesizedType;
|
|
363
|
-
const createLiteralTypeNode = factory.createLiteralTypeNode;
|
|
364
|
-
factory.createNull;
|
|
365
|
-
const createIdentifier = factory.createIdentifier;
|
|
366
|
-
const createOptionalTypeNode = factory.createOptionalTypeNode;
|
|
367
|
-
const createTupleTypeNode = factory.createTupleTypeNode;
|
|
368
|
-
const createRestTypeNode = factory.createRestTypeNode;
|
|
369
|
-
const createTrue = factory.createTrue;
|
|
370
|
-
const createFalse = factory.createFalse;
|
|
371
|
-
const createIndexedAccessTypeNode = factory.createIndexedAccessTypeNode;
|
|
372
|
-
const createTypeOperatorNode = factory.createTypeOperatorNode;
|
|
373
|
-
const createPrefixUnaryExpression = factory.createPrefixUnaryExpression;
|
|
374
|
-
//#endregion
|
|
375
|
-
//#region src/parser.ts
|
|
376
|
-
const typeKeywordMapper = {
|
|
377
|
-
any: () => keywordTypeNodes.any,
|
|
378
|
-
unknown: () => keywordTypeNodes.unknown,
|
|
379
|
-
void: () => keywordTypeNodes.void,
|
|
380
|
-
number: () => keywordTypeNodes.number,
|
|
381
|
-
integer: () => keywordTypeNodes.number,
|
|
382
|
-
bigint: () => keywordTypeNodes.bigint,
|
|
383
|
-
object: (nodes) => {
|
|
384
|
-
if (!nodes || !nodes.length) return keywordTypeNodes.object;
|
|
385
|
-
return createTypeLiteralNode(nodes);
|
|
386
|
-
},
|
|
387
|
-
string: () => keywordTypeNodes.string,
|
|
388
|
-
boolean: () => keywordTypeNodes.boolean,
|
|
389
|
-
undefined: () => keywordTypeNodes.undefined,
|
|
390
|
-
nullable: void 0,
|
|
391
|
-
null: () => keywordTypeNodes.null,
|
|
392
|
-
nullish: void 0,
|
|
393
|
-
array: (nodes, arrayType) => {
|
|
394
|
-
if (!nodes) return;
|
|
395
|
-
return createArrayDeclaration({
|
|
396
|
-
nodes,
|
|
397
|
-
arrayType
|
|
398
|
-
});
|
|
399
|
-
},
|
|
400
|
-
tuple: (nodes, rest, min, max) => {
|
|
401
|
-
if (!nodes) return;
|
|
402
|
-
if (max) {
|
|
403
|
-
nodes = nodes.slice(0, max);
|
|
404
|
-
if (nodes.length < max && rest) nodes = [...nodes, ...Array(max - nodes.length).fill(rest)];
|
|
405
|
-
}
|
|
406
|
-
if (min) nodes = nodes.map((node, index) => index >= min ? createOptionalTypeNode(node) : node);
|
|
407
|
-
if (typeof max === "undefined" && rest) nodes.push(createRestTypeNode(createArrayTypeNode(rest)));
|
|
408
|
-
return createTupleTypeNode(nodes);
|
|
409
|
-
},
|
|
410
|
-
enum: (name) => {
|
|
411
|
-
if (!name) return;
|
|
412
|
-
return createTypeReferenceNode(name, void 0);
|
|
413
|
-
},
|
|
414
|
-
union: (nodes) => {
|
|
415
|
-
if (!nodes) return;
|
|
416
|
-
return createUnionDeclaration({
|
|
417
|
-
withParentheses: true,
|
|
418
|
-
nodes
|
|
419
|
-
});
|
|
420
|
-
},
|
|
421
|
-
const: (name, format) => {
|
|
422
|
-
if (name === null || name === void 0 || name === "") return;
|
|
423
|
-
if (format === "boolean") {
|
|
424
|
-
if (name === true) return createLiteralTypeNode(createTrue());
|
|
425
|
-
return createLiteralTypeNode(createFalse());
|
|
426
|
-
}
|
|
427
|
-
if (format === "number" && typeof name === "number") return createLiteralTypeNode(createNumericLiteral(name));
|
|
428
|
-
return createLiteralTypeNode(createStringLiteral(name.toString()));
|
|
429
|
-
},
|
|
430
|
-
datetime: () => keywordTypeNodes.string,
|
|
431
|
-
date: (type = "string") => type === "string" ? keywordTypeNodes.string : createTypeReferenceNode(createIdentifier("Date")),
|
|
432
|
-
time: (type = "string") => type === "string" ? keywordTypeNodes.string : createTypeReferenceNode(createIdentifier("Date")),
|
|
433
|
-
uuid: () => keywordTypeNodes.string,
|
|
434
|
-
url: () => keywordTypeNodes.string,
|
|
435
|
-
default: void 0,
|
|
436
|
-
and: (nodes) => {
|
|
437
|
-
if (!nodes) return;
|
|
438
|
-
return createIntersectionDeclaration({
|
|
439
|
-
withParentheses: true,
|
|
440
|
-
nodes
|
|
441
|
-
});
|
|
442
|
-
},
|
|
443
|
-
describe: void 0,
|
|
444
|
-
min: void 0,
|
|
445
|
-
max: void 0,
|
|
446
|
-
optional: void 0,
|
|
447
|
-
matches: () => keywordTypeNodes.string,
|
|
448
|
-
email: () => keywordTypeNodes.string,
|
|
449
|
-
firstName: void 0,
|
|
450
|
-
lastName: void 0,
|
|
451
|
-
password: void 0,
|
|
452
|
-
phone: void 0,
|
|
453
|
-
readOnly: void 0,
|
|
454
|
-
writeOnly: void 0,
|
|
455
|
-
ref: (propertyName) => {
|
|
456
|
-
if (!propertyName) return;
|
|
457
|
-
return createTypeReferenceNode(propertyName, void 0);
|
|
458
|
-
},
|
|
459
|
-
blob: () => createTypeReferenceNode("Blob", []),
|
|
460
|
-
deprecated: void 0,
|
|
461
|
-
example: void 0,
|
|
462
|
-
schema: void 0,
|
|
463
|
-
catchall: void 0,
|
|
464
|
-
name: void 0,
|
|
465
|
-
interface: void 0,
|
|
466
|
-
exclusiveMaximum: void 0,
|
|
467
|
-
exclusiveMinimum: void 0
|
|
468
|
-
};
|
|
469
|
-
/**
|
|
470
|
-
* Recursively parses a schema tree node into a corresponding TypeScript AST node.
|
|
471
|
-
*
|
|
472
|
-
* Maps OpenAPI schema keywords to TypeScript AST nodes using the `typeKeywordMapper`, handling complex types such as unions, intersections, arrays, tuples (with optional/rest elements and length constraints), enums, constants, references, and objects with property modifiers and documentation annotations.
|
|
473
|
-
*
|
|
474
|
-
* @param current - The schema node to parse.
|
|
475
|
-
* @param siblings - Sibling schema nodes, used for context in certain mappings.
|
|
476
|
-
* @param name - The name of the schema or property being parsed.
|
|
477
|
-
* @param options - Parsing options controlling output style, property handling.
|
|
478
|
-
* @returns The generated TypeScript AST node, or `undefined` if the schema keyword is not mapped.
|
|
479
|
-
*/
|
|
480
|
-
const parse = (0, _kubb_plugin_oas.createParser)({
|
|
481
|
-
mapper: typeKeywordMapper,
|
|
482
|
-
handlers: {
|
|
483
|
-
union(tree, options) {
|
|
484
|
-
const { current, schema, name } = tree;
|
|
485
|
-
return typeKeywordMapper.union(current.args.map((it) => this.parse({
|
|
486
|
-
schema,
|
|
487
|
-
parent: current,
|
|
488
|
-
name,
|
|
489
|
-
current: it,
|
|
490
|
-
siblings: []
|
|
491
|
-
}, options)).filter(Boolean));
|
|
492
|
-
},
|
|
493
|
-
and(tree, options) {
|
|
494
|
-
const { current, schema, name } = tree;
|
|
495
|
-
return typeKeywordMapper.and(current.args.map((it) => this.parse({
|
|
496
|
-
schema,
|
|
497
|
-
parent: current,
|
|
498
|
-
name,
|
|
499
|
-
current: it,
|
|
500
|
-
siblings: []
|
|
501
|
-
}, options)).filter(Boolean));
|
|
502
|
-
},
|
|
503
|
-
array(tree, options) {
|
|
504
|
-
const { current, schema, name } = tree;
|
|
505
|
-
return typeKeywordMapper.array(current.args.items.map((it) => this.parse({
|
|
506
|
-
schema,
|
|
507
|
-
parent: current,
|
|
508
|
-
name,
|
|
509
|
-
current: it,
|
|
510
|
-
siblings: []
|
|
511
|
-
}, options)).filter(Boolean), options.arrayType);
|
|
512
|
-
},
|
|
513
|
-
enum(tree, options) {
|
|
514
|
-
const { current } = tree;
|
|
515
|
-
if (options.enumType === "inlineLiteral") {
|
|
516
|
-
const enumValues = current.args.items.map((item) => item.value).filter((value) => value !== void 0 && value !== null).map((value) => {
|
|
517
|
-
const format = typeof value === "number" ? "number" : typeof value === "boolean" ? "boolean" : "string";
|
|
518
|
-
return typeKeywordMapper.const(value, format);
|
|
519
|
-
}).filter(Boolean);
|
|
520
|
-
return typeKeywordMapper.union(enumValues);
|
|
521
|
-
}
|
|
522
|
-
return typeKeywordMapper.enum(["asConst", "asPascalConst"].includes(options.enumType) ? `${current.args.typeName}Key` : current.args.typeName);
|
|
523
|
-
},
|
|
524
|
-
ref(tree, _options) {
|
|
525
|
-
const { current } = tree;
|
|
526
|
-
return typeKeywordMapper.ref(current.args.name);
|
|
527
|
-
},
|
|
528
|
-
blob() {
|
|
529
|
-
return typeKeywordMapper.blob();
|
|
530
|
-
},
|
|
531
|
-
tuple(tree, options) {
|
|
532
|
-
const { current, schema, name } = tree;
|
|
533
|
-
return typeKeywordMapper.tuple(current.args.items.map((it) => this.parse({
|
|
534
|
-
schema,
|
|
535
|
-
parent: current,
|
|
536
|
-
name,
|
|
537
|
-
current: it,
|
|
538
|
-
siblings: []
|
|
539
|
-
}, options)).filter(Boolean), current.args.rest && (this.parse({
|
|
540
|
-
schema,
|
|
541
|
-
parent: current,
|
|
542
|
-
name,
|
|
543
|
-
current: current.args.rest,
|
|
544
|
-
siblings: []
|
|
545
|
-
}, options) ?? void 0), current.args.min, current.args.max);
|
|
546
|
-
},
|
|
547
|
-
const(tree, _options) {
|
|
548
|
-
const { current } = tree;
|
|
549
|
-
return typeKeywordMapper.const(current.args.name, current.args.format);
|
|
550
|
-
},
|
|
551
|
-
object(tree, options) {
|
|
552
|
-
const { current, schema, name } = tree;
|
|
553
|
-
const properties = Object.entries(current.args?.properties || {}).filter((item) => {
|
|
554
|
-
const schemas = item[1];
|
|
555
|
-
return schemas && typeof schemas.map === "function";
|
|
556
|
-
}).map(([name, schemas]) => {
|
|
557
|
-
const mappedName = schemas.find((schema) => schema.keyword === _kubb_plugin_oas.schemaKeywords.name)?.args || name;
|
|
558
|
-
const isNullish = schemas.some((schema) => schema.keyword === _kubb_plugin_oas.schemaKeywords.nullish);
|
|
559
|
-
const isNullable = schemas.some((schema) => schema.keyword === _kubb_plugin_oas.schemaKeywords.nullable);
|
|
560
|
-
const isOptional = schemas.some((schema) => schema.keyword === _kubb_plugin_oas.schemaKeywords.optional);
|
|
561
|
-
const isReadonly = schemas.some((schema) => schema.keyword === _kubb_plugin_oas.schemaKeywords.readOnly);
|
|
562
|
-
const describeSchema = schemas.find((schema) => schema.keyword === _kubb_plugin_oas.schemaKeywords.describe);
|
|
563
|
-
const deprecatedSchema = schemas.find((schema) => schema.keyword === _kubb_plugin_oas.schemaKeywords.deprecated);
|
|
564
|
-
const defaultSchema = schemas.find((schema) => schema.keyword === _kubb_plugin_oas.schemaKeywords.default);
|
|
565
|
-
const exampleSchema = schemas.find((schema) => schema.keyword === _kubb_plugin_oas.schemaKeywords.example);
|
|
566
|
-
const schemaSchema = schemas.find((schema) => schema.keyword === _kubb_plugin_oas.schemaKeywords.schema);
|
|
567
|
-
const minSchema = schemas.find((schema) => schema.keyword === _kubb_plugin_oas.schemaKeywords.min);
|
|
568
|
-
const maxSchema = schemas.find((schema) => schema.keyword === _kubb_plugin_oas.schemaKeywords.max);
|
|
569
|
-
const matchesSchema = schemas.find((schema) => schema.keyword === _kubb_plugin_oas.schemaKeywords.matches);
|
|
570
|
-
let type = schemas.map((it) => this.parse({
|
|
571
|
-
schema,
|
|
572
|
-
parent: current,
|
|
573
|
-
name,
|
|
574
|
-
current: it,
|
|
575
|
-
siblings: schemas
|
|
576
|
-
}, options)).filter(Boolean)[0];
|
|
577
|
-
if (isNullable) type = createUnionDeclaration({ nodes: [type, keywordTypeNodes.null] });
|
|
578
|
-
if (isNullish && ["undefined", "questionTokenAndUndefined"].includes(options.optionalType)) type = createUnionDeclaration({ nodes: [type, keywordTypeNodes.undefined] });
|
|
579
|
-
if (isOptional && ["undefined", "questionTokenAndUndefined"].includes(options.optionalType)) type = createUnionDeclaration({ nodes: [type, keywordTypeNodes.undefined] });
|
|
580
|
-
return appendJSDocToNode({
|
|
581
|
-
node: createPropertySignature({
|
|
582
|
-
questionToken: isOptional || isNullish ? ["questionToken", "questionTokenAndUndefined"].includes(options.optionalType) : false,
|
|
583
|
-
name: mappedName,
|
|
584
|
-
type,
|
|
585
|
-
readOnly: isReadonly
|
|
586
|
-
}),
|
|
587
|
-
comments: [
|
|
588
|
-
describeSchema ? `@description ${jsStringEscape(describeSchema.args)}` : void 0,
|
|
589
|
-
deprecatedSchema ? "@deprecated" : void 0,
|
|
590
|
-
minSchema ? `@minLength ${minSchema.args}` : void 0,
|
|
591
|
-
maxSchema ? `@maxLength ${maxSchema.args}` : void 0,
|
|
592
|
-
matchesSchema ? `@pattern ${matchesSchema.args}` : void 0,
|
|
593
|
-
defaultSchema ? `@default ${defaultSchema.args}` : void 0,
|
|
594
|
-
exampleSchema ? `@example ${exampleSchema.args}` : void 0,
|
|
595
|
-
schemaSchema?.args?.type || schemaSchema?.args?.format ? [`@type ${schemaSchema?.args?.type || "unknown"}${!isOptional ? "" : " | undefined"}`, schemaSchema?.args?.format].filter(Boolean).join(", ") : void 0
|
|
596
|
-
].filter(Boolean)
|
|
597
|
-
});
|
|
598
|
-
});
|
|
599
|
-
let additionalProperties;
|
|
600
|
-
if (current.args?.additionalProperties?.length) {
|
|
601
|
-
let additionalPropertiesType = current.args.additionalProperties.map((it) => this.parse({
|
|
602
|
-
schema,
|
|
603
|
-
parent: current,
|
|
604
|
-
name,
|
|
605
|
-
current: it,
|
|
606
|
-
siblings: []
|
|
607
|
-
}, options)).filter(Boolean).at(0);
|
|
608
|
-
if (current.args?.additionalProperties.some((schema) => (0, _kubb_plugin_oas.isKeyword)(schema, _kubb_plugin_oas.schemaKeywords.nullable))) additionalPropertiesType = createUnionDeclaration({ nodes: [additionalPropertiesType, keywordTypeNodes.null] });
|
|
609
|
-
additionalProperties = createIndexSignature(properties.length > 0 ? keywordTypeNodes.unknown : additionalPropertiesType);
|
|
610
|
-
}
|
|
611
|
-
let patternProperties;
|
|
612
|
-
if (current.args?.patternProperties) {
|
|
613
|
-
const allPatternSchemas = Object.values(current.args.patternProperties).flat();
|
|
614
|
-
if (allPatternSchemas.length > 0) {
|
|
615
|
-
patternProperties = allPatternSchemas.map((it) => this.parse({
|
|
616
|
-
schema,
|
|
617
|
-
parent: current,
|
|
618
|
-
name,
|
|
619
|
-
current: it,
|
|
620
|
-
siblings: []
|
|
621
|
-
}, options)).filter(Boolean).at(0);
|
|
622
|
-
if (allPatternSchemas.some((schema) => (0, _kubb_plugin_oas.isKeyword)(schema, _kubb_plugin_oas.schemaKeywords.nullable))) patternProperties = createUnionDeclaration({ nodes: [patternProperties, keywordTypeNodes.null] });
|
|
623
|
-
patternProperties = createIndexSignature(patternProperties);
|
|
624
|
-
}
|
|
625
|
-
}
|
|
626
|
-
return typeKeywordMapper.object([
|
|
627
|
-
...properties,
|
|
628
|
-
additionalProperties,
|
|
629
|
-
patternProperties
|
|
630
|
-
].filter(Boolean));
|
|
631
|
-
},
|
|
632
|
-
datetime() {
|
|
633
|
-
return typeKeywordMapper.datetime();
|
|
634
|
-
},
|
|
635
|
-
date(tree) {
|
|
636
|
-
const { current } = tree;
|
|
637
|
-
return typeKeywordMapper.date(current.args.type);
|
|
638
|
-
},
|
|
639
|
-
time(tree) {
|
|
640
|
-
const { current } = tree;
|
|
641
|
-
return typeKeywordMapper.time(current.args.type);
|
|
642
|
-
}
|
|
643
|
-
}
|
|
644
|
-
});
|
|
645
|
-
//#endregion
|
|
646
|
-
//#region src/components/Type.tsx
|
|
647
|
-
function Type({ name, typedName, tree, keysToOmit, schema, optionalType, arrayType, syntaxType, enumType, enumKeyCasing, description }) {
|
|
648
|
-
const typeNodes = [];
|
|
649
|
-
if (!tree.length) return "";
|
|
650
|
-
const schemaFromTree = tree.find((item) => item.keyword === _kubb_plugin_oas.schemaKeywords.schema);
|
|
651
|
-
const enumSchemas = _kubb_plugin_oas.SchemaGenerator.deepSearch(tree, _kubb_plugin_oas.schemaKeywords.enum);
|
|
652
|
-
let type = tree.map((current, _index, siblings) => parse({
|
|
653
|
-
name,
|
|
654
|
-
schema,
|
|
655
|
-
parent: void 0,
|
|
656
|
-
current,
|
|
657
|
-
siblings
|
|
658
|
-
}, {
|
|
659
|
-
optionalType,
|
|
660
|
-
arrayType,
|
|
661
|
-
enumType
|
|
662
|
-
})).filter(Boolean).at(0) || typeKeywordMapper.undefined();
|
|
663
|
-
if (["asConst", "asPascalConst"].includes(enumType) && enumSchemas.length > 0) {
|
|
664
|
-
const isDirectEnum = schema.type === "array" && schema.items !== void 0;
|
|
665
|
-
const isEnumOnly = "enum" in schema && schema.enum;
|
|
666
|
-
if (isDirectEnum || isEnumOnly) {
|
|
667
|
-
type = createTypeReferenceNode(`${enumSchemas[0].args.typeName}Key`);
|
|
668
|
-
if (schema.type === "array") if (arrayType === "generic") type = createTypeReferenceNode(createIdentifier("Array"), [type]);
|
|
669
|
-
else type = createArrayTypeNode(type);
|
|
670
|
-
}
|
|
671
|
-
}
|
|
672
|
-
if (schemaFromTree && (0, _kubb_plugin_oas.isKeyword)(schemaFromTree, _kubb_plugin_oas.schemaKeywords.schema)) {
|
|
673
|
-
const isNullish = tree.some((item) => item.keyword === _kubb_plugin_oas.schemaKeywords.nullish);
|
|
674
|
-
const isNullable = tree.some((item) => item.keyword === _kubb_plugin_oas.schemaKeywords.nullable);
|
|
675
|
-
const isOptional = tree.some((item) => item.keyword === _kubb_plugin_oas.schemaKeywords.optional);
|
|
676
|
-
if (isNullable) type = createUnionDeclaration({ nodes: [type, keywordTypeNodes.null] });
|
|
677
|
-
if (isNullish && ["undefined", "questionTokenAndUndefined"].includes(optionalType)) type = createUnionDeclaration({ nodes: [type, keywordTypeNodes.undefined] });
|
|
678
|
-
if (isOptional && ["undefined", "questionTokenAndUndefined"].includes(optionalType)) type = createUnionDeclaration({ nodes: [type, keywordTypeNodes.undefined] });
|
|
679
|
-
}
|
|
680
|
-
const useTypeGeneration = syntaxType === "type" || [syntaxKind.union].includes(type.kind) || !!keysToOmit?.length;
|
|
681
|
-
typeNodes.push(createTypeDeclaration({
|
|
682
|
-
name,
|
|
683
|
-
isExportable: true,
|
|
684
|
-
type: keysToOmit?.length ? createOmitDeclaration({
|
|
685
|
-
keys: keysToOmit,
|
|
686
|
-
type,
|
|
687
|
-
nonNullable: true
|
|
688
|
-
}) : type,
|
|
689
|
-
syntax: useTypeGeneration ? "type" : "interface",
|
|
690
|
-
comments: [
|
|
691
|
-
schema.title ? `${jsStringEscape(schema.title)}` : void 0,
|
|
692
|
-
description ? `@description ${jsStringEscape(description)}` : void 0,
|
|
693
|
-
schema.deprecated ? "@deprecated" : void 0,
|
|
694
|
-
schema.minLength ? `@minLength ${schema.minLength}` : void 0,
|
|
695
|
-
schema.maxLength ? `@maxLength ${schema.maxLength}` : void 0,
|
|
696
|
-
schema.pattern ? `@pattern ${schema.pattern}` : void 0,
|
|
697
|
-
schema.default ? `@default ${schema.default}` : void 0,
|
|
698
|
-
schema.example ? `@example ${schema.example}` : void 0
|
|
699
|
-
]
|
|
700
|
-
}));
|
|
701
|
-
const enums = [...new Set(enumSchemas)].map((enumSchema) => {
|
|
702
|
-
const name = enumType === "asPascalConst" ? pascalCase(enumSchema.args.name) : camelCase(enumSchema.args.name);
|
|
703
|
-
const typeName = ["asConst", "asPascalConst"].includes(enumType) ? `${enumSchema.args.typeName}Key` : enumSchema.args.typeName;
|
|
704
|
-
const [nameNode, typeNode] = createEnumDeclaration({
|
|
705
|
-
name,
|
|
706
|
-
typeName,
|
|
707
|
-
enums: enumSchema.args.items.map((item) => item.value === void 0 ? void 0 : [trimQuotes(item.name?.toString()), item.value]).filter(Boolean),
|
|
708
|
-
type: enumType,
|
|
709
|
-
enumKeyCasing
|
|
710
|
-
});
|
|
711
|
-
return {
|
|
712
|
-
nameNode,
|
|
713
|
-
typeNode,
|
|
714
|
-
name,
|
|
715
|
-
typeName
|
|
716
|
-
};
|
|
717
|
-
});
|
|
718
|
-
const shouldExportEnums = enumType !== "inlineLiteral";
|
|
719
|
-
const shouldExportType = enumType === "inlineLiteral" || enums.every((item) => item.typeName !== name);
|
|
720
|
-
return /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsxs)(_kubb_react_fabric_jsx_runtime.Fragment, { children: [shouldExportEnums && enums.map(({ name, nameNode, typeName, typeNode }) => /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsxs)(_kubb_react_fabric_jsx_runtime.Fragment, { children: [nameNode && /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Source, {
|
|
721
|
-
name,
|
|
722
|
-
isExportable: true,
|
|
723
|
-
isIndexable: true,
|
|
724
|
-
isTypeOnly: false,
|
|
725
|
-
children: (0, _kubb_fabric_core_parsers_typescript.safePrint)(nameNode)
|
|
726
|
-
}), /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Source, {
|
|
727
|
-
name: typeName,
|
|
728
|
-
isIndexable: true,
|
|
729
|
-
isExportable: [
|
|
730
|
-
"enum",
|
|
731
|
-
"asConst",
|
|
732
|
-
"asPascalConst",
|
|
733
|
-
"constEnum",
|
|
734
|
-
"literal",
|
|
735
|
-
void 0
|
|
736
|
-
].includes(enumType),
|
|
737
|
-
isTypeOnly: [
|
|
738
|
-
"asConst",
|
|
739
|
-
"asPascalConst",
|
|
740
|
-
"literal",
|
|
741
|
-
void 0
|
|
742
|
-
].includes(enumType),
|
|
743
|
-
children: (0, _kubb_fabric_core_parsers_typescript.safePrint)(typeNode)
|
|
744
|
-
})] })), shouldExportType && /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Source, {
|
|
745
|
-
name: typedName,
|
|
746
|
-
isTypeOnly: true,
|
|
747
|
-
isExportable: true,
|
|
748
|
-
isIndexable: true,
|
|
749
|
-
children: (0, _kubb_fabric_core_parsers_typescript.safePrint)(...typeNodes)
|
|
750
|
-
})] });
|
|
751
|
-
}
|
|
752
|
-
//#endregion
|
|
753
|
-
Object.defineProperty(exports, "SyntaxKind", {
|
|
754
|
-
enumerable: true,
|
|
755
|
-
get: function() {
|
|
756
|
-
return SyntaxKind;
|
|
757
|
-
}
|
|
758
|
-
});
|
|
759
|
-
Object.defineProperty(exports, "Type", {
|
|
760
|
-
enumerable: true,
|
|
761
|
-
get: function() {
|
|
762
|
-
return Type;
|
|
763
|
-
}
|
|
764
|
-
});
|
|
765
|
-
Object.defineProperty(exports, "__name", {
|
|
766
|
-
enumerable: true,
|
|
767
|
-
get: function() {
|
|
768
|
-
return __name;
|
|
769
|
-
}
|
|
770
|
-
});
|
|
771
|
-
Object.defineProperty(exports, "__toESM", {
|
|
772
|
-
enumerable: true,
|
|
773
|
-
get: function() {
|
|
774
|
-
return __toESM;
|
|
775
|
-
}
|
|
776
|
-
});
|
|
777
|
-
Object.defineProperty(exports, "appendJSDocToNode", {
|
|
778
|
-
enumerable: true,
|
|
779
|
-
get: function() {
|
|
780
|
-
return appendJSDocToNode;
|
|
781
|
-
}
|
|
782
|
-
});
|
|
783
|
-
Object.defineProperty(exports, "camelCase", {
|
|
784
|
-
enumerable: true,
|
|
785
|
-
get: function() {
|
|
786
|
-
return camelCase;
|
|
787
|
-
}
|
|
788
|
-
});
|
|
789
|
-
Object.defineProperty(exports, "createArrayDeclaration", {
|
|
790
|
-
enumerable: true,
|
|
791
|
-
get: function() {
|
|
792
|
-
return createArrayDeclaration;
|
|
793
|
-
}
|
|
794
|
-
});
|
|
795
|
-
Object.defineProperty(exports, "createArrayTypeNode", {
|
|
796
|
-
enumerable: true,
|
|
797
|
-
get: function() {
|
|
798
|
-
return createArrayTypeNode;
|
|
799
|
-
}
|
|
800
|
-
});
|
|
801
|
-
Object.defineProperty(exports, "createEnumDeclaration", {
|
|
802
|
-
enumerable: true,
|
|
803
|
-
get: function() {
|
|
804
|
-
return createEnumDeclaration;
|
|
805
|
-
}
|
|
806
|
-
});
|
|
807
|
-
Object.defineProperty(exports, "createFalse", {
|
|
808
|
-
enumerable: true,
|
|
809
|
-
get: function() {
|
|
810
|
-
return createFalse;
|
|
811
|
-
}
|
|
812
|
-
});
|
|
813
|
-
Object.defineProperty(exports, "createIdentifier", {
|
|
814
|
-
enumerable: true,
|
|
815
|
-
get: function() {
|
|
816
|
-
return createIdentifier;
|
|
817
|
-
}
|
|
818
|
-
});
|
|
819
|
-
Object.defineProperty(exports, "createIndexSignature", {
|
|
820
|
-
enumerable: true,
|
|
821
|
-
get: function() {
|
|
822
|
-
return createIndexSignature;
|
|
823
|
-
}
|
|
824
|
-
});
|
|
825
|
-
Object.defineProperty(exports, "createIndexedAccessTypeNode", {
|
|
826
|
-
enumerable: true,
|
|
827
|
-
get: function() {
|
|
828
|
-
return createIndexedAccessTypeNode;
|
|
829
|
-
}
|
|
830
|
-
});
|
|
831
|
-
Object.defineProperty(exports, "createIntersectionDeclaration", {
|
|
832
|
-
enumerable: true,
|
|
833
|
-
get: function() {
|
|
834
|
-
return createIntersectionDeclaration;
|
|
835
|
-
}
|
|
836
|
-
});
|
|
837
|
-
Object.defineProperty(exports, "createLiteralTypeNode", {
|
|
838
|
-
enumerable: true,
|
|
839
|
-
get: function() {
|
|
840
|
-
return createLiteralTypeNode;
|
|
841
|
-
}
|
|
842
|
-
});
|
|
843
|
-
Object.defineProperty(exports, "createNumericLiteral", {
|
|
844
|
-
enumerable: true,
|
|
845
|
-
get: function() {
|
|
846
|
-
return createNumericLiteral;
|
|
847
|
-
}
|
|
848
|
-
});
|
|
849
|
-
Object.defineProperty(exports, "createOmitDeclaration", {
|
|
850
|
-
enumerable: true,
|
|
851
|
-
get: function() {
|
|
852
|
-
return createOmitDeclaration;
|
|
853
|
-
}
|
|
854
|
-
});
|
|
855
|
-
Object.defineProperty(exports, "createOptionalTypeNode", {
|
|
856
|
-
enumerable: true,
|
|
857
|
-
get: function() {
|
|
858
|
-
return createOptionalTypeNode;
|
|
859
|
-
}
|
|
860
|
-
});
|
|
861
|
-
Object.defineProperty(exports, "createPrefixUnaryExpression", {
|
|
862
|
-
enumerable: true,
|
|
863
|
-
get: function() {
|
|
864
|
-
return createPrefixUnaryExpression;
|
|
865
|
-
}
|
|
866
|
-
});
|
|
867
|
-
Object.defineProperty(exports, "createPropertySignature", {
|
|
868
|
-
enumerable: true,
|
|
869
|
-
get: function() {
|
|
870
|
-
return createPropertySignature;
|
|
871
|
-
}
|
|
872
|
-
});
|
|
873
|
-
Object.defineProperty(exports, "createRestTypeNode", {
|
|
874
|
-
enumerable: true,
|
|
875
|
-
get: function() {
|
|
876
|
-
return createRestTypeNode;
|
|
877
|
-
}
|
|
878
|
-
});
|
|
879
|
-
Object.defineProperty(exports, "createStringLiteral", {
|
|
880
|
-
enumerable: true,
|
|
881
|
-
get: function() {
|
|
882
|
-
return createStringLiteral;
|
|
883
|
-
}
|
|
884
|
-
});
|
|
885
|
-
Object.defineProperty(exports, "createTrue", {
|
|
886
|
-
enumerable: true,
|
|
887
|
-
get: function() {
|
|
888
|
-
return createTrue;
|
|
889
|
-
}
|
|
890
|
-
});
|
|
891
|
-
Object.defineProperty(exports, "createTupleTypeNode", {
|
|
892
|
-
enumerable: true,
|
|
893
|
-
get: function() {
|
|
894
|
-
return createTupleTypeNode;
|
|
895
|
-
}
|
|
896
|
-
});
|
|
897
|
-
Object.defineProperty(exports, "createTypeAliasDeclaration", {
|
|
898
|
-
enumerable: true,
|
|
899
|
-
get: function() {
|
|
900
|
-
return createTypeAliasDeclaration;
|
|
901
|
-
}
|
|
902
|
-
});
|
|
903
|
-
Object.defineProperty(exports, "createTypeDeclaration", {
|
|
904
|
-
enumerable: true,
|
|
905
|
-
get: function() {
|
|
906
|
-
return createTypeDeclaration;
|
|
907
|
-
}
|
|
908
|
-
});
|
|
909
|
-
Object.defineProperty(exports, "createTypeLiteralNode", {
|
|
910
|
-
enumerable: true,
|
|
911
|
-
get: function() {
|
|
912
|
-
return createTypeLiteralNode;
|
|
913
|
-
}
|
|
914
|
-
});
|
|
915
|
-
Object.defineProperty(exports, "createTypeOperatorNode", {
|
|
916
|
-
enumerable: true,
|
|
917
|
-
get: function() {
|
|
918
|
-
return createTypeOperatorNode;
|
|
919
|
-
}
|
|
920
|
-
});
|
|
921
|
-
Object.defineProperty(exports, "createTypeReferenceNode", {
|
|
922
|
-
enumerable: true,
|
|
923
|
-
get: function() {
|
|
924
|
-
return createTypeReferenceNode;
|
|
925
|
-
}
|
|
926
|
-
});
|
|
927
|
-
Object.defineProperty(exports, "createUnionDeclaration", {
|
|
928
|
-
enumerable: true,
|
|
929
|
-
get: function() {
|
|
930
|
-
return createUnionDeclaration;
|
|
931
|
-
}
|
|
932
|
-
});
|
|
933
|
-
Object.defineProperty(exports, "createUrlTemplateType", {
|
|
934
|
-
enumerable: true,
|
|
935
|
-
get: function() {
|
|
936
|
-
return createUrlTemplateType;
|
|
937
|
-
}
|
|
938
|
-
});
|
|
939
|
-
Object.defineProperty(exports, "getUnknownType", {
|
|
940
|
-
enumerable: true,
|
|
941
|
-
get: function() {
|
|
942
|
-
return getUnknownType;
|
|
943
|
-
}
|
|
944
|
-
});
|
|
945
|
-
Object.defineProperty(exports, "jsStringEscape", {
|
|
946
|
-
enumerable: true,
|
|
947
|
-
get: function() {
|
|
948
|
-
return jsStringEscape;
|
|
949
|
-
}
|
|
950
|
-
});
|
|
951
|
-
Object.defineProperty(exports, "keywordTypeNodes", {
|
|
952
|
-
enumerable: true,
|
|
953
|
-
get: function() {
|
|
954
|
-
return keywordTypeNodes;
|
|
955
|
-
}
|
|
956
|
-
});
|
|
957
|
-
Object.defineProperty(exports, "modifiers", {
|
|
958
|
-
enumerable: true,
|
|
959
|
-
get: function() {
|
|
960
|
-
return modifiers;
|
|
961
|
-
}
|
|
962
|
-
});
|
|
963
|
-
Object.defineProperty(exports, "pascalCase", {
|
|
964
|
-
enumerable: true,
|
|
965
|
-
get: function() {
|
|
966
|
-
return pascalCase;
|
|
967
|
-
}
|
|
968
|
-
});
|
|
969
|
-
Object.defineProperty(exports, "syntaxKind", {
|
|
970
|
-
enumerable: true,
|
|
971
|
-
get: function() {
|
|
972
|
-
return syntaxKind;
|
|
973
|
-
}
|
|
974
|
-
});
|
|
975
|
-
Object.defineProperty(exports, "trimQuotes", {
|
|
976
|
-
enumerable: true,
|
|
977
|
-
get: function() {
|
|
978
|
-
return trimQuotes;
|
|
979
|
-
}
|
|
980
|
-
});
|
|
981
|
-
|
|
982
|
-
//# sourceMappingURL=components-DeNDKlzf.cjs.map
|