@kubb/plugin-ts 3.2.0 → 3.3.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.
Files changed (73) hide show
  1. package/dist/{chunk-OJLL42LQ.js → chunk-2FMMBGL3.js} +47 -43
  2. package/dist/chunk-2FMMBGL3.js.map +1 -0
  3. package/dist/{chunk-KFZ72XC5.cjs → chunk-663J2WTL.cjs} +19 -15
  4. package/dist/chunk-663J2WTL.cjs.map +1 -0
  5. package/dist/{chunk-UE4AMVPZ.cjs → chunk-PNGMUZT2.cjs} +45 -42
  6. package/dist/chunk-PNGMUZT2.cjs.map +1 -0
  7. package/dist/{chunk-S2CJKQ76.js → chunk-XCUOQALP.js} +11 -7
  8. package/dist/chunk-XCUOQALP.js.map +1 -0
  9. package/dist/components.cjs +3 -3
  10. package/dist/components.d.cts +3 -2
  11. package/dist/components.d.ts +3 -2
  12. package/dist/components.js +1 -1
  13. package/dist/generators.cjs +4 -4
  14. package/dist/generators.d.cts +1 -1
  15. package/dist/generators.d.ts +1 -1
  16. package/dist/generators.js +2 -2
  17. package/dist/index.cjs +4 -4
  18. package/dist/index.d.cts +1 -1
  19. package/dist/index.d.ts +1 -1
  20. package/dist/index.js +2 -2
  21. package/dist/{types-Dy6NIaQp.d.cts → types-9taMMp9y.d.cts} +6 -0
  22. package/dist/{types-Dy6NIaQp.d.ts → types-9taMMp9y.d.ts} +6 -0
  23. package/package.json +9 -9
  24. package/src/components/Type.tsx +46 -40
  25. package/src/generators/__snapshots__/bodyUploadFileApiAssetsPost.ts +5 -5
  26. package/src/generators/__snapshots__/catTypeAsConst.ts +10 -10
  27. package/src/generators/__snapshots__/createPet.ts +27 -28
  28. package/src/generators/__snapshots__/createPetWithUnknownTypeUnknown.ts +27 -28
  29. package/src/generators/__snapshots__/deletePet.ts +5 -6
  30. package/src/generators/__snapshots__/dogTypeAsConst.ts +10 -10
  31. package/src/generators/__snapshots__/enumAllOf.ts +7 -7
  32. package/src/generators/__snapshots__/enumArray.ts +12 -16
  33. package/src/generators/__snapshots__/enumInObject.ts +10 -10
  34. package/src/generators/__snapshots__/enumItems.ts +5 -5
  35. package/src/generators/__snapshots__/enumNames.ts +3 -3
  36. package/src/generators/__snapshots__/enumNamesConst.ts +3 -3
  37. package/src/generators/__snapshots__/enumNamesLiteral.ts +2 -2
  38. package/src/generators/__snapshots__/enumNamesPascalConst.ts +5 -5
  39. package/src/generators/__snapshots__/enumNamesType.ts +5 -5
  40. package/src/generators/__snapshots__/enumNullableMember.ts +5 -5
  41. package/src/generators/__snapshots__/enumNullableType.ts +5 -5
  42. package/src/generators/__snapshots__/enumString.ts +7 -7
  43. package/src/generators/__snapshots__/enumVarNamesType.ts +5 -5
  44. package/src/generators/__snapshots__/getPets.ts +19 -20
  45. package/src/generators/__snapshots__/mixedValueTypeConst.ts +6 -6
  46. package/src/generators/__snapshots__/nullConstNull.ts +4 -5
  47. package/src/generators/__snapshots__/numberValueConst.ts +6 -6
  48. package/src/generators/__snapshots__/petMapper.ts +14 -14
  49. package/src/generators/__snapshots__/petQuestionToken.ts +18 -19
  50. package/src/generators/__snapshots__/petQuestionTokenAndUndefined.ts +18 -19
  51. package/src/generators/__snapshots__/petUndefined.ts +18 -19
  52. package/src/generators/__snapshots__/pets.ts +13 -13
  53. package/src/generators/__snapshots__/petsInterface.ts +14 -0
  54. package/src/generators/__snapshots__/petsStoreAdvancedDiscriminator.ts +32 -29
  55. package/src/generators/__snapshots__/petsStoreDiscriminator.ts +10 -10
  56. package/src/generators/__snapshots__/petsStoreRef.ts +1 -1
  57. package/src/generators/__snapshots__/plainDateDate.ts +1 -1
  58. package/src/generators/__snapshots__/plainDateString.ts +1 -1
  59. package/src/generators/__snapshots__/plainEmail.ts +1 -1
  60. package/src/generators/__snapshots__/plainFile.ts +1 -1
  61. package/src/generators/__snapshots__/plainTimeDate.ts +1 -1
  62. package/src/generators/__snapshots__/plainUuid.ts +1 -1
  63. package/src/generators/__snapshots__/readOnly.ts +19 -20
  64. package/src/generators/__snapshots__/showPetById.ts +24 -25
  65. package/src/generators/__snapshots__/stringValueConst.ts +6 -6
  66. package/src/generators/typeGenerator.tsx +4 -2
  67. package/src/{parser/index.ts → parser.ts} +2 -1
  68. package/src/plugin.ts +2 -0
  69. package/src/types.ts +6 -0
  70. package/dist/chunk-KFZ72XC5.cjs.map +0 -1
  71. package/dist/chunk-OJLL42LQ.js.map +0 -1
  72. package/dist/chunk-S2CJKQ76.js.map +0 -1
  73. package/dist/chunk-UE4AMVPZ.cjs.map +0 -1
