@kubb/plugin-ts 3.0.0-alpha.14 → 3.0.0-alpha.16

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 (91) hide show
  1. package/dist/chunk-HDNWB2MI.js +296 -0
  2. package/dist/chunk-HDNWB2MI.js.map +1 -0
  3. package/dist/{chunk-GAQFG5UG.cjs → chunk-LDIMQXBB.cjs} +65 -343
  4. package/dist/chunk-LDIMQXBB.cjs.map +1 -0
  5. package/dist/chunk-ROJIL5DA.cjs +325 -0
  6. package/dist/chunk-ROJIL5DA.cjs.map +1 -0
  7. package/dist/{chunk-3WKPPYM2.js → chunk-UNKUJK3W.js} +56 -331
  8. package/dist/chunk-UNKUJK3W.js.map +1 -0
  9. package/dist/components.cjs +5 -11
  10. package/dist/components.cjs.map +1 -1
  11. package/dist/components.d.cts +15 -44
  12. package/dist/components.d.ts +15 -44
  13. package/dist/components.js +1 -5
  14. package/dist/components.js.map +1 -1
  15. package/dist/generators.cjs +17 -0
  16. package/dist/generators.cjs.map +1 -0
  17. package/dist/generators.d.cts +11 -0
  18. package/dist/generators.d.ts +11 -0
  19. package/dist/generators.js +4 -0
  20. package/dist/generators.js.map +1 -0
  21. package/dist/index.cjs +4 -4
  22. package/dist/index.d.cts +5 -123
  23. package/dist/index.d.ts +5 -123
  24. package/dist/index.js +2 -2
  25. package/dist/types-fG0pOv-_.d.cts +123 -0
  26. package/dist/types-fG0pOv-_.d.ts +123 -0
  27. package/package.json +20 -12
  28. package/src/components/OasType.tsx +3 -50
  29. package/src/components/{Schema.tsx → Type.tsx} +14 -50
  30. package/src/components/index.ts +1 -2
  31. package/src/generators/__snapshots__/bodyUploadFileApiAssetsPost.ts +6 -0
  32. package/src/generators/__snapshots__/catTypeAsConst.ts +11 -0
  33. package/src/generators/__snapshots__/createPet.ts +34 -0
  34. package/src/generators/__snapshots__/createPetWithUnknownTypeUnknown.ts +34 -0
  35. package/src/generators/__snapshots__/deletePet.ts +5 -0
  36. package/src/generators/__snapshots__/dogTypeAsConst.ts +11 -0
  37. package/src/generators/__snapshots__/enumAllOf.ts +10 -0
  38. package/src/generators/__snapshots__/enumArray.ts +15 -0
  39. package/src/generators/__snapshots__/enumInObject.ts +13 -0
  40. package/src/generators/__snapshots__/enumItems.ts +8 -0
  41. package/src/generators/__snapshots__/enumNames.ts +6 -0
  42. package/src/generators/__snapshots__/enumNamesConst.ts +6 -0
  43. package/src/generators/__snapshots__/enumNamesLiteral.ts +3 -0
  44. package/src/generators/__snapshots__/enumNamesPascalConst.ts +8 -0
  45. package/src/generators/__snapshots__/enumNamesType.ts +8 -0
  46. package/src/generators/__snapshots__/enumNullableMember.ts +8 -0
  47. package/src/generators/__snapshots__/enumNullableType.ts +8 -0
  48. package/src/generators/__snapshots__/enumString.ts +10 -0
  49. package/src/generators/__snapshots__/enumVarNamesType.ts +8 -0
  50. package/src/generators/__snapshots__/getPets.ts +27 -0
  51. package/src/generators/__snapshots__/mixedValueTypeConst.ts +9 -0
  52. package/src/generators/__snapshots__/nullConstNull.ts +6 -0
  53. package/src/generators/__snapshots__/numberValueConst.ts +9 -0
  54. package/src/generators/__snapshots__/petMapper.ts +15 -0
  55. package/src/generators/__snapshots__/petQuestionToken.ts +15 -0
  56. package/src/generators/__snapshots__/petQuestionTokenAndUndefined.ts +15 -0
  57. package/src/generators/__snapshots__/petUndefined.ts +15 -0
  58. package/src/generators/__snapshots__/pets.ts +14 -0
  59. package/src/generators/__snapshots__/petsStoreDiscriminator.ts +13 -0
  60. package/src/generators/__snapshots__/petsStoreRef.ts +1 -0
  61. package/src/generators/__snapshots__/plainDateDate.ts +1 -0
  62. package/src/generators/__snapshots__/plainDateString.ts +1 -0
  63. package/src/generators/__snapshots__/plainEmail.ts +1 -0
  64. package/src/generators/__snapshots__/plainFile.ts +1 -0
  65. package/src/generators/__snapshots__/plainTimeDate.ts +1 -0
  66. package/src/generators/__snapshots__/plainUuid.ts +1 -0
  67. package/src/generators/__snapshots__/showPetById.ts +32 -0
  68. package/src/generators/__snapshots__/stringValueConst.ts +9 -0
  69. package/src/generators/index.ts +2 -0
  70. package/src/generators/oasGenerator.tsx +23 -0
  71. package/src/generators/typeGenerator.tsx +194 -0
  72. package/src/plugin.ts +4 -7
  73. package/src/types.ts +2 -5
  74. package/dist/chunk-3WKPPYM2.js.map +0 -1
  75. package/dist/chunk-FH2ZK3AD.cjs +0 -42
  76. package/dist/chunk-FH2ZK3AD.cjs.map +0 -1
  77. package/dist/chunk-GAQFG5UG.cjs.map +0 -1
  78. package/dist/chunk-T4IY5VUG.js +0 -38
  79. package/dist/chunk-T4IY5VUG.js.map +0 -1
  80. package/dist/oas.cjs +0 -8
  81. package/dist/oas.cjs.map +0 -1
  82. package/dist/oas.d.cts +0 -1
  83. package/dist/oas.d.ts +0 -1
  84. package/dist/oas.js +0 -6
  85. package/dist/oas.js.map +0 -1
  86. package/src/OperationGenerator.tsx +0 -59
  87. package/src/SchemaGenerator.tsx +0 -36
  88. package/src/components/OperationSchema.tsx +0 -161
  89. package/src/components/__snapshots__/Schema/pets.ts +0 -27
  90. package/src/components/__snapshots__/Schema/showPetById.ts +0 -32
  91. package/src/oas/index.ts +0 -1
