@kubb/swagger-ts 2.6.6 → 2.7.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.
@@ -1,42 +1,4 @@
1
- 'use strict';
2
-
3
- var transformers2 = require('@kubb/core/transformers');
4
- var parser = require('@kubb/parser');
5
- var factory2 = require('@kubb/parser/factory');
6
- var react = require('@kubb/react');
7
- var hooks = require('@kubb/swagger/hooks');
8
- var swagger = require('@kubb/swagger');
9
- var utils$1 = require('@kubb/swagger/utils');
10
- var core = require('@kubb/core');
11
- var utils = require('@kubb/core/utils');
12
- var path = require('path');
13
- var jsxRuntime = require('@kubb/react/jsx-runtime');
14
-
15
- function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
16
-
17
- function _interopNamespace(e) {
18
- if (e && e.__esModule) return e;
19
- var n = Object.create(null);
20
- if (e) {
21
- Object.keys(e).forEach(function (k) {
22
- if (k !== 'default') {
23
- var d = Object.getOwnPropertyDescriptor(e, k);
24
- Object.defineProperty(n, k, d.get ? d : {
25
- enumerable: true,
26
- get: function () { return e[k]; }
27
- });
28
- }
29
- });
30
- }
31
- n.default = e;
32
- return Object.freeze(n);
33
- }
34
-
35
- var transformers2__default = /*#__PURE__*/_interopDefault(transformers2);
36
- var factory2__namespace = /*#__PURE__*/_interopNamespace(factory2);
37
- var path__default = /*#__PURE__*/_interopDefault(path);
38
-
39
- var __accessCheck = (obj, member, msg) => {
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 _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; }var __accessCheck = (obj, member, msg) => {
40
2
  if (!member.has(obj))
41
3
  throw TypeError("Cannot " + msg);
42
4
  };
@@ -53,15 +15,53 @@ var __privateMethod = (obj, member, method) => {
53
15
  __accessCheck(obj, member, "access private method");
54
16
  return method;
55
17
  };
18
+
19
+ // src/components/Mutation.tsx
20
+ var _transformers = require('@kubb/core/transformers'); var _transformers2 = _interopRequireDefault(_transformers);
21
+ var _parser = require('@kubb/parser');
22
+ var _factory = require('@kubb/parser/factory'); var factory3 = _interopRequireWildcard(_factory); var factory2 = _interopRequireWildcard(_factory); var factory = _interopRequireWildcard(_factory);
23
+ var _react = require('@kubb/react');
24
+ var _hooks = require('@kubb/swagger/hooks');
25
+
26
+ // src/TypeBuilder.ts
27
+
28
+
29
+ var _swagger = require('@kubb/swagger');
30
+ var _utils = require('@kubb/swagger/utils');
31
+
32
+ // src/TypeGenerator.ts
33
+ var _core = require('@kubb/core');
34
+
35
+ var _utils3 = require('@kubb/core/utils');
36
+
37
+
38
+
39
+
40
+ // src/plugin.ts
41
+ var _path = require('path'); var _path2 = _interopRequireDefault(_path);
42
+
43
+
44
+
45
+
46
+
47
+ // src/OperationGenerator.tsx
48
+
49
+
50
+
51
+ // src/components/Oas.tsx
52
+
53
+
54
+
55
+ var _jsxruntime = require('@kubb/react/jsx-runtime');
56
56
  function Template({
57
57
  name,
58
58
  typeName,
59
59
  api
60
60
  }) {
61
- return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
61
+ return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _jsxruntime.Fragment, { children: [
62
62
  `export const ${name} = ${JSON.stringify(api, void 0, 2)} as const`,
63
- /* @__PURE__ */ jsxRuntime.jsx("br", {}),
64
- /* @__PURE__ */ jsxRuntime.jsx(react.Type, { name: typeName, export: true, children: `Infer<typeof ${name}>` })
63
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "br", {}),
64
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.Type, { name: typeName, export: true, children: `Infer<typeof ${name}>` })
65
65
  ] });
66
66
  }
67
67
  var defaultTemplates = { default: Template };
@@ -70,115 +70,123 @@ function Oas({
70
70
  typeName,
71
71
  Template: Template2 = defaultTemplates.default
72
72
  }) {
73
- const oas = hooks.useOas();
74
- return /* @__PURE__ */ jsxRuntime.jsx(Template2, { name, typeName, api: oas.api });
73
+ const oas = _hooks.useOas.call(void 0, );
74
+ return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, Template2, { name, typeName, api: oas.api });
75
75
  }
76
76
  Oas.File = function({ name, typeName, templates = defaultTemplates }) {
77
- const { key: pluginKey2 } = react.usePlugin();
78
- const file = react.useFile({ name, pluginKey: pluginKey2 });
77
+ const { key: pluginKey2 } = _react.usePlugin.call(void 0, );
78
+ const file = _react.useFile.call(void 0, { name, extName: ".ts", pluginKey: pluginKey2 });
79
79
  const Template2 = templates.default;
80
- return /* @__PURE__ */ jsxRuntime.jsxs(
81
- react.File,
80
+ return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.Editor, { language: "typescript", children: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0,
81
+ _react.File,
82
82
  {
83
83
  baseName: file.baseName,
84
84
  path: file.path,
85
85
  meta: file.meta,
86
86
  children: [
87
- /* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { name: ["Infer"], path: "@kubb/swagger-ts/oas", isTypeOnly: true }),
88
- /* @__PURE__ */ jsxRuntime.jsx(react.File.Source, { children: /* @__PURE__ */ jsxRuntime.jsx(Oas, { Template: Template2, name, typeName }) })
87
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.File.Import, { name: ["Infer"], path: "@kubb/swagger-ts/oas", isTypeOnly: true }),
88
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.File.Source, { children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, Oas, { Template: Template2, name, typeName }) })
89
89
  ]
90
90
  }