@@ -3,7 +3,8 @@ import { jsxs, Fragment, jsx } from '@kubb/react/jsx-runtime';
3
3
  import transformers2 from '@kubb/core/transformers';
4
4
  import { print } from '@kubb/parser-ts';
5
5
  import * as factory from '@kubb/parser-ts/factory';
6
- import { schemaKeywords, SchemaGenerator, isKeyword } from '@kubb/plugin-oas';
6
+ import { createTypeDeclaration } from '@kubb/parser-ts/factory';
7
+ import { schemaKeywords, isKeyword, SchemaGenerator } from '@kubb/plugin-oas';
7
8
 
8
9
  var __create = Object.create;
9
10
  var __defProp = Object.defineProperty;
@@ -34,9 +35,9 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
34
35
  mod
35
36
  ));
36
37
 
37
- // ../../node_modules/.pnpm/tsup@8.3.5_@microsoft+api-extractor@7.48.0_@types+node@20.17.10__@swc+core@1.7.22_jiti@2.4.1__hkerfy4gjupxun6rli2ifyvj2q/node_modules/tsup/assets/esm_shims.js
38
+ // ../../node_modules/.pnpm/tsup@8.3.5_@microsoft+api-extractor@7.48.1_@types+node@20.17.10__@swc+core@1.7.22_jiti@2.4.1__77u6eq5nvhzfov6ddvuxt4wipe/node_modules/tsup/assets/esm_shims.js
38
39
  var init_esm_shims = __esm({
39
- "../../node_modules/.pnpm/tsup@8.3.5_@microsoft+api-extractor@7.48.0_@types+node@20.17.10__@swc+core@1.7.22_jiti@2.4.1__hkerfy4gjupxun6rli2ifyvj2q/node_modules/tsup/assets/esm_shims.js"() {
40
+ "../../node_modules/.pnpm/tsup@8.3.5_@microsoft+api-extractor@7.48.1_@types+node@20.17.10__@swc+core@1.7.22_jiti@2.4.1__77u6eq5nvhzfov6ddvuxt4wipe/node_modules/tsup/assets/esm_shims.js"() {
40
41
  }
41
42
  });
42
43
 
@@ -2215,7 +2216,7 @@ function OasType({ name, typeName, api }) {
2215
2216
  init_esm_shims();
2216
2217
  var import_react3 = __toESM(require_react());
2217
2218
 
2218
- // src/parser/index.ts
2219
+ // src/parser.ts
2219
2220
  init_esm_shims();
2220
2221
  var typeKeywordMapper = {
2221
2222
  any: () => factory.keywordTypeNodes.any,
@@ -2423,52 +2424,61 @@ function parse({ parent, current, siblings }, options) {
2423
2424
  }
2424
2425
  return void 0;
2425
2426
  }
2426
- function Type2({ name, typedName, tree, keysToOmit, optionalType, enumType, mapper, description }) {
2427
+ function Type2({ name, typedName, tree, keysToOmit, optionalType, syntaxType, enumType, mapper, description }) {
2427
2428
  const typeNodes = [];
2428
2429
  if (!tree.length) {
2429
2430
  return "";
2430
2431
  }
2431
- const isNullish = tree.some((item) => item.keyword === schemaKeywords.nullish);
2432
- const isNullable = tree.some((item) => item.keyword === schemaKeywords.nullable);
2433
- const isOptional = tree.some((item) => item.keyword === schemaKeywords.optional);
2432
+ const schema = tree.find((item) => item.keyword === schemaKeywords.schema);
2434
2433
  let type = tree.map(
2435
- (schema, _index, siblings) => parse(
2436
- { parent: void 0, current: schema, siblings },
2434
+ (schema2, _index, siblings) => parse(
2435
+ { parent: void 0, current: schema2, siblings },
2437
2436
  {
2438
2437
  name,
2439
- typeName: typedName,
2438
+ typedName,
2440
2439
  description,
2441
2440
  keysToOmit,
2442
2441
  optionalType,
2443
2442
  enumType,
2444
- mapper
2443
+ mapper,
2444
+ syntaxType
2445
2445
  }
2446
2446
  )
2447
2447
  ).filter(Boolean).at(0) || typeKeywordMapper.undefined();
2448
- if (isNullable) {
2449
- type = factory.createUnionDeclaration({
2450
- nodes: [type, factory.keywordTypeNodes.null]
2451
- });
2452
- }
2453
- if (isNullish && ["undefined", "questionTokenAndUndefined"].includes(optionalType)) {
2454
- type = factory.createUnionDeclaration({
2455
- nodes: [type, factory.keywordTypeNodes.undefined]
2456
- });
2457
- }
2458
- if (isOptional && ["undefined", "questionTokenAndUndefined"].includes(optionalType)) {
2459
- type = factory.createUnionDeclaration({
2460
- nodes: [type, factory.keywordTypeNodes.undefined]
2461
- });
2448
+ if (schema && isKeyword(schema, schemaKeywords.schema) && schema.args.type !== "object") {
2449
+ const isNullish = tree.some((item) => item.keyword === schemaKeywords.nullish);
2450
+ const isNullable = tree.some((item) => item.keyword === schemaKeywords.nullable);
2451
+ const isOptional = tree.some((item) => item.keyword === schemaKeywords.optional);
2452
+ if (isNullable) {
2453
+ type = factory.createUnionDeclaration({
2454
+ nodes: [type, factory.keywordTypeNodes.null]
2455
+ });
2456
+ }
2457
+ if (isNullish && ["undefined", "questionTokenAndUndefined"].includes(optionalType)) {
2458
+ type = factory.createUnionDeclaration({
2459
+ nodes: [type, factory.keywordTypeNodes.undefined]
2460
+ });
2461
+ }
2462
+ if (isOptional && ["undefined", "questionTokenAndUndefined"].includes(optionalType)) {
2463
+ type = factory.createUnionDeclaration({
2464
+ nodes: [type, factory.keywordTypeNodes.undefined]
2465
+ });
2466
+ }
2462
2467
  }
2463
- const node = factory.createTypeAliasDeclaration({
2464
- modifiers: [factory.modifiers.export],
2465
- name,
2466
- type: keysToOmit?.length ? factory.createOmitDeclaration({
2467
- keys: keysToOmit,
2468
- type,
2469
- nonNullable: true
2470
- }) : type
2471
- });
2468
+ const useTypeGeneration = syntaxType === "type" || [factory.syntaxKind.union].includes(type.kind) || !!keysToOmit?.length;
2469
+ typeNodes.push(
2470
+ createTypeDeclaration({
2471
+ name,
2472
+ isExportable: true,
2473
+ type: keysToOmit?.length ? factory.createOmitDeclaration({
2474
+ keys: keysToOmit,
2475
+ type,
2476
+ nonNullable: true
2477
+ }) : type,
2478
+ syntax: useTypeGeneration ? "type" : "interface",
2479
+ description: description ? transformers2.jsStringEscape(description) : void 0
2480
+ })
2481
+ );
2472
2482
  const enumSchemas = SchemaGenerator.deepSearch(tree, schemaKeywords.enum);
2473
2483
  const enums = [...new Set(enumSchemas)].map((enumSchema) => {
2474
2484
  const name2 = enumType === "asPascalConst" ? transformers2.pascalCase(enumSchema.args.name) : transformers2.camelCase(enumSchema.args.name);
@@ -2486,12 +2496,6 @@ function Type2({ name, typedName, tree, keysToOmit, optionalType, enumType, mapp
2486
2496
  typeName
2487
2497
  };
2488
2498
  });
2489
- typeNodes.push(
2490
- factory.appendJSDocToNode({
2491
- node,
2492
- comments: [description ? `@description ${transformers2.jsStringEscape(description)}` : void 0].filter(Boolean)
2493
- })
2494
- );
2495
2499
  return /* @__PURE__ */ jsxs(import_react3.Fragment, { children: [
2496
2500
  enums.map(({ name: name2, nameNode, typeName, typeNode }, index) => /* @__PURE__ */ jsxs(import_react3.Fragment, { children: [
2497
2501
  nameNode && /* @__PURE__ */ jsx(File.Source, { name: name2, isExportable: true, isIndexable: true, children: print([nameNode]) }),
@@ -2535,5 +2539,5 @@ react/cjs/react.development.js:
2535
2539
  */
2536
2540
 
2537
2541
  export { OasType, Type2 as Type, init_esm_shims };
2538
- //# sourceMappingURL=chunk-OJLL42LQ.js.map
2539
- //# sourceMappingURL=chunk-OJLL42LQ.js.map
2542
+ //# sourceMappingURL=chunk-2FMMBGL3.js.map
2543
+ //# sourceMappingURL=chunk-2FMMBGL3.js.map