@@ -1,17 +1,11 @@
1
1
  'use strict';
2
2
 
3
- var chunkFH2ZK3AD_cjs = require('./chunk-FH2ZK3AD.cjs');
4
- var path = require('path');
5
- var core = require('@kubb/core');
6
- var transformers2 = require('@kubb/core/transformers');
7
- var utils = require('@kubb/core/utils');
8
- var pluginOas = require('@kubb/plugin-oas');
9
- var components = require('@kubb/plugin-oas/components');
10
3
  var react = require('@kubb/react');
11
- var hooks = require('@kubb/plugin-oas/hooks');
12
4
  var jsxRuntime = require('@kubb/react/jsx-runtime');
5
+ var transformers2 = require('@kubb/core/transformers');
13
6
  var parserTs = require('@kubb/parser-ts');
14
7
  var factory = require('@kubb/parser-ts/factory');
8
+ var pluginOas = require('@kubb/plugin-oas');
15
9
 
16
10
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
17
11
 
@@ -33,14 +27,48 @@ function _interopNamespace(e) {
33
27
  return Object.freeze(n);
34
28
  }
35
29
 
36
- var path__default = /*#__PURE__*/_interopDefault(path);
37
30
  var transformers2__default = /*#__PURE__*/_interopDefault(transformers2);
38
31
  var factory__namespace = /*#__PURE__*/_interopNamespace(factory);
39
32
 
