@kubb/plugin-ts 3.0.0-alpha.2 → 3.0.0-alpha.21

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 (94) hide show
  1. package/README.md +13 -4
  2. package/dist/chunk-3IKQZT26.cjs +2541 -0
  3. package/dist/chunk-3IKQZT26.cjs.map +1 -0
  4. package/dist/chunk-CAATRNVS.js +2514 -0
  5. package/dist/chunk-CAATRNVS.js.map +1 -0
  6. package/dist/chunk-CPJWNK44.js +307 -0
  7. package/dist/chunk-CPJWNK44.js.map +1 -0
  8. package/dist/chunk-YLKAQOZ5.cjs +336 -0
  9. package/dist/chunk-YLKAQOZ5.cjs.map +1 -0
  10. package/dist/components.cjs +11 -6
  11. package/dist/components.cjs.map +1 -1
  12. package/dist/components.d.cts +14 -44
  13. package/dist/components.d.ts +14 -44
  14. package/dist/components.js +2 -10
  15. package/dist/components.js.map +1 -1
  16. package/dist/generators.cjs +17 -0
  17. package/dist/generators.cjs.map +1 -0
  18. package/dist/generators.d.cts +10 -0
  19. package/dist/generators.d.ts +10 -0
  20. package/dist/generators.js +4 -0
  21. package/dist/generators.js.map +1 -0
  22. package/dist/index.cjs +12 -4
  23. package/dist/index.cjs.map +1 -1
  24. package/dist/index.d.cts +4 -122
  25. package/dist/index.d.ts +4 -122
  26. package/dist/index.js +3 -8
  27. package/dist/index.js.map +1 -1
  28. package/dist/types-W01J9acJ.d.cts +106 -0
  29. package/dist/types-W01J9acJ.d.ts +106 -0
  30. package/package.json +21 -15
  31. package/src/components/OasType.tsx +11 -58
  32. package/src/components/Type.tsx +133 -0
  33. package/src/components/index.ts +1 -2
  34. package/src/generators/__snapshots__/bodyUploadFileApiAssetsPost.ts +6 -0
  35. package/src/generators/__snapshots__/catTypeAsConst.ts +11 -0
  36. package/src/generators/__snapshots__/createPet.ts +34 -0
  37. package/src/generators/__snapshots__/createPetWithUnknownTypeUnknown.ts +34 -0
  38. package/src/generators/__snapshots__/deletePet.ts +5 -0
  39. package/src/generators/__snapshots__/dogTypeAsConst.ts +11 -0
  40. package/src/generators/__snapshots__/enumAllOf.ts +10 -0
  41. package/src/generators/__snapshots__/enumArray.ts +19 -0
  42. package/src/generators/__snapshots__/enumInObject.ts +13 -0
  43. package/src/generators/__snapshots__/enumItems.ts +8 -0
  44. package/src/generators/__snapshots__/enumNames.ts +6 -0
  45. package/src/generators/__snapshots__/enumNamesConst.ts +6 -0
  46. package/src/generators/__snapshots__/enumNamesLiteral.ts +3 -0
  47. package/src/generators/__snapshots__/enumNamesPascalConst.ts +8 -0
  48. package/src/generators/__snapshots__/enumNamesType.ts +8 -0
  49. package/src/generators/__snapshots__/enumNullableMember.ts +8 -0
  50. package/src/generators/__snapshots__/enumNullableType.ts +8 -0
  51. package/src/generators/__snapshots__/enumString.ts +10 -0
  52. package/src/generators/__snapshots__/enumVarNamesType.ts +8 -0
  53. package/src/generators/__snapshots__/getPets.ts +27 -0
  54. package/src/generators/__snapshots__/mixedValueTypeConst.ts +9 -0
  55. package/src/generators/__snapshots__/nullConstNull.ts +6 -0
  56. package/src/generators/__snapshots__/numberValueConst.ts +9 -0
  57. package/src/generators/__snapshots__/petMapper.ts +15 -0
  58. package/src/generators/__snapshots__/petQuestionToken.ts +15 -0
  59. package/src/generators/__snapshots__/petQuestionTokenAndUndefined.ts +15 -0
  60. package/src/generators/__snapshots__/petUndefined.ts +15 -0
  61. package/src/generators/__snapshots__/pets.ts +14 -0
  62. package/src/generators/__snapshots__/petsStoreDiscriminator.ts +13 -0
  63. package/src/generators/__snapshots__/petsStoreRef.ts +1 -0
  64. package/src/generators/__snapshots__/plainDateDate.ts +1 -0
  65. package/src/generators/__snapshots__/plainDateString.ts +1 -0
  66. package/src/generators/__snapshots__/plainEmail.ts +1 -0
  67. package/src/generators/__snapshots__/plainFile.ts +1 -0
  68. package/src/generators/__snapshots__/plainTimeDate.ts +1 -0
  69. package/src/generators/__snapshots__/plainUuid.ts +1 -0
  70. package/src/generators/__snapshots__/showPetById.ts +32 -0
  71. package/src/generators/__snapshots__/stringValueConst.ts +9 -0
  72. package/src/generators/index.ts +2 -0
  73. package/src/generators/oasGenerator.tsx +29 -0
  74. package/src/generators/typeGenerator.tsx +200 -0
  75. package/src/parser/index.ts +2 -1
  76. package/src/plugin.ts +21 -20
  77. package/src/types.ts +9 -35
  78. package/dist/chunk-JF3PKBEA.cjs +0 -608
  79. package/dist/chunk-JF3PKBEA.cjs.map +0 -1
  80. package/dist/chunk-PU22CLWV.js +0 -608
  81. package/dist/chunk-PU22CLWV.js.map +0 -1
  82. package/dist/oas.cjs +0 -1
  83. package/dist/oas.cjs.map +0 -1
  84. package/dist/oas.d.cts +0 -1
  85. package/dist/oas.d.ts +0 -1
  86. package/dist/oas.js +0 -1
  87. package/dist/oas.js.map +0 -1
  88. package/src/OperationGenerator.tsx +0 -49
  89. package/src/SchemaGenerator.tsx +0 -31
  90. package/src/components/OperationSchema.tsx +0 -161
  91. package/src/components/Schema.tsx +0 -135
  92. package/src/components/__snapshots__/Schema/pets.ts +0 -23
  93. package/src/components/__snapshots__/Schema/showPetById.ts +0 -28
  94. package/src/oas/index.ts +0 -1
