@kubb/plugin-ts 5.0.0-alpha.8 → 5.0.0-beta.10

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.
Files changed (43) hide show
  1. package/LICENSE +17 -10
  2. package/README.md +26 -7
  3. package/dist/index.cjs +1526 -4
  4. package/dist/index.cjs.map +1 -0
  5. package/dist/index.d.ts +574 -4
  6. package/dist/index.js +1488 -2
  7. package/dist/index.js.map +1 -0
  8. package/extension.yaml +632 -0
  9. package/package.json +43 -65
  10. package/src/components/{v2/Enum.tsx → Enum.tsx} +33 -17
  11. package/src/components/Type.tsx +31 -161
  12. package/src/constants.ts +15 -5
  13. package/src/factory.ts +295 -39
  14. package/src/generators/typeGenerator.tsx +248 -420
  15. package/src/index.ts +9 -2
  16. package/src/plugin.ts +67 -205
  17. package/src/printers/functionPrinter.ts +197 -0
  18. package/src/printers/printerTs.ts +329 -0
  19. package/src/resolvers/resolverTs.ts +66 -0
  20. package/src/types.ts +238 -94
  21. package/src/utils.ts +129 -0
  22. package/dist/components-CRu8IKY3.js +0 -729
  23. package/dist/components-CRu8IKY3.js.map +0 -1
  24. package/dist/components-DeNDKlzf.cjs +0 -982
  25. package/dist/components-DeNDKlzf.cjs.map +0 -1
  26. package/dist/components.cjs +0 -3
  27. package/dist/components.d.ts +0 -36
  28. package/dist/components.js +0 -2
  29. package/dist/generators.cjs +0 -4
  30. package/dist/generators.d.ts +0 -480
  31. package/dist/generators.js +0 -2
  32. package/dist/plugin-D5NGPj0v.js +0 -1232
  33. package/dist/plugin-D5NGPj0v.js.map +0 -1
  34. package/dist/plugin-MLTxoa8p.cjs +0 -1279
  35. package/dist/plugin-MLTxoa8p.cjs.map +0 -1
  36. package/dist/types-CsvB6X5Y.d.ts +0 -167
  37. package/src/components/index.ts +0 -1
  38. package/src/components/v2/Type.tsx +0 -59
  39. package/src/generators/index.ts +0 -2
  40. package/src/generators/v2/typeGenerator.tsx +0 -171
  41. package/src/generators/v2/utils.ts +0 -140
  42. package/src/parser.ts +0 -389
  43. package/src/printer.ts +0 -368
