@kubb/plugin-ts 4.0.0 → 4.1.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.
Files changed (30) hide show
  1. package/dist/{components-CTopmaD3.cjs → components-BlMLL1s7.cjs} +17 -11
  2. package/dist/{components-CTopmaD3.cjs.map → components-BlMLL1s7.cjs.map} +1 -1
  3. package/dist/{components-BKIt6l3E.js → components-DaYIAKg5.js} +17 -11
  4. package/dist/{components-BKIt6l3E.js.map → components-DaYIAKg5.js.map} +1 -1
  5. package/dist/components.cjs +1 -1
  6. package/dist/components.js +1 -1
  7. package/dist/generators.cjs +2 -2
  8. package/dist/generators.js +2 -2
  9. package/dist/index.cjs +2 -2
  10. package/dist/index.js +2 -2
  11. package/dist/{plugin-CxMJgMjV.cjs → plugin-CxUQoqgN.cjs} +5 -3
  12. package/dist/plugin-CxUQoqgN.cjs.map +1 -0
  13. package/dist/{plugin-nmU_mIiP.js → plugin-D1oIzd18.js} +5 -3
  14. package/dist/plugin-D1oIzd18.js.map +1 -0
  15. package/package.json +7 -8
  16. package/src/components/Type.tsx +20 -8
  17. package/src/generators/__snapshots__/enumAllOf.ts +2 -2
  18. package/src/generators/__snapshots__/enumArray20.ts +2 -2
  19. package/src/generators/__snapshots__/enumInObject.ts +2 -2
  20. package/src/generators/__snapshots__/enumItems.ts +2 -2
  21. package/src/generators/__snapshots__/enumNamesType.ts +2 -2
  22. package/src/generators/__snapshots__/enumNullableMember.ts +2 -2
  23. package/src/generators/__snapshots__/enumNullableType.ts +2 -2
  24. package/src/generators/__snapshots__/enumString.ts +2 -2
  25. package/src/generators/__snapshots__/enumVarNamesType.ts +2 -2
  26. package/src/generators/__snapshots__/pascalEnum.ts +13 -0
  27. package/src/generators/typeGenerator.tsx +5 -1
  28. package/src/parser.ts +4 -3
  29. package/dist/plugin-CxMJgMjV.cjs.map +0 -1
  30. package/dist/plugin-nmU_mIiP.js.map +0 -1
@@ -1748,7 +1748,7 @@ function parse({ current, siblings, name }, options) {
1748
1748
  current: schema,
1749
1749
  siblings
1750
1750
  }, options)).filter(Boolean));
1751
- if (isKeyword(current, schemaKeywords.enum)) return typeKeywordMapper.enum(current.args.typeName);
1751
+ if (isKeyword(current, schemaKeywords.enum)) return typeKeywordMapper.enum(options.enumType === "asConst" ? `${current.args.typeName}Key` : current.args.typeName);
1752
1752
  if (isKeyword(current, schemaKeywords.ref)) return typeKeywordMapper.ref(current.args.name);
1753
1753
  if (isKeyword(current, schemaKeywords.blob)) return value();
