@kubb/swagger-ts 2.11.1 → 2.12.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.
@@ -12,14 +12,9 @@ var _components = require('@kubb/swagger/components');
12
12
 
13
13
  // src/components/OasType.tsx
14
14
 
15
-
16
15
  var _hooks = require('@kubb/swagger/hooks');
17
16
  var _jsxruntime = require('@kubb/react/jsx-runtime');
18
- function Template({
19
- name,
20
- typeName,
21
- api
22
- }) {
17
+ function Template({ name, typeName, api }) {
23
18
  return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _jsxruntime.Fragment, { children: [
24
19
  `export const ${name} = ${JSON.stringify(api, void 0, 2)} as const`,
25
20
  /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "br", {}),
@@ -27,30 +22,19 @@ function Template({
27
22
  ] });
28
23
  }
29
24
  var defaultTemplates = { default: Template };
30
- function OasType({
31
- name,
32
- typeName,
33
- Template: Template2 = defaultTemplates.default
34
- }) {
25
+ function OasType({ name, typeName, Template: Template2 = defaultTemplates.default }) {
35
26
  const oas = _hooks.useOas.call(void 0, );
36
27
  return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, Template2, { name, typeName, api: oas.api });
37
28
  }
38
29
  OasType.File = function({ name, typeName, templates = defaultTemplates }) {
39
30
  const { key: pluginKey2 } = _react.usePlugin.call(void 0, );
40
- const file = _react.useGetFile.call(void 0, { name, extName: ".ts", pluginKey: pluginKey2 });
31
+ const pluginManager = _react.usePluginManager.call(void 0, );
32
+ const file = pluginManager.getFile({ name, extName: ".ts", pluginKey: pluginKey2 });
41
33
  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
- ) });
34
+ return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.Editor, { language: "typescript", children: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _react.File, { baseName: file.baseName, path: file.path, meta: file.meta, children: [
35
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.File.Import, { name: ["Infer"], path: "@kubb/swagger-ts/oas", isTypeOnly: true }),
36
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.File.Source, { children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, OasType, { Template: Template2, name, typeName }) })
37
+ ] }) });
54
38
  };
55
39
  OasType.templates = defaultTemplates;
56
40
 
@@ -83,7 +67,6 @@ var typeKeywordMapper = {
83
67
  }
84
68
  return factory.createTypeLiteralNode(nodes);
85
69
  },
86
- lazy: void 0,
87
70
  string: () => factory.keywordTypeNodes.string,
88
71
  boolean: () => factory.keywordTypeNodes.boolean,
89
72
  undefined: () => factory.keywordTypeNodes.undefined,
@@ -165,72 +148,67 @@ var typeKeywordMapper = {
165
148
  format: void 0,
166
149
  catchall: void 0
167
150
  };
168
- function parseTypeMeta(item, options) {
169
- const mapper = options.mapper || typeKeywordMapper;
170
- const value = mapper[item.keyword];
151
+ function parseTypeMeta(parent, current, options) {
152
+ const value = typeKeywordMapper[current.keyword];
171
153
  if (!value) {
172
154
  return void 0;
173
155
  }
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));
156
+ if (_swagger.isKeyword.call(void 0, current, _swagger.schemaKeywords.union)) {
157
+ return typeKeywordMapper.union(current.args.map((schema) => parseTypeMeta(current, schema, options)).filter(Boolean));
177
158
  }
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));
159
+ if (_swagger.isKeyword.call(void 0, current, _swagger.schemaKeywords.and)) {
160
+ return typeKeywordMapper.and(current.args.map((schema) => parseTypeMeta(current, schema, options)).filter(Boolean));
181
161
  }
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));
162
+ if (_swagger.isKeyword.call(void 0, current, _swagger.schemaKeywords.array)) {
163
+ return typeKeywordMapper.array(current.args.items.map((schema) => parseTypeMeta(current, schema, options)).filter(Boolean));
185
164
  }