@@ -1,1232 +0,0 @@
1
- import "./chunk--u3MIqq1.js";
2
- import { A as keywordTypeNodes, C as createTypeDeclaration, D as createUnionDeclaration, E as createTypeReferenceNode, F as camelCase, I as pascalCase, M as syntaxKind, N as jsStringEscape, O as createUrlTemplateType, P as trimQuotes, S as createTypeAliasDeclaration, T as createTypeOperatorNode, _ as createPropertySignature, a as createArrayTypeNode, b as createTrue, c as createIdentifier, d as createIntersectionDeclaration, f as createLiteralTypeNode, g as createPrefixUnaryExpression, h as createOptionalTypeNode, i as createArrayDeclaration, j as modifiers, k as getUnknownType, l as createIndexSignature, m as createOmitDeclaration, n as SyntaxKind, o as createEnumDeclaration, p as createNumericLiteral, r as appendJSDocToNode, s as createFalse, t as Type$1, u as createIndexedAccessTypeNode, v as createRestTypeNode, w as createTypeLiteralNode, x as createTupleTypeNode, y as createStringLiteral } from "./components-CRu8IKY3.js";
3
- import path from "node:path";
4
- import { applyParamsCasing, collect, createProperty, createSchema, isPlainStringType, walk } from "@kubb/ast";
5
- import { createGenerator, createPlugin, definePrinter, getBarrelFiles, getMode, resolveOptions } from "@kubb/core";
6
- import { OperationGenerator, SchemaGenerator, buildOperation, buildSchema, isKeyword, pluginOasName, schemaKeywords } from "@kubb/plugin-oas";
7
- import { useKubb, useMode, usePluginDriver } from "@kubb/core/hooks";
8
- import { safePrint } from "@kubb/fabric-core/parsers/typescript";
9
- import { createReactGenerator } from "@kubb/plugin-oas/generators";
10
- import { useOas, useOperationManager, useSchemaManager } from "@kubb/plugin-oas/hooks";
11
- import { applyParamsCasing as applyParamsCasing$1, getBanner, getFooter, getImports, isParameterSchema } from "@kubb/plugin-oas/utils";
12
- import { File } from "@kubb/react-fabric";
13
- import ts from "typescript";
14
- import { Fragment, jsx, jsxs } from "@kubb/react-fabric/jsx-runtime";
15
- //#region ../../internals/utils/src/object.ts
16
- /**
17
- * Serializes a primitive value to a JSON string literal, stripping any surrounding quote characters first.
18
- *
19
- * @example
20
- * stringify('hello') // '"hello"'
21
- * stringify('"hello"') // '"hello"'
22
- */
23
- function stringify(value) {
24
- if (value === void 0 || value === null) return "\"\"";
25
- return JSON.stringify(trimQuotes(value.toString()));
26
- }
27
- //#endregion
28
- //#region src/generators/typeGenerator.tsx
29
- function printCombinedSchema({ name, schemas, driver }) {
30
- const properties = {};
31
- if (schemas.response) properties["response"] = createUnionDeclaration({ nodes: schemas.responses.map((res) => {
32
- return createTypeReferenceNode(createIdentifier(driver.resolveName({
33
- name: res.name,
34
- pluginName: pluginTsName,
35
- type: "function"
36
- })), void 0);
37
- }) });
38
- if (schemas.request) properties["request"] = createTypeReferenceNode(createIdentifier(driver.resolveName({
39
- name: schemas.request.name,
40
- pluginName: pluginTsName,
41
- type: "function"
42
- })), void 0);
43
- if (schemas.pathParams) properties["pathParams"] = createTypeReferenceNode(createIdentifier(driver.resolveName({
44
- name: schemas.pathParams.name,
45
- pluginName: pluginTsName,
46
- type: "function"
47
- })), void 0);
48
- if (schemas.queryParams) properties["queryParams"] = createTypeReferenceNode(createIdentifier(driver.resolveName({
49
- name: schemas.queryParams.name,
50
- pluginName: pluginTsName,
51
- type: "function"
52
- })), void 0);
53
- if (schemas.headerParams) properties["headerParams"] = createTypeReferenceNode(createIdentifier(driver.resolveName({
54
- name: schemas.headerParams.name,
55
- pluginName: pluginTsName,
56
- type: "function"
57
- })), void 0);
58
- if (schemas.errors) properties["errors"] = createUnionDeclaration({ nodes: schemas.errors.map((error) => {
59
- return createTypeReferenceNode(createIdentifier(driver.resolveName({
60
- name: error.name,
61
- pluginName: pluginTsName,
62
- type: "function"
63
- })), void 0);
64
- }) });
65
- return safePrint(createTypeAliasDeclaration({
66
- name,
67
- type: createTypeLiteralNode(Object.keys(properties).map((key) => {
68
- const type = properties[key];
69
- if (!type) return;
70
- return createPropertySignature({
71
- name: pascalCase(key),
72
- type
73
- });
74
- }).filter(Boolean)),
75
- modifiers: [modifiers.export]
76
- }));
77
- }
78
- function printRequestSchema({ baseName, operation, schemas, driver }) {
79
- const name = driver.resolveName({
80
- name: `${baseName} Request`,
81
- pluginName: pluginTsName,
82
- type: "type"
83
- });
84
- const results = [];
85
- const dataRequestProperties = [];
86
- if (schemas.request) {
87
- const identifier = driver.resolveName({
88
- name: schemas.request.name,
89
- pluginName: pluginTsName,
90
- type: "type"
91
- });
92
- dataRequestProperties.push(createPropertySignature({
93
- name: "data",
94
- questionToken: true,
95
- type: createTypeReferenceNode(createIdentifier(identifier), void 0)
96
- }));
97
- } else dataRequestProperties.push(createPropertySignature({
98
- name: "data",
99
- questionToken: true,
100
- type: keywordTypeNodes.never
101
- }));
102
- if (schemas.pathParams) {
103
- const identifier = driver.resolveName({
104
- name: schemas.pathParams.name,
105
- pluginName: pluginTsName,
106
- type: "type"
107
- });
108
- dataRequestProperties.push(createPropertySignature({
109
- name: "pathParams",
110
- type: createTypeReferenceNode(createIdentifier(identifier), void 0)
111
- }));
112
- } else dataRequestProperties.push(createPropertySignature({
113
- name: "pathParams",
114
- questionToken: true,
115
- type: keywordTypeNodes.never
116
- }));
117
- if (schemas.queryParams) {
118
- const identifier = driver.resolveName({
119
- name: schemas.queryParams.name,
120
- pluginName: pluginTsName,
121
- type: "type"
122
- });
123
- dataRequestProperties.push(createPropertySignature({
124
- name: "queryParams",
125
- questionToken: true,
126
- type: createTypeReferenceNode(createIdentifier(identifier), void 0)
127
- }));
128
- } else dataRequestProperties.push(createPropertySignature({
129
- name: "queryParams",
130
- questionToken: true,
131
- type: keywordTypeNodes.never
132
- }));
133
- if (schemas.headerParams) {
134
- const identifier = driver.resolveName({
135
- name: schemas.headerParams.name,
136
- pluginName: pluginTsName,
137
- type: "type"
138
- });
139
- dataRequestProperties.push(createPropertySignature({
140
- name: "headerParams",
141
- questionToken: true,
142
- type: createTypeReferenceNode(createIdentifier(identifier), void 0)
143
- }));
144
- } else dataRequestProperties.push(createPropertySignature({
145
- name: "headerParams",
146
- questionToken: true,
147
- type: keywordTypeNodes.never
148
- }));
149
- dataRequestProperties.push(createPropertySignature({
150
- name: "url",
151
- type: createUrlTemplateType(operation.path)
152
- }));
153
- const dataRequestNode = createTypeAliasDeclaration({
154
- name,
155
- type: createTypeLiteralNode(dataRequestProperties),
156
- modifiers: [modifiers.export]
157
- });
158
- results.push(safePrint(dataRequestNode));
159
- return results.join("\n\n");
160
- }
161
- function printResponseSchema({ baseName, schemas, driver, unknownType }) {
162
- const results = [];
163
- const name = driver.resolveName({
164
- name: `${baseName} ResponseData`,
165
- pluginName: pluginTsName,
166
- type: "type"
167
- });
168
- if (schemas.responses && schemas.responses.length > 0) {
169
- const responsesProperties = schemas.responses.map((res) => {
170
- const identifier = driver.resolveName({
171
- name: res.name,
172
- pluginName: pluginTsName,
173
- type: "type"
174
- });
175
- return createPropertySignature({
176
- name: res.statusCode?.toString() ?? "default",
177
- type: createTypeReferenceNode(createIdentifier(identifier), void 0)
178
- });
179
- });
180
- const responsesNode = createTypeAliasDeclaration({
181
- name: `${baseName}Responses`,
182
- type: createTypeLiteralNode(responsesProperties),
183
- modifiers: [modifiers.export]
184
- });
185
- results.push(safePrint(responsesNode));
186
- const responseNode = createTypeAliasDeclaration({
187
- name,
188
- type: createIndexedAccessTypeNode(createTypeReferenceNode(createIdentifier(`${baseName}Responses`), void 0), createTypeOperatorNode(ts.SyntaxKind.KeyOfKeyword, createTypeReferenceNode(createIdentifier(`${baseName}Responses`), void 0))),
189
- modifiers: [modifiers.export]
190
- });
191
- results.push(safePrint(responseNode));
192
- } else {
193
- const responseNode = createTypeAliasDeclaration({
194
- name,
195
- modifiers: [modifiers.export],
196
- type: getUnknownType(unknownType)
197
- });
198
- results.push(safePrint(responseNode));
199
- }
200
- return results.join("\n\n");
201
- }
202
- const typeGenerator$1 = createReactGenerator({
203
- name: "typescript",
204
- Operation({ operation, generator, plugin }) {
205
- const { options, options: { enumType, enumKeyCasing, syntaxType, optionalType, arrayType, unknownType, paramsCasing } } = plugin;
206
- const mode = useMode();
207
- const driver = usePluginDriver();
208
- const oas = useOas();
209
- const { getSchemas, getFile, getName, getGroup } = useOperationManager(generator);
210
- const schemaManager = useSchemaManager();
211
- const name = getName(operation, {
212
- type: "type",
213
- pluginName: pluginTsName
214
- });
215
- const file = getFile(operation);
216
- const schemas = getSchemas(operation);
217
- const schemaGenerator = new SchemaGenerator(options, {
218
- fabric: generator.context.fabric,
219
- oas,
220
- events: generator.context.events,
221
- plugin,
222
- driver,
223
- mode,
224
- override: options.override
225
- });
226
- const operationSchemas = [
227
- schemas.pathParams,
228
- schemas.queryParams,
229
- schemas.headerParams,
230
- schemas.statusCodes,
231
- schemas.request,
232
- schemas.response
233
- ].flat().filter(Boolean);
234
- const mapOperationSchema = ({ name, schema, description, keysToOmit, ...options }) => {
235
- const transformedSchema = paramsCasing && isParameterSchema(name) ? applyParamsCasing$1(schema, paramsCasing) : schema;
236
- const tree = schemaGenerator.parse({
237
- schema: transformedSchema,
238
- name,
239
- parentName: null
240
- });
241
- const imports = getImports(tree);
242
- const group = options.operation ? getGroup(options.operation) : void 0;
243
- const type = {
244
- name: schemaManager.getName(name, { type: "type" }),
245
- typedName: schemaManager.getName(name, { type: "type" }),
246
- file: schemaManager.getFile(options.operationName || name, { group })
247
- };
248
- return /* @__PURE__ */ jsxs(Fragment, { children: [mode === "split" && imports.map((imp) => /* @__PURE__ */ jsx(File.Import, {
249
- root: file.path,
250
- path: imp.path,
251
- name: imp.name,
252
- isTypeOnly: true
253
- }, [
254
- name,
255
- imp.name,
256
- imp.path,
257
- imp.isTypeOnly
258
- ].join("-"))), /* @__PURE__ */ jsx(Type$1, {
259
- name: type.name,
260
- typedName: type.typedName,
261
- description,
262
- tree,
263
- schema: transformedSchema,
264
- enumType,
265
- enumKeyCasing,
266
- optionalType,
267
- arrayType,
268
- keysToOmit,
269
- syntaxType
270
- })] });
271
- };
272
- const responseName = schemaManager.getName(schemas.response.name, { type: "type" });
273
- const combinedSchemaName = operation.method === "get" ? `${name}Query` : `${name}Mutation`;
274
- return /* @__PURE__ */ jsxs(File, {
275
- baseName: file.baseName,
276
- path: file.path,
277
- meta: file.meta,
278
- banner: getBanner({
279
- oas,
280
- output: plugin.options.output,
281
- config: driver.config
282
- }),
283
- footer: getFooter({
284
- oas,
285
- output: plugin.options.output
286
- }),
287
- children: [operationSchemas.map(mapOperationSchema), generator.context.UNSTABLE_NAMING ? /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(File.Source, {
288
- name: `${name}Request`,
289
- isExportable: true,
290
- isIndexable: true,
291
- isTypeOnly: true,
292
- children: printRequestSchema({
293
- baseName: name,
294
- operation,
295
- schemas,
296
- driver
297
- })
298
- }), /* @__PURE__ */ jsx(File.Source, {
299
- name: responseName,
300
- isExportable: true,
301
- isIndexable: true,
302
- isTypeOnly: true,
303
- children: printResponseSchema({
304
- baseName: name,
305
- schemas,
306
- driver,
307
- unknownType
308
- })
309
- })] }) : /* @__PURE__ */ jsx(File.Source, {
310
- name: combinedSchemaName,
311
- isExportable: true,
312
- isIndexable: true,
313
- isTypeOnly: true,
314
- children: printCombinedSchema({
315
- name: combinedSchemaName,
316
- schemas,
317
- driver
318
- })
319
- })]
320
- });
321
- },
322
- Schema({ schema, plugin }) {
323
- const { options: { enumType, enumKeyCasing, syntaxType, optionalType, arrayType, output } } = plugin;
324
- const mode = useMode();
325
- const oas = useOas();
326
- const driver = usePluginDriver();
327
- const { getName, getFile } = useSchemaManager();
328
- const imports = getImports(schema.tree);
329
- const schemaFromTree = schema.tree.find((item) => item.keyword === schemaKeywords.schema);
330
- let typedName = getName(schema.name, { type: "type" });
331
- if (["asConst", "asPascalConst"].includes(enumType) && schemaFromTree && isKeyword(schemaFromTree, schemaKeywords.enum)) typedName = typedName += "Key";
332
- const type = {
333
- name: getName(schema.name, { type: "function" }),
334
- typedName,
335
- file: getFile(schema.name)
336
- };
337
- return /* @__PURE__ */ jsxs(File, {
338
- baseName: type.file.baseName,
339
- path: type.file.path,
340
- meta: type.file.meta,
341
- banner: getBanner({
342
- oas,
343
- output,
344
- config: driver.config
345
- }),
346
- footer: getFooter({
347
- oas,
348
- output
349
- }),
350
- children: [mode === "split" && imports.map((imp) => /* @__PURE__ */ jsx(File.Import, {
351
- root: type.file.path,
352
- path: imp.path,
353
- name: imp.name,
354
- isTypeOnly: true
355
- }, [
356
- schema.name,
357
- imp.path,
358
- imp.isTypeOnly
359
- ].join("-"))), /* @__PURE__ */ jsx(Type$1, {
360
- name: type.name,
361
- typedName: type.typedName,
362
- description: schema.value.description,
363
- tree: schema.tree,
364
- schema: schema.value,
365
- enumType,
366
- enumKeyCasing,
367
- optionalType,
368
- arrayType,
369
- syntaxType
370
- })]
371
- });
372
- }
373
- });
374
- //#endregion
375
- //#region src/constants.ts
376
- /**
377
- * `optionalType` values that cause a property's type to include `| undefined`.
378
- */
379
- const OPTIONAL_ADDS_UNDEFINED = new Set(["undefined", "questionTokenAndUndefined"]);
380
- /**
381
- * `optionalType` values that render the property key with a `?` token.
382
- */
383
- const OPTIONAL_ADDS_QUESTION_TOKEN = new Set(["questionToken", "questionTokenAndUndefined"]);
384
- /**
385
- * `enumType` values that append a `Key` suffix to the generated enum type alias.
386
- */
387
- const ENUM_TYPES_WITH_KEY_SUFFIX = new Set(["asConst", "asPascalConst"]);
388
- /**
389
- * `enumType` values that require a runtime value declaration (object, enum, or literal).
390
- */
391
- const ENUM_TYPES_WITH_RUNTIME_VALUE = new Set([
392
- "enum",
393
- "asConst",
394
- "asPascalConst",
395
- "constEnum",
396
- "literal",
397
- void 0
398
- ]);
399
- /**
400
- * `enumType` values whose type declaration is type-only (no runtime value emitted for the type alias).
401
- */
402
- const ENUM_TYPES_WITH_TYPE_ONLY = new Set([
403
- "asConst",
404
- "asPascalConst",
405
- "literal",
406
- void 0
407
- ]);
408
- //#endregion
409
- //#region src/printer.ts
410
- /**
411
- * Converts a primitive const value to a TypeScript literal type node.
412
- * Handles negative numbers via a prefix unary expression.
413
- */
414
- function constToTypeNode(value, format) {
415
- if (format === "boolean") return createLiteralTypeNode(value === true ? createTrue() : createFalse());
416
- if (format === "number" && typeof value === "number") {
417
- if (value < 0) return createLiteralTypeNode(createPrefixUnaryExpression(SyntaxKind.MinusToken, createNumericLiteral(Math.abs(value))));
418
- return createLiteralTypeNode(createNumericLiteral(value));
419
- }
420
- return createLiteralTypeNode(createStringLiteral(String(value)));
421
- }
422
- /**
423
- * Returns a `Date` reference type node when `representation` is `'date'`, otherwise falls back to `string`.
424
- */
425
- function dateOrStringNode(node) {
426
- return node.representation === "date" ? createTypeReferenceNode(createIdentifier("Date")) : keywordTypeNodes.string;
427
- }
428
- /**
429
- * Maps an array of `SchemaNode`s through the printer, filtering out `null` and `undefined` results.
430
- */
431
- function buildMemberNodes(members, print) {
432
- return (members ?? []).map(print).filter(Boolean);
433
- }
434
- /**
435
- * Builds a TypeScript tuple type node from an array schema's `items`,
436
- * applying min/max slice and optional/rest element rules.
437
- */
438
- function buildTupleNode(node, print) {
439
- let items = (node.items ?? []).map(print).filter(Boolean);
440
- const restNode = node.rest ? print(node.rest) ?? void 0 : void 0;
441
- const { min, max } = node;
442
- if (max !== void 0) {
443
- items = items.slice(0, max);
444
- if (items.length < max && restNode) items = [...items, ...Array(max - items.length).fill(restNode)];
445
- }
446
- if (min !== void 0) items = items.map((item, i) => i >= min ? createOptionalTypeNode(item) : item);
447
- if (max === void 0 && restNode) items.push(createRestTypeNode(createArrayTypeNode(restNode)));
448
- return createTupleTypeNode(items);
449
- }
450
- /**
451
- * Applies `nullable` and optional/nullish `| undefined` union modifiers to a property's resolved base type.
452
- */
453
- function buildPropertyType(schema, baseType, optionalType) {
454
- const addsUndefined = OPTIONAL_ADDS_UNDEFINED.has(optionalType);
455
- let type = baseType;
456
- if (schema.nullable) type = createUnionDeclaration({ nodes: [type, keywordTypeNodes.null] });
457
- if ((schema.nullish || schema.optional) && addsUndefined) type = createUnionDeclaration({ nodes: [type, keywordTypeNodes.undefined] });
458
- return type;
459
- }
460
- /**
461
- * Collects JSDoc annotation strings (description, deprecated, min/max, pattern, default, example, type) for a schema node.
462
- */
463
- function buildPropertyJSDocComments(schema) {
464
- return [
465
- "description" in schema && schema.description ? `@description ${jsStringEscape(schema.description)}` : void 0,
466
- "deprecated" in schema && schema.deprecated ? "@deprecated" : void 0,
467
- "min" in schema && schema.min !== void 0 ? `@minLength ${schema.min}` : void 0,
468
- "max" in schema && schema.max !== void 0 ? `@maxLength ${schema.max}` : void 0,
469
- "pattern" in schema && schema.pattern ? `@pattern ${schema.pattern}` : void 0,
470
- "default" in schema && schema.default !== void 0 ? `@default ${"primitive" in schema && schema.primitive === "string" ? stringify(schema.default) : schema.default}` : void 0,
471
- "example" in schema && schema.example !== void 0 ? `@example ${schema.example}` : void 0,
472
- "primitive" in schema && schema.primitive ? [`@type ${schema.primitive || "unknown"}`, "optional" in schema && schema.optional ? " | undefined" : void 0].filter(Boolean).join("") : void 0
473
- ];
474
- }
475
- /**
476
- * Creates TypeScript index signatures for `additionalProperties` and `patternProperties` on an object schema node.
477
- */
478
- function buildIndexSignatures(node, propertyCount, print) {
479
- const elements = [];
480
- if (node.additionalProperties && node.additionalProperties !== true) {
481
- const additionalType = print(node.additionalProperties) ?? keywordTypeNodes.unknown;
482
- elements.push(createIndexSignature(propertyCount > 0 ? keywordTypeNodes.unknown : additionalType));
483
- } else if (node.additionalProperties === true) elements.push(createIndexSignature(keywordTypeNodes.unknown));
484
- if (node.patternProperties) {
485
- const first = Object.values(node.patternProperties)[0];
486
- if (first) {
487
- let patternType = print(first) ?? keywordTypeNodes.unknown;
488
- if (first.nullable) patternType = createUnionDeclaration({ nodes: [patternType, keywordTypeNodes.null] });
489
- elements.push(createIndexSignature(patternType));
490
- }
491
- }
492
- return elements;
493
- }
494
- /**
495
- * TypeScript type printer built with `definePrinter`.
496
- *
497
- * Converts a `SchemaNode` AST node into a TypeScript AST node:
498
- * - **`printer.print(node)`** — when `options.typeName` is set, returns a full
499
- * `type Name = …` or `interface Name { … }` declaration (`ts.Node`).
500
- * Without `typeName`, returns the raw `ts.TypeNode` for the schema.
501
- *
502
- * Dispatches on `node.type` to the appropriate handler in `nodes`. Options are closed
503
- * over per printer instance, so each call to `printerTs(options)` produces an independent printer.
504
- *
505
- * @example Raw type node (no `typeName`)
506
- * ```ts
507
- * const printer = printerTs({ optionalType: 'questionToken', arrayType: 'array', enumType: 'inlineLiteral' })
508
- * const typeNode = printer.print(schemaNode) // ts.TypeNode
509
- * ```
510
- *
511
- * @example Full declaration (with `typeName`)
512
- * ```ts
513
- * const printer = printerTs({ optionalType: 'questionToken', arrayType: 'array', enumType: 'inlineLiteral', typeName: 'MyType' })
514
- * const declaration = printer.print(schemaNode) // ts.TypeAliasDeclaration | ts.InterfaceDeclaration
515
- * ```
516
- */
517
- const printerTs = definePrinter((options) => {
518
- const addsUndefined = OPTIONAL_ADDS_UNDEFINED.has(options.optionalType);
519
- return {
520
- name: "typescript",
521
- options,
522
- nodes: {
523
- any: () => keywordTypeNodes.any,
524
- unknown: () => keywordTypeNodes.unknown,
525
- void: () => keywordTypeNodes.void,
526
- never: () => keywordTypeNodes.never,
527
- boolean: () => keywordTypeNodes.boolean,
528
- null: () => keywordTypeNodes.null,
529
- blob: () => createTypeReferenceNode("Blob", []),
530
- string: () => keywordTypeNodes.string,
531
- uuid: () => keywordTypeNodes.string,
532
- email: () => keywordTypeNodes.string,
533
- url: (node) => {
534
- if (node.path) return createUrlTemplateType(node.path);
535
- return keywordTypeNodes.string;
536
- },
537
- datetime: () => keywordTypeNodes.string,
538
- number: () => keywordTypeNodes.number,
539
- integer: () => keywordTypeNodes.number,
540
- bigint: () => keywordTypeNodes.bigint,
541
- date: dateOrStringNode,
542
- time: dateOrStringNode,
543
- ref(node) {
544
- if (!node.name) return;
545
- return createTypeReferenceNode(node.name, void 0);
546
- },
547
- enum(node) {
548
- const values = node.namedEnumValues?.map((v) => v.value) ?? node.enumValues ?? [];
549
- if (this.options.enumType === "inlineLiteral" || !node.name) return createUnionDeclaration({
550
- withParentheses: true,
551
- nodes: values.filter((v) => v !== null).map((value) => constToTypeNode(value, typeof value)).filter(Boolean)
552
- }) ?? void 0;
553
- const resolvedName = pascalCase(node.name);
554
- return createTypeReferenceNode(ENUM_TYPES_WITH_KEY_SUFFIX.has(this.options.enumType) ? `${resolvedName}Key` : resolvedName, void 0);
555
- },
556
- union(node) {
557
- const members = node.members ?? [];
558
- const hasStringLiteral = members.some((m) => m.type === "enum" && m.enumType === "string");
559
- const hasPlainString = members.some((m) => isPlainStringType(m));
560
- if (hasStringLiteral && hasPlainString) return createUnionDeclaration({
561
- withParentheses: true,
562
- nodes: members.map((m) => {
563
- if (isPlainStringType(m)) return createIntersectionDeclaration({
564
- nodes: [keywordTypeNodes.string, createTypeLiteralNode([])],
565
- withParentheses: true
566
- });
567
- return this.print(m);
568
- }).filter(Boolean)
569
- }) ?? void 0;
570
- return createUnionDeclaration({
571
- withParentheses: true,
572
- nodes: buildMemberNodes(members, this.print)
573
- }) ?? void 0;
574
- },
575
- intersection(node) {
576
- return createIntersectionDeclaration({
577
- withParentheses: true,
578
- nodes: buildMemberNodes(node.members, this.print)
579
- }) ?? void 0;
580
- },
581
- array(node) {
582
- return createArrayDeclaration({
583
- nodes: (node.items ?? []).map((item) => this.print(item)).filter(Boolean),
584
- arrayType: this.options.arrayType
585
- }) ?? void 0;
586
- },
587
- tuple(node) {
588
- return buildTupleNode(node, this.print);
589
- },
590
- object(node) {
591
- const { print, options } = this;
592
- const addsQuestionToken = OPTIONAL_ADDS_QUESTION_TOKEN.has(options.optionalType);
593
- const propertyNodes = node.properties.map((prop) => {
594
- const baseType = print(prop.schema) ?? keywordTypeNodes.unknown;
595
- const type = buildPropertyType(prop.schema, baseType, options.optionalType);
596
- return appendJSDocToNode({
597
- node: createPropertySignature({
598
- questionToken: prop.schema.optional || prop.schema.nullish ? addsQuestionToken : false,
599
- name: prop.name,
600
- type,
601
- readOnly: prop.schema.readOnly
602
- }),
603
- comments: buildPropertyJSDocComments(prop.schema)
604
- });
605
- });
606
- const allElements = [...propertyNodes, ...buildIndexSignatures(node, propertyNodes.length, print)];
607
- if (!allElements.length) return keywordTypeNodes.object;
608
- return createTypeLiteralNode(allElements);
609
- }
610
- },
611
- print(node) {
612
- let type = this.print(node);
613
- if (!type) return;
614
- if (node.nullable) type = createUnionDeclaration({ nodes: [type, keywordTypeNodes.null] });
615
- if ((node.nullish || node.optional) && addsUndefined) type = createUnionDeclaration({ nodes: [type, keywordTypeNodes.undefined] });
616
- const { typeName, syntaxType = "type", description, keysToOmit } = this.options;
617
- if (!typeName) return type;
618
- const useTypeGeneration = syntaxType === "type" || type.kind === syntaxKind.union || !!keysToOmit?.length;
619
- return createTypeDeclaration({
620
- name: typeName,
621
- isExportable: true,
622
- type: keysToOmit?.length ? createOmitDeclaration({
623
- keys: keysToOmit,
624
- type,
625
- nonNullable: true
626
- }) : type,
627
- syntax: useTypeGeneration ? "type" : "interface",
628
- comments: [
629
- node?.title ? jsStringEscape(node.title) : void 0,
630
- description ? `@description ${jsStringEscape(description)}` : void 0,
631
- node?.deprecated ? "@deprecated" : void 0,
632
- node && "min" in node && node.min !== void 0 ? `@minLength ${node.min}` : void 0,
633
- node && "max" in node && node.max !== void 0 ? `@maxLength ${node.max}` : void 0,
634
- node && "pattern" in node && node.pattern ? `@pattern ${node.pattern}` : void 0,
635
- node?.default ? `@default ${node.default}` : void 0,
636
- node?.example ? `@example ${node.example}` : void 0
637
- ]
638
- });
639
- }
640
- };
641
- });
642
- //#endregion
643
- //#region src/components/v2/Enum.tsx
644
- /**
645
- * Resolves the runtime identifier name and the TypeScript type name for an enum schema node.
646
- *
647
- * The raw `node.name` may be a YAML key such as `"enumNames.Type"` which is not a
648
- * valid TypeScript identifier. `pascalCase` normalizes it unconditionally; for inline enum
649
- * properties the adapter already emits a PascalCase+suffix name so `pascalCase` is a no-op.
650
- */
651
- function getEnumNames(node, enumType) {
652
- const resolved = pascalCase(node.name);
653
- return {
654
- enumName: enumType === "asPascalConst" ? resolved : camelCase(node.name),
655
- typeName: ENUM_TYPES_WITH_KEY_SUFFIX.has(enumType) ? `${resolved}Key` : resolved
656
- };
657
- }
658
- /**
659
- * Renders the enum declaration(s) for a single named `EnumSchemaNode`.
660
- *
661
- * Depending on `enumType` this may emit:
662
- * - A runtime object (`asConst` / `asPascalConst`) plus a `typeof` type alias
663
- * - A `const enum` or plain `enum` declaration (`constEnum` / `enum`)
664
- * - A union literal type alias (`literal`)
665
- *
666
- * The emitted `File.Source` nodes carry the resolved names so that the barrel
667
- * index picks up the correct export identifiers.
668
- */
669
- function Enum({ node, enumType, enumKeyCasing }) {
670
- const { enumName, typeName } = getEnumNames(node, enumType);
671
- const [nameNode, typeNode] = createEnumDeclaration({
672
- name: enumName,
673
- typeName,
674
- enums: node.namedEnumValues?.map((v) => [trimQuotes(v.name.toString()), v.value]) ?? node.enumValues?.filter((v) => v !== null && v !== void 0).map((v) => [trimQuotes(v.toString()), v]) ?? [],
675
- type: enumType,
676
- enumKeyCasing
677
- });
678
- return /* @__PURE__ */ jsxs(Fragment, { children: [nameNode && /* @__PURE__ */ jsx(File.Source, {
679
- name: enumName,
680
- isExportable: true,
681
- isIndexable: true,
682
- isTypeOnly: false,
683
- children: safePrint(nameNode)
684
- }), /* @__PURE__ */ jsx(File.Source, {
685
- name: typeName,
686
- isIndexable: true,
687
- isExportable: ENUM_TYPES_WITH_RUNTIME_VALUE.has(enumType),
688
- isTypeOnly: ENUM_TYPES_WITH_TYPE_ONLY.has(enumType),
689
- children: safePrint(typeNode)
690
- })] });
691
- }
692
- //#endregion
693
- //#region src/components/v2/Type.tsx
694
- function Type({ name, typedName, node, keysToOmit, optionalType, arrayType, syntaxType, enumType, enumKeyCasing, description }) {
695
- const resolvedDescription = description || node?.description;
696
- const enumSchemaNodes = collect(node, { schema(n) {
697
- if (n.type === "enum" && n.name) return n;
698
- } });
699
- const typeNode = printerTs({
700
- optionalType,
701
- arrayType,
702
- enumType,
703
- typeName: name,
704
- syntaxType,
705
- description: resolvedDescription,
706
- keysToOmit
707
- }).print(node);
708
- if (!typeNode) return;
709
- const enums = [...new Map(enumSchemaNodes.map((n) => [n.name, n])).values()].map((node) => {
710
- return {
711
- node,
712
- ...getEnumNames(node, enumType)
713
- };
714
- });
715
- const shouldExportEnums = enumType !== "inlineLiteral";
716
- const shouldExportType = enumType === "inlineLiteral" || enums.every((item) => item.typeName !== name);
717
- return /* @__PURE__ */ jsxs(Fragment, { children: [shouldExportEnums && enums.map(({ node }) => /* @__PURE__ */ jsx(Enum, {
718
- node,
719
- enumType,
720
- enumKeyCasing
721
- })), shouldExportType && /* @__PURE__ */ jsx(File.Source, {
722
- name: typedName,
723
- isTypeOnly: true,
724
- isExportable: true,
725
- isIndexable: true,
726
- children: safePrint(typeNode)
727
- })] });
728
- }
729
- //#endregion
730
- //#region src/generators/v2/utils.ts
731
- /**
732
- * Builds an `ObjectSchemaNode` for a group of parameters (path/query/header).
733
- * Each property is a `ref` schema pointing to the individually-resolved parameter type.
734
- * The ref name includes the parameter location so generated type names follow
735
- * the `<OperationId><Location><ParamName>` convention.
736
- */
737
- function buildParamsSchema({ params, operationId, resolveName }) {
738
- return createSchema({
739
- type: "object",
740
- properties: params.map((param) => createProperty({
741
- name: param.name,
742
- schema: createSchema({
743
- type: "ref",
744
- name: resolveName({
745
- name: `${operationId} ${pascalCase(param.in)} ${param.name}`,
746
- type: "function"
747
- }),
748
- optional: !param.required
749
- })
750
- }))
751
- });
752
- }
753
- /**
754
- * Builds an `ObjectSchemaNode` representing the `<OperationId>RequestConfig` type:
755
- * - `data` → request body ref (optional) or `never`
756
- * - `pathParams` → inline object of path param refs, or `never`
757
- * - `queryParams` → inline object of query param refs (optional), or `never`
758
- * - `headerParams` → inline object of header param refs (optional), or `never`
759
- * - `url` → Express-style template literal (plugin-ts extension, handled by printer)
760
- */
761
- function buildDataSchemaNode({ node, resolveName }) {
762
- const pathParams = node.parameters.filter((p) => p.in === "path");
763
- const queryParams = node.parameters.filter((p) => p.in === "query");
764
- const headerParams = node.parameters.filter((p) => p.in === "header");
765
- return createSchema({
766
- type: "object",
767
- properties: [
768
- createProperty({
769
- name: "data",
770
- schema: node.requestBody ? createSchema({
771
- type: "ref",
772
- name: resolveName({
773
- name: `${node.operationId} Data`,
774
- type: "function"
775
- }),
776
- optional: true
777
- }) : createSchema({
778
- type: "never",
779
- optional: true
780
- })
781
- }),
782
- createProperty({
783
- name: "pathParams",
784
- schema: pathParams.length > 0 ? buildParamsSchema({
785
- params: pathParams,
786
- operationId: node.operationId,
787
- resolveName
788
- }) : createSchema({
789
- type: "never",
790
- optional: true
791
- })
792
- }),
793
- createProperty({
794
- name: "queryParams",
795
- schema: queryParams.length > 0 ? createSchema({
796
- ...buildParamsSchema({
797
- params: queryParams,
798
- operationId: node.operationId,
799
- resolveName
800
- }),
801
- optional: true
802
- }) : createSchema({
803
- type: "never",
804
- optional: true
805
- })
806
- }),
807
- createProperty({
808
- name: "headerParams",
809
- schema: headerParams.length > 0 ? createSchema({
810
- ...buildParamsSchema({
811
- params: headerParams,
812
- operationId: node.operationId,
813
- resolveName
814
- }),
815
- optional: true
816
- }) : createSchema({
817
- type: "never",
818
- optional: true
819
- })
820
- }),
821
- createProperty({
822
- name: "url",
823
- schema: createSchema({
824
- type: "url",
825
- path: node.path
826
- })
827
- })
828
- ]
829
- });
830
- }
831
- /**
832
- * Builds an `ObjectSchemaNode` representing `<OperationId>Responses` — keyed by HTTP status code.
833
- * Numeric status codes produce unquoted numeric keys (e.g. `200:`).
834
- */
835
- function buildResponsesSchemaNode({ node, resolveName }) {
836
- const responsesWithSchema = node.responses.filter((res) => res.schema);
837
- if (responsesWithSchema.length === 0) return null;
838
- return createSchema({
839
- type: "object",
840
- properties: responsesWithSchema.map((res) => createProperty({
841
- name: String(res.statusCode),
842
- schema: createSchema({
843
- type: "ref",
844
- name: resolveName({
845
- name: `${node.operationId} Status ${res.statusCode}`,
846
- type: "function"
847
- })
848
- })
849
- }))
850
- });
851
- }
852
- /**
853
- * Builds a `UnionSchemaNode` representing `<OperationId>Response` — all response types in union format.
854
- * Returns `null` when the operation has no responses with schemas.
855
- */
856
- function buildResponseUnionSchemaNode({ node, resolveName }) {
857
- const responsesWithSchema = node.responses.filter((res) => res.schema);
858
- if (responsesWithSchema.length === 0) return null;
859
- return createSchema({
860
- type: "union",
861
- members: responsesWithSchema.map((res) => createSchema({
862
- type: "ref",
863
- name: resolveName({
864
- name: `${node.operationId} Status ${res.statusCode}`,
865
- type: "function"
866
- })
867
- }))
868
- });
869
- }
870
- //#endregion
871
- //#region src/generators/v2/typeGenerator.tsx
872
- const typeGenerator = createGenerator({
873
- name: "typescript",
874
- type: "react",
875
- Operation({ node, adapter, options }) {
876
- const { enumType, enumKeyCasing, optionalType, arrayType, syntaxType, paramsCasing, group } = options;
877
- const { mode, getFile, resolveName } = useKubb();
878
- const file = getFile({
879
- name: node.operationId,
880
- extname: ".ts",
881
- mode,
882
- options: { group: group ? group.type === "tag" ? { tag: node.tags[0] } : { path: node.path } : void 0 }
883
- });
884
- const params = applyParamsCasing(node.parameters, paramsCasing);
885
- function renderSchemaType({ node: schemaNode, name, typedName, description }) {
886
- if (!schemaNode) return null;
887
- const imports = adapter.getImports(schemaNode, (schemaName) => ({
888
- name: resolveName({
889
- name: schemaName,
890
- type: "type"
891
- }),
892
- path: getFile({
893
- name: schemaName,
894
- extname: ".ts",
895
- mode
896
- }).path
897
- }));
898
- return /* @__PURE__ */ jsxs(Fragment, { children: [mode === "split" && imports.map((imp) => /* @__PURE__ */ jsx(File.Import, {
899
- root: file.path,
900
- path: imp.path,
901
- name: imp.name,
902
- isTypeOnly: true
903
- }, [
904
- name,
905
- imp.path,
906
- imp.isTypeOnly
907
- ].join("-"))), /* @__PURE__ */ jsx(Type, {
908
- name,
909
- typedName,
910
- node: schemaNode,
911
- description,
912
- enumType,
913
- enumKeyCasing,
914
- optionalType,
915
- arrayType,
916
- syntaxType
917
- })] });
918
- }
919
- const paramTypes = params.map((param) => renderSchemaType({
920
- node: param.schema,
921
- name: resolveName({
922
- name: `${node.operationId} ${pascalCase(param.in)} ${param.name}`,
923
- type: "function"
924
- }),
925
- typedName: resolveName({
926
- name: `${node.operationId} ${pascalCase(param.in)} ${param.name}`,
927
- type: "type"
928
- })
929
- }));
930
- const responseTypes = node.responses.filter((res) => res.schema).map((res) => renderSchemaType({
931
- node: res.schema,
932
- name: resolveName({
933
- name: `${node.operationId} Status ${res.statusCode}`,
934
- type: "function"
935
- }),
936
- typedName: resolveName({
937
- name: `${node.operationId} Status ${res.statusCode}`,
938
- type: "type"
939
- }),
940
- description: res.description
941
- }));
942
- const requestType = node.requestBody ? renderSchemaType({
943
- node: node.requestBody,
944
- name: resolveName({
945
- name: `${node.operationId} Data`,
946
- type: "function"
947
- }),
948
- typedName: resolveName({
949
- name: `${node.operationId} Data`,
950
- type: "type"
951
- }),
952
- description: node.requestBody.description
953
- }) : null;
954
- const dataType = renderSchemaType({
955
- node: buildDataSchemaNode({
956
- node: {
957
- ...node,
958
- parameters: params
959
- },
960
- resolveName
961
- }),
962
- name: resolveName({
963
- name: `${node.operationId} RequestConfig`,
964
- type: "function"
965
- }),
966
- typedName: resolveName({
967
- name: `${node.operationId} RequestConfig`,
968
- type: "type"
969
- })
970
- });
971
- const responsesType = renderSchemaType({
972
- node: buildResponsesSchemaNode({
973
- node,
974
- resolveName
975
- }),
976
- name: resolveName({
977
- name: `${node.operationId} Responses`,
978
- type: "function"
979
- }),
980
- typedName: resolveName({
981
- name: `${node.operationId} Responses`,
982
- type: "type"
983
- })
984
- });
985
- const responseType = renderSchemaType({
986
- node: buildResponseUnionSchemaNode({
987
- node,
988
- resolveName
989
- }),
990
- name: resolveName({
991
- name: `${node.operationId} Response`,
992
- type: "function"
993
- }),
994
- typedName: resolveName({
995
- name: `${node.operationId} Response`,
996
- type: "type"
997
- }),
998
- description: "Union of all possible responses"
999
- });
1000
- return /* @__PURE__ */ jsxs(File, {
1001
- baseName: file.baseName,
1002
- path: file.path,
1003
- meta: file.meta,
1004
- children: [
1005
- paramTypes,
1006
- responseTypes,
1007
- requestType,
1008
- dataType,
1009
- responsesType,
1010
- responseType
1011
- ]
1012
- });
1013
- },
1014
- Schema({ node, adapter, options }) {
1015
- const { enumType, enumKeyCasing, syntaxType, optionalType, arrayType } = options;
1016
- const { mode, resolveName, getFile } = useKubb();
1017
- if (!node.name) return;
1018
- const imports = adapter.getImports(node, (schemaName) => ({
1019
- name: resolveName({
1020
- name: schemaName,
1021
- type: "type"
1022
- }),
1023
- path: getFile({
1024
- name: schemaName,
1025
- extname: ".ts",
1026
- mode
1027
- }).path
1028
- }));
1029
- const isEnumSchema = node.type === "enum";
1030
- let typedName = resolveName({
1031
- name: node.name,
1032
- type: "type"
1033
- });
1034
- if (ENUM_TYPES_WITH_KEY_SUFFIX.has(enumType) && isEnumSchema) typedName += "Key";
1035
- const type = {
1036
- name: resolveName({
1037
- name: node.name,
1038
- type: "function"
1039
- }),
1040
- typedName,
1041
- file: getFile({
1042
- name: node.name,
1043
- extname: ".ts",
1044
- mode
1045
- })
1046
- };
1047
- return /* @__PURE__ */ jsxs(File, {
1048
- baseName: type.file.baseName,
1049
- path: type.file.path,
1050
- meta: type.file.meta,
1051
- children: [mode === "split" && imports.map((imp) => /* @__PURE__ */ jsx(File.Import, {
1052
- root: type.file.path,
1053
- path: imp.path,
1054
- name: imp.name,
1055
- isTypeOnly: true
1056
- }, [
1057
- node.name,
1058
- imp.path,
1059
- imp.isTypeOnly
1060
- ].join("-"))), /* @__PURE__ */ jsx(Type, {
1061
- name: type.name,
1062
- typedName: type.typedName,
1063
- node,
1064
- enumType,
1065
- enumKeyCasing,
1066
- optionalType,
1067
- arrayType,
1068
- syntaxType
1069
- })]
1070
- });
1071
- }
1072
- });
1073
- //#endregion
1074
- //#region src/plugin.ts
1075
- const pluginTsName = "plugin-ts";
1076
- const pluginTs = createPlugin((options) => {
1077
- const { output = {
1078
- path: "types",
1079
- barrelType: "named"
1080
- }, group, exclude = [], include, override = [], enumType = "asConst", enumKeyCasing = "none", enumSuffix = "enum", dateType = "string", integerType = "number", unknownType = "any", optionalType = "questionToken", arrayType = "array", emptySchemaType = unknownType, syntaxType = "type", transformers = {}, paramsCasing, generators = [typeGenerator$1, typeGenerator].filter(Boolean), contentType, UNSTABLE_NAMING } = options;
1081
- return {
1082
- name: pluginTsName,
1083
- options: {
1084
- output,
1085
- transformers,
1086
- dateType,
1087
- integerType,
1088
- optionalType,
1089
- arrayType,
1090
- enumType,
1091
- enumKeyCasing,
1092
- enumSuffix,
1093
- unknownType,
1094
- emptySchemaType,
1095
- syntaxType,
1096
- group,
1097
- override,
1098
- paramsCasing,
1099
- usedEnumNames: {}
1100
- },
1101
- pre: [pluginOasName],
1102
- resolvePath(baseName, pathMode, options) {
1103
- const root = path.resolve(this.config.root, this.config.output.path);
1104
- if ((pathMode ?? getMode(path.resolve(root, output.path))) === "single")
1105
- /**
1106
- * when output is a file then we will always append to the same file(output file), see fileManager.addOrAppend
1107
- * Other plugins then need to call addOrAppend instead of just add from the fileManager class
1108
- */
1109
- return path.resolve(root, output.path);
1110
- if (group && (options?.group?.path || options?.group?.tag)) {
1111
- const groupName = group?.name ? group.name : (ctx) => {
1112
- if (group?.type === "path") return `${ctx.group.split("/")[1]}`;
1113
- return `${camelCase(ctx.group)}Controller`;
1114
- };
1115
- return path.resolve(root, output.path, groupName({ group: group.type === "path" ? options.group.path : options.group.tag }), baseName);
1116
- }
1117
- return path.resolve(root, output.path, baseName);
1118
- },
1119
- resolveName(name, type) {
1120
- const resolvedName = pascalCase(name, { isFile: type === "file" });
1121
- if (type) return transformers?.name?.(resolvedName, type) || resolvedName;
1122
- return resolvedName;
1123
- },
1124
- async install() {
1125
- const { config, fabric, plugin, adapter, rootNode, driver, openInStudio } = this;
1126
- const root = path.resolve(config.root, config.output.path);
1127
- const mode = getMode(path.resolve(root, output.path));
1128
- if (adapter) {
1129
- await openInStudio({ ast: true });
1130
- await walk(rootNode, {
1131
- async schema(schemaNode) {
1132
- const writeTasks = generators.map(async (generator) => {
1133
- if (generator.type === "react" && generator.version === "2") {
1134
- const options = resolveOptions(schemaNode, {
1135
- options: plugin.options,
1136
- exclude,
1137
- include,
1138
- override
1139
- });
1140
- if (options === null) return;
1141
- await buildSchema(schemaNode, {
1142
- options,
1143
- adapter,
1144
- config,
1145
- fabric,
1146
- Component: generator.Schema,
1147
- plugin,
1148
- driver,
1149
- mode,
1150
- version: generator.version
1151
- });
1152
- }
1153
- });
1154
- await Promise.all(writeTasks);
1155
- },
1156
- async operation(operationNode) {
1157
- const writeTasks = generators.map(async (generator) => {
1158
- if (generator.type === "react" && generator.version === "2") {
1159
- const options = resolveOptions(operationNode, {
1160
- options: plugin.options,
1161
- exclude,
1162
- include,
1163
- override
1164
- });
1165
- if (options === null) return;
1166
- await buildOperation(operationNode, {
1167
- options,
1168
- adapter,
1169
- config,
1170
- fabric,
1171
- Component: generator.Operation,
1172
- plugin,
1173
- driver,
1174
- mode,
1175
- version: generator.version
1176
- });
1177
- }
1178
- });
1179
- await Promise.all(writeTasks);
1180
- }
1181
- }, { depth: "shallow" });
1182
- const barrelFiles = await getBarrelFiles(this.fabric.files, {
1183
- type: output.barrelType ?? "named",
1184
- root,
1185
- output,
1186
- meta: { pluginName: this.plugin.name }
1187
- });
1188
- await this.upsertFile(...barrelFiles);
1189
- return;
1190
- }
1191
- const oas = await this.getOas();
1192
- const schemaFiles = await new SchemaGenerator(this.plugin.options, {
1193
- fabric: this.fabric,
1194
- oas,
1195
- driver: this.driver,
1196
- events: this.events,
1197
- plugin: this.plugin,
1198
- contentType,
1199
- include: void 0,
1200
- override,
1201
- mode,
1202
- output: output.path
1203
- }).build(...generators);
1204
- await this.upsertFile(...schemaFiles);
1205
- const operationFiles = await new OperationGenerator(this.plugin.options, {
1206
- fabric: this.fabric,
1207
- oas,
1208
- driver: this.driver,
1209
- events: this.events,
1210
- plugin: this.plugin,
1211
- contentType,
1212
- exclude,
1213
- include,
1214
- override,
1215
- mode,
1216
- UNSTABLE_NAMING
1217
- }).build(...generators);
1218
- await this.upsertFile(...operationFiles);
1219
- const barrelFiles = await getBarrelFiles(this.fabric.files, {
1220
- type: output.barrelType ?? "named",
1221
- root,
1222
- output,
1223
- meta: { pluginName: this.plugin.name }
1224
- });
1225
- await this.upsertFile(...barrelFiles);
1226
- }
1227
- };
1228
- });
1229
- //#endregion
1230
- export { typeGenerator$1 as i, pluginTsName as n, typeGenerator as r, pluginTs as t };
1231
-
1232
- //# sourceMappingURL=plugin-D5NGPj0v.js.map