@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 +61 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.js +62 -2
- package/dist/index.js.map +1 -1
- package/package.json +5 -8
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -2,7 +2,7 @@ import { n as __name, t as __exportAll } from "./rolldown-runtime-CthDji9g.js";
|
|
|
2
2
|
import { createRequire } from "node:module";
|
|
3
3
|
import { parserTs } from "@kubb/parser-ts";
|
|
4
4
|
import { File, jsxRenderer } from "kubb/jsx";
|
|
5
|
-
import { Resolver, ast, createResolver, defineGenerator, definePlugin, isStringType, syncSchemaRef } from "kubb/kit";
|
|
5
|
+
import { Resolver, assertPluginOption, ast, createResolver, defineGenerator, definePlugin, isStringType, syncSchemaRef } from "kubb/kit";
|
|
6
6
|
import { Fragment, jsx, jsxs } from "kubb/jsx/jsx-runtime";
|
|
7
7
|
//#region ../../internals/utils/src/casing.ts
|
|
8
8
|
/**
|
|
@@ -1317,7 +1317,7 @@ function buildPropertyJSDocComments(schema, optional) {
|
|
|
1317
1317
|
!isArray && meta && "min" in meta && meta.min !== void 0 ? `@minLength ${meta.min}` : null,
|
|
1318
1318
|
!isArray && meta && "max" in meta && meta.max !== void 0 ? `@maxLength ${meta.max}` : null,
|
|
1319
1319
|
meta && "pattern" in meta && meta.pattern ? `@pattern ${meta.pattern}` : null,
|
|
1320
|
-
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,
|
|
1320
|
+
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,
|
|
1321
1321
|
...exampleValues.map((example) => `@example ${formatExample(example)}`)
|
|
1322
1322
|
].filter(Boolean);
|
|
1323
1323
|
const typeTag = comments.length && meta && "primitive" in meta && meta.primitive ? [`@type ${meta.primitive}`, optional ?? isSchemaOptional(schema) ? " | undefined" : null].filter(Boolean).join("") : null;
|
|
@@ -1875,6 +1875,53 @@ const resolverTs = createResolver({
|
|
|
1875
1875
|
* cross-plugin dependency references.
|
|
1876
1876
|
*/
|
|
1877
1877
|
const pluginTsName = "plugin-ts";
|
|
1878
|
+
const allowedEnumTypes = [
|
|
1879
|
+
"asConst",
|
|
1880
|
+
"enum",
|
|
1881
|
+
"constEnum",
|
|
1882
|
+
"literal",
|
|
1883
|
+
"inlineLiteral"
|
|
1884
|
+
];
|
|
1885
|
+
const allowedSyntaxTypes = ["type", "interface"];
|
|
1886
|
+
const allowedArrayTypes = ["array", "generic"];
|
|
1887
|
+
const allowedOptionalTypes = [
|
|
1888
|
+
"questionToken",
|
|
1889
|
+
"undefined",
|
|
1890
|
+
"questionTokenAndUndefined"
|
|
1891
|
+
];
|
|
1892
|
+
/**
|
|
1893
|
+
* Throws when an enum-like option holds a value outside its allowed set. Options left out are skipped.
|
|
1894
|
+
*/
|
|
1895
|
+
function assertEnumLikeOptions({ prefix, options }) {
|
|
1896
|
+
const checks = [
|
|
1897
|
+
{
|
|
1898
|
+
option: "enum.type",
|
|
1899
|
+
value: options.enum?.type,
|
|
1900
|
+
allowed: allowedEnumTypes
|
|
1901
|
+
},
|
|
1902
|
+
{
|
|
1903
|
+
option: "syntaxType",
|
|
1904
|
+
value: options.syntaxType,
|
|
1905
|
+
allowed: allowedSyntaxTypes
|
|
1906
|
+
},
|
|
1907
|
+
{
|
|
1908
|
+
option: "arrayType",
|
|
1909
|
+
value: options.arrayType,
|
|
1910
|
+
allowed: allowedArrayTypes
|
|
1911
|
+
},
|
|
1912
|
+
{
|
|
1913
|
+
option: "optionalType",
|
|
1914
|
+
value: options.optionalType,
|
|
1915
|
+
allowed: allowedOptionalTypes
|
|
1916
|
+
}
|
|
1917
|
+
];
|
|
1918
|
+
for (const { option, value, allowed } of checks) if (value !== void 0) assertPluginOption({
|
|
1919
|
+
plugin: pluginTsName,
|
|
1920
|
+
option: `${prefix}${option}`,
|
|
1921
|
+
value,
|
|
1922
|
+
allowed
|
|
1923
|
+
});
|
|
1924
|
+
}
|
|
1878
1925
|
/**
|
|
1879
1926
|
* Generates TypeScript `type` aliases and `interface` declarations from an
|
|
1880
1927
|
* OpenAPI spec. The foundation that every other Kubb plugin builds on:
|
|
@@ -1915,6 +1962,19 @@ const pluginTs = definePlugin((options) => {
|
|
|
1915
1962
|
name: pluginTsName,
|
|
1916
1963
|
options,
|
|
1917
1964
|
hooks: { "kubb:plugin:setup"(ctx) {
|
|
1965
|
+
assertEnumLikeOptions({
|
|
1966
|
+
prefix: "",
|
|
1967
|
+
options: {
|
|
1968
|
+
enum: resolvedEnum,
|
|
1969
|
+
syntaxType,
|
|
1970
|
+
arrayType,
|
|
1971
|
+
optionalType
|
|
1972
|
+
}
|
|
1973
|
+
});
|
|
1974
|
+
for (const [index, entry] of override.entries()) assertEnumLikeOptions({
|
|
1975
|
+
prefix: `override[${index}].options.`,
|
|
1976
|
+
options: entry.options
|
|
1977
|
+
});
|
|
1918
1978
|
ctx.setOptions({
|
|
1919
1979
|
output,
|
|
1920
1980
|
exclude,
|