186
- if (_swagger.isKeyword.call(void 0, item, _swagger.schemaKeywords.enum)) {
187
- const value2 = mapper[item.keyword];
188
- return value2(item.args.typeName);
165
+ if (_swagger.isKeyword.call(void 0, current, _swagger.schemaKeywords.enum)) {
166
+ return typeKeywordMapper.enum(current.args.typeName);
189
167
  }
190
- if (_swagger.isKeyword.call(void 0, item, _swagger.schemaKeywords.ref)) {
191
- const value2 = mapper[item.keyword];
192
- return value2(item.args.name);
168
+ if (_swagger.isKeyword.call(void 0, current, _swagger.schemaKeywords.ref)) {
169
+ return typeKeywordMapper.ref(current.args.name);
193
170
  }
194
- if (_swagger.isKeyword.call(void 0, item, _swagger.schemaKeywords.blob)) {
171
+ if (_swagger.isKeyword.call(void 0, current, _swagger.schemaKeywords.blob)) {
195
172
  return value();
196
173
  }
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
- );
174
+ if (_swagger.isKeyword.call(void 0, current, _swagger.schemaKeywords.tuple)) {
175
+ return typeKeywordMapper.tuple(current.args.map((schema) => parseTypeMeta(current, schema, options)).filter(Boolean));
202
176
  }
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);
177
+ if (_swagger.isKeyword.call(void 0, current, _swagger.schemaKeywords.const)) {
178
+ return typeKeywordMapper.const(current.args.name, current.args.format);
206
179
  }
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];
180
+ if (_swagger.isKeyword.call(void 0, current, _swagger.schemaKeywords.object)) {
181
+ const properties = Object.entries(_optionalChain([current, 'access', _ => _.args, 'optionalAccess', _2 => _2.properties]) || {}).filter((item) => {
182
+ const schemas = item[1];
211
183
  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];
184
+ }).map((item) => {
185
+ const name = item[0];
186
+ const schemas = item[1];
187
+ const isNullish = schemas.some((schema) => schema.keyword === _swagger.schemaKeywords.nullish);
188
+ const isNullable = schemas.some((schema) => schema.keyword === _swagger.schemaKeywords.nullable);
189
+ const isOptional = schemas.some((schema) => schema.keyword === _swagger.schemaKeywords.optional);
190
+ const isReadonly = schemas.some((schema) => schema.keyword === _swagger.schemaKeywords.readOnly);
191
+ const describeSchema = schemas.find((schema) => schema.keyword === _swagger.schemaKeywords.describe);
192
+ const deprecatedSchema = schemas.find((schema) => schema.keyword === _swagger.schemaKeywords.deprecated);
193
+ const defaultSchema = schemas.find((schema) => schema.keyword === _swagger.schemaKeywords.default);
194
+ const exampleSchema = schemas.find((schema) => schema.keyword === _swagger.schemaKeywords.example);
195
+ const typeSchema = schemas.find((schema) => schema.keyword === _swagger.schemaKeywords.type);
196
+ const formatSchema = schemas.find((schema) => schema.keyword === _swagger.schemaKeywords.format);
197
+ let type = schemas.map((schema) => parseTypeMeta(current, schema, options)).filter(Boolean)[0];
226
198
  if (isNullable) {
227
- type = factory.createUnionDeclaration({ nodes: [type, factory.keywordTypeNodes.null] });
199
+ type = factory.createUnionDeclaration({
200
+ nodes: [type, factory.keywordTypeNodes.null]
201
+ });
228
202
  }
229
203
  if (isNullish && ["undefined", "questionTokenAndUndefined"].includes(options.optionalType)) {
230
- type = factory.createUnionDeclaration({ nodes: [type, factory.keywordTypeNodes.undefined] });
204
+ type = factory.createUnionDeclaration({
205
+ nodes: [type, factory.keywordTypeNodes.undefined]
206
+ });
231
207
  }
232
208
  if (isOptional && ["undefined", "questionTokenAndUndefined"].includes(options.optionalType)) {
233
- type = factory.createUnionDeclaration({ nodes: [type, factory.keywordTypeNodes.undefined] });
209
+ type = factory.createUnionDeclaration({
210
+ nodes: [type, factory.keywordTypeNodes.undefined]
211
+ });
234
212
  }
235
213
  const propertySignature = factory.createPropertySignature({
236
214
  questionToken: isOptional && ["questionToken", "questionTokenAndUndefined"].includes(options.optionalType),
@@ -242,17 +220,19 @@ function parseTypeMeta(item, options) {
242
220
  node: propertySignature,
243
221
  comments: [
244
222
  describeSchema ? `@description ${_transformers2.default.jsStringEscape(describeSchema.args)}` : void 0,
245
- deprecatedSchema ? `@deprecated` : void 0,
223
+ deprecatedSchema ? "@deprecated" : void 0,
246
224
  defaultSchema ? `@default ${defaultSchema.args}` : void 0,
247
225
  exampleSchema ? `@example ${exampleSchema.args}` : void 0,
248
226
  typeSchema ? `@type ${typeSchema.args}${!isOptional ? "" : " | undefined"} ${_optionalChain([formatSchema, 'optionalAccess', _3 => _3.args]) || ""}` : void 0
249
227
  ].filter(Boolean)
250
228
  });
251
229
  });
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));
230
+ const additionalProperties = _optionalChain([current, 'access', _4 => _4.args, 'optionalAccess', _5 => _5.additionalProperties, 'optionalAccess', _6 => _6.length]) ? factory.createIndexSignature(
231
+ current.args.additionalProperties.map((schema) => parseTypeMeta(current, schema, options)).filter(Boolean).at(0)
232
+ ) : void 0;
233
+ return typeKeywordMapper.object([...properties, additionalProperties].filter(Boolean));
254
234
  }
255
- if (item.keyword in mapper) {
235
+ if (current.keyword in typeKeywordMapper) {
256
236
  return value();
257
237
  }
258
238
  return void 0;
@@ -266,40 +246,48 @@ function typeParser(schemas, options) {
266
246
  const isNullish = schemas.some((item) => item.keyword === _swagger.schemaKeywords.nullish);
267
247
  const isNullable = schemas.some((item) => item.keyword === _swagger.schemaKeywords.nullable);
268
248
  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();
249
+ let type = schemas.map((schema) => parseTypeMeta(void 0, schema, options)).filter(Boolean).at(0) || typeKeywordMapper.undefined();
270
250
  if (isNullable) {
271
- type = factory.createUnionDeclaration({ nodes: [type, factory.keywordTypeNodes.null] });
251
+ type = factory.createUnionDeclaration({
252
+ nodes: [type, factory.keywordTypeNodes.null]
253
+ });
272
254
  }
273
255
  if (isNullish && ["undefined", "questionTokenAndUndefined"].includes(options.optionalType)) {
274
- type = factory.createUnionDeclaration({ nodes: [type, factory.keywordTypeNodes.undefined] });
256
+ type = factory.createUnionDeclaration({
257
+ nodes: [type, factory.keywordTypeNodes.undefined]
258
+ });
275
259
  }
276
260
  if (isOptional && ["undefined", "questionTokenAndUndefined"].includes(options.optionalType)) {
277
- type = factory.createUnionDeclaration({ nodes: [type, factory.keywordTypeNodes.undefined] });
261
+ type = factory.createUnionDeclaration({
262
+ nodes: [type, factory.keywordTypeNodes.undefined]
263
+ });
278
264
  }
279
265
  const node = factory.createTypeAliasDeclaration({
280
266
  modifiers: [factory.modifiers.export],
281
267
  name: options.name,
282
- type: _optionalChain([options, 'access', _7 => _7.keysToOmit, 'optionalAccess', _8 => _8.length]) ? factory.createOmitDeclaration({ keys: options.keysToOmit, type, nonNullable: true }) : type
268
+ type: _optionalChain([options, 'access', _7 => _7.keysToOmit, 'optionalAccess', _8 => _8.length]) ? factory.createOmitDeclaration({
269
+ keys: options.keysToOmit,
270
+ type,
271
+ nonNullable: true
272
+ }) : type
283
273
  });
284
274
  const enumSchemas = _swagger.SchemaGenerator.deepSearch(schemas, _swagger.schemaKeywords.enum);
285
275
  if (enumSchemas) {
286
276
  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
- }));
277
+ extraNodes.push(
278
+ ...factory.createEnumDeclaration({
279
+ name: _transformers2.default.camelCase(enumSchema.args.name),
280
+ typeName: enumSchema.args.typeName,
281
+ 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(Boolean),
282
+ type: options.enumType
283
+ })
284
+ );
295
285
  });
296
286
  }
297
287
  nodes.push(
298
288
  factory.appendJSDocToNode({
299
289
  node,
300
- comments: [
301
- options.description ? `@description ${_transformers2.default.jsStringEscape(options.description)}` : void 0
302
- ].filter(Boolean)
290
+ comments: [options.description ? `@description ${_transformers2.default.jsStringEscape(options.description)}` : void 0].filter(Boolean)
303
291
  })
304
292
  );
