@kubb/plugin-ts 3.0.0-alpha.0

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.
@@ -0,0 +1,621 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }// src/plugin.ts
2
+ var _path = require('path'); var _path2 = _interopRequireDefault(_path);
3
+ var _core = require('@kubb/core');
4
+ var _transformers = require('@kubb/core/transformers'); var _transformers2 = _interopRequireDefault(_transformers);
5
+ var _utils = require('@kubb/core/utils');
6
+ var _pluginoas = require('@kubb/plugin-oas');
7
+
8
+ // src/OperationGenerator.tsx
9
+
10
+ var _components = require('@kubb/plugin-oas/components');
11
+ var _react = require('@kubb/react');
12
+
13
+ // src/components/OasType.tsx
14
+
15
+ var _hooks = require('@kubb/plugin-oas/hooks');
16
+ var _jsxruntime = require('@kubb/react/jsx-runtime');
17
+ function Template({ name, typeName, api }) {
18
+ return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _jsxruntime.Fragment, { children: [
19
+ `export const ${name} = ${JSON.stringify(api, void 0, 2)} as const`,
20
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "br", {}),
21
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.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 = _hooks.useOas.call(void 0, );
27
+ return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, Template2, { name, typeName, api: oas.api });
28
+ }
29
+ OasType.File = function({ name, typeName, templates = defaultTemplates }) {
30
+ const {
31
+ pluginManager,
32
+ plugin: { key: pluginKey }
33
+ } = _react.useApp.call(void 0, );
34
+ const file = pluginManager.getFile({ name, extName: ".ts", pluginKey });
35
+ const Template2 = templates.default;
36
+ return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.Parser, { language: "typescript", children: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _react.File, { baseName: file.baseName, path: file.path, meta: file.meta, children: [
37
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.File.Import, { name: ["Infer"], path: "@kubb/oas", isTypeOnly: true }),
38
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.File.Source, { children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, OasType, { Template: Template2, name, typeName }) })
39
+ ] }) });
40
+ };
41
+ OasType.templates = defaultTemplates;
42
+
43
+ // src/components/OperationSchema.tsx
44
+
45
+ var _parserts = require('@kubb/parser-ts');
46
+ var _factory = require('@kubb/parser-ts/factory'); var factory3 = _interopRequireWildcard(_factory); var factory2 = _interopRequireWildcard(_factory); var factory = _interopRequireWildcard(_factory);
47
+
48
+
49
+
50
+
51
+ // src/SchemaGenerator.tsx
52
+
53
+
54
+
55
+
56
+ // src/components/Schema.tsx
57
+
58
+
59
+
60
+
61
+
62
+
63
+
64
+
65
+ // src/parser/index.ts
66
+
67
+
68
+
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 (_pluginoas.isKeyword.call(void 0, current, _pluginoas.schemaKeywords.union)) {
168
+ return typeKeywordMapper.union(current.args.map((schema) => parse(current, schema, options)).filter(Boolean));
169
+ }
170
+ if (_pluginoas.isKeyword.call(void 0, current, _pluginoas.schemaKeywords.and)) {
171
+ return typeKeywordMapper.and(current.args.map((schema) => parse(current, schema, options)).filter(Boolean));
172
+ }
173
+ if (_pluginoas.isKeyword.call(void 0, current, _pluginoas.schemaKeywords.array)) {
174
+ return typeKeywordMapper.array(current.args.items.map((schema) => parse(current, schema, options)).filter(Boolean));
175
+ }
176
+ if (_pluginoas.isKeyword.call(void 0, current, _pluginoas.schemaKeywords.enum)) {
177
+ return typeKeywordMapper.enum(current.args.typeName);
178
+ }
179
+ if (_pluginoas.isKeyword.call(void 0, current, _pluginoas.schemaKeywords.ref)) {
180
+ return typeKeywordMapper.ref(current.args.name);
181
+ }
182
+ if (_pluginoas.isKeyword.call(void 0, current, _pluginoas.schemaKeywords.blob)) {
183
+ return value();
184
+ }
185
+ if (_pluginoas.isKeyword.call(void 0, current, _pluginoas.schemaKeywords.tuple)) {
186
+ return typeKeywordMapper.tuple(current.args.items.map((schema) => parse(current, schema, options)).filter(Boolean));
187
+ }
188
+ if (_pluginoas.isKeyword.call(void 0, current, _pluginoas.schemaKeywords.const)) {
189
+ return typeKeywordMapper.const(current.args.name, current.args.format);
190
+ }
191
+ if (_pluginoas.isKeyword.call(void 0, current, _pluginoas.schemaKeywords.object)) {
192
+ const properties = Object.entries(_optionalChain([current, 'access', _ => _.args, 'optionalAccess', _2 => _2.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 === _pluginoas.schemaKeywords.name);
197
+ const mappedName = _optionalChain([nameSchema, 'optionalAccess', _3 => _3.args]) || name;
198
+ if (_optionalChain([options, 'access', _4 => _4.mapper, 'optionalAccess', _5 => _5[mappedName]])) {
199
+ return _optionalChain([options, 'access', _6 => _6.mapper, 'optionalAccess', _7 => _7[mappedName]]);
200
+ }
201
+ const isNullish = schemas.some((schema) => schema.keyword === _pluginoas.schemaKeywords.nullish);
202
+ const isNullable = schemas.some((schema) => schema.keyword === _pluginoas.schemaKeywords.nullable);
203
+ const isOptional = schemas.some((schema) => schema.keyword === _pluginoas.schemaKeywords.optional);
204
+ const isReadonly = schemas.some((schema) => schema.keyword === _pluginoas.schemaKeywords.readOnly);
205
+ const describeSchema = schemas.find((schema) => schema.keyword === _pluginoas.schemaKeywords.describe);
206
+ const deprecatedSchema = schemas.find((schema) => schema.keyword === _pluginoas.schemaKeywords.deprecated);
207
+ const defaultSchema = schemas.find((schema) => schema.keyword === _pluginoas.schemaKeywords.default);
208
+ const exampleSchema = schemas.find((schema) => schema.keyword === _pluginoas.schemaKeywords.example);
209
+ const schemaSchema = schemas.find((schema) => schema.keyword === _pluginoas.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 ${_transformers2.default.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
+ _optionalChain([schemaSchema, 'optionalAccess', _8 => _8.args, 'optionalAccess', _9 => _9.type]) || _optionalChain([schemaSchema, 'optionalAccess', _10 => _10.args, 'optionalAccess', _11 => _11.format]) ? [`@type ${_optionalChain([schemaSchema, 'optionalAccess', _12 => _12.args, 'optionalAccess', _13 => _13.type]) || "unknown"}${!isOptional ? "" : " | undefined"}`, _optionalChain([schemaSchema, 'optionalAccess', _14 => _14.args, 'optionalAccess', _15 => _15.format])].filter(Boolean).join(", ") : void 0
240
+ ].filter(Boolean)
241
+ });
242
+ });
243
+ const additionalProperties = _optionalChain([current, 'access', _16 => _16.args, 'optionalAccess', _17 => _17.additionalProperties, 'optionalAccess', _18 => _18.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 (_pluginoas.isKeyword.call(void 0, current, _pluginoas.schemaKeywords.datetime)) {
249
+ return typeKeywordMapper.datetime();
250
+ }
251
+ if (_pluginoas.isKeyword.call(void 0, current, _pluginoas.schemaKeywords.date)) {
252
+ return typeKeywordMapper.date(current.args.type);
253
+ }
254
+ if (_pluginoas.isKeyword.call(void 0, current, _pluginoas.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
+
265
+ function Schema(props) {
266
+ const { keysToOmit, description } = props;
267
+ const { tree, name } = _hooks.useSchema.call(void 0, );
268
+ const {
269
+ pluginManager,
270
+ plugin: {
271
+ options: { mapper, enumType, optionalType }
272
+ }
273
+ } = _react.useApp.call(void 0, );
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 === _pluginoas.schemaKeywords.nullish);
290
+ const isNullable = tree.some((item) => item.keyword === _pluginoas.schemaKeywords.nullable);
291
+ const isOptional = tree.some((item) => item.keyword === _pluginoas.schemaKeywords.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: _optionalChain([keysToOmit, 'optionalAccess', _19 => _19.length]) ? factory2.createOmitDeclaration({
312
+ keys: keysToOmit,
313
+ type,
314
+ nonNullable: true
315
+ }) : type
316
+ });
317
+ const enumSchemas = _pluginoas.SchemaGenerator.deepSearch(tree, _pluginoas.schemaKeywords.enum);
318
+ if (enumSchemas) {
319
+ enumSchemas.forEach((enumSchema) => {
320
+ extraNodes.push(
321
+ ...factory2.createEnumDeclaration({
322
+ name: _transformers2.default.camelCase(enumSchema.args.name),
323
+ typeName: enumSchema.args.typeName,
324
+ enums: enumSchema.args.items.map((item) => item.value === void 0 ? void 0 : [_transformers2.default.trimQuotes(_optionalChain([item, 'access', _20 => _20.name, 'optionalAccess', _21 => _21.toString, 'call', _22 => _22()])), item.value]).filter(Boolean),
325
+ type: enumType
326
+ })
327
+ );
328
+ });
329
+ }
330
+ nodes.push(
331
+ factory2.appendJSDocToNode({
332
+ node,
333
+ comments: [description ? `@description ${_transformers2.default.jsStringEscape(description)}` : void 0].filter(Boolean)
334
+ })
335
+ );
336
+ const filterdNodes = nodes.filter(
337
+ (node2) => !extraNodes.some(
338
+ (extraNode) => _optionalChain([extraNode, 'optionalAccess', _23 => _23.name, 'optionalAccess', _24 => _24.escapedText]) === _optionalChain([node2, 'optionalAccess', _25 => _25.name, 'optionalAccess', _26 => _26.escapedText])
339
+ )
340
+ );
341
+ return _parserts.print.call(void 0, [...extraNodes, ...filterdNodes]);
342
+ }
343
+ Schema.File = function({}) {
344
+ const { pluginManager } = _react.useApp.call(void 0, );
345
+ const { schema } = _hooks.useSchema.call(void 0, );
346
+ return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _components.Oas.Schema.File, { output: pluginManager.config.output.path, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.File.Source, { children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, Schema, { description: _optionalChain([schema, 'optionalAccess', _27 => _27.description]) }) }) });
347
+ };
348
+
349
+ // src/SchemaGenerator.tsx
350
+
351
+ var SchemaGenerator2 = class extends _pluginoas.SchemaGenerator {
352
+ async schema(name, schema, options) {
353
+ const { oas, pluginManager, plugin, mode, output } = this.context;
354
+ const root = _react.createRoot.call(void 0, {
355
+ logger: pluginManager.logger
356
+ });
357
+ const tree = this.parse({ schema, name });
358
+ root.render(
359
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.App, { pluginManager, plugin: { ...plugin, options }, mode, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _components.Oas, { oas, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _components.Oas.Schema, { name, value: schema, tree, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, Schema.File, {}) }) }) })
360
+ );
361
+ return root.files;
362
+ }
363
+ };
364
+
365
+ // src/components/OperationSchema.tsx
366
+
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: _transformers2.default.pascalCase(key),
436
+ type
437
+ });
438
+ }).filter(Boolean)
439
+ ),
440
+ modifiers: [factory3.modifiers.export]
441
+ });
442
+ return _parserts.print.call(void 0, namespaceNode);
443
+ }
444
+ function OperationSchema({ keysToOmit, description }) {
445
+ return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, Schema, { keysToOmit, description });
446
+ }
447
+ OperationSchema.File = function({}) {
448
+ const { pluginManager, plugin, mode, fileManager } = _react.useApp.call(void 0, );
449
+ const oas = _hooks.useOas.call(void 0, );
450
+ const { getSchemas, getFile, getName } = _hooks.useOperationManager.call(void 0, );
451
+ const operation = _hooks.useOperation.call(void 0, );
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__ */ _jsxruntime.jsxs.call(void 0, _components.Oas.Schema, { name, value: schema, tree, children: [
466
+ mode === "split" && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _components.Oas.Schema.Imports, { extName: plugin.options.extName, isTypeOnly: true }),
467
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.File.Source, { children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, OperationSchema, { description, keysToOmit }) })
468
+ ] }, i);
469
+ };
470
+ return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.Parser, { language: "typescript", children: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _react.File, { baseName: file.baseName, path: file.path, meta: file.meta, children: [
471
+ items.map(mapItem),
472
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.File.Source, { children: printCombinedSchema({ name: factoryName, operation, schemas, pluginManager }) })
473
+ ] }) });
474
+ };
475
+
476
+ // src/OperationGenerator.tsx
477
+
478
+ var OperationGenerator = class extends _pluginoas.OperationGenerator {
479
+ async all(operations) {
480
+ const { oas, pluginManager, plugin, mode } = this.context;
481
+ const root = _react.createRoot.call(void 0, {
482
+ logger: pluginManager.logger
483
+ });
484
+ root.render(
485
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.App, { pluginManager, plugin, mode, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _components.Oas, { oas, operations, generator: this, children: plugin.options.oasType && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, 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 = _react.createRoot.call(void 0, {
492
+ logger: pluginManager.logger
493
+ });
494
+ root.render(
495
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.App, { pluginManager, plugin: { ...plugin, options }, mode, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _components.Oas, { oas, operations: [operation], generator: this, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _components.Oas.Operation, { operation, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, OperationSchema.File, {}) }) }) })
496
+ );
497
+ return root.files;
498
+ }
499
+ };
500
+
501
+ // src/plugin.ts
502
+ var pluginTsName = "plugin-ts";
503
+ var pluginTs = _core.createPlugin.call(void 0, (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 = _optionalChain([group, 'optionalAccess', _28 => _28.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: [_pluginoas.pluginOasName],
537
+ resolvePath(baseName, pathMode, options2) {
538
+ const root = _path2.default.resolve(this.config.root, this.config.output.path);
539
+ const mode = _nullishCoalesce(pathMode, () => ( _core.FileManager.getMode(_path2.default.resolve(root, output.path))));
540
+ if (mode === "single") {
541
+ return _path2.default.resolve(root, output.path);
542
+ }
543
+ if (_optionalChain([options2, 'optionalAccess', _29 => _29.tag]) && _optionalChain([group, 'optionalAccess', _30 => _30.type]) === "tag") {
544
+ const tag = _transformers.camelCase.call(void 0, options2.tag);
545
+ return _path2.default.resolve(root, _utils.renderTemplate.call(void 0, template, { tag }), baseName);
546
+ }
547
+ return _path2.default.resolve(root, output.path, baseName);
548
+ },
549
+ resolveName(name, type) {
550
+ const resolvedName = _transformers.pascalCase.call(void 0, name, { isFile: type === "file" });
551
+ if (type) {
552
+ return _optionalChain([transformers4, 'optionalAccess', _31 => _31.name, 'optionalCall', _32 => _32(resolvedName, type)]) || resolvedName;
553
+ }
554
+ return resolvedName;
555
+ },
556
+ async writeFile(path2, source) {
557
+ if (!path2.endsWith(".ts") || !source) {
558
+ return;
559
+ }
560
+ return this.fileManager.write(path2, source, { sanity: false });
561
+ },
562
+ async buildStart() {
563
+ const [swaggerPlugin] = _core.PluginManager.getDependedPlugins(this.plugins, [_pluginoas.pluginOasName]);
564
+ const oas = await swaggerPlugin.api.getOas();
565
+ const root = _path2.default.resolve(this.config.root, this.config.output.path);
566
+ const mode = _core.FileManager.getMode(_path2.default.resolve(root, output.path));
567
+ const schemaGenerator = new SchemaGenerator2(this.plugin.options, {
568
+ oas,
569
+ pluginManager: this.pluginManager,
570
+ plugin: this.plugin,
571
+ contentType: swaggerPlugin.api.contentType,
572
+ include: void 0,
573
+ override,
574
+ mode,
575
+ output: output.path
576
+ });
577
+ const schemaFiles = await schemaGenerator.build();
578
+ await this.addFile(...schemaFiles);
579
+ const operationGenerator = new OperationGenerator(this.plugin.options, {
580
+ oas,
581
+ pluginManager: this.pluginManager,
582
+ plugin: this.plugin,
583
+ contentType: swaggerPlugin.api.contentType,
584
+ exclude,
585
+ include,
586
+ override,
587
+ mode
588
+ });
589
+ const operationFiles = await operationGenerator.build();
590
+ await this.addFile(...operationFiles);
591
+ },
592
+ async buildEnd() {
593
+ if (this.config.output.write === false) {
594
+ return;
595
+ }
596
+ const root = _path2.default.resolve(this.config.root, this.config.output.path);
597
+ await this.fileManager.addIndexes({
598
+ root,
599
+ output,
600
+ meta: { pluginKey: this.plugin.key },
601
+ logger: this.logger
602
+ });
603
+ }
604
+ };
605
+ });
606
+
607
+ // src/index.ts
608
+ var definePluginDefault = pluginTs;
609
+ var definePlugin = pluginTs;
610
+ var src_default = definePluginDefault;
611
+
612
+
613
+
614
+
615
+
616
+
617
+
618
+
619
+
620
+ exports.OasType = OasType; exports.Schema = Schema; exports.OperationSchema = OperationSchema; exports.pluginTsName = pluginTsName; exports.pluginTs = pluginTs; exports.definePlugin = definePlugin; exports.src_default = src_default;
621
+ //# sourceMappingURL=chunk-XCNZFEPR.cjs.map