@kubb/swagger-ts 2.10.0 → 2.11.1

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