33
+ var __create = Object.create;
34
+ var __defProp = Object.defineProperty;
35
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
36
+ var __getOwnPropNames = Object.getOwnPropertyNames;
37
+ var __getProtoOf = Object.getPrototypeOf;
38
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
39
+ var __esm = (fn, res) => function __init() {
40
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
41
+ };
42
+ var __commonJS = (cb, mod) => function __require() {
43
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
44
+ };
45
+ var __copyProps = (to, from, except, desc) => {
46
+ if (from && typeof from === "object" || typeof from === "function") {
47
+ for (let key of __getOwnPropNames(from))
48
+ if (!__hasOwnProp.call(to, key) && key !== except)
49
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
50
+ }
51
+ return to;
52
+ };
53
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
54
+ // If the importer is in node compatibility mode or this is not an ESM
55
+ // file that has been converted to a CommonJS file using a Babel-
56
+ // compatible transform (i.e. "__esModule" has not been set), then set
57
+ // "default" to the CommonJS "module.exports" for node compatibility.
58
+ __defProp(target, "default", { value: mod, enumerable: true }) ,
59
+ mod
60
+ ));
61
+
62
+ // ../../node_modules/.pnpm/tsup@8.2.4_@microsoft+api-extractor@7.47.7_@types+node@20.16.5__@swc+core@1.7.22_jiti@1.21.6__vgec2xea2cg5zleragji3g6qgq/node_modules/tsup/assets/cjs_shims.js
63
+ var init_cjs_shims = __esm({
64
+ "../../node_modules/.pnpm/tsup@8.2.4_@microsoft+api-extractor@7.47.7_@types+node@20.16.5__@swc+core@1.7.22_jiti@1.21.6__vgec2xea2cg5zleragji3g6qgq/node_modules/tsup/assets/cjs_shims.js"() {
65
+ }
66
+ });
67
+
40
68
  // ../../node_modules/.pnpm/react@18.3.1/node_modules/react/cjs/react.production.min.js