91
- );
91
+ ) });
92
92
  };
93
93
  Oas.templates = defaultTemplates;
94
+
95
+ // src/components/Query.tsx
96
+
97
+
98
+
99
+
100
+
101
+
94
102
  function printCombinedSchema(name, operation, schemas) {
95
103
  const properties = {
96
- "response": factory2__namespace.createTypeReferenceNode(
97
- factory2__namespace.createIdentifier(schemas.response.name),
104
+ "response": factory.createTypeReferenceNode(
105
+ factory.createIdentifier(schemas.response.name),
98
106
  void 0
99
107
  )
100
108
  };
101
109
  if (schemas.request) {
102
- properties["request"] = factory2__namespace.createTypeReferenceNode(
103
- factory2__namespace.createIdentifier(schemas.request.name),
110
+ properties["request"] = factory.createTypeReferenceNode(
111
+ factory.createIdentifier(schemas.request.name),
104
112
  void 0
105
113
  );
106
114
  }
107
115
  if (schemas.pathParams) {
108
- properties["pathParams"] = factory2__namespace.createTypeReferenceNode(
109
- factory2__namespace.createIdentifier(schemas.pathParams.name),
116
+ properties["pathParams"] = factory.createTypeReferenceNode(
117
+ factory.createIdentifier(schemas.pathParams.name),
110
118
  void 0
111
119
  );
112
120
  }
113
121
  if (schemas.queryParams) {
114
- properties["queryParams"] = factory2__namespace.createTypeReferenceNode(
115
- factory2__namespace.createIdentifier(schemas.queryParams.name),
122
+ properties["queryParams"] = factory.createTypeReferenceNode(
123
+ factory.createIdentifier(schemas.queryParams.name),
116
124
  void 0
117
125
  );
118
126
  }
119
127
  if (schemas.headerParams) {
120
- properties["headerParams"] = factory2__namespace.createTypeReferenceNode(
121
- factory2__namespace.createIdentifier(schemas.headerParams.name),
128
+ properties["headerParams"] = factory.createTypeReferenceNode(
129
+ factory.createIdentifier(schemas.headerParams.name),
122
130
  void 0
123
131
  );
124
132
  }
125
133
  if (schemas.errors) {
126
- properties["errors"] = factory2__namespace.createUnionDeclaration({
134
+ properties["errors"] = factory.createUnionDeclaration({
127
135
  nodes: schemas.errors.map((error) => {
128
- return factory2__namespace.createTypeReferenceNode(
129
- factory2__namespace.createIdentifier(error.name),
136
+ return factory.createTypeReferenceNode(
137
+ factory.createIdentifier(error.name),
130
138
  void 0
131
139
  );
132
140
  })
133
141
  });
134
142
  }
135
- const namespaceNode = factory2__namespace.createTypeAliasDeclaration({
143
+ const namespaceNode = factory.createTypeAliasDeclaration({
136
144
  name: operation.method === "get" ? `${name}Query` : `${name}Mutation`,
137
- type: factory2__namespace.createTypeLiteralNode(
145
+ type: factory.createTypeLiteralNode(
138
146
  Object.keys(properties).map((key) => {
139
147
  const type = properties[key];
140
148
  if (!type) {
141
149
  return void 0;
142
150
  }
143
- return factory2__namespace.createPropertySignature(
151
+ return factory.createPropertySignature(
144
152
  {
145
- name: transformers2__default.default.pascalCase(key),
153
+ name: _transformers2.default.pascalCase(key),
146
154
  type
147
155
  }
148
156
  );
149
157
  }).filter(Boolean)
150
158
  ),
151
- modifiers: [factory2__namespace.modifiers.export]
159
+ modifiers: [factory.modifiers.export]
152
160
  });
153
- return parser.print(namespaceNode);
161
+ return _parser.print.call(void 0, namespaceNode);
154
162
  }
155
163
  function Query({
156
164
  builder
157
165
  }) {
158
166
  const { source } = builder.build();
159
- return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: source });
167
+ return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _jsxruntime.Fragment, { children: source });
160
168
  }
161
169
  Query.File = function({ mode }) {
162
- const { options } = react.usePlugin();
163
- const schemas = hooks.useSchemas();
164
- const pluginManager = react.usePluginManager();
165
- const oas = hooks.useOas();
166
- const file = hooks.useOperationFile();
167
- const factoryName = hooks.useOperationName({ type: "type" });
168
- const operation = hooks.useOperation();
170
+ const { options } = _react.usePlugin.call(void 0, );
171
+ const schemas = _hooks.useSchemas.call(void 0, );
172
+ const pluginManager = _react.usePluginManager.call(void 0, );
173
+ const oas = _hooks.useOas.call(void 0, );
174
+ const file = _hooks.useOperationFile.call(void 0, );
175
+ const factoryName = _hooks.useOperationName.call(void 0, { type: "type" });
176
+ const operation = _hooks.useOperation.call(void 0, );
169
177
  const builder = new TypeBuilder(options, { oas, pluginManager }).add(schemas.pathParams).add(schemas.queryParams).add(schemas.headerParams).add(schemas.response).add(schemas.statusCodes);
170
178
  const { source, imports } = builder.build();
171
- return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: /* @__PURE__ */ jsxRuntime.jsxs(
172
- react.File,
179
+ return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.Editor, { language: "typescript", children: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0,
180
+ _react.File,
173
181
  {
174
182
  baseName: file.baseName,
175
183
  path: file.path,
176
184
  meta: file.meta,
177
185
  children: [
178
186
  mode === "directory" && imports.map((item, index) => {
179
- return /* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { root: file.path, ...item }, index);
187
+ return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.File.Import, { root: file.path, ...item }, index);
180
188
  }),
181
- /* @__PURE__ */ jsxRuntime.jsxs(react.File.Source, { children: [
189
+ /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _react.File.Source, { children: [
182
190
  source,
183
191
  printCombinedSchema(factoryName, operation, schemas)
184
192
  ] })
@@ -186,33 +194,36 @@ Query.File = function({ mode }) {
186
194
  }
187
195
  ) });
188
196
  };
189
- var OperationGenerator = class extends swagger.OperationGenerator {
197
+
198
+ // src/OperationGenerator.tsx
199
+
200
+ var OperationGenerator = class extends _swagger.OperationGenerator {
190
201
  async all() {
191
202
  const { oas, pluginManager, plugin } = this.context;
192
203
  if (!plugin.options.oasType) {
193
204
  return null;
194
205
  }
195
- const root = react.createRoot({ logger: pluginManager.logger });
206
+ const root = _react.createRoot.call(void 0, { logger: pluginManager.logger });
196
207
  root.render(
197
- /* @__PURE__ */ jsxRuntime.jsx(Oas.File, { name: "oas", typeName: "Oas" }),
208
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, Oas.File, { name: "oas", typeName: "Oas" }),
198
209
  { meta: { oas, pluginManager, plugin } }
199
210
  );
200
211
  return root.files;
201
212
  }
202
213
  async get(operation, schemas, options) {
203
214
  const { oas, pluginManager, plugin, mode = "directory" } = this.context;
204
- const root = react.createRoot({ logger: pluginManager.logger });
215
+ const root = _react.createRoot.call(void 0, { logger: pluginManager.logger });
205
216
  root.render(
206
- /* @__PURE__ */ jsxRuntime.jsx(Query.File, { mode }),
217
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, Query.File, { mode }),
207
218
  { meta: { oas, pluginManager, plugin: { ...plugin, options }, schemas, operation } }
208
219
  );
209
220
  return root.files;
210
221
  }
211
222
  async post(operation, schemas, options) {
212
223
  const { oas, pluginManager, plugin, mode = "directory" } = this.context;
213
- const root = react.createRoot({ logger: pluginManager.logger });
224
+ const root = _react.createRoot.call(void 0, { logger: pluginManager.logger });
214
225
  root.render(
215
- /* @__PURE__ */ jsxRuntime.jsx(Mutation.File, { mode }),
226
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, Mutation.File, { mode }),
216
227
  { meta: { oas, pluginManager, plugin: { ...plugin, options }, schemas, operation } }
217
228
  );
218
229
  return root.files;
@@ -231,7 +242,7 @@ var OperationGenerator = class extends swagger.OperationGenerator {
231
242
  // src/plugin.ts
232
243
  var pluginName = "swagger-ts";
233
244
  var pluginKey = [pluginName];
234
- var definePlugin = core.createPlugin((options) => {
245
+ var definePlugin = _core.createPlugin.call(void 0, (options) => {
235
246
  const {
236
247
  output = { path: "types" },
237
248
  group,
@@ -245,7 +256,7 @@ var definePlugin = core.createPlugin((options) => {
245
256
  transformers: transformers5 = {},
246
257
  oasType = false
247
258
  } = options;
248
- const template = group?.output ? group.output : `${output.path}/{{tag}}Controller`;
259
+ const template = _optionalChain([group, 'optionalAccess', _ => _.output]) ? group.output : `${output.path}/{{tag}}Controller`;
249
260
  return {
250
261
  name: pluginName,
251
262
  options: {
@@ -258,23 +269,23 @@ var definePlugin = core.createPlugin((options) => {
258
269
  usedEnumNames: {},
259
270
  unknownType
260
271
  },
261
- pre: [swagger.pluginName],
272
+ pre: [_swagger.pluginName],
262
273
  resolvePath(baseName, directory, options2) {
263
- const root = path__default.default.resolve(this.config.root, this.config.output.path);
264
- const mode = core.FileManager.getMode(path__default.default.resolve(root, output.path));
274
+ const root = _path2.default.resolve(this.config.root, this.config.output.path);
275
+ const mode = _core.FileManager.getMode(_path2.default.resolve(root, output.path));
265
276
  if (mode === "file") {
266
- return path__default.default.resolve(root, output.path);
277
+ return _path2.default.resolve(root, output.path);
267
278
  }
268
- if (options2?.tag && group?.type === "tag") {
269
- const tag = transformers2.camelCase(options2.tag);
270
- return path__default.default.resolve(root, utils.renderTemplate(template, { tag }), baseName);
279
+ if (_optionalChain([options2, 'optionalAccess', _2 => _2.tag]) && _optionalChain([group, 'optionalAccess', _3 => _3.type]) === "tag") {
280
+ const tag = _transformers.camelCase.call(void 0, options2.tag);
281
+ return _path2.default.resolve(root, _utils3.renderTemplate.call(void 0, template, { tag }), baseName);
271
282
  }
272
- return path__default.default.resolve(root, output.path, baseName);
283
+ return _path2.default.resolve(root, output.path, baseName);
273
284
  },
274
285
  resolveName(name, type) {
275
- const resolvedName = transformers2.pascalCase(name, { isFile: type === "file" });
286
+ const resolvedName = _transformers.pascalCase.call(void 0, name, { isFile: type === "file" });
276
287
  if (type) {
277
- return transformers5?.name?.(resolvedName, type) || resolvedName;
288
+ return _optionalChain([transformers5, 'optionalAccess', _4 => _4.name, 'optionalCall', _5 => _5(resolvedName, type)]) || resolvedName;
278
289
  }
279
290
  return resolvedName;
280
291
  },
@@ -285,11 +296,11 @@ var definePlugin = core.createPlugin((options) => {
285
296
  return this.fileManager.write(source, writePath, { sanity: false });
286
297
  },
287
298
  async buildStart() {
288
- const [swaggerPlugin] = core.PluginManager.getDependedPlugins(this.plugins, [swagger.pluginName]);
299
+ const [swaggerPlugin] = _core.PluginManager.getDependedPlugins(this.plugins, [_swagger.pluginName]);
289
300
  const oas = await swaggerPlugin.api.getOas();
290
301
  const schemas = await swaggerPlugin.api.getSchemas();
291
- const root = path__default.default.resolve(this.config.root, this.config.output.path);
292
- const mode = core.FileManager.getMode(path__default.default.resolve(root, output.path));
302
+ const root = _path2.default.resolve(this.config.root, this.config.output.path);
303
+ const mode = _core.FileManager.getMode(_path2.default.resolve(root, output.path));
293
304
  const builder = new TypeBuilder(this.plugin.options, { oas, pluginManager: this.pluginManager });
294
305
  builder.add(
295
306
  Object.entries(schemas).map(([name, schema]) => ({ name, schema }))
@@ -351,7 +362,7 @@ var definePlugin = core.createPlugin((options) => {
351
362
  if (this.config.output.write === false) {
352
363
  return;
353
364
  }
354
- const root = path__default.default.resolve(this.config.root, this.config.output.path);
365
+ const root = _path2.default.resolve(this.config.root, this.config.output.path);
355
366
  await this.fileManager.addIndexes({
356
367
  root,
357
368
  output,
@@ -363,7 +374,7 @@ var definePlugin = core.createPlugin((options) => {
363
374
 
364
375
  // src/TypeGenerator.ts
365
376
  var _usedAliasNames, _getTypeFromProperties, getTypeFromProperties_fn, _getRefAlias, getRefAlias_fn, _getParsedSchema, getParsedSchema_fn, _getBaseTypeFromSchema, getBaseTypeFromSchema_fn, _unknownReturn, unknownReturn_get;
366
- var TypeGenerator = class extends core.Generator {
377
+ var TypeGenerator = class extends _core.Generator {
367
378
  constructor() {
368
379
  super(...arguments);
369
380
  /**
@@ -401,18 +412,18 @@ var TypeGenerator = class extends core.Generator {
401
412
  return this.extraNodes;
402
413
  }
403
414
  if (optional) {
404
- type = factory2__namespace.createUnionDeclaration({ nodes: [type, factory2__namespace.keywordTypeNodes.undefined] });
415
+ type = factory2.createUnionDeclaration({ nodes: [type, factory2.keywordTypeNodes.undefined] });
405
416
  }
406
- const node = factory2__namespace.createTypeAliasDeclaration({
407
- modifiers: [factory2__namespace.modifiers.export],
417
+ const node = factory2.createTypeAliasDeclaration({
418
+ modifiers: [factory2.modifiers.export],
408
419
  name: this.context.pluginManager.resolveName({ name: baseName, pluginKey, type: "type" }),
409
- type: keysToOmit?.length ? factory2__namespace.createOmitDeclaration({ keys: keysToOmit, type, nonNullable: true }) : type
420
+ type: _optionalChain([keysToOmit, 'optionalAccess', _6 => _6.length]) ? factory2.createOmitDeclaration({ keys: keysToOmit, type, nonNullable: true }) : type
410
421
  });
411
422
  if (description) {
412
423
  nodes.push(
413
- factory2__namespace.appendJSDocToNode({
424
+ factory2.appendJSDocToNode({
414
425
  node,
415
- comments: [`@description ${transformers2__default.default.trim(description)}`]
426
+ comments: [`@description ${_transformers2.default.trim(description)}`]
416
427
  })
417
428
  );
418
429
  } else {
@@ -420,7 +431,7 @@ var TypeGenerator = class extends core.Generator {
420
431
  }
421
432
  const filterdNodes = nodes.filter(
422
433
  (node2) => !this.extraNodes.some(
423
- (extraNode) => extraNode?.name?.escapedText === node2?.name?.escapedText
434
+ (extraNode) => _optionalChain([extraNode, 'optionalAccess', _7 => _7.name, 'optionalAccess', _8 => _8.escapedText]) === _optionalChain([node2, 'optionalAccess', _9 => _9.name, 'optionalAccess', _10 => _10.escapedText])
424
435
  )
425
436
  );
426
437
  return [...this.extraNodes, ...filterdNodes];
@@ -438,16 +449,16 @@ var TypeGenerator = class extends core.Generator {
438
449
  if (schema && !schema.nullable) {
439
450
  return type;
440
451
  }
441
- return factory2__namespace.createUnionDeclaration({ nodes: [type, factory2__namespace.keywordTypeNodes.null] });
452
+ return factory2.createUnionDeclaration({ nodes: [type, factory2.keywordTypeNodes.null] });
442
453
  }
443
454
  };
444
455
  _usedAliasNames = new WeakMap();
445
456
  _getTypeFromProperties = new WeakSet();
446
457
  getTypeFromProperties_fn = function(baseSchema, baseName) {
447
458
  const { optionalType } = this.options;
448
- const properties = baseSchema?.properties || {};
449
- const required = baseSchema?.required;
450
- const additionalProperties = baseSchema?.additionalProperties;
459
+ const properties = _optionalChain([baseSchema, 'optionalAccess', _11 => _11.properties]) || {};
460
+ const required = _optionalChain([baseSchema, 'optionalAccess', _12 => _12.required]);
461
+ const additionalProperties = _optionalChain([baseSchema, 'optionalAccess', _13 => _13.additionalProperties]);
451
462
  const members = Object.keys(properties).map((name) => {
452
463
  const schema = properties[name];
453
464
  const isRequired = Array.isArray(required) ? required.includes(name) : !!required;
@@ -456,19 +467,19 @@ getTypeFromProperties_fn = function(baseSchema, baseName) {
456
467
  return null;
457
468
  }
458
469
  if (!isRequired && ["undefined", "questionTokenAndUndefined"].includes(optionalType)) {
459
- type = factory2__namespace.createUnionDeclaration({ nodes: [type, factory2__namespace.keywordTypeNodes.undefined] });
470
+ type = factory2.createUnionDeclaration({ nodes: [type, factory2.keywordTypeNodes.undefined] });
460
471
  }
461
- const propertySignature = factory2__namespace.createPropertySignature({
472
+ const propertySignature = factory2.createPropertySignature({
462
473
  questionToken: ["questionToken", "questionTokenAndUndefined"].includes(optionalType) && !isRequired,
463
474
  name,
464
475
  type,
465
476
  readOnly: schema.readOnly
466
477
  });
467
- return factory2__namespace.appendJSDocToNode({
478
+ return factory2.appendJSDocToNode({
468
479
  node: propertySignature,
469
480
  comments: [
470
481
  schema.description ? `@description ${schema.description}` : void 0,
471
- schema.type ? `@type ${schema.type?.toString()}${isRequired ? "" : " | undefined"} ${schema.format || ""}` : void 0,
482
+ schema.type ? `@type ${_optionalChain([schema, 'access', _14 => _14.type, 'optionalAccess', _15 => _15.toString, 'call', _16 => _16()])}${isRequired ? "" : " | undefined"} ${schema.format || ""}` : void 0,
472
483
  schema.example ? `@example ${schema.example}` : void 0,
473
484
  schema.deprecated ? `@deprecated` : void 0,
474
485
  schema.default !== void 0 && typeof schema.default === "string" ? `@default '${schema.default}'` : void 0,
@@ -479,19 +490,19 @@ getTypeFromProperties_fn = function(baseSchema, baseName) {
479
490
  if (additionalProperties) {
480
491
  const type = additionalProperties === true ? __privateGet(this, _unknownReturn, unknownReturn_get) : this.getTypeFromSchema(additionalProperties);
481
492
  if (type) {
482
- members.push(factory2__namespace.createIndexSignature(type));
493
+ members.push(factory2.createIndexSignature(type));
483
494
  }
484
495
  }
485
- return factory2__namespace.createTypeLiteralNode(members.filter(Boolean));
496
+ return factory2.createTypeLiteralNode(members.filter(Boolean));
486
497
  };
487
498
  _getRefAlias = new WeakSet();
488
499
  getRefAlias_fn = function(obj, _baseName) {
489
500
  const { $ref } = obj;
490
501
  let ref = this.refs[$ref];
491
502
  if (ref) {
492
- return factory2__namespace.createTypeReferenceNode(ref.propertyName, void 0);
503
+ return factory2.createTypeReferenceNode(ref.propertyName, void 0);
493
504
  }
494
- const originalName = utils.getUniqueName($ref.replace(/.+\//, ""), __privateGet(this, _usedAliasNames));
505
+ const originalName = _utils3.getUniqueName.call(void 0, $ref.replace(/.+\//, ""), __privateGet(this, _usedAliasNames));
495
506
  const propertyName = this.context.pluginManager.resolveName({ name: originalName, pluginKey, type: "type" });
496
507
  ref = this.refs[$ref] = {
497
508
  propertyName,
@@ -504,11 +515,11 @@ getRefAlias_fn = function(obj, _baseName) {
504
515
  path: path2 || "",
505
516
  isTypeOnly: true
506
517
  });
507
- return factory2__namespace.createTypeReferenceNode(ref.propertyName, void 0);
518
+ return factory2.createTypeReferenceNode(ref.propertyName, void 0);
508
519
  };
509
520
  _getParsedSchema = new WeakSet();
510
521
  getParsedSchema_fn = function(schema) {
511
- const parsedSchema = utils$1.getSchemaFactory(this.context.oas)(schema);
522
+ const parsedSchema = _utils.getSchemaFactory.call(void 0, this.context.oas)(schema);
512
523
  return parsedSchema;
513
524
  };
514
525
  _getBaseTypeFromSchema = new WeakSet();
@@ -517,12 +528,12 @@ getBaseTypeFromSchema_fn = function(_schema, baseName) {
517
528
  if (!schema) {
518
529
  return __privateGet(this, _unknownReturn, unknownReturn_get);
519
530
  }
520
- if (utils$1.isReference(schema)) {
531
+ if (_utils.isReference.call(void 0, schema)) {
521
532
  return __privateMethod(this, _getRefAlias, getRefAlias_fn).call(this, schema, baseName);
522
533
  }
523
534
  if (schema.oneOf) {
524
535
  const schemaWithoutOneOf = { ...schema, oneOf: void 0 };
525
- const union = factory2__namespace.createUnionDeclaration({
536
+ const union = factory2.createUnionDeclaration({
526
537
  withParentheses: true,
527
538
  nodes: schema.oneOf.map((item) => {
528
539
  return item && this.getTypeFromSchema(item);
@@ -531,7 +542,7 @@ getBaseTypeFromSchema_fn = function(_schema, baseName) {
531
542
  })
532
543
  });
533
544
  if (schemaWithoutOneOf.properties) {
534
- return factory2__namespace.createIntersectionDeclaration({
545
+ return factory2.createIntersectionDeclaration({
535
546
  nodes: [this.getTypeFromSchema(schemaWithoutOneOf, baseName), union].filter(Boolean)
536
547
  });
537
548
  }
@@ -539,7 +550,7 @@ getBaseTypeFromSchema_fn = function(_schema, baseName) {
539
550
  }
540
551
  if (schema.anyOf) {
541
552
  const schemaWithoutAnyOf = { ...schema, anyOf: void 0 };
542
- const union = factory2__namespace.createUnionDeclaration({
553
+ const union = factory2.createUnionDeclaration({
543
554
  withParentheses: true,
544
555
  nodes: schema.anyOf.map((item) => {
545
556
  return item && this.getTypeFromSchema(item);
@@ -548,7 +559,7 @@ getBaseTypeFromSchema_fn = function(_schema, baseName) {
548
559
  })
549
560
  });
550
561
  if (schemaWithoutAnyOf.properties) {
551
- return factory2__namespace.createIntersectionDeclaration({
562
+ return factory2.createIntersectionDeclaration({
552
563
  nodes: [this.getTypeFromSchema(schemaWithoutAnyOf, baseName), union].filter(Boolean)
553
564
  });
554
565
  }
@@ -556,7 +567,7 @@ getBaseTypeFromSchema_fn = function(_schema, baseName) {
556
567
  }
557
568
  if (schema.allOf) {
558
569
  const schemaWithoutAllOf = { ...schema, allOf: void 0 };
559
- const and = factory2__namespace.createIntersectionDeclaration({
570
+ const and = factory2.createIntersectionDeclaration({
560
571
  withParentheses: true,
561
572
  nodes: schema.allOf.map((item) => {
562
573
  return item && this.getTypeFromSchema(item);
@@ -565,47 +576,47 @@ getBaseTypeFromSchema_fn = function(_schema, baseName) {
565
576
  })
566
577
  });
567
578
  if (schemaWithoutAllOf.properties) {
568
- return factory2__namespace.createIntersectionDeclaration({
579
+ return factory2.createIntersectionDeclaration({
569
580
  nodes: [this.getTypeFromSchema(schemaWithoutAllOf, baseName), and].filter(Boolean)
570
581
  });
571
582
  }
572
583
  return and;
573
584
  }
574
585
  if (schema.enum && baseName) {
575
- const enumName = utils.getUniqueName(baseName, this.options.usedEnumNames);
586
+ const enumName = _utils3.getUniqueName.call(void 0, baseName, this.options.usedEnumNames);
576
587
  let enums = [...new Set(schema.enum)].map((key) => [key, key]);
577
588
  const extensionEnums = ["x-enumNames", "x-enum-varnames"].filter((extensionKey) => extensionKey in schema).map(
578
- (extensionKey) => [...new Set(schema[extensionKey])].map((key, index) => [key, schema.enum?.[index]])
589
+ (extensionKey) => [...new Set(schema[extensionKey])].map((key, index) => [key, _optionalChain([schema, 'access', _17 => _17.enum, 'optionalAccess', _18 => _18[index]])])
579
590
  );
580
591
  if (extensionEnums.length > 0 && extensionEnums[0]) {
581
592
  enums = extensionEnums[0];
582
593
  }
583
594
  this.extraNodes.push(
584
- ...factory2__namespace.createEnumDeclaration({
585
- name: transformers2__default.default.camelCase(enumName),
595
+ ...factory2.createEnumDeclaration({
596
+ name: _transformers2.default.camelCase(enumName),
586
597
  typeName: this.context.pluginManager.resolveName({ name: enumName, pluginKey, type: "type" }),
587
598
  enums,
588
599
  type: this.options.enumType
589
600
  })
590
601
  );
591
- return factory2__namespace.createTypeReferenceNode(this.context.pluginManager.resolveName({ name: enumName, pluginKey, type: "type" }), void 0);
602
+ return factory2.createTypeReferenceNode(this.context.pluginManager.resolveName({ name: enumName, pluginKey, type: "type" }), void 0);
592
603
  }
593
604
  if (schema.enum) {
594
- return factory2__namespace.createUnionDeclaration({
605
+ return factory2.createUnionDeclaration({
595
606
  nodes: schema.enum.map((name) => {
596
- return factory2__namespace.createLiteralTypeNode(typeof name === "number" ? factory2__namespace.createNumericLiteral(name) : factory2__namespace.createStringLiteral(`${name}`));
607
+ return factory2.createLiteralTypeNode(typeof name === "number" ? factory2.createNumericLiteral(name) : factory2.createStringLiteral(`${name}`));
597
608
  })
598
609
  });
599
610
  }
600
611
  if ("items" in schema) {
601
612
  const node = this.getTypeFromSchema(schema.items, baseName);
602
613
  if (node) {
603
- return factory2__namespace.createArrayTypeNode(node);
614
+ return factory2.createArrayTypeNode(node);
604
615
  }
605
616
  }
606
617
  if ("prefixItems" in schema) {
607
618
  const prefixItems = schema.prefixItems;
608
- return factory2__namespace.createTupleDeclaration({
619
+ return factory2.createTupleDeclaration({
609
620
  nodes: prefixItems.map((item) => {
610
621
  return this.getTypeFromSchema(item, void 0);
611
622
  })
@@ -617,18 +628,18 @@ getBaseTypeFromSchema_fn = function(_schema, baseName) {
617
628
  if (version === "3.1" && "const" in schema) {
618
629
  if (schema["const"]) {
619
630
  if (typeof schema["const"] === "string") {
620
- return factory2__namespace.createLiteralTypeNode(factory2__namespace.createStringLiteral(schema["const"]));
631
+ return factory2.createLiteralTypeNode(factory2.createStringLiteral(schema["const"]));
621
632
  } else if (typeof schema["const"] === "number") {
622
- return factory2__namespace.createLiteralTypeNode(factory2__namespace.createNumericLiteral(schema["const"]));
633
+ return factory2.createLiteralTypeNode(factory2.createNumericLiteral(schema["const"]));
623
634
  }
624
635
  } else {
625
- return factory2.keywordTypeNodes.null;
636
+ return _factory.keywordTypeNodes.null;
626
637
  }
627
638
  }
628
639
  if (schema.type) {
629
640
  if (Array.isArray(schema.type)) {
630
641
  const [type, nullable] = schema.type;
631
- return factory2__namespace.createUnionDeclaration({
642
+ return factory2.createUnionDeclaration({
632
643
  nodes: [
633
644
  this.getTypeFromSchema(
634
645
  {
@@ -637,38 +648,38 @@ getBaseTypeFromSchema_fn = function(_schema, baseName) {
637
648
  },
638
649
  baseName
639
650
  ),
640
- nullable ? factory2__namespace.createLiteralTypeNode(factory2__namespace.createNull()) : void 0
651
+ nullable ? factory2.createLiteralTypeNode(factory2.createNull()) : void 0
641
652
  ].filter(Boolean)
642
653
  });
643
654
  }
644
655
  if (this.options.dateType === "date" && ["date", "date-time"].some((item) => item === schema.format)) {
645
- return factory2__namespace.createTypeReferenceNode(factory2__namespace.createIdentifier("Date"));
656
+ return factory2.createTypeReferenceNode(factory2.createIdentifier("Date"));
646
657
  }
647
- if (schema.type in factory2__namespace.keywordTypeNodes) {
648
- return factory2__namespace.keywordTypeNodes[schema.type];
658
+ if (schema.type in factory2.keywordTypeNodes) {
659
+ return factory2.keywordTypeNodes[schema.type];
649
660
  }
650
661
  }
651
662
  if (schema.format === "binary") {
652
- return factory2__namespace.createTypeReferenceNode("Blob", []);
663
+ return factory2.createTypeReferenceNode("Blob", []);
653
664
  }
654
665
  return __privateGet(this, _unknownReturn, unknownReturn_get);
655
666
  };
656
667
  _unknownReturn = new WeakSet();
657
668
  unknownReturn_get = function() {
658
669
  if (this.options.unknownType === "any") {
659
- return factory2__namespace.keywordTypeNodes.any;
670
+ return factory2.keywordTypeNodes.any;
660
671
  }
661
- return factory2__namespace.keywordTypeNodes.unknown;
672
+ return factory2.keywordTypeNodes.unknown;
662
673
  };
663
674
 
664
675
  // src/TypeBuilder.ts
665
- var TypeBuilder = class extends swagger.OasBuilder {
676
+ var TypeBuilder = class extends _swagger.OasBuilder {
666
677
  build(name) {
667
678
  const importMeta = [];
668
679
  const codes = [];
669
- const generated = this.items.filter((operationSchema) => name ? operationSchema.name === name : true).sort(transformers2__default.default.nameSorter).map((operationSchema) => {
680
+ const generated = this.items.filter((operationSchema) => name ? operationSchema.name === name : true).sort(_transformers2.default.nameSorter).map((operationSchema) => {
670
681
  const generator = new TypeGenerator(this.options, this.context);
671
- const required = Array.isArray(operationSchema.schema?.required) ? !!operationSchema.schema.required.length : !!operationSchema.schema?.required;
682
+ const required = Array.isArray(_optionalChain([operationSchema, 'access', _19 => _19.schema, 'optionalAccess', _20 => _20.required])) ? !!operationSchema.schema.required.length : !!_optionalChain([operationSchema, 'access', _21 => _21.schema, 'optionalAccess', _22 => _22.required]);
672
683
  const sources = generator.build({
673
684
  schema: operationSchema.schema,
674
685
  baseName: operationSchema.name,
@@ -684,9 +695,9 @@ var TypeBuilder = class extends swagger.OasBuilder {
684
695
  },
685
696
  sources
686
697
  };
687
- }).sort(utils$1.refsSorter);
698
+ }).sort(_utils.refsSorter);
688
699
  generated.forEach((item) => {
689
- codes.push(parser.print(item.sources));
700
+ codes.push(_parser.print.call(void 0, item.sources));
690
701
  });
691
702
  const imports = importMeta.map((item) => {
692
703
  return {
@@ -697,98 +708,101 @@ var TypeBuilder = class extends swagger.OasBuilder {
697
708
  });
698
709
  return {
699
710
  imports,
700
- source: transformers2__default.default.combineCodes(codes)
711
+ source: _transformers2.default.combineCodes(codes)
701
712
  };
702
713
  }
703
714
  };
715
+
716
+ // src/components/Mutation.tsx
717
+
704
718
  function printCombinedSchema2(name, operation, schemas) {
705
719
  const properties = {
706
- "response": factory2__namespace.createTypeReferenceNode(
707
- factory2__namespace.createIdentifier(schemas.response.name),
720
+ "response": factory3.createTypeReferenceNode(
721
+ factory3.createIdentifier(schemas.response.name),
708
722
  void 0
709
723
  )
710
724
  };
711
725
  if (schemas.request) {
712
- properties["request"] = factory2__namespace.createTypeReferenceNode(
713
- factory2__namespace.createIdentifier(schemas.request.name),
726
+ properties["request"] = factory3.createTypeReferenceNode(
727
+ factory3.createIdentifier(schemas.request.name),
714
728
  void 0
715
729
  );
716
730
  }
717
731
  if (schemas.pathParams) {
718
- properties["pathParams"] = factory2__namespace.createTypeReferenceNode(
719
- factory2__namespace.createIdentifier(schemas.pathParams.name),
732
+ properties["pathParams"] = factory3.createTypeReferenceNode(
733
+ factory3.createIdentifier(schemas.pathParams.name),
720
734
  void 0
721
735
  );
722
736
  }
723
737
  if (schemas.queryParams) {
724
- properties["queryParams"] = factory2__namespace.createTypeReferenceNode(
725
- factory2__namespace.createIdentifier(schemas.queryParams.name),
738
+ properties["queryParams"] = factory3.createTypeReferenceNode(
739
+ factory3.createIdentifier(schemas.queryParams.name),
726
740
  void 0
727
741
  );
728
742
  }
729
743
  if (schemas.headerParams) {
730
- properties["headerParams"] = factory2__namespace.createTypeReferenceNode(
731
- factory2__namespace.createIdentifier(schemas.headerParams.name),
744
+ properties["headerParams"] = factory3.createTypeReferenceNode(
745
+ factory3.createIdentifier(schemas.headerParams.name),
732
746
  void 0
733
747
  );
734
748
  }
735
749
  if (schemas.errors) {
736
- properties["errors"] = factory2__namespace.createUnionDeclaration({
750
+ properties["errors"] = factory3.createUnionDeclaration({
737
751
  nodes: schemas.errors.map((error) => {
738
- return factory2__namespace.createTypeReferenceNode(
739
- factory2__namespace.createIdentifier(error.name),
752
+ return factory3.createTypeReferenceNode(
753
+ factory3.createIdentifier(error.name),
740
754
  void 0
741
755
  );
742
756
  })
743
757
  });
744
758
  }
745
- const namespaceNode = factory2__namespace.createTypeAliasDeclaration({
759
+ const namespaceNode = factory3.createTypeAliasDeclaration({
746
760
  name: operation.method === "get" ? `${name}Query` : `${name}Mutation`,
747
- type: factory2__namespace.createTypeLiteralNode(
761
+ type: factory3.createTypeLiteralNode(
748
762
  Object.keys(properties).map((key) => {
749
763
  const type = properties[key];
750
764
  if (!type) {
751
765
  return void 0;
752
766
  }
753
- return factory2__namespace.createPropertySignature(
767
+ return factory3.createPropertySignature(
754
768
  {
755
- name: transformers2__default.default.pascalCase(key),
769
+ name: _transformers2.default.pascalCase(key),
756
770
  type
757
771
  }
758
772
  );
759
773
  }).filter(Boolean)
760
774
  ),
761
- modifiers: [factory2__namespace.modifiers.export]
775
+ modifiers: [factory3.modifiers.export]
762
776
  });
763
- return parser.print(namespaceNode);
777
+ return _parser.print.call(void 0, namespaceNode);
764
778
  }
765
779
  function Mutation({
766
780
  builder
767
781
  }) {
768
782
  const { source } = builder.build();
769
- return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: source });
783
+ return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _jsxruntime.Fragment, { children: source });
770
784
  }
771
785
  Mutation.File = function({ mode }) {
772
- const { options } = react.usePlugin();
773
- const schemas = hooks.useSchemas();
774
- const pluginManager = react.usePluginManager();
775
- const oas = hooks.useOas();
776
- const file = hooks.useOperationFile();
777
- const factoryName = hooks.useOperationName({ type: "type" });
778
- const operation = hooks.useOperation();
786
+ const { options } = _react.usePlugin.call(void 0, );
787
+ const schemas = _hooks.useSchemas.call(void 0, );
788
+ const pluginManager = _react.usePluginManager.call(void 0, );
789
+ const oas = _hooks.useOas.call(void 0, );
790
+ const file = _hooks.useOperationFile.call(void 0, );
791
+ const factoryName = _hooks.useOperationName.call(void 0, { type: "type" });
792
+ const operation = _hooks.useOperation.call(void 0, );
779
793
  const builder = new TypeBuilder(options, { oas, pluginManager }).add(schemas.pathParams).add(schemas.queryParams).add(schemas.headerParams).add(schemas.response).add(schemas.request).add(schemas.statusCodes);
780
794
  const { source, imports } = builder.build();
781
- return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: /* @__PURE__ */ jsxRuntime.jsxs(
782
- react.File,
795
+ return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.Editor, { language: "typescript", children: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0,
796
+ _react.File,
783
797
  {
784
798
  baseName: file.baseName,
785
799
  path: file.path,
786
800
  meta: file.meta,
787
801
  children: [
788
802
  mode === "directory" && imports.map((item, index) => {
789
- return /* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { root: file.path, ...item }, index);
803
+ return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.File.Import, { root: file.path, ...item }, index);
790
804
  }),
791
- /* @__PURE__ */ jsxRuntime.jsxs(react.File.Source, { children: [
805
+ /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _react.File.Source, { children: [
792
806
  source,
793
807
  printCombinedSchema2(factoryName, operation, schemas)
794
808
  ] })
@@ -797,11 +811,12 @@ Mutation.File = function({ mode }) {
797
811
  ) });
798
812
  };
799
813
 
800
- exports.Mutation = Mutation;
801
- exports.Oas = Oas;
802
- exports.Query = Query;
803
- exports.definePlugin = definePlugin;
804
- exports.pluginKey = pluginKey;
805
- exports.pluginName = pluginName;
806
- //# sourceMappingURL=out.js.map
807
- //# sourceMappingURL=chunk-3QUKTW23.cjs.map
814
+
815
+
816
+
817
+
818
+
819
+
820
+
821
+ exports.Mutation = Mutation; exports.Oas = Oas; exports.Query = Query; exports.pluginName = pluginName; exports.pluginKey = pluginKey; exports.definePlugin = definePlugin;
822
+ //# sourceMappingURL=chunk-T5JLEKOF.cjs.map