@kubb/plugin-ts 3.16.2 → 3.16.3

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 (39) hide show
  1. package/dist/components-6F5RoYuJ.js +2240 -0
  2. package/dist/components-6F5RoYuJ.js.map +1 -0
  3. package/dist/components-B-Jx1kI5.cjs +2256 -0
  4. package/dist/components-B-Jx1kI5.cjs.map +1 -0
  5. package/dist/components.cjs +3 -15
  6. package/dist/components.d.cts +40 -26
  7. package/dist/components.d.ts +40 -26
  8. package/dist/components.js +3 -3
  9. package/dist/generators.cjs +4 -16
  10. package/dist/generators.d.cts +8 -9
  11. package/dist/generators.d.ts +8 -9
  12. package/dist/generators.js +4 -4
  13. package/dist/index.cjs +4 -17
  14. package/dist/index.d.cts +6 -8
  15. package/dist/index.d.ts +6 -8
  16. package/dist/index.js +3 -6
  17. package/dist/plugin-BXxI6FcR.cjs +378 -0
  18. package/dist/plugin-BXxI6FcR.cjs.map +1 -0
  19. package/dist/plugin-DXUISuTd.js +355 -0
  20. package/dist/plugin-DXUISuTd.js.map +1 -0
  21. package/dist/types-BL0qEGbB.d.cts +1223 -0
  22. package/dist/types-DFDnGwpy.d.ts +1223 -0
  23. package/package.json +22 -27
  24. package/dist/chunk-AUYOLJ62.js +0 -358
  25. package/dist/chunk-AUYOLJ62.js.map +0 -1
  26. package/dist/chunk-NAZDWNS6.cjs +0 -387
  27. package/dist/chunk-NAZDWNS6.cjs.map +0 -1
  28. package/dist/chunk-NDI35YW5.cjs +0 -2611
  29. package/dist/chunk-NDI35YW5.cjs.map +0 -1
  30. package/dist/chunk-V4C2DOV5.js +0 -2585
  31. package/dist/chunk-V4C2DOV5.js.map +0 -1
  32. package/dist/components.cjs.map +0 -1
  33. package/dist/components.js.map +0 -1
  34. package/dist/generators.cjs.map +0 -1
  35. package/dist/generators.js.map +0 -1
  36. package/dist/index.cjs.map +0 -1
  37. package/dist/index.js.map +0 -1
  38. package/dist/types-DkvPgLAK.d.cts +0 -116
  39. package/dist/types-DkvPgLAK.d.ts +0 -116