41
- var require_react_production_min = chunkFH2ZK3AD_cjs.__commonJS({
69
+ var require_react_production_min = __commonJS({
42
70
  "../../node_modules/.pnpm/react@18.3.1/node_modules/react/cjs/react.production.min.js"(exports) {
43
- chunkFH2ZK3AD_cjs.init_cjs_shims();
71
+ init_cjs_shims();
44
72
  var l = Symbol.for("react.element");
45
73
  var n = Symbol.for("react.portal");
46
74
  var p = Symbol.for("react.fragment");
@@ -311,9 +339,9 @@ var require_react_production_min = chunkFH2ZK3AD_cjs.__commonJS({
311
339
  });
312
340
 
313
341
  // ../../node_modules/.pnpm/react@18.3.1/node_modules/react/cjs/react.development.js
314
- var require_react_development = chunkFH2ZK3AD_cjs.__commonJS({
342
+ var require_react_development = __commonJS({
315
343
  "../../node_modules/.pnpm/react@18.3.1/node_modules/react/cjs/react.development.js"(exports, module) {
316
- chunkFH2ZK3AD_cjs.init_cjs_shims();
344
+ init_cjs_shims();
317
345
  if (process.env.NODE_ENV !== "production") {
318
346
  (function() {
319
347
  if (typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== "undefined" && typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart === "function") {
@@ -2184,9 +2212,9 @@ var require_react_development = chunkFH2ZK3AD_cjs.__commonJS({
2184
2212
  });
2185
2213
 
2186
2214
  // ../../node_modules/.pnpm/react@18.3.1/node_modules/react/index.js
2187
- var require_react = chunkFH2ZK3AD_cjs.__commonJS({
2215
+ var require_react = __commonJS({
2188
2216
  "../../node_modules/.pnpm/react@18.3.1/node_modules/react/index.js"(exports, module) {
2189
- chunkFH2ZK3AD_cjs.init_cjs_shims();
2217
+ init_cjs_shims();
2190
2218
  if (process.env.NODE_ENV === "production") {
2191
2219
  module.exports = require_react_production_min();
2192
2220
  } else {
@@ -2195,55 +2223,25 @@ var require_react = chunkFH2ZK3AD_cjs.__commonJS({
2195
2223
  }
2196
2224
  });
2197
2225
 
2198
- // src/index.ts
2199
- chunkFH2ZK3AD_cjs.init_cjs_shims();
2200
-
2201
- // src/plugin.ts
2202
- chunkFH2ZK3AD_cjs.init_cjs_shims();
2203
-
2204
- // src/OperationGenerator.tsx
2205
- chunkFH2ZK3AD_cjs.init_cjs_shims();
2226
+ // src/components/index.ts
2227
+ init_cjs_shims();
2206
2228
 
2207
2229
  // src/components/OasType.tsx
2208
- chunkFH2ZK3AD_cjs.init_cjs_shims();
2209
- function Template({ name, typeName, api }) {
2230
+ init_cjs_shims();
2231
+ function OasType({ name, typeName, api }) {
2210
2232
  return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
2211
2233
  /* @__PURE__ */ jsxRuntime.jsx(react.File.Source, { name, isExportable: true, isIndexable: true, children: `export const ${name} = ${JSON.stringify(api, void 0, 2)} as const` }),
2212
2234
  /* @__PURE__ */ jsxRuntime.jsx("br", {}),
2213
2235
  /* @__PURE__ */ jsxRuntime.jsx(react.File.Source, { name: typeName, isExportable: true, isIndexable: true, isTypeOnly: true, children: /* @__PURE__ */ jsxRuntime.jsx(react.Type, { name: typeName, export: true, children: `Infer<typeof ${name}>` }) })
2214
2236
  ] });
2215
2237
  }
2216
- var defaultTemplates = { default: Template };
2217
- function OasType({ name, typeName, Template: Template2 = defaultTemplates.default }) {
2218
- const oas = hooks.useOas();
2219
- return /* @__PURE__ */ jsxRuntime.jsx(Template2, { name, typeName, api: oas.api });
2220
- }
2221
- OasType.File = function({ name, typeName, templates = defaultTemplates }) {
2222
- const {
2223
- pluginManager,
2224
- plugin: { key: pluginKey }
2225
- } = react.useApp();
2226
- const file = pluginManager.getFile({ name, extName: ".ts", pluginKey });
2227
- const Template2 = templates.default;
2228
- return /* @__PURE__ */ jsxRuntime.jsxs(react.File, { baseName: file.baseName, path: file.path, meta: file.meta, children: [
2229
- /* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { name: ["Infer"], path: "@kubb/oas", isTypeOnly: true }),
2230
- /* @__PURE__ */ jsxRuntime.jsx(OasType, { Template: Template2, name, typeName })
2231
- ] });
2232
- };
2233
- OasType.templates = defaultTemplates;
2234
-
2235
- // src/components/OperationSchema.tsx
2236
- chunkFH2ZK3AD_cjs.init_cjs_shims();
2237
2238
 
2238
- // src/SchemaGenerator.tsx
2239
- chunkFH2ZK3AD_cjs.init_cjs_shims();
2240
-
2241
- // src/components/Schema.tsx
2242
- chunkFH2ZK3AD_cjs.init_cjs_shims();
2243
- var import_react3 = chunkFH2ZK3AD_cjs.__toESM(require_react(), 1);
2239
+ // src/components/Type.tsx
2240
+ init_cjs_shims();
2241
+ var import_react3 = __toESM(require_react());
2244
2242
 
2245
2243
  // src/parser/index.ts
2246
- chunkFH2ZK3AD_cjs.init_cjs_shims();
2244
+ init_cjs_shims();
2247
2245
  var typeKeywordMapper = {
2248
2246
  any: () => factory__namespace.keywordTypeNodes.any,
2249
2247
  unknown: () => factory__namespace.keywordTypeNodes.unknown,
@@ -2437,28 +2435,7 @@ function parse(parent, current, options) {
2437
2435
  }
2438
2436
  return void 0;
2439
2437
  }
2440
- function Schema(props) {
2441
- const { keysToOmit, description } = props;
2442
- const { tree, name } = hooks.useSchema();
2443
- const {
2444
- pluginManager,
2445
- plugin: {
2446
- options: { mapper, enumType, optionalType }
2447
- }
2448
- } = react.useApp();
2449
- if (enumType === "asPascalConst") {
2450
- pluginManager.logger.emit("warning", `enumType '${enumType}' is deprecated`);
2451
- }
2452
- const resolvedName = pluginManager.resolveName({
2453
- name,
2454
- pluginKey: [pluginTsName],
2455
- type: "function"
2456
- });
2457
- const typeName = pluginManager.resolveName({
2458
- name,
2459
- pluginKey: [pluginTsName],
2460
- type: "type"
2461
- });
2438
+ function Type2({ name, typedName, tree, keysToOmit, optionalType, enumType, mapper, description }) {
2462
2439
  const typeNodes = [];
2463
2440
  if (!tree.length) {
2464
2441
  return "";
@@ -2468,8 +2445,8 @@ function Schema(props) {
2468
2445
  const isOptional = tree.some((item) => item.keyword === pluginOas.schemaKeywords.optional);
2469
2446
  let type = tree.map(
2470
2447
  (schema) => parse(void 0, schema, {
2471
- name: resolvedName,
2472
- typeName,
2448
+ name,
2449
+ typeName: typedName,
2473
2450
  description,
2474
2451
  keysToOmit,
2475
2452
  optionalType,
@@ -2494,7 +2471,7 @@ function Schema(props) {
2494
2471
  }
2495
2472
  const node = factory__namespace.createTypeAliasDeclaration({
2496
2473
  modifiers: [factory__namespace.modifiers.export],
2497
- name: resolvedName,
2474
+ name,
2498
2475
  type: keysToOmit?.length ? factory__namespace.createOmitDeclaration({
2499
2476
  keys: keysToOmit,
2500
2477
  type,
@@ -2504,10 +2481,10 @@ function Schema(props) {
2504
2481
  const enumSchemas = pluginOas.SchemaGenerator.deepSearch(tree, pluginOas.schemaKeywords.enum);
2505
2482
  const enums = enumSchemas.map((enumSchema) => {
2506
2483
  const name2 = enumType === "asPascalConst" ? transformers2__default.default.pascalCase(enumSchema.args.name) : transformers2__default.default.camelCase(enumSchema.args.name);
2507
- const typeName2 = enumSchema.args.typeName;
2484
+ const typeName = enumSchema.args.typeName;
2508
2485
  const [nameNode, typeNode] = factory__namespace.createEnumDeclaration({
2509
2486
  name: name2,
2510
- typeName: typeName2,
2487
+ typeName,
2511
2488
  enums: enumSchema.args.items.map((item) => item.value === void 0 ? void 0 : [transformers2__default.default.trimQuotes(item.name?.toString()), item.value]).filter(Boolean),
2512
2489
  type: enumType
2513
2490
  });
@@ -2515,7 +2492,7 @@ function Schema(props) {
2515
2492
  nameNode,
2516
2493
  typeNode,
2517
2494
  name: name2,
2518
- typeName: typeName2
2495
+ typeName
2519
2496
  };
2520
2497
  });
2521
2498
  typeNodes.push(
@@ -2525,266 +2502,13 @@ function Schema(props) {
2525
2502
  })
2526
2503
  );
2527
2504
  return /* @__PURE__ */ jsxRuntime.jsxs(import_react3.Fragment, { children: [
2528
- enums.map(({ name: name2, nameNode, typeName: typeName2, typeNode }, index) => /* @__PURE__ */ jsxRuntime.jsxs(import_react3.Fragment, { children: [
2505
+ enums.map(({ name: name2, nameNode, typeName, typeNode }, index) => /* @__PURE__ */ jsxRuntime.jsxs(import_react3.Fragment, { children: [
2529
2506
  nameNode && /* @__PURE__ */ jsxRuntime.jsx(react.File.Source, { name: name2, isExportable: true, isIndexable: true, children: parserTs.print([nameNode]) }),
2530
- /* @__PURE__ */ jsxRuntime.jsx(react.File.Source, { name: typeName2, isIndexable: true, isExportable: ["enum", "asConst", "constEnum", "literal", void 0].includes(enumType), isTypeOnly: true, children: parserTs.print([typeNode]) })
2507
+ /* @__PURE__ */ jsxRuntime.jsx(react.File.Source, { name: typeName, isIndexable: true, isExportable: ["enum", "asConst", "constEnum", "literal", void 0].includes(enumType), isTypeOnly: true, children: parserTs.print([typeNode]) })
2531
2508
  ] }, [name2, nameNode].join("-"))),
2532
- enums.every((item) => item.typeName !== resolvedName) && /* @__PURE__ */ jsxRuntime.jsx(react.File.Source, { name: typeName, isTypeOnly: true, isExportable: true, isIndexable: true, children: parserTs.print(typeNodes) })
2509
+ enums.every((item) => item.typeName !== name) && /* @__PURE__ */ jsxRuntime.jsx(react.File.Source, { name: typedName, isTypeOnly: true, isExportable: true, isIndexable: true, children: parserTs.print(typeNodes) })
2533
2510
  ] });
2534
2511
  }
2535
- Schema.File = function({}) {
2536
- const { pluginManager } = react.useApp();
2537
- const { schema } = hooks.useSchema();
2538
- return /* @__PURE__ */ jsxRuntime.jsx(components.Oas.Schema.File, { isTypeOnly: true, output: pluginManager.config.output.path, children: /* @__PURE__ */ jsxRuntime.jsx(Schema, { description: schema?.description }) });
2539
- };
2540
- var SchemaGenerator2 = class extends pluginOas.SchemaGenerator {
2541
- async schema(name, schema, options) {
2542
- const { oas, pluginManager, plugin, mode, output } = this.context;
2543
- const root = react.createRoot({
2544
- logger: pluginManager.logger
2545
- });
2546
- const tree = this.parse({ schema, name });
2547
- const Component = () => /* @__PURE__ */ jsxRuntime.jsx(react.App, { pluginManager, plugin: { ...plugin, options }, mode, children: /* @__PURE__ */ jsxRuntime.jsx(components.Oas, { oas, children: /* @__PURE__ */ jsxRuntime.jsx(components.Oas.Schema, { name, value: schema, tree, children: /* @__PURE__ */ jsxRuntime.jsx(Schema.File, {}) }) }) });
2548
- Component.displayName = transformers2.pascalCase(name);
2549
- root.render(/* @__PURE__ */ jsxRuntime.jsx(Component, {}));
2550
- return root.files;
2551
- }
2552
- };
2553
- function printCombinedSchema({
2554
- name,
2555
- operation,
2556
- schemas,
2557
- pluginManager
2558
- }) {
2559
- const properties = {};
2560
- if (schemas.response) {
2561
- const identifier = pluginManager.resolveName({
2562
- name: schemas.response.name,
2563
- pluginKey: [pluginTsName],
2564
- type: "function"
2565
- });
2566
- properties["response"] = factory__namespace.createTypeReferenceNode(factory__namespace.createIdentifier(identifier), void 0);
2567
- }
2568
- if (schemas.request) {
2569
- const identifier = pluginManager.resolveName({
2570
- name: schemas.request.name,
2571
- pluginKey: [pluginTsName],
2572
- type: "function"
2573
- });
2574
- properties["request"] = factory__namespace.createTypeReferenceNode(factory__namespace.createIdentifier(identifier), void 0);
2575
- }
2576
- if (schemas.pathParams) {
2577
- const identifier = pluginManager.resolveName({
2578
- name: schemas.pathParams.name,
2579
- pluginKey: [pluginTsName],
2580
- type: "function"
2581
- });
2582
- properties["pathParams"] = factory__namespace.createTypeReferenceNode(factory__namespace.createIdentifier(identifier), void 0);
2583
- }
2584
- if (schemas.queryParams) {
2585
- const identifier = pluginManager.resolveName({
2586
- name: schemas.queryParams.name,
2587
- pluginKey: [pluginTsName],
2588
- type: "function"
2589
- });
2590
- properties["queryParams"] = factory__namespace.createTypeReferenceNode(factory__namespace.createIdentifier(identifier), void 0);
2591
- }
2592
- if (schemas.headerParams) {
2593
- const identifier = pluginManager.resolveName({
2594
- name: schemas.headerParams.name,
2595
- pluginKey: [pluginTsName],
2596
- type: "function"
2597
- });
2598
- properties["headerParams"] = factory__namespace.createTypeReferenceNode(factory__namespace.createIdentifier(identifier), void 0);
2599
- }
2600
- if (schemas.errors) {
2601
- properties["errors"] = factory__namespace.createUnionDeclaration({
2602
- nodes: schemas.errors.map((error) => {
2603
- const identifier = pluginManager.resolveName({
2604
- name: error.name,
2605
- pluginKey: [pluginTsName],
2606
- type: "function"
2607
- });
2608
- return factory__namespace.createTypeReferenceNode(factory__namespace.createIdentifier(identifier), void 0);
2609
- })
2610
- });
2611
- }
2612
- const namespaceNode = factory__namespace.createTypeAliasDeclaration({
2613
- name,
2614
- type: factory__namespace.createTypeLiteralNode(
2615
- Object.keys(properties).map((key) => {
2616
- const type = properties[key];
2617
- if (!type) {
2618
- return void 0;
2619
- }
2620
- return factory__namespace.createPropertySignature({
2621
- name: transformers2__default.default.pascalCase(key),
2622
- type
2623
- });
2624
- }).filter(Boolean)
2625
- ),
2626
- modifiers: [factory__namespace.modifiers.export]
2627
- });
2628
- return parserTs.print([namespaceNode]);
2629
- }
2630
- function OperationSchema({ keysToOmit, description }) {
2631
- return /* @__PURE__ */ jsxRuntime.jsx(Schema, { keysToOmit, description });
2632
- }
2633
- OperationSchema.File = function({}) {
2634
- const { pluginManager, plugin, mode } = react.useApp();
2635
- const oas = hooks.useOas();
2636
- const { getSchemas, getFile, getName } = hooks.useOperationManager();
2637
- const operation = hooks.useOperation();
2638
- const file = getFile(operation);
2639
- const schemas = getSchemas(operation);
2640
- const factoryName = getName(operation, { type: "type" });
2641
- const generator = new SchemaGenerator2(plugin.options, {
2642
- oas,
2643
- plugin,
2644
- pluginManager,
2645
- mode,
2646
- override: plugin.options.override
2647
- });
2648
- const items = [schemas.pathParams, schemas.queryParams, schemas.headerParams, schemas.statusCodes, schemas.request, schemas.response].flat().filter(Boolean);
2649
- const mapItem = ({ name, schema, description, keysToOmit, ...options }, i) => {
2650
- const tree = generator.parse({ schema, name });
2651
- return /* @__PURE__ */ jsxRuntime.jsxs(components.Oas.Schema, { name, value: schema, tree, children: [
2652
- mode === "split" && /* @__PURE__ */ jsxRuntime.jsx(components.Oas.Schema.Imports, { isTypeOnly: true }),
2653
- /* @__PURE__ */ jsxRuntime.jsx(OperationSchema, { description, keysToOmit })
2654
- ] }, i);
2655
- };
2656
- const combinedSchemaName = operation.method === "get" ? `${factoryName}Query` : `${factoryName}Mutation`;
2657
- return /* @__PURE__ */ jsxRuntime.jsxs(react.File, { baseName: file.baseName, path: file.path, meta: file.meta, children: [
2658
- items.map(mapItem),
2659
- /* @__PURE__ */ jsxRuntime.jsx(react.File.Source, { name: combinedSchemaName, isExportable: true, isIndexable: true, isTypeOnly: true, children: printCombinedSchema({ name: combinedSchemaName, operation, schemas, pluginManager }) })
2660
- ] });
2661
- };
2662
- var OperationGenerator = class extends pluginOas.OperationGenerator {
2663
- async all(operations) {
2664
- const { oas, pluginManager, plugin, mode } = this.context;
2665
- const root = react.createRoot({
2666
- logger: pluginManager.logger
2667
- });
2668
- const Component = () => /* @__PURE__ */ jsxRuntime.jsx(react.App, { pluginManager, plugin, mode, children: /* @__PURE__ */ jsxRuntime.jsx(components.Oas, { oas, operations, generator: this, children: plugin.options.oasType && /* @__PURE__ */ jsxRuntime.jsx(OasType.File, { name: "oas", typeName: "Oas" }) }) });
2669
- Component.displayName = transformers2.pascalCase("operations");
2670
- root.render(/* @__PURE__ */ jsxRuntime.jsx(Component, {}));
2671
- return root.files;
2672
- }
2673
- async operation(operation, options) {
2674
- const { oas, pluginManager, plugin, mode } = this.context;
2675
- const root = react.createRoot({
2676
- logger: pluginManager.logger
2677
- });
2678
- const Component = () => /* @__PURE__ */ jsxRuntime.jsx(react.App, { pluginManager, plugin: { ...plugin, options }, mode, children: /* @__PURE__ */ jsxRuntime.jsx(components.Oas, { oas, operations: [operation], generator: this, children: /* @__PURE__ */ jsxRuntime.jsx(components.Oas.Operation, { operation, children: /* @__PURE__ */ jsxRuntime.jsx(OperationSchema.File, {}) }) }) });
2679
- Component.displayName = transformers2.pascalCase(operation.getOperationId());
2680
- root.render(/* @__PURE__ */ jsxRuntime.jsx(Component, {}));
2681
- return root.files;
2682
- }
2683
- };
2684
-
2685
- // src/plugin.ts
2686
- var pluginTsName = "plugin-ts";
2687
- var pluginTs = core.createPlugin((options) => {
2688
- const {
2689
- output = { path: "types" },
2690
- group,
2691
- exclude = [],
2692
- include,
2693
- override = [],
2694
- enumType = "asConst",
2695
- enumSuffix = "",
2696
- dateType = "string",
2697
- unknownType = "any",
2698
- optionalType = "questionToken",
2699
- transformers: transformers4 = {},
2700
- oasType = false,
2701
- mapper = {}
2702
- } = options;
2703
- const template = group?.output ? group.output : `${output.path}/{{tag}}Controller`;
2704
- return {
2705
- name: pluginTsName,
2706
- output: {
2707
- exportType: "barrelNamed",
2708
- ...output
2709
- },
2710
- options: {
2711
- extName: output.extName,
2712
- transformers: transformers4,
2713
- dateType,
2714
- optionalType,
2715
- oasType,
2716
- enumType,
2717
- enumSuffix,
2718
- // keep the used enumnames between SchemaGenerator and OperationGenerator per plugin(pluginKey)
2719
- usedEnumNames: {},
2720
- unknownType,
2721
- override,
2722
- mapper
2723
- },
2724
- pre: [pluginOas.pluginOasName],
2725
- resolvePath(baseName, pathMode, options2) {
2726
- const root = path__default.default.resolve(this.config.root, this.config.output.path);
2727
- const mode = pathMode ?? core.FileManager.getMode(path__default.default.resolve(root, output.path));
2728
- if (mode === "single") {
2729
- return path__default.default.resolve(root, output.path);
2730
- }
2731
- if (options2?.tag && group?.type === "tag") {
2732
- const tag = transformers2.camelCase(options2.tag);
2733
- return path__default.default.resolve(root, utils.renderTemplate(template, { tag }), baseName);
2734
- }
2735
- return path__default.default.resolve(root, output.path, baseName);
2736
- },
2737
- resolveName(name, type) {
2738
- const resolvedName = transformers2.pascalCase(name, { isFile: type === "file" });
2739
- if (type) {
2740
- return transformers4?.name?.(resolvedName, type) || resolvedName;
2741
- }
2742
- return resolvedName;
2743
- },
2744
- async buildStart() {
2745
- const [swaggerPlugin] = core.PluginManager.getDependedPlugins(this.plugins, [pluginOas.pluginOasName]);
2746
- const oas = await swaggerPlugin.context.getOas();
2747
- const root = path__default.default.resolve(this.config.root, this.config.output.path);
2748
- const mode = core.FileManager.getMode(path__default.default.resolve(root, output.path));
2749
- const schemaGenerator = new SchemaGenerator2(this.plugin.options, {
2750
- oas,
2751
- pluginManager: this.pluginManager,
2752
- plugin: this.plugin,
2753
- contentType: swaggerPlugin.context.contentType,
2754
- include: void 0,
2755
- override,
2756
- mode,
2757
- output: output.path
2758
- });
2759
- const schemaFiles = await schemaGenerator.build();
2760
- await this.addFile(...schemaFiles);
2761
- const operationGenerator = new OperationGenerator(this.plugin.options, {
2762
- oas,
2763
- pluginManager: this.pluginManager,
2764
- plugin: this.plugin,
2765
- contentType: swaggerPlugin.context.contentType,
2766
- exclude,
2767
- include,
2768
- override,
2769
- mode
2770
- });
2771
- const operationFiles = await operationGenerator.build();
2772
- await this.addFile(...operationFiles);
2773
- if (this.config.output.exportType) {
2774
- const barrelFiles = await this.fileManager.getBarrelFiles({
2775
- root,
2776
- output,
2777
- files: this.fileManager.files,
2778
- meta: {
2779
- pluginKey: this.plugin.key
2780
- },
2781
- logger: this.logger
2782
- });
2783
- await this.addFile(...barrelFiles);
2784
- }
2785
- }
2786
- };
2787
- });
2788
2512
  /*! Bundled license information:
2789
2513
 
2790
2514
  react/cjs/react.production.min.js:
@@ -2811,9 +2535,7 @@ react/cjs/react.development.js:
2811
2535
  */
2812
2536
 
2813
2537
  exports.OasType = OasType;
2814
- exports.OperationSchema = OperationSchema;
2815
- exports.Schema = Schema;
2816
- exports.pluginTs = pluginTs;
2817
- exports.pluginTsName = pluginTsName;
2818
- //# sourceMappingURL=chunk-GAQFG5UG.cjs.map
2819
- //# sourceMappingURL=chunk-GAQFG5UG.cjs.map
2538
+ exports.Type = Type2;
2539
+ exports.init_cjs_shims = init_cjs_shims;
2540
+ //# sourceMappingURL=chunk-LDIMQXBB.cjs.map
2541
+ //# sourceMappingURL=chunk-LDIMQXBB.cjs.map