@kubb/plugin-ts 5.0.5 → 5.0.7
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 +94 -31
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -2
- package/dist/index.js +95 -32
- package/dist/index.js.map +1 -1
- package/package.json +5 -8
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;
|
|
@@ -1850,6 +1850,9 @@ const typeGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1850
1850
|
}
|
|
1851
1851
|
});
|
|
1852
1852
|
//#endregion
|
|
1853
|
+
//#region package.json
|
|
1854
|
+
var version = "5.0.7";
|
|
1855
|
+
//#endregion
|
|
1853
1856
|
//#region src/resolvers/resolverTs.ts
|
|
1854
1857
|
/**
|
|
1855
1858
|
* Default resolver used by `@kubb/plugin-ts`. Decides the names and file paths
|
|
@@ -1894,6 +1897,53 @@ const resolverTs = (0, kubb_kit.createResolver)({
|
|
|
1894
1897
|
* cross-plugin dependency references.
|
|
1895
1898
|
*/
|
|
1896
1899
|
const pluginTsName = "plugin-ts";
|
|
1900
|
+
const allowedEnumTypes = [
|
|
1901
|
+
"asConst",
|
|
1902
|
+
"enum",
|
|
1903
|
+
"constEnum",
|
|
1904
|
+
"literal",
|
|
1905
|
+
"inlineLiteral"
|
|
1906
|
+
];
|
|
1907
|
+
const allowedSyntaxTypes = ["type", "interface"];
|
|
1908
|
+
const allowedArrayTypes = ["array", "generic"];
|
|
1909
|
+
const allowedOptionalTypes = [
|
|
1910
|
+
"questionToken",
|
|
1911
|
+
"undefined",
|
|
1912
|
+
"questionTokenAndUndefined"
|
|
1913
|
+
];
|
|
1914
|
+
/**
|
|
1915
|
+
* Throws when an enum-like option holds a value outside its allowed set. Options left out are skipped.
|
|
1916
|
+
*/
|
|
1917
|
+
function assertEnumLikeOptions({ prefix, options }) {
|
|
1918
|
+
const checks = [
|
|
1919
|
+
{
|
|
1920
|
+
option: "enum.type",
|
|
1921
|
+
value: options.enum?.type,
|
|
1922
|
+
allowed: allowedEnumTypes
|
|
1923
|
+
},
|
|
1924
|
+
{
|
|
1925
|
+
option: "syntaxType",
|
|
1926
|
+
value: options.syntaxType,
|
|
1927
|
+
allowed: allowedSyntaxTypes
|
|
1928
|
+
},
|
|
1929
|
+
{
|
|
1930
|
+
option: "arrayType",
|
|
1931
|
+
value: options.arrayType,
|
|
1932
|
+
allowed: allowedArrayTypes
|
|
1933
|
+
},
|
|
1934
|
+
{
|
|
1935
|
+
option: "optionalType",
|
|
1936
|
+
value: options.optionalType,
|
|
1937
|
+
allowed: allowedOptionalTypes
|
|
1938
|
+
}
|
|
1939
|
+
];
|
|
1940
|
+
for (const { option, value, allowed } of checks) if (value !== void 0) (0, kubb_kit.assertPluginOption)({
|
|
1941
|
+
plugin: pluginTsName,
|
|
1942
|
+
option: `${prefix}${option}`,
|
|
1943
|
+
value,
|
|
1944
|
+
allowed
|
|
1945
|
+
});
|
|
1946
|
+
}
|
|
1897
1947
|
/**
|
|
1898
1948
|
* Generates TypeScript `type` aliases and `interface` declarations from an
|
|
1899
1949
|
* OpenAPI spec. The foundation that every other Kubb plugin builds on:
|
|
@@ -1918,39 +1968,52 @@ const pluginTsName = "plugin-ts";
|
|
|
1918
1968
|
* })
|
|
1919
1969
|
* ```
|
|
1920
1970
|
*/
|
|
1921
|
-
const pluginTs = (0, kubb_kit.definePlugin)(
|
|
1922
|
-
|
|
1923
|
-
path: "types",
|
|
1924
|
-
barrel: { type: "named" }
|
|
1925
|
-
}, group, exclude = [], include, override = [], enum: enumOptions = {}, optionalType = "questionToken", arrayType = "array", syntaxType = "type", printer, resolver: userResolver, macros: userMacros } = options;
|
|
1926
|
-
const groupConfig = createGroupConfig(group);
|
|
1927
|
-
const resolvedEnum = {
|
|
1928
|
-
type: enumOptions.type ?? "asConst",
|
|
1929
|
-
constCasing: enumOptions.constCasing ?? "camelCase",
|
|
1930
|
-
typeSuffix: enumOptions.typeSuffix ?? "Key",
|
|
1931
|
-
keyCasing: enumOptions.keyCasing ?? "none"
|
|
1932
|
-
};
|
|
1933
|
-
return {
|
|
1971
|
+
const pluginTs = (0, kubb_kit.definePlugin)({
|
|
1972
|
+
meta: {
|
|
1934
1973
|
name: pluginTsName,
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1974
|
+
version,
|
|
1975
|
+
compatibility: { kubb: ">=5.8.0" }
|
|
1976
|
+
},
|
|
1977
|
+
setup(options) {
|
|
1978
|
+
const { output = {
|
|
1979
|
+
path: "types",
|
|
1980
|
+
barrel: { type: "named" }
|
|
1981
|
+
}, group, exclude = [], include, override = [], enum: enumOptions = {}, optionalType = "questionToken", arrayType = "array", syntaxType = "type", printer, resolver: userResolver, macros: userMacros } = options;
|
|
1982
|
+
const resolvedEnum = {
|
|
1983
|
+
type: enumOptions.type ?? "asConst",
|
|
1984
|
+
constCasing: enumOptions.constCasing ?? "camelCase",
|
|
1985
|
+
typeSuffix: enumOptions.typeSuffix ?? "Key",
|
|
1986
|
+
keyCasing: enumOptions.keyCasing ?? "none"
|
|
1987
|
+
};
|
|
1988
|
+
assertEnumLikeOptions({
|
|
1989
|
+
prefix: "",
|
|
1990
|
+
options: {
|
|
1945
1991
|
enum: resolvedEnum,
|
|
1946
1992
|
syntaxType,
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
1993
|
+
arrayType,
|
|
1994
|
+
optionalType
|
|
1995
|
+
}
|
|
1996
|
+
});
|
|
1997
|
+
for (const [index, entry] of override.entries()) assertEnumLikeOptions({
|
|
1998
|
+
prefix: `override[${index}].options.`,
|
|
1999
|
+
options: entry.options
|
|
2000
|
+
});
|
|
2001
|
+
(0, kubb_kit.setResolver)(userResolver ? kubb_kit.Resolver.merge(resolverTs, userResolver) : resolverTs);
|
|
2002
|
+
if (userMacros?.length) (0, kubb_kit.setMacros)(userMacros);
|
|
2003
|
+
(0, kubb_kit.addGenerator)(typeGenerator);
|
|
2004
|
+
return {
|
|
2005
|
+
output,
|
|
2006
|
+
exclude,
|
|
2007
|
+
include,
|
|
2008
|
+
override,
|
|
2009
|
+
optionalType,
|
|
2010
|
+
group: createGroupConfig(group),
|
|
2011
|
+
arrayType,
|
|
2012
|
+
enum: resolvedEnum,
|
|
2013
|
+
syntaxType,
|
|
2014
|
+
printer
|
|
2015
|
+
};
|
|
2016
|
+
}
|
|
1954
2017
|
});
|
|
1955
2018
|
//#endregion
|
|
1956
2019
|
//#region src/printers/functionParams.ts
|