@@ -0,0 +1,355 @@
1
+ import { OasType, Type } from "./components-6F5RoYuJ.js";
2
+ import path from "node:path";
3
+ import { FileManager, PluginManager, createPlugin } from "@kubb/core";
4
+ import transformers, { camelCase, pascalCase } from "@kubb/core/transformers";
5
+ import { OperationGenerator, SchemaGenerator, createReactGenerator, pluginOasName } from "@kubb/plugin-oas";
6
+ import { print } from "@kubb/parser-ts";
7
+ import * as factory from "@kubb/parser-ts/factory";
8
+ import { Oas } from "@kubb/plugin-oas/components";
9
+ import { useOas, useOperationManager, useSchemaManager } from "@kubb/plugin-oas/hooks";
10
+ import { getBanner, getFooter } from "@kubb/plugin-oas/utils";
11
+ import { File, useApp } from "@kubb/react";
12
+ import { jsx, jsxs } from "@kubb/react/jsx-runtime";
13
+
14
+ //#region src/generators/typeGenerator.tsx
15
+ function printCombinedSchema({ name, schemas, pluginManager }) {
16
+ const properties = {};
17
+ if (schemas.response) properties["response"] = factory.createUnionDeclaration({ nodes: schemas.responses.map((res) => {
18
+ const identifier = pluginManager.resolveName({
19
+ name: res.name,
20
+ pluginKey: [pluginTsName],
21
+ type: "function"
22
+ });
23
+ return factory.createTypeReferenceNode(factory.createIdentifier(identifier), void 0);
24
+ }) });
25
+ if (schemas.request) {
26
+ const identifier = pluginManager.resolveName({
27
+ name: schemas.request.name,
28
+ pluginKey: [pluginTsName],
29
+ type: "function"
30
+ });
31
+ properties["request"] = factory.createTypeReferenceNode(factory.createIdentifier(identifier), void 0);
32
+ }
33
+ if (schemas.pathParams) {
34
+ const identifier = pluginManager.resolveName({
35
+ name: schemas.pathParams.name,
36
+ pluginKey: [pluginTsName],
37
+ type: "function"
38
+ });
39
+ properties["pathParams"] = factory.createTypeReferenceNode(factory.createIdentifier(identifier), void 0);
40
+ }
41
+ if (schemas.queryParams) {
42
+ const identifier = pluginManager.resolveName({
43
+ name: schemas.queryParams.name,
44
+ pluginKey: [pluginTsName],
45
+ type: "function"
46
+ });
47
+ properties["queryParams"] = factory.createTypeReferenceNode(factory.createIdentifier(identifier), void 0);
48
+ }
49
+ if (schemas.headerParams) {
50
+ const identifier = pluginManager.resolveName({
51
+ name: schemas.headerParams.name,
52
+ pluginKey: [pluginTsName],
53
+ type: "function"
54
+ });
55
+ properties["headerParams"] = factory.createTypeReferenceNode(factory.createIdentifier(identifier), void 0);
56
+ }
57
+ if (schemas.errors) properties["errors"] = factory.createUnionDeclaration({ nodes: schemas.errors.map((error) => {
58
+ const identifier = pluginManager.resolveName({
59
+ name: error.name,
60
+ pluginKey: [pluginTsName],
61
+ type: "function"
62
+ });
63
+ return factory.createTypeReferenceNode(factory.createIdentifier(identifier), void 0);
64
+ }) });
65
+ const namespaceNode = factory.createTypeAliasDeclaration({
66
+ name,
67
+ type: factory.createTypeLiteralNode(Object.keys(properties).map((key) => {
68
+ const type = properties[key];
69
+ if (!type) return void 0;
70
+ return factory.createPropertySignature({
71
+ name: transformers.pascalCase(key),
72
+ type
73
+ });
74
+ }).filter(Boolean)),
75
+ modifiers: [factory.modifiers.export]
76
+ });
77
+ return print([namespaceNode]);
78
+ }
79
+ const typeGenerator = createReactGenerator({
80
+ name: "typescript",
81
+ Operation({ operation, options }) {
82
+ const { mapper, enumType, syntaxType, optionalType } = options;
83
+ const { plugin, pluginManager, mode } = useApp();
84
+ const oas = useOas();
85
+ const { getSchemas, getFile, getName, getGroup } = useOperationManager();
86
+ const schemaManager = useSchemaManager();
87
+ const file = getFile(operation);
88
+ const schemas = getSchemas(operation);
89
+ const type = getName(operation, {
90
+ type: "function",
91
+ pluginKey: [pluginTsName]
92
+ });
93
+ const combinedSchemaName = operation.method === "get" ? `${type}Query` : `${type}Mutation`;
94
+ const schemaGenerator = new SchemaGenerator(options, {
95
+ oas,
96
+ plugin,
97
+ pluginManager,
98
+ mode,
99
+ override: options.override
100
+ });
101
+ const operationSchemas = [
102
+ schemas.pathParams,
103
+ schemas.queryParams,
104
+ schemas.headerParams,
105
+ schemas.statusCodes,
106
+ schemas.request,
107
+ schemas.response
108
+ ].flat().filter(Boolean);
109
+ const mapOperationSchema = ({ name, schema: schemaObject, description, keysToOmit,...options$1 }) => {
110
+ const tree = schemaGenerator.parse({
111
+ schemaObject,
112
+ name
113
+ });
114
+ const imports = schemaManager.getImports(tree);
115
+ const group = options$1.operation ? getGroup(options$1.operation) : void 0;
116
+ const type$1 = {
117
+ name: schemaManager.getName(name, { type: "type" }),
118
+ typedName: schemaManager.getName(name, { type: "type" }),
119
+ file: schemaManager.getFile(options$1.operationName || name, { group })
120
+ };
121
+ return /* @__PURE__ */ jsxs(Oas.Schema, {
122
+ name,
123
+ schemaObject,
124
+ tree,
125
+ children: [mode === "split" && imports.map((imp) => /* @__PURE__ */ jsx(File.Import, {
126
+ root: file.path,
127
+ path: imp.path,
128
+ name: imp.name,
129
+ isTypeOnly: true
130
+ }, [
131
+ name,
132
+ imp.name,
133
+ imp.path,
134
+ imp.isTypeOnly
135
+ ].join("-"))), /* @__PURE__ */ jsx(Type, {
136
+ name: type$1.name,
137
+ typedName: type$1.typedName,
138
+ description,
139
+ tree,
140
+ schema: schemaObject,
141
+ mapper,
142
+ enumType,
143
+ optionalType,
144
+ keysToOmit,
145
+ syntaxType
146
+ })]
147
+ }, [name, schemaObject.$ref].join("-"));
148
+ };
149
+ return /* @__PURE__ */ jsxs(File, {
150
+ baseName: file.baseName,
151
+ path: file.path,
152
+ meta: file.meta,
153
+ banner: getBanner({
154
+ oas,
155
+ output: plugin.options.output,
156
+ config: pluginManager.config
157
+ }),
158
+ footer: getFooter({
159
+ oas,
160
+ output: plugin.options.output
161
+ }),
162
+ children: [operationSchemas.map(mapOperationSchema), /* @__PURE__ */ jsx(File.Source, {
163
+ name: combinedSchemaName,
164
+ isExportable: true,
165
+ isIndexable: true,
166
+ isTypeOnly: true,
167
+ children: printCombinedSchema({
168
+ name: combinedSchemaName,
169
+ schemas,
170
+ pluginManager
171
+ })
172
+ })]
173
+ });
174
+ },
175
+ Schema({ schema, options }) {
176
+ const { mapper, enumType, syntaxType, optionalType } = options;
177
+ const { mode, plugin: { options: { output } }, pluginManager } = useApp();
178
+ const oas = useOas();
179
+ const { getName, getImports, getFile } = useSchemaManager();
180
+ const imports = getImports(schema.tree);
181
+ if (enumType === "asPascalConst") console.warn(`enumType '${enumType}' is deprecated`);
182
+ const type = {
183
+ name: getName(schema.name, { type: "function" }),
184
+ typedName: getName(schema.name, { type: "type" }),
185
+ file: getFile(schema.name)
186
+ };
187
+ return /* @__PURE__ */ jsxs(File, {
188
+ baseName: type.file.baseName,
189
+ path: type.file.path,
190
+ meta: type.file.meta,
191
+ banner: getBanner({
192
+ oas,
193
+ output,
194
+ config: pluginManager.config
195
+ }),
196
+ footer: getFooter({
197
+ oas,
198
+ output
199
+ }),
200
+ children: [mode === "split" && imports.map((imp) => /* @__PURE__ */ jsx(File.Import, {
201
+ root: type.file.path,
202
+ path: imp.path,
203
+ name: imp.name,
204
+ isTypeOnly: true
205
+ }, [
206
+ schema.name,
207
+ imp.path,
208
+ imp.isTypeOnly
209
+ ].join("-"))), /* @__PURE__ */ jsx(Type, {
210
+ name: type.name,
211
+ typedName: type.typedName,
212
+ description: schema.value.description,
213
+ tree: schema.tree,
214
+ schema: schema.value,
215
+ mapper,
216
+ enumType,
217
+ optionalType,
218
+ syntaxType
219
+ })]
220
+ });
221
+ }
222
+ });
223
+
224
+ //#endregion
225
+ //#region src/generators/oasGenerator.tsx
226
+ const oasGenerator = createReactGenerator({
227
+ name: "oas",
228
+ Operations() {
229
+ const { pluginManager, plugin: { options: { output }, key: pluginKey } } = useApp();
230
+ const oas = useOas();
231
+ const file = pluginManager.getFile({
232
+ name: "oas",
233
+ extname: ".ts",
234
+ pluginKey
235
+ });
236
+ return /* @__PURE__ */ jsxs(File, {
237
+ baseName: file.baseName,
238
+ path: file.path,
239
+ meta: file.meta,
240
+ banner: getBanner({
241
+ oas,
242
+ output,
243
+ config: pluginManager.config
244
+ }),
245
+ footer: getFooter({
246
+ oas,
247
+ output
248
+ }),
249
+ children: [/* @__PURE__ */ jsx(File.Import, {
250
+ name: ["Infer"],
251
+ path: "@kubb/oas",
252
+ isTypeOnly: true
253
+ }), /* @__PURE__ */ jsx(OasType, {
254
+ name: "oas",
255
+ typeName: "Oas",
256
+ api: oas.api
257
+ })]
258
+ });
259
+ }
260
+ });
261
+
262
+ //#endregion
263
+ //#region src/plugin.ts
264
+ const pluginTsName = "plugin-ts";
265
+ const pluginTs = createPlugin((options) => {
266
+ const { output = {
267
+ path: "types",
268
+ barrelType: "named"
269
+ }, group, exclude = [], include, override = [], enumType = "asConst", enumSuffix = "enum", dateType = "string", unknownType = "any", optionalType = "questionToken", emptySchemaType = unknownType, syntaxType = "type", transformers: transformers$1 = {}, oasType = false, mapper = {}, generators = [typeGenerator, oasType === "infer" ? oasGenerator : void 0].filter(Boolean), contentType } = options;
270
+ return {
271
+ name: pluginTsName,
272
+ options: {
273
+ output,
274
+ transformers: transformers$1,
275
+ dateType,
276
+ optionalType,
277
+ oasType,
278
+ enumType,
279
+ enumSuffix,
280
+ usedEnumNames: {},
281
+ unknownType,
282
+ emptySchemaType,
283
+ syntaxType,
284
+ group,
285
+ override,
286
+ mapper
287
+ },
288
+ pre: [pluginOasName],
289
+ resolvePath(baseName, pathMode, options$1) {
290
+ const root = path.resolve(this.config.root, this.config.output.path);
291
+ const mode = pathMode ?? FileManager.getMode(path.resolve(root, output.path));
292
+ if (mode === "single")
293
+ /**
294
+ * when output is a file then we will always append to the same file(output file), see fileManager.addOrAppend
295
+ * Other plugins then need to call addOrAppend instead of just add from the fileManager class
296
+ */
297
+ return path.resolve(root, output.path);
298
+ if (group && (options$1?.group?.path || options$1?.group?.tag)) {
299
+ const groupName = group?.name ? group.name : (ctx) => {
300
+ if (group?.type === "path") return `${ctx.group.split("/")[1]}`;
301
+ return `${camelCase(ctx.group)}Controller`;
302
+ };
303
+ return path.resolve(root, output.path, groupName({ group: group.type === "path" ? options$1.group.path : options$1.group.tag }), baseName);
304
+ }
305
+ return path.resolve(root, output.path, baseName);
306
+ },
307
+ resolveName(name, type) {
308
+ const resolvedName = pascalCase(name, { isFile: type === "file" });
309
+ if (type) return transformers$1?.name?.(resolvedName, type) || resolvedName;
310
+ return resolvedName;
311
+ },
312
+ async buildStart() {
313
+ const [swaggerPlugin] = PluginManager.getDependedPlugins(this.plugins, [pluginOasName]);
314
+ const oas = await swaggerPlugin.context.getOas();
315
+ const root = path.resolve(this.config.root, this.config.output.path);
316
+ const mode = FileManager.getMode(path.resolve(root, output.path));
317
+ const schemaGenerator = new SchemaGenerator(this.plugin.options, {
318
+ oas,
319
+ pluginManager: this.pluginManager,
320
+ plugin: this.plugin,
321
+ contentType,
322
+ include: void 0,
323
+ override,
324
+ mode,
325
+ output: output.path
326
+ });
327
+ const schemaFiles = await schemaGenerator.build(...generators);
328
+ await this.addFile(...schemaFiles);
329
+ const operationGenerator = new OperationGenerator(this.plugin.options, {
330
+ oas,
331
+ pluginManager: this.pluginManager,
332
+ plugin: this.plugin,
333
+ contentType,
334
+ exclude,
335
+ include,
336
+ override,
337
+ mode
338
+ });
339
+ const operationFiles = await operationGenerator.build(...generators);
340
+ await this.addFile(...operationFiles);
341
+ const barrelFiles = await this.fileManager.getBarrelFiles({
342
+ type: output.barrelType ?? "named",
343
+ root,
344
+ output,
345
+ meta: { pluginKey: this.plugin.key },
346
+ logger: this.logger
347
+ });
348
+ await this.addFile(...barrelFiles);
349
+ }
350
+ };
351
+ });
352
+
353
+ //#endregion
354
+ export { oasGenerator, pluginTs, pluginTsName, typeGenerator };
355
+ //# sourceMappingURL=plugin-DXUISuTd.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin-DXUISuTd.js","names":["properties: Record<string, ts.TypeNode>","options","type","options","groupName: Group['name']","transformers"],"sources":["../src/generators/typeGenerator.tsx","../src/generators/oasGenerator.tsx","../src/plugin.ts"],"sourcesContent":["import type { PluginManager } from '@kubb/core'\nimport transformers from '@kubb/core/transformers'\nimport { print } from '@kubb/parser-ts'\nimport * as factory from '@kubb/parser-ts/factory'\nimport { createReactGenerator, type OperationSchemas, type OperationSchema as OperationSchemaType, SchemaGenerator } from '@kubb/plugin-oas'\nimport { Oas } from '@kubb/plugin-oas/components'\nimport { useOas, useOperationManager, useSchemaManager } from '@kubb/plugin-oas/hooks'\nimport { getBanner, getFooter } from '@kubb/plugin-oas/utils'\nimport { File, useApp } from '@kubb/react'\nimport type ts from 'typescript'\nimport { Type } from '../components'\nimport { pluginTsName } from '../plugin.ts'\nimport type { PluginTs } from '../types'\n\nfunction printCombinedSchema({ name, schemas, pluginManager }: { name: string; schemas: OperationSchemas; pluginManager: PluginManager }): string {\n const properties: Record<string, ts.TypeNode> = {}\n\n if (schemas.response) {\n properties['response'] = factory.createUnionDeclaration({\n nodes: schemas.responses.map((res) => {\n const identifier = pluginManager.resolveName({\n name: res.name,\n pluginKey: [pluginTsName],\n type: 'function',\n })\n\n return factory.createTypeReferenceNode(factory.createIdentifier(identifier), undefined)\n }),\n })!\n }\n\n if (schemas.request) {\n const identifier = pluginManager.resolveName({\n name: schemas.request.name,\n pluginKey: [pluginTsName],\n type: 'function',\n })\n properties['request'] = factory.createTypeReferenceNode(factory.createIdentifier(identifier), undefined)\n }\n\n if (schemas.pathParams) {\n const identifier = pluginManager.resolveName({\n name: schemas.pathParams.name,\n pluginKey: [pluginTsName],\n type: 'function',\n })\n properties['pathParams'] = factory.createTypeReferenceNode(factory.createIdentifier(identifier), undefined)\n }\n\n if (schemas.queryParams) {\n const identifier = pluginManager.resolveName({\n name: schemas.queryParams.name,\n pluginKey: [pluginTsName],\n type: 'function',\n })\n properties['queryParams'] = factory.createTypeReferenceNode(factory.createIdentifier(identifier), undefined)\n }\n\n if (schemas.headerParams) {\n const identifier = pluginManager.resolveName({\n name: schemas.headerParams.name,\n pluginKey: [pluginTsName],\n type: 'function',\n })\n properties['headerParams'] = factory.createTypeReferenceNode(factory.createIdentifier(identifier), undefined)\n }\n\n if (schemas.errors) {\n properties['errors'] = factory.createUnionDeclaration({\n nodes: schemas.errors.map((error) => {\n const identifier = pluginManager.resolveName({\n name: error.name,\n pluginKey: [pluginTsName],\n type: 'function',\n })\n\n return factory.createTypeReferenceNode(factory.createIdentifier(identifier), undefined)\n }),\n })!\n }\n\n const namespaceNode = factory.createTypeAliasDeclaration({\n name,\n type: factory.createTypeLiteralNode(\n Object.keys(properties)\n .map((key) => {\n const type = properties[key]\n if (!type) {\n return undefined\n }\n\n return factory.createPropertySignature({\n name: transformers.pascalCase(key),\n type,\n })\n })\n .filter(Boolean),\n ),\n modifiers: [factory.modifiers.export],\n })\n\n return print([namespaceNode])\n}\n\nexport const typeGenerator = createReactGenerator<PluginTs>({\n name: 'typescript',\n Operation({ operation, options }) {\n const { mapper, enumType, syntaxType, optionalType } = options\n\n const { plugin, pluginManager, mode } = useApp<PluginTs>()\n const oas = useOas()\n const { getSchemas, getFile, getName, getGroup } = useOperationManager()\n const schemaManager = useSchemaManager()\n\n const file = getFile(operation)\n const schemas = getSchemas(operation)\n const type = getName(operation, { type: 'function', pluginKey: [pluginTsName] })\n const combinedSchemaName = operation.method === 'get' ? `${type}Query` : `${type}Mutation`\n const schemaGenerator = new SchemaGenerator(options, {\n oas,\n plugin,\n pluginManager,\n mode,\n override: options.override,\n })\n\n const operationSchemas = [schemas.pathParams, schemas.queryParams, schemas.headerParams, schemas.statusCodes, schemas.request, schemas.response]\n .flat()\n .filter(Boolean)\n\n const mapOperationSchema = ({ name, schema: schemaObject, description, keysToOmit, ...options }: OperationSchemaType) => {\n const tree = schemaGenerator.parse({ schemaObject, name })\n const imports = schemaManager.getImports(tree)\n const group = options.operation ? getGroup(options.operation) : undefined\n\n const type = {\n name: schemaManager.getName(name, { type: 'type' }),\n typedName: schemaManager.getName(name, { type: 'type' }),\n file: schemaManager.getFile(options.operationName || name, { group }),\n }\n\n return (\n <Oas.Schema key={[name, schemaObject.$ref].join('-')} name={name} schemaObject={schemaObject} tree={tree}>\n {mode === 'split' &&\n imports.map((imp) => (\n <File.Import key={[name, imp.name, imp.path, imp.isTypeOnly].join('-')} root={file.path} path={imp.path} name={imp.name} isTypeOnly />\n ))}\n <Type\n name={type.name}\n typedName={type.typedName}\n description={description}\n tree={tree}\n schema={schemaObject}\n mapper={mapper}\n enumType={enumType}\n optionalType={optionalType}\n keysToOmit={keysToOmit}\n syntaxType={syntaxType}\n />\n </Oas.Schema>\n )\n }\n\n return (\n <File\n baseName={file.baseName}\n path={file.path}\n meta={file.meta}\n banner={getBanner({ oas, output: plugin.options.output, config: pluginManager.config })}\n footer={getFooter({ oas, output: plugin.options.output })}\n >\n {operationSchemas.map(mapOperationSchema)}\n\n <File.Source name={combinedSchemaName} isExportable isIndexable isTypeOnly>\n {printCombinedSchema({ name: combinedSchemaName, schemas, pluginManager })}\n </File.Source>\n </File>\n )\n },\n Schema({ schema, options }) {\n const { mapper, enumType, syntaxType, optionalType } = options\n const {\n mode,\n plugin: {\n options: { output },\n },\n pluginManager,\n } = useApp<PluginTs>()\n const oas = useOas()\n\n const { getName, getImports, getFile } = useSchemaManager()\n const imports = getImports(schema.tree)\n\n if (enumType === 'asPascalConst') {\n console.warn(`enumType '${enumType}' is deprecated`)\n }\n\n const type = {\n name: getName(schema.name, { type: 'function' }),\n typedName: getName(schema.name, { type: 'type' }),\n file: getFile(schema.name),\n }\n\n return (\n <File\n baseName={type.file.baseName}\n path={type.file.path}\n meta={type.file.meta}\n banner={getBanner({ oas, output, config: pluginManager.config })}\n footer={getFooter({ oas, output })}\n >\n {mode === 'split' &&\n imports.map((imp) => (\n <File.Import key={[schema.name, imp.path, imp.isTypeOnly].join('-')} root={type.file.path} path={imp.path} name={imp.name} isTypeOnly />\n ))}\n <Type\n name={type.name}\n typedName={type.typedName}\n description={schema.value.description}\n tree={schema.tree}\n schema={schema.value}\n mapper={mapper}\n enumType={enumType}\n optionalType={optionalType}\n syntaxType={syntaxType}\n />\n </File>\n )\n },\n})\n","import { createReactGenerator } from '@kubb/plugin-oas'\nimport { useOas } from '@kubb/plugin-oas/hooks'\nimport { getBanner, getFooter } from '@kubb/plugin-oas/utils'\nimport { File, useApp } from '@kubb/react'\nimport { OasType } from '../components'\nimport type { PluginTs } from '../types.ts'\n\nexport const oasGenerator = createReactGenerator<PluginTs>({\n name: 'oas',\n Operations() {\n const {\n pluginManager,\n plugin: {\n options: { output },\n key: pluginKey,\n },\n } = useApp<PluginTs>()\n const oas = useOas()\n\n const file = pluginManager.getFile({ name: 'oas', extname: '.ts', pluginKey })\n\n return (\n <File\n baseName={file.baseName}\n path={file.path}\n meta={file.meta}\n banner={getBanner({ oas, output, config: pluginManager.config })}\n footer={getFooter({ oas, output })}\n >\n <File.Import name={['Infer']} path=\"@kubb/oas\" isTypeOnly />\n\n <OasType name={'oas'} typeName={'Oas'} api={oas.api} />\n </File>\n )\n },\n})\n","import path from 'node:path'\n\nimport { FileManager, type Group, PluginManager, createPlugin } from '@kubb/core'\nimport { camelCase, pascalCase } from '@kubb/core/transformers'\nimport { OperationGenerator, SchemaGenerator, pluginOasName } from '@kubb/plugin-oas'\n\nimport type { Plugin } from '@kubb/core'\nimport type { PluginOas as SwaggerPluginOptions } from '@kubb/plugin-oas'\nimport { oasGenerator, typeGenerator } from './generators'\nimport type { PluginTs } from './types.ts'\n\nexport const pluginTsName = 'plugin-ts' satisfies PluginTs['name']\n\nexport const pluginTs = createPlugin<PluginTs>((options) => {\n const {\n output = { path: 'types', barrelType: 'named' },\n group,\n exclude = [],\n include,\n override = [],\n enumType = 'asConst',\n enumSuffix = 'enum',\n dateType = 'string',\n unknownType = 'any',\n optionalType = 'questionToken',\n emptySchemaType = unknownType,\n syntaxType = 'type',\n transformers = {},\n oasType = false,\n mapper = {},\n generators = [typeGenerator, oasType === 'infer' ? oasGenerator : undefined].filter(Boolean),\n contentType,\n } = options\n\n return {\n name: pluginTsName,\n options: {\n output,\n transformers,\n dateType,\n optionalType,\n oasType,\n enumType,\n enumSuffix,\n // keep the used enumnames between SchemaGenerator and OperationGenerator per plugin(pluginKey)\n usedEnumNames: {},\n unknownType,\n emptySchemaType,\n syntaxType,\n group,\n override,\n mapper,\n },\n pre: [pluginOasName],\n resolvePath(baseName, pathMode, options) {\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = pathMode ?? FileManager.getMode(path.resolve(root, output.path))\n\n if (mode === 'single') {\n /**\n * when output is a file then we will always append to the same file(output file), see fileManager.addOrAppend\n * Other plugins then need to call addOrAppend instead of just add from the fileManager class\n */\n return path.resolve(root, output.path)\n }\n\n if (group && (options?.group?.path || options?.group?.tag)) {\n const groupName: Group['name'] = group?.name\n ? group.name\n : (ctx) => {\n if (group?.type === 'path') {\n return `${ctx.group.split('/')[1]}`\n }\n return `${camelCase(ctx.group)}Controller`\n }\n\n return path.resolve(\n root,\n output.path,\n groupName({\n group: group.type === 'path' ? options.group.path! : options.group.tag!,\n }),\n baseName,\n )\n }\n\n return path.resolve(root, output.path, baseName)\n },\n resolveName(name, type) {\n const resolvedName = pascalCase(name, { isFile: type === 'file' })\n\n if (type) {\n return transformers?.name?.(resolvedName, type) || resolvedName\n }\n\n return resolvedName\n },\n async buildStart() {\n const [swaggerPlugin]: [Plugin<SwaggerPluginOptions>] = PluginManager.getDependedPlugins<SwaggerPluginOptions>(this.plugins, [pluginOasName])\n\n const oas = await swaggerPlugin.context.getOas()\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = FileManager.getMode(path.resolve(root, output.path))\n\n const schemaGenerator = new SchemaGenerator(this.plugin.options, {\n oas,\n pluginManager: this.pluginManager,\n plugin: this.plugin,\n contentType,\n include: undefined,\n override,\n mode,\n output: output.path,\n })\n\n const schemaFiles = await schemaGenerator.build(...generators)\n await this.addFile(...schemaFiles)\n\n const operationGenerator = new OperationGenerator(this.plugin.options, {\n oas,\n pluginManager: this.pluginManager,\n plugin: this.plugin,\n contentType,\n exclude,\n include,\n override,\n mode,\n })\n\n const operationFiles = await operationGenerator.build(...generators)\n await this.addFile(...operationFiles)\n\n const barrelFiles = await this.fileManager.getBarrelFiles({\n type: output.barrelType ?? 'named',\n root,\n output,\n meta: {\n pluginKey: this.plugin.key,\n },\n logger: this.logger,\n })\n\n await this.addFile(...barrelFiles)\n },\n }\n})\n"],"mappings":";;;;;;;;;;;;;;AAcA,SAAS,oBAAoB,EAAE,MAAM,SAAS,eAA0F,EAAU;CAChJ,MAAMA,aAA0C,CAAE;AAElD,KAAI,QAAQ,UACV,WAAW,cAAc,QAAQ,uBAAuB,EACtD,OAAO,QAAQ,UAAU,IAAI,CAAC,QAAQ;EACpC,MAAM,aAAa,cAAc,YAAY;GAC3C,MAAM,IAAI;GACV,WAAW,CAAC,YAAa;GACzB,MAAM;EACP,EAAC;AAEF,SAAO,QAAQ,wBAAwB,QAAQ,iBAAiB,WAAW,EAAE,OAAU;CACxF,EAAC,CACH,EAAC;AAGJ,KAAI,QAAQ,SAAS;EACnB,MAAM,aAAa,cAAc,YAAY;GAC3C,MAAM,QAAQ,QAAQ;GACtB,WAAW,CAAC,YAAa;GACzB,MAAM;EACP,EAAC;EACF,WAAW,aAAa,QAAQ,wBAAwB,QAAQ,iBAAiB,WAAW,EAAE,OAAU;CACzG;AAED,KAAI,QAAQ,YAAY;EACtB,MAAM,aAAa,cAAc,YAAY;GAC3C,MAAM,QAAQ,WAAW;GACzB,WAAW,CAAC,YAAa;GACzB,MAAM;EACP,EAAC;EACF,WAAW,gBAAgB,QAAQ,wBAAwB,QAAQ,iBAAiB,WAAW,EAAE,OAAU;CAC5G;AAED,KAAI,QAAQ,aAAa;EACvB,MAAM,aAAa,cAAc,YAAY;GAC3C,MAAM,QAAQ,YAAY;GAC1B,WAAW,CAAC,YAAa;GACzB,MAAM;EACP,EAAC;EACF,WAAW,iBAAiB,QAAQ,wBAAwB,QAAQ,iBAAiB,WAAW,EAAE,OAAU;CAC7G;AAED,KAAI,QAAQ,cAAc;EACxB,MAAM,aAAa,cAAc,YAAY;GAC3C,MAAM,QAAQ,aAAa;GAC3B,WAAW,CAAC,YAAa;GACzB,MAAM;E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