305
293
  const filterdNodes = nodes.filter(
@@ -315,7 +303,9 @@ function typeParser(schemas, options) {
315
303
  var SchemaGenerator2 = class extends _swagger.SchemaGenerator {
316
304
  async schema(name, object) {
317
305
  const { oas, pluginManager, mode, plugin, output } = this.context;
318
- const root = _react.createRoot.call(void 0, { logger: pluginManager.logger });
306
+ const root = _react.createRoot.call(void 0, {
307
+ logger: pluginManager.logger
308
+ });
319
309
  root.render(
320
310
  /* @__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
311
  { meta: { pluginManager, plugin } }
@@ -323,13 +313,18 @@ var SchemaGenerator2 = class extends _swagger.SchemaGenerator {
323
313
  return root.files;
324
314
  }
325
315
  // 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
- } = {}) {
316
+ getSource(name, schemas, { keysToOmit, description } = {}) {
330
317
  const texts = [];
331
- const resolvedName = this.context.pluginManager.resolveName({ name, pluginKey, type: "function" });
332
- const resvoledTypeName = this.context.pluginManager.resolveName({ name, pluginKey, type: "type" });
318
+ const resolvedName = this.context.pluginManager.resolveName({
319
+ name,
320
+ pluginKey,
321
+ type: "function"
322
+ });
323
+ const resvoledTypeName = this.context.pluginManager.resolveName({
324
+ name,
325
+ pluginKey,
326
+ type: "type"
327
+ });
333
328
  const typeOutput = typeParser(schemas, {
334
329
  name: resolvedName,
335
330
  typeName: resvoledTypeName,
@@ -354,42 +349,24 @@ var SchemaGenerator2 = class extends _swagger.SchemaGenerator {
354
349
 
355
350
  function printCombinedSchema(name, operation, schemas) {
356
351
  const properties = {
357
- "response": factory2.createTypeReferenceNode(
358
- factory2.createIdentifier(schemas.response.name),
359
- void 0
360
- )
352
+ response: factory2.createTypeReferenceNode(factory2.createIdentifier(schemas.response.name), void 0)
361
353
  };
362
354
  if (schemas.request) {
363
- properties["request"] = factory2.createTypeReferenceNode(
364
- factory2.createIdentifier(schemas.request.name),
365
- void 0
366
- );
355
+ properties["request"] = factory2.createTypeReferenceNode(factory2.createIdentifier(schemas.request.name), void 0);
367
356
  }
368
357
  if (schemas.pathParams) {
369
- properties["pathParams"] = factory2.createTypeReferenceNode(
370
- factory2.createIdentifier(schemas.pathParams.name),
371
- void 0
372
- );
358
+ properties["pathParams"] = factory2.createTypeReferenceNode(factory2.createIdentifier(schemas.pathParams.name), void 0);
373
359
  }
374
360
  if (schemas.queryParams) {
375
- properties["queryParams"] = factory2.createTypeReferenceNode(
376
- factory2.createIdentifier(schemas.queryParams.name),
377
- void 0
378
- );
361
+ properties["queryParams"] = factory2.createTypeReferenceNode(factory2.createIdentifier(schemas.queryParams.name), void 0);
379
362
  }
380
363
  if (schemas.headerParams) {
381
- properties["headerParams"] = factory2.createTypeReferenceNode(
382
- factory2.createIdentifier(schemas.headerParams.name),
383
- void 0
384
- );
364
+ properties["headerParams"] = factory2.createTypeReferenceNode(factory2.createIdentifier(schemas.headerParams.name), void 0);
385
365
  }
386
366
  if (schemas.errors) {
387
367
  properties["errors"] = factory2.createUnionDeclaration({
388
368
  nodes: schemas.errors.map((error) => {
389
- return factory2.createTypeReferenceNode(
390
- factory2.createIdentifier(error.name),
391
- void 0
392
- );
369
+ return factory2.createTypeReferenceNode(factory2.createIdentifier(error.name), void 0);
393
370
  })
394
371
  });
395
372
  }
@@ -401,12 +378,10 @@ function printCombinedSchema(name, operation, schemas) {
401
378
  if (!type) {
402
379
  return void 0;
403
380
  }
404
- return factory2.createPropertySignature(
405
- {
406
- name: _transformers2.default.pascalCase(key),
407
- type
408
- }
409
- );
381
+ return factory2.createPropertySignature({
382
+ name: _transformers2.default.pascalCase(key),
383
+ type
384
+ });
410
385
  }).filter(Boolean)
411
386
  ),
412
387
  modifiers: [factory2.modifiers.export]
@@ -420,37 +395,27 @@ OperationSchema.File = function({ mode = "directory" }) {
420
395
  const plugin = _react.usePlugin.call(void 0, );
421
396
  const pluginManager = _react.usePluginManager.call(void 0, );
422
397
  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" });
398
+ const { getSchemas, getFile, getName } = _hooks.useOperationManager.call(void 0, );
426
399
  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);
400
+ const file = getFile(operation);
401
+ const schemas = getSchemas(operation);
402
+ const factoryName = getName(operation, { type: "type" });
403
+ const generator = new SchemaGenerator2(plugin.options, {
404
+ oas,
405
+ plugin,
406
+ pluginManager
407
+ });
408
+ const items = [schemas.pathParams, schemas.queryParams, schemas.headerParams, schemas.statusCodes, schemas.request, schemas.response].flat().filter(Boolean);
436
409
  const mapItem = ({ name, schema: object, ...options }, i) => {
437
410
  return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _components.Oas.Schema, { generator, name, object, children: [
438
411
  mode === "directory" && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _components.Schema.Imports, { isTypeOnly: true }),
439
412
  /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.File.Source, { children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _components.Schema.Source, { options }) })
440
413
  ] }, i);
441
414
  };
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
- ) });
415
+ return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.Editor, { language: "typescript", children: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _react.File, { baseName: file.baseName, path: file.path, meta: file.meta, children: [
416
+ items.map(mapItem),
417
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.File.Source, { children: printCombinedSchema(factoryName, operation, schemas) })
418
+ ] }) });
454
419
  };
455
420
 
456
421
  // src/OperationGenerator.tsx
@@ -458,7 +423,9 @@ OperationSchema.File = function({ mode = "directory" }) {
458
423
  var OperationGenerator = class extends _swagger.OperationGenerator {
459
424
  async all(operations) {
460
425
  const { oas, pluginManager, plugin } = this.context;
461
- const root = _react.createRoot.call(void 0, { logger: pluginManager.logger });
426
+ const root = _react.createRoot.call(void 0, {
427
+ logger: pluginManager.logger
428
+ });
462
429
  root.render(
463
430
  /* @__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
431
  { meta: { pluginManager, plugin } }
@@ -467,7 +434,9 @@ var OperationGenerator = class extends _swagger.OperationGenerator {
467
434
  }
468
435
  async operation(operation, options) {
469
436
  const { oas, pluginManager, plugin, mode } = this.context;
470
- const root = _react.createRoot.call(void 0, { logger: pluginManager.logger });
437
+ const root = _react.createRoot.call(void 0, {
438
+ logger: pluginManager.logger
439
+ });
471
440
  root.render(
472
441
  /* @__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
442
  { meta: { pluginManager, plugin: { ...plugin, options } } }
@@ -554,33 +523,27 @@ var definePlugin = _core.createPlugin.call(void 0, (options) => {
554
523
  const oas = await swaggerPlugin.api.getOas();
555
524
  const root = _path2.default.resolve(this.config.root, this.config.output.path);
556
525
  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
- );
526
+ const schemaGenerator = new SchemaGenerator2(this.plugin.options, {
527
+ oas,
528
+ pluginManager: this.pluginManager,
529
+ plugin: this.plugin,
530
+ contentType: swaggerPlugin.api.contentType,
531
+ include: void 0,
532
+ mode,
533
+ output: output.path
534
+ });
569
535
  const schemaFiles = await schemaGenerator.build();
570
536
  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
- );
537
+ const operationGenerator = new OperationGenerator(this.plugin.options, {
538
+ oas,
539
+ pluginManager: this.pluginManager,
540
+ plugin: this.plugin,
541
+ contentType: swaggerPlugin.api.contentType,
542
+ exclude,
543
+ include,
544
+ override,
545
+ mode
546
+ });
584
547
  const operationFiles = await operationGenerator.build();
585
548
  await this.addFile(...operationFiles);
586
549
  },
@@ -610,4 +573,4 @@ var src_default = definePluginDefault;
610
573
 
611
574
 
612
575
  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
576
+ //# sourceMappingURL=chunk-IVO3V2IW.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/plugin.ts","../src/OperationGenerator.tsx","../src/components/OasType.tsx","../src/components/OperationSchema.tsx","../src/SchemaGenerator.tsx","../src/typeParser.ts","../src/index.ts"],"names":["createRoot","Generator","Oas","Template","pluginKey","transformers","print","factory","Editor","File","usePlugin","usePluginManager","Schema","useOas","node","jsx","SchemaGenerator","Fragment","jsxs","options"],"mappings":";AAAA,OAAO,UAAU;AAEjB,SAAS,cAAc,aAAa,qBAAqB;AACzD,SAAS,WAAW,kBAAkB;AACtC,SAAS,sBAAsB;AAC/B,SAAS,cAAc,yBAAyB;;;ACLhD,SAAS,cAAAA,mBAAkB;AAC3B,SAAS,sBAAsBC,kBAAiB;AAChD,SAAS,OAAAC,YAAW;;;ACFpB,SAAS,QAAQ,MAAM,MAAM,WAAW,wBAAwB;AAChE,SAAS,cAAc;AAiBnB,mBAEE,KAFF;AAFJ,SAAS,SAAS,EAAE,MAAM,UAAU,IAAI,GAA6B;AACnE,SACE,iCACG;AAAA,oBAAgB,IAAI,MAAM,KAAK,UAAU,KAAK,QAAW,CAAC,CAAC;AAAA,IAC5D,oBA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,QAAQ,KAAK;AAAA,QACb,aAAa,cAAc,IAAI;AAAA,QAC/B;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,MACF,CAAC;AAED,YAAM,iBAAiB,MAAM,mBAAmB,MAAM;AACtD,YAAM,KAAK,QAAQ,GAAG,cAAc;AAAA,IACtC;AAAA,IACA,MAAM,WAAW;AACf,UAAI,KAAK,OAAO,OAAO,UAAU,OAAO;AACtC;AAAA,MACF;AAEA,YAAM,OAAO,KAAK,QAAQ,KAAK,OAAO,MAAM,KAAK,OAAO,OAAO,IAAI;AAEnE,YAAM,KAAK,YAAY,WAAW;AAAA,QAChC;AAAA,QACA;AAAA,QACA,MAAM,EAAE,WAAW,KAAK,OAAO,IAAI;AAAA,MACrC,CAAC;AAAA,IACH;AAAA,EACF;AACF,CAAC;;;AM3HD,IAAM,sBAAsB;AAE5B,IAAO,cAAQ","sourcesContent":["import path from 'node:path'\n\nimport { createPlugin, FileManager, PluginManager } from '@kubb/core'\nimport { camelCase, pascalCase } from '@kubb/core/transformers'\nimport { renderTemplate } from '@kubb/core/utils'\nimport { pluginName as swaggerPluginName } from '@kubb/swagger'\n\nimport { OperationGenerator } from './OperationGenerator.tsx'\nimport { SchemaGenerator } from './SchemaGenerator.tsx'\n\nimport type { Plugin } from '@kubb/core'\nimport type { PluginOptions as SwaggerPluginOptions } from '@kubb/swagger'\nimport type { PluginOptions } from './types.ts'\nexport const pluginName = 'swagger-ts' satisfies PluginOptions['name']\nexport const pluginKey: PluginOptions['key'] = [pluginName] satisfies PluginOptions['key']\n\nexport const definePlugin = createPlugin<PluginOptions>((options) => {\n const {\n output = { path: 'types' },\n group,\n exclude = [],\n include,\n override = [],\n enumType = 'asConst',\n enumSuffix = '',\n dateType = 'string',\n unknownType = 'any',\n optionalType = 'questionToken',\n transformers = {},\n oasType = false,\n } = options\n const template = group?.output ? group.output : `${output.path}/{{tag}}Controller`\n\n return {\n name: pluginName,\n options: {\n transformers,\n dateType,\n optionalType,\n oasType,\n enumType,\n enumSuffix,\n // keep the used enumnames between SchemaGenerator and OperationGenerator per plugin(pluginKey)\n usedEnumNames: {},\n unknownType,\n },\n pre: [swaggerPluginName],\n resolvePath(baseName, pathMode, options) {\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = pathMode ?? FileManager.getMode(path.resolve(root, output.path))\n\n if (mode === 'file') {\n /**\n * when output is a file then we will always append to the same file(output file), see fileManager.addOrAppend\n * Other plugins then need to call addOrAppend instead of just add from the fileManager class\n */\n return path.resolve(root, output.path)\n }\n\n if (options?.tag && group?.type === 'tag') {\n const tag = camelCase(options.tag)\n\n return path.resolve(root, renderTemplate(template, { tag }), baseName)\n }\n\n return path.resolve(root, output.path, baseName)\n },\n resolveName(name, type) {\n const resolvedName = pascalCase(name, { isFile: type === 'file' })\n\n if (type) {\n return transformers?.name?.(resolvedName, type) || resolvedName\n }\n\n return resolvedName\n },\n async writeFile(source, writePath) {\n if (!writePath.endsWith('.ts') || !source) {\n return\n }\n\n return this.fileManager.write(source, writePath, { sanity: false })\n },\n async buildStart() {\n const [swaggerPlugin]: [Plugin<SwaggerPluginOptions>] = PluginManager.getDependedPlugins<SwaggerPluginOptions>(this.plugins, [swaggerPluginName])\n\n const oas = await swaggerPlugin.api.getOas()\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = FileManager.getMode(path.resolve(root, output.path))\n\n const schemaGenerator = new SchemaGenerator(this.plugin.options, {\n oas,\n pluginManager: this.pluginManager,\n plugin: this.plugin,\n contentType: swaggerPlugin.api.contentType,\n include: undefined,\n mode,\n output: output.path,\n })\n\n const schemaFiles = await schemaGenerator.build()\n await this.addFile(...schemaFiles)\n\n const operationGenerator = new OperationGenerator(this.plugin.options, {\n oas,\n pluginManager: this.pluginManager,\n plugin: this.plugin,\n contentType: swaggerPlugin.api.contentType,\n exclude,\n include,\n override,\n mode,\n })\n\n const operationFiles = await operationGenerator.build()\n await this.addFile(...operationFiles)\n },\n async buildEnd() {\n if (this.config.output.write === false) {\n return\n }\n\n const root = path.resolve(this.config.root, this.config.output.path)\n\n await this.fileManager.addIndexes({\n root,\n output,\n meta: { pluginKey: this.plugin.key },\n })\n },\n }\n})\n","import { createRoot } from '@kubb/react'\nimport { OperationGenerator as Generator } from '@kubb/swagger'\nimport { Oas } from '@kubb/swagger/components'\n\nimport { OasType } from './components/OasType.tsx'\nimport { OperationSchema } from './components/OperationSchema.tsx'\n\nimport type { AppContextProps } from '@kubb/react'\nimport type { OperationMethodResult } from '@kubb/swagger'\nimport type { Operation } from '@kubb/swagger/oas'\nimport type { FileMeta, PluginOptions } from './types.ts'\n\nexport class OperationGenerator extends Generator<PluginOptions['resolvedOptions'], PluginOptions> {\n async all(operations: Operation[]): OperationMethodResult<FileMeta> {\n const { oas, pluginManager, plugin } = this.context\n\n const root = createRoot<AppContextProps<PluginOptions['appMeta']>>({\n logger: pluginManager.logger,\n })\n\n root.render(\n <Oas oas={oas} operations={operations} getOperationSchemas={(...props) => this.getSchemas(...props)}>\n {plugin.options.oasType && <OasType.File name=\"oas\" typeName=\"Oas\" />}\n </Oas>,\n { meta: { pluginManager, plugin } },\n )\n\n return root.files\n }\n\n async operation(operation: Operation, options: PluginOptions['resolvedOptions']): OperationMethodResult<FileMeta> {\n const { oas, pluginManager, plugin, mode } = this.context\n\n const root = createRoot<AppContextProps<PluginOptions['appMeta']>>({\n logger: pluginManager.logger,\n })\n root.render(\n <Oas oas={oas} operations={[operation]} getOperationSchemas={(...props) => this.getSchemas(...props)}>\n <Oas.Operation operation={operation}>\n <OperationSchema.File mode={mode} />\n </Oas.Operation>\n </Oas>,\n { meta: { pluginManager, plugin: { ...plugin, options } } },\n )\n\n return root.files\n }\n\n async get(): OperationMethodResult<FileMeta> {\n return null\n }\n\n async post(): OperationMethodResult<FileMeta> {\n return null\n }\n\n async put(): OperationMethodResult<FileMeta> {\n return null\n }\n async patch(): OperationMethodResult<FileMeta> {\n return null\n }\n async delete(): OperationMethodResult<FileMeta> {\n return null\n }\n}\n","import { Editor, File, Type, usePlugin, usePluginManager } from '@kubb/react'\nimport { useOas } from '@kubb/swagger/hooks'\n\nimport type { OasTypes } from '@kubb/swagger/oas'\nimport type { ReactNode } from 'react'\nimport type { FileMeta, PluginOptions } from '../types.ts'\n\ntype TemplateProps = {\n /**\n * Name of the function\n */\n name: string\n typeName: string\n api: OasTypes.OASDocument\n}\n\nfunction Template({ name, typeName, api }: TemplateProps): ReactNode {\n return (\n <>\n {`export const ${name} = ${JSON.stringify(api, undefined, 2)} as const`}\n <br />\n <Type name={typeName} export>\n {`Infer<typeof ${name}>`}\n </Type>\n </>\n )\n}\n\nconst defaultTemplates = { default: Template } as const\n\ntype Props = {\n name: string\n typeName: string\n /**\n * This will make it possible to override the default behaviour.\n */\n Template?: React.ComponentType<React.ComponentProps<typeof Template>>\n}\n\nexport function OasType({ name, typeName, Template = defaultTemplates.default }: Props): ReactNode {\n const oas = useOas()\n\n return <Template name={name} typeName={typeName} api={oas.api} />\n}\n\ntype FileProps = {\n name: string\n typeName: string\n /**\n * This will make it possible to override the default behaviour.\n */\n templates?: typeof defaultTemplates\n}\n\nOasType.File = function ({ name, typeName, templates = defaultTemplates }: FileProps): ReactNode {\n const { key: pluginKey } = usePlugin<PluginOptions>()\n const pluginManager = usePluginManager()\n const file = pluginManager.getFile({ name, extName: '.ts', pluginKey })\n\n const Template = templates.default\n\n return (\n <Editor language=\"typescript\">\n <File<FileMeta> baseName={file.baseName} path={file.path} meta={file.meta}>\n <File.Import name={['Infer']} path=\"@kubb/swagger-ts/oas\" isTypeOnly />\n <File.Source>\n <OasType Template={Template} name={name} typeName={typeName} />\n </File.Source>\n </File>\n </Editor>\n )\n}\n\nOasType.templates = defaultTemplates\n","/* eslint-disable no-empty-pattern */\n/* eslint-disable @typescript-eslint/ban-types */\nimport transformers from '@kubb/core/transformers'\nimport { print } from '@kubb/parser'\nimport * as factory from '@kubb/parser/factory'\nimport { Editor, File, usePlugin, usePluginManager } from '@kubb/react'\nimport { Oas, Schema } from '@kubb/swagger/components'\nimport { useOas, useOperation, useOperationManager } from '@kubb/swagger/hooks'\n\nimport { SchemaGenerator } from '../SchemaGenerator.tsx'\n\nimport type { KubbFile } from '@kubb/core'\nimport type { ts } from '@kubb/parser'\nimport type { OperationSchema as OperationSchemaType } from '@kubb/swagger'\nimport type { OperationSchemas } from '@kubb/swagger'\nimport type { Operation } from '@kubb/swagger/oas'\nimport type { ReactNode } from 'react'\nimport type { FileMeta, PluginOptions } from '../types.ts'\n\ntype Props = {}\n\nfunction printCombinedSchema(name: string, operation: Operation, schemas: OperationSchemas): string {\n const properties: Record<string, ts.TypeNode> = {\n response: factory.createTypeReferenceNode(factory.createIdentifier(schemas.response.name), undefined),\n }\n\n if (schemas.request) {\n properties['request'] = factory.createTypeReferenceNode(factory.createIdentifier(schemas.request.name), undefined)\n }\n\n if (schemas.pathParams) {\n properties['pathParams'] = factory.createTypeReferenceNode(factory.createIdentifier(schemas.pathParams.name), undefined)\n }\n\n if (schemas.queryParams) {\n properties['queryParams'] = factory.createTypeReferenceNode(factory.createIdentifier(schemas.queryParams.name), undefined)\n }\n\n if (schemas.headerParams) {\n properties['headerParams'] = factory.createTypeReferenceNode(factory.createIdentifier(schemas.headerParams.name), undefined)\n }\n\n if (schemas.errors) {\n properties['errors'] = factory.createUnionDeclaration({\n nodes: schemas.errors.map((error) => {\n return factory.createTypeReferenceNode(factory.createIdentifier(error.name), undefined)\n }),\n })!\n }\n\n const namespaceNode = factory.createTypeAliasDeclaration({\n name: operation.method === 'get' ? `${name}Query` : `${name}Mutation`,\n type: factory.createTypeLiteralNode(\n Object.keys(properties)\n .map((key) => {\n const type = properties[key]\n if (!type) {\n return undefined\n }\n\n return factory.createPropertySignature({\n name: transformers.pascalCase(key),\n type,\n })\n })\n .filter(Boolean),\n ),\n modifiers: [factory.modifiers.export],\n })\n\n return print(namespaceNode)\n}\n\nexport function OperationSchema({}: Props): ReactNode {\n return <></>\n}\n\ntype FileProps = {\n mode: KubbFile.Mode | undefined\n}\n\nOperationSchema.File = function ({ mode = 'directory' }: FileProps): ReactNode {\n const plugin = usePlugin<PluginOptions>()\n\n const pluginManager = usePluginManager()\n const oas = useOas()\n const { getSchemas, getFile, getName } = useOperationManager()\n const operation = useOperation()\n\n const file = getFile(operation)\n const schemas = getSchemas(operation)\n const factoryName = getName(operation, { type: 'type' })\n const generator = new SchemaGenerator(plugin.options, {\n oas,\n plugin,\n pluginManager,\n })\n\n const items = [schemas.pathParams, schemas.queryParams, schemas.headerParams, schemas.statusCodes, schemas.request, schemas.response].flat().filter(Boolean)\n\n const mapItem = ({ name, schema: object, ...options }: OperationSchemaType, i: number) => {\n return (\n <Oas.Schema key={i} generator={generator} name={name} object={object}>\n {mode === 'directory' && <Schema.Imports isTypeOnly />}\n <File.Source>\n <Schema.Source options={options} />\n </File.Source>\n </Oas.Schema>\n )\n }\n\n return (\n <Editor language=\"typescript\">\n <File<FileMeta> baseName={file.baseName} path={file.path} meta={file.meta}>\n {items.map(mapItem)}\n\n <File.Source>{printCombinedSchema(factoryName, operation, schemas)}</File.Source>\n </File>\n </Editor>\n )\n}\n","import { createRoot } from '@kubb/react'\nimport { SchemaGenerator as Generator } from '@kubb/swagger'\nimport { Oas, Schema } from '@kubb/swagger/components'\nimport { pluginKey as swaggerTypeScriptPluginKey } from '@kubb/swagger-ts'\n\nimport { pluginKey } from './plugin.ts'\nimport { typeParser } from './typeParser.ts'\n\nimport type { AppContextProps } from '@kubb/react'\nimport type { Schema as SchemaType, SchemaGeneratorBuildOptions, SchemaMethodResult } from '@kubb/swagger'\nimport type { SchemaObject } from '@kubb/swagger/oas'\nimport type { FileMeta, PluginOptions } from './types.ts'\n\nexport class SchemaGenerator extends Generator<PluginOptions['resolvedOptions'], PluginOptions> {\n async schema(name: string, object: SchemaObject): SchemaMethodResult<FileMeta> {\n const { oas, pluginManager, mode, plugin, output } = this.context\n\n const root = createRoot<AppContextProps<PluginOptions['appMeta']>>({\n logger: pluginManager.logger,\n })\n\n root.render(\n <Oas oas={oas}>\n <Oas.Schema generator={this} name={name} object={object}>\n <Schema.File isTypeOnly output={output} mode={mode} />\n </Oas.Schema>\n </Oas>,\n { meta: { pluginManager, plugin } },\n )\n\n return root.files\n }\n // TODO convert to a react component called `Schema.Parser` with props parser as part of the SchemaContext\n getSource(name: string, schemas: SchemaType[], { keysToOmit, description }: SchemaGeneratorBuildOptions = {}): string[] {\n const texts: string[] = []\n\n const resolvedName = this.context.pluginManager.resolveName({\n name,\n pluginKey,\n type: 'function',\n })\n const resvoledTypeName = this.context.pluginManager.resolveName({\n name,\n pluginKey: swaggerTypeScriptPluginKey,\n type: 'type',\n })\n\n const typeOutput = typeParser(schemas, {\n name: resolvedName,\n typeName: resvoledTypeName,\n description,\n enumType: this.options.enumType || 'asConst',\n optionalType: this.options.optionalType,\n keysToOmit,\n })\n\n texts.push(typeOutput)\n\n return texts\n }\n /**\n * @deprecated only used for testing\n */\n\n buildSource(name: string, schema: SchemaObject, options: SchemaGeneratorBuildOptions = {}): string[] {\n const schemas = this.buildSchemas(schema, name)\n\n return this.getSource(name, schemas, options)\n }\n}\n","import transformers from '@kubb/core/transformers'\nimport { print } from '@kubb/parser'\nimport * as factory from '@kubb/parser/factory'\nimport { SchemaGenerator, isKeyword, schemaKeywords } from '@kubb/swagger'\n\nimport type { ts } from '@kubb/parser'\nimport type { Schema, SchemaKeywordMapper, SchemaMapper } from '@kubb/swagger'\n\nexport const typeKeywordMapper = {\n any: () => factory.keywordTypeNodes.any,\n unknown: () => factory.keywordTypeNodes.unknown,\n number: () => factory.keywordTypeNodes.number,\n integer: () => factory.keywordTypeNodes.number,\n object: (nodes?: ts.TypeElement[]) => {\n if (!nodes) {\n return factory.keywordTypeNodes.object\n }\n\n return factory.createTypeLiteralNode(nodes)\n },\n string: () => factory.keywordTypeNodes.string,\n boolean: () => factory.keywordTypeNodes.boolean,\n undefined: () => factory.keywordTypeNodes.undefined,\n nullable: undefined,\n null: () => factory.keywordTypeNodes.null,\n nullish: undefined,\n array: (nodes?: ts.TypeNode[]) => {\n if (!nodes) {\n return undefined\n }\n\n return factory.createArrayDeclaration({ nodes })\n },\n tuple: (nodes?: ts.TypeNode[]) => {\n if (!nodes) {\n return undefined\n }\n\n return factory.createTupleTypeNode(nodes)\n },\n enum: (name?: string) => {\n if (!name) {\n return undefined\n }\n\n return factory.createTypeReferenceNode(name, undefined)\n },\n union: (nodes?: ts.TypeNode[]) => {\n if (!nodes) {\n return undefined\n }\n\n return factory.createUnionDeclaration({\n withParentheses: true,\n nodes,\n })\n },\n const: (name?: string | number, format?: 'string' | 'number') => {\n if (!name) {\n return undefined\n }\n\n if (format === 'number') {\n return factory.createLiteralTypeNode(factory.createNumericLiteral(name))\n }\n\n return factory.createLiteralTypeNode(factory.createStringLiteral(name.toString()))\n },\n datetime: () => factory.keywordTypeNodes.string,\n date: () => factory.createTypeReferenceNode(factory.createIdentifier('Date')),\n uuid: undefined,\n url: undefined,\n strict: undefined,\n default: undefined,\n and: (nodes?: ts.TypeNode[]) => {\n if (!nodes) {\n return undefined\n }\n\n return factory.createIntersectionDeclaration({\n withParentheses: true,\n nodes,\n })\n },\n describe: undefined,\n min: undefined,\n max: undefined,\n optional: undefined,\n matches: undefined,\n email: undefined,\n firstName: undefined,\n lastName: undefined,\n password: undefined,\n phone: undefined,\n readOnly: undefined,\n ref: (propertyName?: string) => {\n if (!propertyName) {\n return undefined\n }\n\n return factory.createTypeReferenceNode(propertyName, undefined)\n },\n blob: () => factory.createTypeReferenceNode('Blob', []),\n deprecated: undefined,\n example: undefined,\n type: undefined,\n format: undefined,\n catchall: undefined,\n} satisfies SchemaMapper<ts.Node | null | undefined>\n\ntype ParserOptions = {\n name: string\n typeName?: string\n description?: string\n /**\n * @default `'questionToken'`\n */\n optionalType: 'questionToken' | 'undefined' | 'questionTokenAndUndefined'\n /**\n * @default `'asConst'`\n */\n enumType: 'enum' | 'asConst' | 'asPascalConst' | 'constEnum' | 'literal'\n keysToOmit?: string[]\n mapper?: SchemaMapper\n}\n\nexport function parseTypeMeta(parent: Schema | undefined, current: Schema, options: ParserOptions): ts.Node | null | undefined {\n const value = typeKeywordMapper[current.keyword as keyof typeof typeKeywordMapper]\n\n if (!value) {\n return undefined\n }\n\n if (isKeyword(current, schemaKeywords.union)) {\n return typeKeywordMapper.union(current.args.map((schema) => parseTypeMeta(current, schema, options)).filter(Boolean) as ts.TypeNode[])\n }\n\n if (isKeyword(current, schemaKeywords.and)) {\n return typeKeywordMapper.and(current.args.map((schema) => parseTypeMeta(current, schema, options)).filter(Boolean) as ts.TypeNode[])\n }\n\n if (isKeyword(current, schemaKeywords.array)) {\n return typeKeywordMapper.array(current.args.items.map((schema) => parseTypeMeta(current, schema, options)).filter(Boolean) as ts.TypeNode[])\n }\n\n if (isKeyword(current, schemaKeywords.enum)) {\n return typeKeywordMapper.enum(current.args.typeName)\n }\n\n if (isKeyword(current, schemaKeywords.ref)) {\n return typeKeywordMapper.ref(current.args.name)\n }\n\n if (isKeyword(current, schemaKeywords.blob)) {\n return value()\n }\n\n if (isKeyword(current, schemaKeywords.tuple)) {\n return typeKeywordMapper.tuple(current.args.map((schema) => parseTypeMeta(current, schema, options)).filter(Boolean) as ts.TypeNode[])\n }\n\n if (isKeyword(current, schemaKeywords.const)) {\n return typeKeywordMapper.const(current.args.name, current.args.format)\n }\n\n if (isKeyword(current, schemaKeywords.object)) {\n const properties = Object.entries(current.args?.properties || {})\n .filter((item) => {\n const schemas = item[1]\n return schemas && typeof schemas.map === 'function'\n })\n .map((item) => {\n const name = item[0]\n const schemas = item[1]\n\n const isNullish = schemas.some((schema) => schema.keyword === schemaKeywords.nullish)\n const isNullable = schemas.some((schema) => schema.keyword === schemaKeywords.nullable)\n const isOptional = schemas.some((schema) => schema.keyword === schemaKeywords.optional)\n const isReadonly = schemas.some((schema) => schema.keyword === schemaKeywords.readOnly)\n const describeSchema = schemas.find((schema) => schema.keyword === schemaKeywords.describe) as SchemaKeywordMapper['describe'] | undefined\n const deprecatedSchema = schemas.find((schema) => schema.keyword === schemaKeywords.deprecated) as SchemaKeywordMapper['deprecated'] | undefined\n const defaultSchema = schemas.find((schema) => schema.keyword === schemaKeywords.default) as SchemaKeywordMapper['default'] | undefined\n const exampleSchema = schemas.find((schema) => schema.keyword === schemaKeywords.example) as SchemaKeywordMapper['example'] | undefined\n const typeSchema = schemas.find((schema) => schema.keyword === schemaKeywords.type) as SchemaKeywordMapper['type'] | undefined\n const formatSchema = schemas.find((schema) => schema.keyword === schemaKeywords.format) as SchemaKeywordMapper['format'] | undefined\n\n let type = schemas.map((schema) => parseTypeMeta(current, schema, options)).filter(Boolean)[0] as ts.TypeNode\n\n if (isNullable) {\n type = factory.createUnionDeclaration({\n nodes: [type, factory.keywordTypeNodes.null],\n }) as ts.TypeNode\n }\n\n if (isNullish && ['undefined', 'questionTokenAndUndefined'].includes(options.optionalType as string)) {\n type = factory.createUnionDeclaration({\n nodes: [type, factory.keywordTypeNodes.undefined],\n }) as ts.TypeNode\n }\n\n if (isOptional && ['undefined', 'questionTokenAndUndefined'].includes(options.optionalType as string)) {\n type = factory.createUnionDeclaration({\n nodes: [type, factory.keywordTypeNodes.undefined],\n }) as ts.TypeNode\n }\n\n const propertySignature = factory.createPropertySignature({\n questionToken: isOptional && ['questionToken', 'questionTokenAndUndefined'].includes(options.optionalType as string),\n name,\n type,\n readOnly: isReadonly,\n })\n\n return factory.appendJSDocToNode({\n node: propertySignature,\n comments: [\n describeSchema ? `@description ${transformers.jsStringEscape(describeSchema.args)}` : undefined,\n deprecatedSchema ? '@deprecated' : undefined,\n defaultSchema ? `@default ${defaultSchema.args}` : undefined,\n exampleSchema ? `@example ${exampleSchema.args}` : undefined,\n typeSchema ? `@type ${typeSchema.args}${!isOptional ? '' : ' | undefined'} ${formatSchema?.args || ''}` : undefined,\n ].filter(Boolean),\n })\n })\n\n const additionalProperties = current.args?.additionalProperties?.length\n ? factory.createIndexSignature(\n current.args.additionalProperties\n .map((schema) => parseTypeMeta(current, schema, options))\n .filter(Boolean)\n .at(0) as ts.TypeNode,\n )\n : undefined\n\n return typeKeywordMapper.object([...properties, additionalProperties].filter(Boolean))\n }\n\n if (current.keyword in typeKeywordMapper) {\n return value()\n }\n\n return undefined\n}\n\nexport function typeParser(schemas: Schema[], options: ParserOptions): string {\n const nodes: ts.Node[] = []\n const extraNodes: ts.Node[] = []\n\n if (!schemas.length) {\n return ''\n }\n\n const isNullish = schemas.some((item) => item.keyword === schemaKeywords.nullish)\n const isNullable = schemas.some((item) => item.keyword === schemaKeywords.nullable)\n const isOptional = schemas.some((item) => item.keyword === schemaKeywords.optional)\n\n let type =\n (schemas\n .map((schema) => parseTypeMeta(undefined, schema, options))\n .filter(Boolean)\n .at(0) as ts.TypeNode) || typeKeywordMapper.undefined()\n\n if (isNullable) {\n type = factory.createUnionDeclaration({\n nodes: [type, factory.keywordTypeNodes.null],\n }) as ts.TypeNode\n }\n\n if (isNullish && ['undefined', 'questionTokenAndUndefined'].includes(options.optionalType as string)) {\n type = factory.createUnionDeclaration({\n nodes: [type, factory.keywordTypeNodes.undefined],\n }) as ts.TypeNode\n }\n\n if (isOptional && ['undefined', 'questionTokenAndUndefined'].includes(options.optionalType as string)) {\n type = factory.createUnionDeclaration({\n nodes: [type, factory.keywordTypeNodes.undefined],\n }) as ts.TypeNode\n }\n\n const node = factory.createTypeAliasDeclaration({\n modifiers: [factory.modifiers.export],\n name: options.name,\n type: options.keysToOmit?.length\n ? factory.createOmitDeclaration({\n keys: options.keysToOmit,\n type,\n nonNullable: true,\n })\n : type,\n })\n\n const enumSchemas = SchemaGenerator.deepSearch(schemas, schemaKeywords.enum)\n if (enumSchemas) {\n enumSchemas.forEach((enumSchema) => {\n extraNodes.push(\n ...factory.createEnumDeclaration({\n name: transformers.camelCase(enumSchema.args.name),\n typeName: enumSchema.args.typeName,\n enums: enumSchema.args.items\n .map((item) => (item.value === undefined ? undefined : [transformers.trimQuotes(item.name?.toString()), item.value]))\n .filter(Boolean) as unknown as [string, string][],\n type: options.enumType,\n }),\n )\n })\n }\n\n nodes.push(\n factory.appendJSDocToNode({\n node,\n comments: [options.description ? `@description ${transformers.jsStringEscape(options.description)}` : undefined].filter(Boolean),\n }),\n )\n\n const filterdNodes = nodes.filter(\n (node: ts.Node) =>\n !extraNodes.some(\n (extraNode: ts.Node) => (extraNode as ts.TypeAliasDeclaration)?.name?.escapedText === (node as ts.TypeAliasDeclaration)?.name?.escapedText,\n ),\n )\n\n return print([...extraNodes, ...filterdNodes])\n}\n","import { definePlugin } from './plugin.ts'\n\nexport { definePlugin, pluginKey, pluginName } from './plugin.ts'\nexport type * from './types.ts'\n\n/**\n * @deprecated Use `import { definePlugin } from '@kubb/swagger-ts'`\n */\nconst definePluginDefault = definePlugin\n\nexport default definePluginDefault\n"]}
@@ -1,9 +1,9 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
3
 
4
- var _chunkY5R6DTFDcjs = require('./chunk-Y5R6DTFD.cjs');
4
+ var _chunkIVO3V2IWcjs = require('./chunk-IVO3V2IW.cjs');
5
5
 
6
6
 
7
7
 
8
- exports.OasType = _chunkY5R6DTFDcjs.OasType; exports.OperationSchema = _chunkY5R6DTFDcjs.OperationSchema;
8
+ exports.OasType = _chunkIVO3V2IWcjs.OasType; exports.OperationSchema = _chunkIVO3V2IWcjs.OperationSchema;
9
9
  //# sourceMappingURL=components.cjs.map
@@ -10,7 +10,7 @@ type TemplateProps = {
10
10
  typeName: string;
11
11
  api: OasTypes.OASDocument;
12
12
  };
13
- declare function Template({ name, typeName, api, }: TemplateProps): ReactNode;
13
+ declare function Template({ name, typeName, api }: TemplateProps): ReactNode;
14
14
  declare const defaultTemplates: {
15
15
  readonly default: typeof Template;
16
16
  };
@@ -22,7 +22,7 @@ type Props$1 = {
22
22
  */
23
23
  Template?: React.ComponentType<React.ComponentProps<typeof Template>>;
24
24
  };
25
- declare function OasType({ name, typeName, Template, }: Props$1): ReactNode;
25
+ declare function OasType({ name, typeName, Template }: Props$1): ReactNode;
26
26
  declare namespace OasType {
27
27
  var File: ({ name, typeName, templates }: FileProps$1) => ReactNode;
28
28
  var templates: {