@kubb/plugin-ts 5.0.5 → 5.0.6

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.
package/dist/index.cjs CHANGED
@@ -1336,7 +1336,7 @@ function buildPropertyJSDocComments(schema, optional) {
1336
1336
  !isArray && meta && "min" in meta && meta.min !== void 0 ? `@minLength ${meta.min}` : null,
1337
1337
  !isArray && meta && "max" in meta && meta.max !== void 0 ? `@maxLength ${meta.max}` : null,
1338
1338
  meta && "pattern" in meta && meta.pattern ? `@pattern ${meta.pattern}` : null,
1339
- meta && "default" in meta && meta.default !== void 0 ? `@default ${"primitive" in meta && meta.primitive === "string" && typeof meta.default === "string" ? stringify(meta.default) : meta.default}` : null,
1339
+ meta && "default" in meta && meta.default !== void 0 ? `@default ${"primitive" in meta && meta.primitive === "string" && typeof meta.default === "string" ? stringify(meta.default) : formatExample(meta.default)}` : null,
1340
1340
  ...exampleValues.map((example) => `@example ${formatExample(example)}`)
1341
1341
  ].filter(Boolean);
1342
1342
  const typeTag = comments.length && meta && "primitive" in meta && meta.primitive ? [`@type ${meta.primitive}`, optional ?? isSchemaOptional(schema) ? " | undefined" : null].filter(Boolean).join("") : null;
@@ -1894,6 +1894,53 @@ const resolverTs = (0, kubb_kit.createResolver)({
1894
1894
  * cross-plugin dependency references.
1895
1895
  */
1896
1896
  const pluginTsName = "plugin-ts";
1897
+ const allowedEnumTypes = [
1898
+ "asConst",
1899
+ "enum",
1900
+ "constEnum",
1901
+ "literal",
1902
+ "inlineLiteral"
1903
+ ];
1904
+ const allowedSyntaxTypes = ["type", "interface"];
1905
+ const allowedArrayTypes = ["array", "generic"];
1906
+ const allowedOptionalTypes = [
1907
+ "questionToken",
1908
+ "undefined",
1909
+ "questionTokenAndUndefined"
1910
+ ];
1911
+ /**
1912
+ * Throws when an enum-like option holds a value outside its allowed set. Options left out are skipped.
1913
+ */
1914
+ function assertEnumLikeOptions({ prefix, options }) {
1915
+ const checks = [
1916
+ {
1917
+ option: "enum.type",
1918
+ value: options.enum?.type,
1919
+ allowed: allowedEnumTypes
1920
+ },
1921
+ {
1922
+ option: "syntaxType",
1923
+ value: options.syntaxType,
1924
+ allowed: allowedSyntaxTypes
1925
+ },
1926
+ {
1927
+ option: "arrayType",
1928
+ value: options.arrayType,
1929
+ allowed: allowedArrayTypes
1930
+ },
1931
+ {
1932
+ option: "optionalType",
1933
+ value: options.optionalType,
1934
+ allowed: allowedOptionalTypes
1935
+ }
1936
+ ];
1937
+ for (const { option, value, allowed } of checks) if (value !== void 0) (0, kubb_kit.assertPluginOption)({
1938
+ plugin: pluginTsName,
1939
+ option: `${prefix}${option}`,
1940
+ value,
1941
+ allowed
1942
+ });
1943
+ }
1897
1944
  /**
1898
1945
  * Generates TypeScript `type` aliases and `interface` declarations from an
1899
1946
  * OpenAPI spec. The foundation that every other Kubb plugin builds on:
@@ -1934,6 +1981,19 @@ const pluginTs = (0, kubb_kit.definePlugin)((options) => {
1934
1981
  name: pluginTsName,
1935
1982
  options,
1936
1983
  hooks: { "kubb:plugin:setup"(ctx) {
1984
+ assertEnumLikeOptions({
1985
+ prefix: "",
1986
+ options: {
1987
+ enum: resolvedEnum,
1988
+ syntaxType,
1989
+ arrayType,
1990
+ optionalType
1991
+ }
1992
+ });
1993
+ for (const [index, entry] of override.entries()) assertEnumLikeOptions({
1994
+ prefix: `override[${index}].options.`,
1995
+ options: entry.options
1996
+ });
1937
1997
  ctx.setOptions({
1938
1998
  output,
1939
1999
  exclude,