@kubb/oas 4.12.6 → 4.12.8
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 +3 -189
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +16 -11
- package/dist/index.d.ts +16 -11
- package/dist/index.js +2 -188
- package/dist/index.js.map +1 -1
- package/package.json +6 -5
- package/src/utils.spec.ts +1 -0
package/dist/index.d.cts
CHANGED
|
@@ -79,7 +79,7 @@ type ExecutedMeta<H extends PluginLifecycleHooks = PluginLifecycleHooks> = {
|
|
|
79
79
|
* console.log('Starting Kubb generation')
|
|
80
80
|
* })
|
|
81
81
|
*
|
|
82
|
-
* events.on('plugin:end', (plugin, duration) => {
|
|
82
|
+
* events.on('plugin:end', (plugin, { duration }) => {
|
|
83
83
|
* console.log(`Plugin ${plugin.name} completed in ${duration}ms`)
|
|
84
84
|
* })
|
|
85
85
|
* ```
|
|
@@ -148,21 +148,21 @@ interface KubbEvents {
|
|
|
148
148
|
*/
|
|
149
149
|
'hooks:end': [];
|
|
150
150
|
/**
|
|
151
|
-
* Emitted when a single hook execution starts.
|
|
152
|
-
*/
|
|
153
|
-
'hook:start': [command: string];
|
|
154
|
-
/**
|
|
155
|
-
* Emitted to execute a hook command (e.g., format or lint).
|
|
151
|
+
* Emitted when a single hook execution starts. (e.g., format or lint).
|
|
156
152
|
* The callback should be invoked when the command completes.
|
|
157
153
|
*/
|
|
158
|
-
'hook:
|
|
159
|
-
|
|
154
|
+
'hook:start': [{
|
|
155
|
+
id?: string;
|
|
156
|
+
command: string;
|
|
160
157
|
args?: readonly string[];
|
|
161
|
-
}
|
|
158
|
+
}];
|
|
162
159
|
/**
|
|
163
160
|
* Emitted when a single hook execution completes.
|
|
164
161
|
*/
|
|
165
|
-
'hook:end': [
|
|
162
|
+
'hook:end': [{
|
|
163
|
+
id?: string;
|
|
164
|
+
command: string;
|
|
165
|
+
}];
|
|
166
166
|
/**
|
|
167
167
|
* Emitted when a new version of Kubb is available.
|
|
168
168
|
*/
|
|
@@ -225,8 +225,13 @@ interface KubbEvents {
|
|
|
225
225
|
'plugin:start': [plugin: Plugin];
|
|
226
226
|
/**
|
|
227
227
|
* Emitted when a plugin completes execution.
|
|
228
|
+
* Duration in ms
|
|
228
229
|
*/
|
|
229
|
-
'plugin:end': [plugin: Plugin,
|
|
230
|
+
'plugin:end': [plugin: Plugin, meta: {
|
|
231
|
+
duration: number;
|
|
232
|
+
success: boolean;
|
|
233
|
+
error?: Error;
|
|
234
|
+
}];
|
|
230
235
|
/**
|
|
231
236
|
* Emitted when plugin hook progress tracking starts.
|
|
232
237
|
* Contains the hook name and list of plugins to execute.
|
package/dist/index.d.ts
CHANGED
|
@@ -79,7 +79,7 @@ type ExecutedMeta<H extends PluginLifecycleHooks = PluginLifecycleHooks> = {
|
|
|
79
79
|
* console.log('Starting Kubb generation')
|
|
80
80
|
* })
|
|
81
81
|
*
|
|
82
|
-
* events.on('plugin:end', (plugin, duration) => {
|
|
82
|
+
* events.on('plugin:end', (plugin, { duration }) => {
|
|
83
83
|
* console.log(`Plugin ${plugin.name} completed in ${duration}ms`)
|
|
84
84
|
* })
|
|
85
85
|
* ```
|
|
@@ -148,21 +148,21 @@ interface KubbEvents {
|
|
|
148
148
|
*/
|
|
149
149
|
'hooks:end': [];
|
|
150
150
|
/**
|
|
151
|
-
* Emitted when a single hook execution starts.
|
|
152
|
-
*/
|
|
153
|
-
'hook:start': [command: string];
|
|
154
|
-
/**
|
|
155
|
-
* Emitted to execute a hook command (e.g., format or lint).
|
|
151
|
+
* Emitted when a single hook execution starts. (e.g., format or lint).
|
|
156
152
|
* The callback should be invoked when the command completes.
|
|
157
153
|
*/
|
|
158
|
-
'hook:
|
|
159
|
-
|
|
154
|
+
'hook:start': [{
|
|
155
|
+
id?: string;
|
|
156
|
+
command: string;
|
|
160
157
|
args?: readonly string[];
|
|
161
|
-
}
|
|
158
|
+
}];
|
|
162
159
|
/**
|
|
163
160
|
* Emitted when a single hook execution completes.
|
|
164
161
|
*/
|
|
165
|
-
'hook:end': [
|
|
162
|
+
'hook:end': [{
|
|
163
|
+
id?: string;
|
|
164
|
+
command: string;
|
|
165
|
+
}];
|
|
166
166
|
/**
|
|
167
167
|
* Emitted when a new version of Kubb is available.
|
|
168
168
|
*/
|
|
@@ -225,8 +225,13 @@ interface KubbEvents {
|
|
|
225
225
|
'plugin:start': [plugin: Plugin];
|
|
226
226
|
/**
|
|
227
227
|
* Emitted when a plugin completes execution.
|
|
228
|
+
* Duration in ms
|
|
228
229
|
*/
|
|
229
|
-
'plugin:end': [plugin: Plugin,
|
|
230
|
+
'plugin:end': [plugin: Plugin, meta: {
|
|
231
|
+
duration: number;
|
|
232
|
+
success: boolean;
|
|
233
|
+
error?: Error;
|
|
234
|
+
}];
|
|
230
235
|
/**
|
|
231
236
|
* Emitted when plugin hook progress tracking starts.
|
|
232
237
|
* Contains the hook name and list of plugins to execute.
|
package/dist/index.js
CHANGED
|
@@ -4,8 +4,9 @@ import jsonpointer from "jsonpointer";
|
|
|
4
4
|
import BaseOas from "oas";
|
|
5
5
|
import OASNormalize from "oas-normalize";
|
|
6
6
|
import path from "node:path";
|
|
7
|
-
import {
|
|
7
|
+
import { URLPath } from "@kubb/core/utils";
|
|
8
8
|
import { isRef } from "oas/types";
|
|
9
|
+
import { isPlainObject, mergeDeep } from "remeda";
|
|
9
10
|
import swagger2openapi from "swagger2openapi";
|
|
10
11
|
|
|
11
12
|
//#region rolldown:runtime
|
|
@@ -51,193 +52,6 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
51
52
|
var __toCommonJS = (mod) => __hasOwnProp.call(mod, "module.exports") ? mod["module.exports"] : __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
52
53
|
var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
|
53
54
|
|
|
54
|
-
//#endregion
|
|
55
|
-
//#region ../../node_modules/.pnpm/camelcase@8.0.0/node_modules/camelcase/index.js
|
|
56
|
-
const UPPERCASE = /[\p{Lu}]/u;
|
|
57
|
-
const LOWERCASE = /[\p{Ll}]/u;
|
|
58
|
-
const LEADING_CAPITAL = /^[\p{Lu}](?![\p{Lu}])/gu;
|
|
59
|
-
const IDENTIFIER = /([\p{Alpha}\p{N}_]|$)/u;
|
|
60
|
-
const SEPARATORS = /[_.\- ]+/;
|
|
61
|
-
const LEADING_SEPARATORS = /* @__PURE__ */ new RegExp("^" + SEPARATORS.source);
|
|
62
|
-
const SEPARATORS_AND_IDENTIFIER = new RegExp(SEPARATORS.source + IDENTIFIER.source, "gu");
|
|
63
|
-
const NUMBERS_AND_IDENTIFIER = new RegExp("\\d+" + IDENTIFIER.source, "gu");
|
|
64
|
-
const preserveCamelCase = (string, toLowerCase, toUpperCase, preserveConsecutiveUppercase$1) => {
|
|
65
|
-
let isLastCharLower = false;
|
|
66
|
-
let isLastCharUpper = false;
|
|
67
|
-
let isLastLastCharUpper = false;
|
|
68
|
-
let isLastLastCharPreserved = false;
|
|
69
|
-
for (let index = 0; index < string.length; index++) {
|
|
70
|
-
const character = string[index];
|
|
71
|
-
isLastLastCharPreserved = index > 2 ? string[index - 3] === "-" : true;
|
|
72
|
-
if (isLastCharLower && UPPERCASE.test(character)) {
|
|
73
|
-
string = string.slice(0, index) + "-" + string.slice(index);
|
|
74
|
-
isLastCharLower = false;
|
|
75
|
-
isLastLastCharUpper = isLastCharUpper;
|
|
76
|
-
isLastCharUpper = true;
|
|
77
|
-
index++;
|
|
78
|
-
} else if (isLastCharUpper && isLastLastCharUpper && LOWERCASE.test(character) && (!isLastLastCharPreserved || preserveConsecutiveUppercase$1)) {
|
|
79
|
-
string = string.slice(0, index - 1) + "-" + string.slice(index - 1);
|
|
80
|
-
isLastLastCharUpper = isLastCharUpper;
|
|
81
|
-
isLastCharUpper = false;
|
|
82
|
-
isLastCharLower = true;
|
|
83
|
-
} else {
|
|
84
|
-
isLastCharLower = toLowerCase(character) === character && toUpperCase(character) !== character;
|
|
85
|
-
isLastLastCharUpper = isLastCharUpper;
|
|
86
|
-
isLastCharUpper = toUpperCase(character) === character && toLowerCase(character) !== character;
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
return string;
|
|
90
|
-
};
|
|
91
|
-
const preserveConsecutiveUppercase = (input, toLowerCase) => {
|
|
92
|
-
LEADING_CAPITAL.lastIndex = 0;
|
|
93
|
-
return input.replaceAll(LEADING_CAPITAL, (match) => toLowerCase(match));
|
|
94
|
-
};
|
|
95
|
-
const postProcess = (input, toUpperCase) => {
|
|
96
|
-
SEPARATORS_AND_IDENTIFIER.lastIndex = 0;
|
|
97
|
-
NUMBERS_AND_IDENTIFIER.lastIndex = 0;
|
|
98
|
-
return input.replaceAll(NUMBERS_AND_IDENTIFIER, (match, pattern, offset) => ["_", "-"].includes(input.charAt(offset + match.length)) ? match : toUpperCase(match)).replaceAll(SEPARATORS_AND_IDENTIFIER, (_, identifier) => toUpperCase(identifier));
|
|
99
|
-
};
|
|
100
|
-
function camelCase$1(input, options) {
|
|
101
|
-
if (!(typeof input === "string" || Array.isArray(input))) throw new TypeError("Expected the input to be `string | string[]`");
|
|
102
|
-
options = {
|
|
103
|
-
pascalCase: false,
|
|
104
|
-
preserveConsecutiveUppercase: false,
|
|
105
|
-
...options
|
|
106
|
-
};
|
|
107
|
-
if (Array.isArray(input)) input = input.map((x) => x.trim()).filter((x) => x.length).join("-");
|
|
108
|
-
else input = input.trim();
|
|
109
|
-
if (input.length === 0) return "";
|
|
110
|
-
const toLowerCase = options.locale === false ? (string) => string.toLowerCase() : (string) => string.toLocaleLowerCase(options.locale);
|
|
111
|
-
const toUpperCase = options.locale === false ? (string) => string.toUpperCase() : (string) => string.toLocaleUpperCase(options.locale);
|
|
112
|
-
if (input.length === 1) {
|
|
113
|
-
if (SEPARATORS.test(input)) return "";
|
|
114
|
-
return options.pascalCase ? toUpperCase(input) : toLowerCase(input);
|
|
115
|
-
}
|
|
116
|
-
if (input !== toLowerCase(input)) input = preserveCamelCase(input, toLowerCase, toUpperCase, options.preserveConsecutiveUppercase);
|
|
117
|
-
input = input.replace(LEADING_SEPARATORS, "");
|
|
118
|
-
input = options.preserveConsecutiveUppercase ? preserveConsecutiveUppercase(input, toLowerCase) : toLowerCase(input);
|
|
119
|
-
if (options.pascalCase) input = toUpperCase(input.charAt(0)) + input.slice(1);
|
|
120
|
-
return postProcess(input, toUpperCase);
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
//#endregion
|
|
124
|
-
//#region ../core/src/transformers/casing.ts
|
|
125
|
-
function camelCase(text, { isFile, prefix = "", suffix = "" } = {}) {
|
|
126
|
-
if (isFile) {
|
|
127
|
-
const splitArray = text.split(".");
|
|
128
|
-
return splitArray.map((item, i) => i === splitArray.length - 1 ? camelCase(item, {
|
|
129
|
-
prefix,
|
|
130
|
-
suffix
|
|
131
|
-
}) : camelCase(item)).join("/");
|
|
132
|
-
}
|
|
133
|
-
return camelCase$1(`${prefix} ${text} ${suffix}`, {
|
|
134
|
-
pascalCase: false,
|
|
135
|
-
preserveConsecutiveUppercase: true
|
|
136
|
-
}).replace(/[^a-zA-Z0-9]/g, "");
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
//#endregion
|
|
140
|
-
//#region ../core/src/transformers/transformReservedWord.ts
|
|
141
|
-
function isValidVarName(name) {
|
|
142
|
-
try {
|
|
143
|
-
Function(`var ${name}`);
|
|
144
|
-
} catch (_e) {
|
|
145
|
-
return false;
|
|
146
|
-
}
|
|
147
|
-
return true;
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
//#endregion
|
|
151
|
-
//#region ../core/src/utils/URLPath.ts
|
|
152
|
-
var URLPath = class {
|
|
153
|
-
path;
|
|
154
|
-
#options;
|
|
155
|
-
constructor(path$1, options = {}) {
|
|
156
|
-
this.path = path$1;
|
|
157
|
-
this.#options = options;
|
|
158
|
-
return this;
|
|
159
|
-
}
|
|
160
|
-
/**
|
|
161
|
-
* Convert Swagger path to URLPath(syntax of Express)
|
|
162
|
-
* @example /pet/{petId} => /pet/:petId
|
|
163
|
-
*/
|
|
164
|
-
get URL() {
|
|
165
|
-
return this.toURLPath();
|
|
166
|
-
}
|
|
167
|
-
get isURL() {
|
|
168
|
-
try {
|
|
169
|
-
if (new URL(this.path)?.href) return true;
|
|
170
|
-
} catch (_error) {
|
|
171
|
-
return false;
|
|
172
|
-
}
|
|
173
|
-
return false;
|
|
174
|
-
}
|
|
175
|
-
/**
|
|
176
|
-
* Convert Swagger path to template literals/ template strings(camelcase)
|
|
177
|
-
* @example /pet/{petId} => `/pet/${petId}`
|
|
178
|
-
* @example /account/monetary-accountID => `/account/${monetaryAccountId}`
|
|
179
|
-
* @example /account/userID => `/account/${userId}`
|
|
180
|
-
*/
|
|
181
|
-
get template() {
|
|
182
|
-
return this.toTemplateString();
|
|
183
|
-
}
|
|
184
|
-
get object() {
|
|
185
|
-
return this.toObject();
|
|
186
|
-
}
|
|
187
|
-
get params() {
|
|
188
|
-
return this.getParams();
|
|
189
|
-
}
|
|
190
|
-
toObject({ type = "path", replacer, stringify } = {}) {
|
|
191
|
-
const object = {
|
|
192
|
-
url: type === "path" ? this.toURLPath() : this.toTemplateString({ replacer }),
|
|
193
|
-
params: this.getParams()
|
|
194
|
-
};
|
|
195
|
-
if (stringify) {
|
|
196
|
-
if (type === "template") return JSON.stringify(object).replaceAll("'", "").replaceAll(`"`, "");
|
|
197
|
-
if (object.params) return `{ url: '${object.url}', params: ${JSON.stringify(object.params).replaceAll("'", "").replaceAll(`"`, "")} }`;
|
|
198
|
-
return `{ url: '${object.url}' }`;
|
|
199
|
-
}
|
|
200
|
-
return object;
|
|
201
|
-
}
|
|
202
|
-
/**
|
|
203
|
-
* Convert Swagger path to template literals/ template strings(camelcase)
|
|
204
|
-
* @example /pet/{petId} => `/pet/${petId}`
|
|
205
|
-
* @example /account/monetary-accountID => `/account/${monetaryAccountId}`
|
|
206
|
-
* @example /account/userID => `/account/${userId}`
|
|
207
|
-
*/
|
|
208
|
-
toTemplateString({ prefix = "", replacer } = {}) {
|
|
209
|
-
const found = this.path.match(/{(\w|-)*}/g);
|
|
210
|
-
let newPath = this.path.replaceAll("{", "${");
|
|
211
|
-
if (found) newPath = found.reduce((prev, path$1) => {
|
|
212
|
-
const pathWithoutBrackets = path$1.replaceAll("{", "").replaceAll("}", "");
|
|
213
|
-
let param = isValidVarName(pathWithoutBrackets) ? pathWithoutBrackets : camelCase(pathWithoutBrackets);
|
|
214
|
-
if (this.#options.casing === "camelcase") param = camelCase(param);
|
|
215
|
-
return prev.replace(path$1, `\${${replacer ? replacer(param) : param}}`);
|
|
216
|
-
}, this.path);
|
|
217
|
-
return `\`${prefix}${newPath}\``;
|
|
218
|
-
}
|
|
219
|
-
getParams(replacer) {
|
|
220
|
-
const found = this.path.match(/{(\w|-)*}/g);
|
|
221
|
-
if (!found) return;
|
|
222
|
-
const params = {};
|
|
223
|
-
found.forEach((item) => {
|
|
224
|
-
item = item.replaceAll("{", "").replaceAll("}", "");
|
|
225
|
-
let param = isValidVarName(item) ? item : camelCase(item);
|
|
226
|
-
if (this.#options.casing === "camelcase") param = camelCase(param);
|
|
227
|
-
const key = replacer ? replacer(param) : param;
|
|
228
|
-
params[key] = key;
|
|
229
|
-
}, this.path);
|
|
230
|
-
return params;
|
|
231
|
-
}
|
|
232
|
-
/**
|
|
233
|
-
* Convert Swagger path to URLPath(syntax of Express)
|
|
234
|
-
* @example /pet/{petId} => /pet/:petId
|
|
235
|
-
*/
|
|
236
|
-
toURLPath() {
|
|
237
|
-
return this.path.replaceAll("{", ":").replaceAll("}", "");
|
|
238
|
-
}
|
|
239
|
-
};
|
|
240
|
-
|
|
241
55
|
//#endregion
|
|
242
56
|
//#region ../../node_modules/.pnpm/tslib@2.8.1/node_modules/tslib/tslib.es6.mjs
|
|
243
57
|
var tslib_es6_exports = /* @__PURE__ */ __export({
|