@@ -1,608 +0,0 @@
1
- // src/plugin.ts
2
- import path from "path";
3
- import { FileManager, PluginManager, createPlugin } from "@kubb/core";
4
- import { camelCase, pascalCase } from "@kubb/core/transformers";
5
- import { renderTemplate } from "@kubb/core/utils";
6
- import { pluginOasName } from "@kubb/plugin-oas";
7
-
8
- // src/OperationGenerator.tsx
9
- import { OperationGenerator as Generator2 } from "@kubb/plugin-oas";
10
- import { Oas as Oas4 } from "@kubb/plugin-oas/components";
11
- import { App as App2, createRoot as createRoot2 } from "@kubb/react";
12
-
13
- // src/components/OasType.tsx
14
- import { Parser, File, Type, useApp } from "@kubb/react";
15
- import { useOas } from "@kubb/plugin-oas/hooks";
16
- import { Fragment, jsx, jsxs } from "@kubb/react/jsx-runtime";
17
- function Template({ name, typeName, api }) {
18
- return /* @__PURE__ */ jsxs(Fragment, { children: [
19
- `export const ${name} = ${JSON.stringify(api, void 0, 2)} as const`,
20
- /* @__PURE__ */ jsx("br", {}),
21
- /* @__PURE__ */ jsx(Type, { name: typeName, export: true, children: `Infer<typeof ${name}>` })
22
- ] });
23
- }
24
- var defaultTemplates = { default: Template };
25
- function OasType({ name, typeName, Template: Template2 = defaultTemplates.default }) {
26
- const oas = useOas();
27
- return /* @__PURE__ */ jsx(Template2, { name, typeName, api: oas.api });
28
- }
29
- OasType.File = function({ name, typeName, templates = defaultTemplates }) {
30
- const {
31
- pluginManager,
32
- plugin: { key: pluginKey }
33
- } = useApp();
34
- const file = pluginManager.getFile({ name, extName: ".ts", pluginKey });
35
- const Template2 = templates.default;
36
- return /* @__PURE__ */ jsx(Parser, { language: "typescript", children: /* @__PURE__ */ jsxs(File, { baseName: file.baseName, path: file.path, meta: file.meta, children: [
37
- /* @__PURE__ */ jsx(File.Import, { name: ["Infer"], path: "@kubb/oas", isTypeOnly: true }),
38
- /* @__PURE__ */ jsx(File.Source, { children: /* @__PURE__ */ jsx(OasType, { Template: Template2, name, typeName }) })
39
- ] }) });
40
- };
41
- OasType.templates = defaultTemplates;
42
-
43
- // src/components/OperationSchema.tsx
44
- import transformers3 from "@kubb/core/transformers";
45
- import { print as print2 } from "@kubb/parser-ts";
46
- import * as factory3 from "@kubb/parser-ts/factory";
47
- import { Oas as Oas3 } from "@kubb/plugin-oas/components";
48
- import { useOas as useOas2, useOperation, useOperationManager } from "@kubb/plugin-oas/hooks";
49
- import { File as File3, Parser as Parser2, useApp as useApp3 } from "@kubb/react";
50
-
51
- // src/SchemaGenerator.tsx
52
- import { SchemaGenerator as Generator } from "@kubb/plugin-oas";
53
- import { Oas as Oas2 } from "@kubb/plugin-oas/components";
54
- import { App, createRoot } from "@kubb/react";
55
-
56
- // src/components/Schema.tsx
57
- import { Oas } from "@kubb/plugin-oas/components";
58
- import { File as File2, useApp as useApp2 } from "@kubb/react";
59
- import transformers2 from "@kubb/core/transformers";
60
- import { print } from "@kubb/parser-ts";
61
- import * as factory2 from "@kubb/parser-ts/factory";
62
- import { SchemaGenerator, schemaKeywords as schemaKeywords2 } from "@kubb/plugin-oas";
63
- import { useSchema } from "@kubb/plugin-oas/hooks";
64
-
65
- // src/parser/index.ts
66
- import transformers from "@kubb/core/transformers";
67
- import * as factory from "@kubb/parser-ts/factory";
68
- import { isKeyword, schemaKeywords } from "@kubb/plugin-oas";
69
- var typeKeywordMapper = {
70
- any: () => factory.keywordTypeNodes.any,
71
- unknown: () => factory.keywordTypeNodes.unknown,
72
- number: () => factory.keywordTypeNodes.number,
73
- integer: () => factory.keywordTypeNodes.number,
74
- object: (nodes) => {
75
- if (!nodes || !nodes.length) {
76
- return factory.keywordTypeNodes.object;
77
- }
78
- return factory.createTypeLiteralNode(nodes);
79
- },
80
- string: () => factory.keywordTypeNodes.string,
81
- boolean: () => factory.keywordTypeNodes.boolean,
82
- undefined: () => factory.keywordTypeNodes.undefined,
83
- nullable: void 0,
84
- null: () => factory.keywordTypeNodes.null,
85
- nullish: void 0,
86
- array: (nodes) => {
87
- if (!nodes) {
88
- return void 0;
89
- }
90
- return factory.createArrayDeclaration({ nodes });
91
- },
92
- tuple: (nodes) => {
93
- if (!nodes) {
94
- return void 0;
95
- }
96
- return factory.createTupleTypeNode(nodes);
97
- },
98
- enum: (name) => {
99
- if (!name) {
100
- return void 0;
101
- }
102
- return factory.createTypeReferenceNode(name, void 0);
103
- },
104
- union: (nodes) => {
105
- if (!nodes) {
106
- return void 0;
107
- }
108
- return factory.createUnionDeclaration({
109
- withParentheses: true,
110
- nodes
111
- });
112
- },
113
- const: (name, format) => {
114
- if (!name) {
115
- return void 0;
116
- }
117
- if (format === "number") {
118
- return factory.createLiteralTypeNode(factory.createNumericLiteral(name));
119
- }
120
- return factory.createLiteralTypeNode(factory.createStringLiteral(name.toString()));
121
- },
122
- datetime: () => factory.keywordTypeNodes.string,
123
- date: (type = "string") => type === "string" ? factory.keywordTypeNodes.string : factory.createTypeReferenceNode(factory.createIdentifier("Date")),
124
- time: (type = "string") => type === "string" ? factory.keywordTypeNodes.string : factory.createTypeReferenceNode(factory.createIdentifier("Date")),
125
- uuid: void 0,
126
- url: void 0,
127
- strict: void 0,
128
- default: void 0,
129
- and: (nodes) => {
130
- if (!nodes) {
131
- return void 0;
132
- }
133
- return factory.createIntersectionDeclaration({
134
- withParentheses: true,
135
- nodes
136
- });
137
- },
138
- describe: void 0,
139
- min: void 0,
140
- max: void 0,
141
- optional: void 0,
142
- matches: void 0,
143
- email: void 0,
144
- firstName: void 0,
145
- lastName: void 0,
146
- password: void 0,
147
- phone: void 0,
148
- readOnly: void 0,
149
- ref: (propertyName) => {
150
- if (!propertyName) {
151
- return void 0;
152
- }
153
- return factory.createTypeReferenceNode(propertyName, void 0);
154
- },
155
- blob: () => factory.createTypeReferenceNode("Blob", []),
156
- deprecated: void 0,
157
- example: void 0,
158
- schema: void 0,
159
- catchall: void 0,
160
- name: void 0
161
- };
162
- function parse(parent, current, options) {
163
- const value = typeKeywordMapper[current.keyword];
164
- if (!value) {
165
- return void 0;
166
- }
167
- if (isKeyword(current, schemaKeywords.union)) {
168
- return typeKeywordMapper.union(current.args.map((schema) => parse(current, schema, options)).filter(Boolean));
169
- }
170
- if (isKeyword(current, schemaKeywords.and)) {
171
- return typeKeywordMapper.and(current.args.map((schema) => parse(current, schema, options)).filter(Boolean));
172
- }
173
- if (isKeyword(current, schemaKeywords.array)) {
174
- return typeKeywordMapper.array(current.args.items.map((schema) => parse(current, schema, options)).filter(Boolean));
175
- }
176
- if (isKeyword(current, schemaKeywords.enum)) {
177
- return typeKeywordMapper.enum(current.args.typeName);
178
- }
179
- if (isKeyword(current, schemaKeywords.ref)) {
180
- return typeKeywordMapper.ref(current.args.name);
181
- }
182
- if (isKeyword(current, schemaKeywords.blob)) {
183
- return value();
184
- }
185
- if (isKeyword(current, schemaKeywords.tuple)) {
186
- return typeKeywordMapper.tuple(current.args.items.map((schema) => parse(current, schema, options)).filter(Boolean));
187
- }
188
- if (isKeyword(current, schemaKeywords.const)) {
189
- return typeKeywordMapper.const(current.args.name, current.args.format);
190
- }
191
- if (isKeyword(current, schemaKeywords.object)) {
192
- const properties = Object.entries(current.args?.properties || {}).filter((item) => {
193
- const schemas = item[1];
194
- return schemas && typeof schemas.map === "function";
195
- }).map(([name, schemas]) => {
196
- const nameSchema = schemas.find((schema) => schema.keyword === schemaKeywords.name);
197
- const mappedName = nameSchema?.args || name;
198
- if (options.mapper?.[mappedName]) {
199
- return options.mapper?.[mappedName];
200
- }
201
- const isNullish = schemas.some((schema) => schema.keyword === schemaKeywords.nullish);
202
- const isNullable = schemas.some((schema) => schema.keyword === schemaKeywords.nullable);
203
- const isOptional = schemas.some((schema) => schema.keyword === schemaKeywords.optional);
204
- const isReadonly = schemas.some((schema) => schema.keyword === schemaKeywords.readOnly);
205
- const describeSchema = schemas.find((schema) => schema.keyword === schemaKeywords.describe);
206
- const deprecatedSchema = schemas.find((schema) => schema.keyword === schemaKeywords.deprecated);
207
- const defaultSchema = schemas.find((schema) => schema.keyword === schemaKeywords.default);
208
- const exampleSchema = schemas.find((schema) => schema.keyword === schemaKeywords.example);
209
- const schemaSchema = schemas.find((schema) => schema.keyword === schemaKeywords.schema);
210
- let type = schemas.map((schema) => parse(current, schema, options)).filter(Boolean)[0];
211
- if (isNullable) {
212
- type = factory.createUnionDeclaration({
213
- nodes: [type, factory.keywordTypeNodes.null]
214
- });
215
- }
216
- if (isNullish && ["undefined", "questionTokenAndUndefined"].includes(options.optionalType)) {
217
- type = factory.createUnionDeclaration({
218
- nodes: [type, factory.keywordTypeNodes.undefined]
219
- });
220
- }
221
- if (isOptional && ["undefined", "questionTokenAndUndefined"].includes(options.optionalType)) {
222
- type = factory.createUnionDeclaration({
223
- nodes: [type, factory.keywordTypeNodes.undefined]
224
- });
225
- }
226
- const propertySignature = factory.createPropertySignature({
227
- questionToken: isOptional || isNullish ? ["questionToken", "questionTokenAndUndefined"].includes(options.optionalType) : false,
228
- name: mappedName,
229
- type,
230
- readOnly: isReadonly
231
- });
232
- return factory.appendJSDocToNode({
233
- node: propertySignature,
234
- comments: [
235
- describeSchema ? `@description ${transformers.jsStringEscape(describeSchema.args)}` : void 0,
236
- deprecatedSchema ? "@deprecated" : void 0,
237
- defaultSchema ? `@default ${defaultSchema.args}` : void 0,
238
- exampleSchema ? `@example ${exampleSchema.args}` : void 0,
239
- schemaSchema?.args?.type || schemaSchema?.args?.format ? [`@type ${schemaSchema?.args?.type || "unknown"}${!isOptional ? "" : " | undefined"}`, schemaSchema?.args?.format].filter(Boolean).join(", ") : void 0
240
- ].filter(Boolean)
241
- });
242
- });
243
- const additionalProperties = current.args?.additionalProperties?.length ? factory.createIndexSignature(
244
- current.args.additionalProperties.map((schema) => parse(current, schema, options)).filter(Boolean).at(0)
245
- ) : void 0;
246
- return typeKeywordMapper.object([...properties, additionalProperties].filter(Boolean));
247
- }
248
- if (isKeyword(current, schemaKeywords.datetime)) {
249
- return typeKeywordMapper.datetime();
250
- }
251
- if (isKeyword(current, schemaKeywords.date)) {
252
- return typeKeywordMapper.date(current.args.type);
253
- }
254
- if (isKeyword(current, schemaKeywords.time)) {
255
- return typeKeywordMapper.time(current.args.type);
256
- }
257
- if (current.keyword in typeKeywordMapper) {
258
- return value();
259
- }
260
- return void 0;
261
- }
262
-
263
- // src/components/Schema.tsx
264
- import { jsx as jsx2 } from "@kubb/react/jsx-runtime";
265
- function Schema(props) {
266
- const { keysToOmit, description } = props;
267
- const { tree, name } = useSchema();
268
- const {
269
- pluginManager,
270
- plugin: {
271
- options: { mapper, enumType, optionalType }
272
- }
273
- } = useApp2();
274
- const resolvedName = pluginManager.resolveName({
275
- name,
276
- pluginKey: [pluginTsName],
277
- type: "function"
278
- });
279
- const typeName = pluginManager.resolveName({
280
- name,
281
- pluginKey: [pluginTsName],
282
- type: "type"
283
- });
284
- const nodes = [];
285
- const extraNodes = [];
286
- if (!tree.length) {
287
- return "";
288
- }
289
- const isNullish = tree.some((item) => item.keyword === schemaKeywords2.nullish);
290
- const isNullable = tree.some((item) => item.keyword === schemaKeywords2.nullable);
291
- const isOptional = tree.some((item) => item.keyword === schemaKeywords2.optional);
292
- let type = tree.map((schema) => parse(void 0, schema, { name: resolvedName, typeName, description, keysToOmit, optionalType, enumType, mapper })).filter(Boolean).at(0) || typeKeywordMapper.undefined();
293
- if (isNullable) {
294
- type = factory2.createUnionDeclaration({
295
- nodes: [type, factory2.keywordTypeNodes.null]
296
- });
297
- }
298
- if (isNullish && ["undefined", "questionTokenAndUndefined"].includes(optionalType)) {
299
- type = factory2.createUnionDeclaration({
300
- nodes: [type, factory2.keywordTypeNodes.undefined]
301
- });
302
- }
303
- if (isOptional && ["undefined", "questionTokenAndUndefined"].includes(optionalType)) {
304
- type = factory2.createUnionDeclaration({
305
- nodes: [type, factory2.keywordTypeNodes.undefined]
306
- });
307
- }
308
- const node = factory2.createTypeAliasDeclaration({
309
- modifiers: [factory2.modifiers.export],
310
- name: resolvedName,
311
- type: keysToOmit?.length ? factory2.createOmitDeclaration({
312
- keys: keysToOmit,
313
- type,
314
- nonNullable: true
315
- }) : type
316
- });
317
- const enumSchemas = SchemaGenerator.deepSearch(tree, schemaKeywords2.enum);
318
- if (enumSchemas) {
319
- enumSchemas.forEach((enumSchema) => {
320
- extraNodes.push(
321
- ...factory2.createEnumDeclaration({
322
- name: transformers2.camelCase(enumSchema.args.name),
323
- typeName: enumSchema.args.typeName,
324
- enums: enumSchema.args.items.map((item) => item.value === void 0 ? void 0 : [transformers2.trimQuotes(item.name?.toString()), item.value]).filter(Boolean),
325
- type: enumType
326
- })
327
- );
328
- });
329
- }
330
- nodes.push(
331
- factory2.appendJSDocToNode({
332
- node,
333
- comments: [description ? `@description ${transformers2.jsStringEscape(description)}` : void 0].filter(Boolean)
334
- })
335
- );
336
- const filterdNodes = nodes.filter(
337
- (node2) => !extraNodes.some(
338
- (extraNode) => extraNode?.name?.escapedText === node2?.name?.escapedText
339
- )
340
- );
341
- return print([...extraNodes, ...filterdNodes]);
342
- }
343
- Schema.File = function({}) {
344
- const { pluginManager } = useApp2();
345
- const { schema } = useSchema();
346
- return /* @__PURE__ */ jsx2(Oas.Schema.File, { output: pluginManager.config.output.path, children: /* @__PURE__ */ jsx2(File2.Source, { children: /* @__PURE__ */ jsx2(Schema, { description: schema?.description }) }) });
347
- };
348
-
349
- // src/SchemaGenerator.tsx
350
- import { jsx as jsx3 } from "@kubb/react/jsx-runtime";
351
- var SchemaGenerator2 = class extends Generator {
352
- async schema(name, schema, options) {
353
- const { oas, pluginManager, plugin, mode, output } = this.context;
354
- const root = createRoot({
355
- logger: pluginManager.logger
356
- });
357
- const tree = this.parse({ schema, name });
358
- root.render(
359
- /* @__PURE__ */ jsx3(App, { pluginManager, plugin: { ...plugin, options }, mode, children: /* @__PURE__ */ jsx3(Oas2, { oas, children: /* @__PURE__ */ jsx3(Oas2.Schema, { name, value: schema, tree, children: /* @__PURE__ */ jsx3(Schema.File, {}) }) }) })
360
- );
361
- return root.files;
362
- }
363
- };
364
-
365
- // src/components/OperationSchema.tsx
366
- import { jsx as jsx4, jsxs as jsxs2 } from "@kubb/react/jsx-runtime";
367
- function printCombinedSchema({
368
- name,
369
- operation,
370
- schemas,
371
- pluginManager
372
- }) {
373
- const properties = {};
374
- if (schemas.response) {
375
- const identifier = pluginManager.resolveName({
376
- name: schemas.response.name,
377
- pluginKey: [pluginTsName],
378
- type: "function"
379
- });
380
- properties["response"] = factory3.createTypeReferenceNode(factory3.createIdentifier(identifier), void 0);
381
- }
382
- if (schemas.request) {
383
- const identifier = pluginManager.resolveName({
384
- name: schemas.request.name,
385
- pluginKey: [pluginTsName],
386
- type: "function"
387
- });
388
- properties["request"] = factory3.createTypeReferenceNode(factory3.createIdentifier(identifier), void 0);
389
- }
390
- if (schemas.pathParams) {
391
- const identifier = pluginManager.resolveName({
392
- name: schemas.pathParams.name,
393
- pluginKey: [pluginTsName],
394
- type: "function"
395
- });
396
- properties["pathParams"] = factory3.createTypeReferenceNode(factory3.createIdentifier(identifier), void 0);
397
- }
398
- if (schemas.queryParams) {
399
- const identifier = pluginManager.resolveName({
400
- name: schemas.queryParams.name,
401
- pluginKey: [pluginTsName],
402
- type: "function"
403
- });
404
- properties["queryParams"] = factory3.createTypeReferenceNode(factory3.createIdentifier(identifier), void 0);
405
- }
406
- if (schemas.headerParams) {
407
- const identifier = pluginManager.resolveName({
408
- name: schemas.headerParams.name,
409
- pluginKey: [pluginTsName],
410
- type: "function"
411
- });
412
- properties["headerParams"] = factory3.createTypeReferenceNode(factory3.createIdentifier(identifier), void 0);
413
- }
414
- if (schemas.errors) {
415
- properties["errors"] = factory3.createUnionDeclaration({
416
- nodes: schemas.errors.map((error) => {
417
- const identifier = pluginManager.resolveName({
418
- name: error.name,
419
- pluginKey: [pluginTsName],
420
- type: "function"
421
- });
422
- return factory3.createTypeReferenceNode(factory3.createIdentifier(identifier), void 0);
423
- })
424
- });
425
- }
426
- const namespaceNode = factory3.createTypeAliasDeclaration({
427
- name: operation.method === "get" ? `${name}Query` : `${name}Mutation`,
428
- type: factory3.createTypeLiteralNode(
429
- Object.keys(properties).map((key) => {
430
- const type = properties[key];
431
- if (!type) {
432
- return void 0;
433
- }
434
- return factory3.createPropertySignature({
435
- name: transformers3.pascalCase(key),
436
- type
437
- });
438
- }).filter(Boolean)
439
- ),
440
- modifiers: [factory3.modifiers.export]
441
- });
442
- return print2(namespaceNode);
443
- }
444
- function OperationSchema({ keysToOmit, description }) {
445
- return /* @__PURE__ */ jsx4(Schema, { keysToOmit, description });
446
- }
447
- OperationSchema.File = function({}) {
448
- const { pluginManager, plugin, mode, fileManager } = useApp3();
449
- const oas = useOas2();
450
- const { getSchemas, getFile, getName } = useOperationManager();
451
- const operation = useOperation();
452
- const file = getFile(operation);
453
- const schemas = getSchemas(operation);
454
- const factoryName = getName(operation, { type: "type" });
455
- const generator = new SchemaGenerator2(plugin.options, {
456
- oas,
457
- plugin,
458
- pluginManager,
459
- mode,
460
- override: plugin.options.override
461
- });
462
- const items = [schemas.pathParams, schemas.queryParams, schemas.headerParams, schemas.statusCodes, schemas.request, schemas.response].flat().filter(Boolean);
463
- const mapItem = ({ name, schema, description, keysToOmit, ...options }, i) => {
464
- const tree = generator.parse({ schema, name });
465
- return /* @__PURE__ */ jsxs2(Oas3.Schema, { name, value: schema, tree, children: [
466
- mode === "split" && /* @__PURE__ */ jsx4(Oas3.Schema.Imports, { extName: plugin.options.extName, isTypeOnly: true }),
467
- /* @__PURE__ */ jsx4(File3.Source, { children: /* @__PURE__ */ jsx4(OperationSchema, { description, keysToOmit }) })
468
- ] }, i);
469
- };
470
- return /* @__PURE__ */ jsx4(Parser2, { language: "typescript", children: /* @__PURE__ */ jsxs2(File3, { baseName: file.baseName, path: file.path, meta: file.meta, children: [
471
- items.map(mapItem),
472
- /* @__PURE__ */ jsx4(File3.Source, { children: printCombinedSchema({ name: factoryName, operation, schemas, pluginManager }) })
473
- ] }) });
474
- };
475
-
476
- // src/OperationGenerator.tsx
477
- import { jsx as jsx5 } from "@kubb/react/jsx-runtime";
478
- var OperationGenerator = class extends Generator2 {
479
- async all(operations) {
480
- const { oas, pluginManager, plugin, mode } = this.context;
481
- const root = createRoot2({
482
- logger: pluginManager.logger
483
- });
484
- root.render(
485
- /* @__PURE__ */ jsx5(App2, { pluginManager, plugin, mode, children: /* @__PURE__ */ jsx5(Oas4, { oas, operations, generator: this, children: plugin.options.oasType && /* @__PURE__ */ jsx5(OasType.File, { name: "oas", typeName: "Oas" }) }) })
486
- );
487
- return root.files;
488
- }
489
- async operation(operation, options) {
490
- const { oas, pluginManager, plugin, mode } = this.context;
491
- const root = createRoot2({
492
- logger: pluginManager.logger
493
- });
494
- root.render(
495
- /* @__PURE__ */ jsx5(App2, { pluginManager, plugin: { ...plugin, options }, mode, children: /* @__PURE__ */ jsx5(Oas4, { oas, operations: [operation], generator: this, children: /* @__PURE__ */ jsx5(Oas4.Operation, { operation, children: /* @__PURE__ */ jsx5(OperationSchema.File, {}) }) }) })
496
- );
497
- return root.files;
498
- }
499
- };
500
-
501
- // src/plugin.ts
502
- var pluginTsName = "plugin-ts";
503
- var pluginTs = createPlugin((options) => {
504
- const {
505
- output = { path: "types" },
506
- group,
507
- exclude = [],
508
- include,
509
- override = [],
510
- enumType = "asConst",
511
- enumSuffix = "",
512
- dateType = "string",
513
- unknownType = "any",
514
- optionalType = "questionToken",
515
- transformers: transformers4 = {},
516
- oasType = false,
517
- mapper = {}
518
- } = options;
519
- const template = group?.output ? group.output : `${output.path}/{{tag}}Controller`;
520
- return {
521
- name: pluginTsName,
522
- options: {
523
- extName: output.extName,
524
- transformers: transformers4,
525
- dateType,
526
- optionalType,
527
- oasType,
528
- enumType,
529
- enumSuffix,
530
- // keep the used enumnames between SchemaGenerator and OperationGenerator per plugin(pluginKey)
531
- usedEnumNames: {},
532
- unknownType,
533
- override,
534
- mapper
535
- },
536
- pre: [pluginOasName],
537
- resolvePath(baseName, pathMode, options2) {
538
- const root = path.resolve(this.config.root, this.config.output.path);
539
- const mode = pathMode ?? FileManager.getMode(path.resolve(root, output.path));
540
- if (mode === "single") {
541
- return path.resolve(root, output.path);
542
- }
543
- if (options2?.tag && group?.type === "tag") {
544
- const tag = camelCase(options2.tag);
545
- return path.resolve(root, renderTemplate(template, { tag }), baseName);
546
- }
547
- return path.resolve(root, output.path, baseName);
548
- },
549
- resolveName(name, type) {
550
- const resolvedName = pascalCase(name, { isFile: type === "file" });
551
- if (type) {
552
- return transformers4?.name?.(resolvedName, type) || resolvedName;
553
- }
554
- return resolvedName;
555
- },
556
- async buildStart() {
557
- const [swaggerPlugin] = PluginManager.getDependedPlugins(this.plugins, [pluginOasName]);
558
- const oas = await swaggerPlugin.context.getOas();
559
- const root = path.resolve(this.config.root, this.config.output.path);
560
- const mode = FileManager.getMode(path.resolve(root, output.path));
561
- const schemaGenerator = new SchemaGenerator2(this.plugin.options, {
562
- oas,
563
- pluginManager: this.pluginManager,
564
- plugin: this.plugin,
565
- contentType: swaggerPlugin.context.contentType,
566
- include: void 0,
567
- override,
568
- mode,
569
- output: output.path
570
- });
571
- const schemaFiles = await schemaGenerator.build();
572
- await this.addFile(...schemaFiles);
573
- const operationGenerator = new OperationGenerator(this.plugin.options, {
574
- oas,
575
- pluginManager: this.pluginManager,
576
- plugin: this.plugin,
577
- contentType: swaggerPlugin.context.contentType,
578
- exclude,
579
- include,
580
- override,
581
- mode
582
- });
583
- const operationFiles = await operationGenerator.build();
584
- await this.addFile(...operationFiles);
585
- },
586
- async buildEnd() {
587
- if (this.config.output.write === false) {
588
- return;
589
- }
590
- const root = path.resolve(this.config.root, this.config.output.path);
591
- await this.fileManager.addIndexes({
592
- root,
593
- output,
594
- meta: { pluginKey: this.plugin.key },
595
- logger: this.logger
596
- });
597
- }
598
- };
599
- });
600
-
601
- export {
602
- OasType,
603
- Schema,
604
- OperationSchema,
605
- pluginTsName,
606
- pluginTs
607
- };
608
- //# sourceMappingURL=chunk-PU22CLWV.js.map