1754
1754
  if (isKeyword(current, schemaKeywords.tuple)) return typeKeywordMapper.tuple(current.args.items.map((schema) => parse({
@@ -1791,14 +1791,14 @@ function parse({ current, siblings, name }, options) {
1791
1791
  if (isNullable) type = factory.createUnionDeclaration({ nodes: [type, factory.keywordTypeNodes.null] });
1792
1792
  if (isNullish && ["undefined", "questionTokenAndUndefined"].includes(options.optionalType)) type = factory.createUnionDeclaration({ nodes: [type, factory.keywordTypeNodes.undefined] });
1793
1793
  if (isOptional && ["undefined", "questionTokenAndUndefined"].includes(options.optionalType)) type = factory.createUnionDeclaration({ nodes: [type, factory.keywordTypeNodes.undefined] });
1794
- const propertySignature = factory.createPropertySignature({
1794
+ const propertyNode = factory.createPropertySignature({
1795
1795
  questionToken: isOptional || isNullish ? ["questionToken", "questionTokenAndUndefined"].includes(options.optionalType) : false,
1796
1796
  name: mappedName,
1797
1797
  type,
1798
1798
  readOnly: isReadonly
1799
1799
  });
1800
1800
  return factory.appendJSDocToNode({
1801
- node: propertySignature,
1801
+ node: propertyNode,
1802
1802
  comments: [
1803
1803
  describeSchema ? `@description ${transformers.jsStringEscape(describeSchema.args)}` : void 0,
1804
1804
  deprecatedSchema ? "@deprecated" : void 0,
@@ -1837,6 +1837,7 @@ function Type$1({ name, typedName, tree, keysToOmit, schema, optionalType, synta
1837
1837
  const typeNodes = [];
1838
1838
  if (!tree.length) return "";
1839
1839
  const schemaFromTree = tree.find((item) => item.keyword === schemaKeywords.schema);
1840
+ const enumSchemas = SchemaGenerator.deepSearch(tree, schemaKeywords.enum);
1840
1841
  let type = tree.map((current, _index, siblings) => parse({
1841
1842
  parent: void 0,
1842
1843
  current,
@@ -1851,6 +1852,15 @@ function Type$1({ name, typedName, tree, keysToOmit, schema, optionalType, synta
1851
1852
  mapper,
1852
1853
  syntaxType
1853
1854
  })).filter(Boolean).at(0) || typeKeywordMapper.undefined();
1855
+ if (enumType === "asConst" && enumSchemas.length > 0) {
1856
+ const isDirectEnum = schema.type === "array" && schema.items !== void 0;
1857
+ const isEnumOnly = "enum" in schema && schema.enum;
1858
+ if (isDirectEnum || isEnumOnly) {
1859
+ const typeNameWithKey = `${enumSchemas[0].args.typeName}Key`;
1860
+ type = factory.createTypeReferenceNode(typeNameWithKey);
1861
+ if (schema.type === "array") type = factory.createArrayTypeNode(type);
1862
+ }
1863
+ }
1854
1864
  if (schemaFromTree && isKeyword(schemaFromTree, schemaKeywords.schema)) {
1855
1865
  const isNullish = tree.some((item) => item.keyword === schemaKeywords.nullish);
1856
1866
  const isNullable = tree.some((item) => item.keyword === schemaKeywords.nullable);
@@ -1879,10 +1889,9 @@ function Type$1({ name, typedName, tree, keysToOmit, schema, optionalType, synta
1879
1889
  schema.example ? `@example ${schema.example}` : void 0
1880
1890
  ]
1881
1891
  }));
1882
- const enumSchemas = SchemaGenerator.deepSearch(tree, schemaKeywords.enum);
1883
1892
  const enums = [...new Set(enumSchemas)].map((enumSchema) => {
1884
1893
  const name$1 = enumType === "asPascalConst" ? transformers.pascalCase(enumSchema.args.name) : transformers.camelCase(enumSchema.args.name);
1885
- const typeName = enumSchema.args.typeName;
1894
+ const typeName = enumType === "asConst" ? `${enumSchema.args.typeName}Key` : enumSchema.args.typeName;
1886
1895
  const [nameNode, typeNode] = factory.createEnumDeclaration({
1887
1896
  name: name$1,
1888
1897
  typeName,
@@ -1917,15 +1926,12 @@ function Type$1({ name, typedName, tree, keysToOmit, schema, optionalType, synta
1917
1926
  void 0
1918
1927
  ].includes(enumType),
1919
1928
  children: print([typeNode])
1920
- })] })), enums.every((item) => item.typeName !== name) && /* @__PURE__ */ jsx(File.Source, {
1921
- name: typedName,
1922
- isTypeOnly: true,
1923
- isExportable: true,
1924
- isIndexable: true,
1929
+ })] })), /* @__PURE__ */ jsx(File.Source, {
1930
+ name,
1925
1931
  children: print(typeNodes)
1926
1932
  })] });
1927
1933
  }
1928
1934
 
1929
1935
  //#endregion
1930
1936
  export { OasType, Type$1 as Type };
1931
- //# sourceMappingURL=components-BKIt6l3E.js.map
1937
+ //# sourceMappingURL=components-DaYIAKg5.js.map