@kubb/plugin-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/{SchemaMapper-DlcrPonN.d.ts → SchemaMapper-B2a4K3r2.d.cts} +18 -13
- package/dist/{SchemaMapper-Cjte6oBd.d.cts → SchemaMapper-DesnD5yL.d.ts} +18 -13
- package/dist/{createGenerator-B1p6Pl-d.d.ts → createGenerator-BpFur0uJ.d.ts} +6 -3
- package/dist/{createGenerator-DyVUP-Aj.d.cts → createGenerator-DG5FCAfL.d.cts} +6 -3
- package/dist/generators.d.cts +2 -2
- package/dist/generators.d.ts +2 -2
- package/dist/hooks.d.cts +2 -2
- package/dist/hooks.d.ts +2 -2
- package/dist/index.cjs +24 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +24 -9
- package/dist/index.js.map +1 -1
- package/dist/mocks.d.cts +1 -1
- package/dist/mocks.d.ts +1 -1
- package/dist/utils.d.cts +2 -2
- package/dist/utils.d.ts +2 -2
- package/package.json +5 -6
- package/src/plugin.ts +21 -9
- package/src/types.ts +5 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Fabric } from "@kubb/react-fabric";
|
|
2
1
|
import { KubbFile } from "@kubb/fabric-core/types";
|
|
2
|
+
import { Fabric } from "@kubb/react-fabric";
|
|
3
3
|
import * as OasTypes from "oas/types";
|
|
4
4
|
import { HttpMethods as HttpMethod, OASDocument, SchemaObject, User } from "oas/types";
|
|
5
5
|
import { Operation, Operation as Operation$1 } from "oas/operation";
|
|
@@ -64,7 +64,7 @@ type ExecutedMeta<H extends PluginLifecycleHooks = PluginLifecycleHooks> = {
|
|
|
64
64
|
* console.log('Starting Kubb generation')
|
|
65
65
|
* })
|
|
66
66
|
*
|
|
67
|
-
* events.on('plugin:end', (plugin, duration) => {
|
|
67
|
+
* events.on('plugin:end', (plugin, { duration }) => {
|
|
68
68
|
* console.log(`Plugin ${plugin.name} completed in ${duration}ms`)
|
|
69
69
|
* })
|
|
70
70
|
* ```
|
|
@@ -133,21 +133,21 @@ interface KubbEvents {
|
|
|
133
133
|
*/
|
|
134
134
|
'hooks:end': [];
|
|
135
135
|
/**
|
|
136
|
-
* Emitted when a single hook execution starts.
|
|
137
|
-
*/
|
|
138
|
-
'hook:start': [command: string];
|
|
139
|
-
/**
|
|
140
|
-
* Emitted to execute a hook command (e.g., format or lint).
|
|
136
|
+
* Emitted when a single hook execution starts. (e.g., format or lint).
|
|
141
137
|
* The callback should be invoked when the command completes.
|
|
142
138
|
*/
|
|
143
|
-
'hook:
|
|
144
|
-
|
|
139
|
+
'hook:start': [{
|
|
140
|
+
id?: string;
|
|
141
|
+
command: string;
|
|
145
142
|
args?: readonly string[];
|
|
146
|
-
}
|
|
143
|
+
}];
|
|
147
144
|
/**
|
|
148
145
|
* Emitted when a single hook execution completes.
|
|
149
146
|
*/
|
|
150
|
-
'hook:end': [
|
|
147
|
+
'hook:end': [{
|
|
148
|
+
id?: string;
|
|
149
|
+
command: string;
|
|
150
|
+
}];
|
|
151
151
|
/**
|
|
152
152
|
* Emitted when a new version of Kubb is available.
|
|
153
153
|
*/
|
|
@@ -210,8 +210,13 @@ interface KubbEvents {
|
|
|
210
210
|
'plugin:start': [plugin: Plugin];
|
|
211
211
|
/**
|
|
212
212
|
* Emitted when a plugin completes execution.
|
|
213
|
+
* Duration in ms
|
|
213
214
|
*/
|
|
214
|
-
'plugin:end': [plugin: Plugin,
|
|
215
|
+
'plugin:end': [plugin: Plugin, meta: {
|
|
216
|
+
duration: number;
|
|
217
|
+
success: boolean;
|
|
218
|
+
error?: Error;
|
|
219
|
+
}];
|
|
215
220
|
/**
|
|
216
221
|
* Emitted when plugin hook progress tracking starts.
|
|
217
222
|
* Contains the hook name and list of plugins to execute.
|
|
@@ -990,4 +995,4 @@ type SchemaTree = {
|
|
|
990
995
|
declare function isKeyword<T extends Schema, K extends keyof SchemaKeywordMapper>(meta: T, keyword: K): meta is Extract<T, SchemaKeywordMapper[K]>;
|
|
991
996
|
//#endregion
|
|
992
997
|
export { Plugin as C, AsyncEventEmitter as D, UserPluginWithLifeCycle as E, KubbEvents as O, Output as S, ResolveNameParams as T, contentType as _, SchemaMapper as a, Config as b, schemaKeywords as c, HttpMethod as d, OasTypes as f, SchemaObject$1 as g, Operation$1 as h, SchemaKeywordMapper as i, BaseGenerator as k, isOptional as l, OpenAPIV3_1 as m, SchemaKeyword as n, SchemaTree as o, OpenAPIV3$1 as p, SchemaKeywordBase as r, isKeyword as s, Schema as t, Oas as u, FileMetaBase as v, PluginFactoryOptions as w, Group as x, PluginManager as y };
|
|
993
|
-
//# sourceMappingURL=SchemaMapper-
|
|
998
|
+
//# sourceMappingURL=SchemaMapper-B2a4K3r2.d.cts.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { KubbFile } from "@kubb/fabric-core/types";
|
|
2
1
|
import { Fabric } from "@kubb/react-fabric";
|
|
2
|
+
import { KubbFile } from "@kubb/fabric-core/types";
|
|
3
3
|
import * as OasTypes from "oas/types";
|
|
4
4
|
import { HttpMethods as HttpMethod, OASDocument, SchemaObject, User } from "oas/types";
|
|
5
5
|
import { Operation, Operation as Operation$1 } from "oas/operation";
|
|
@@ -64,7 +64,7 @@ type ExecutedMeta<H extends PluginLifecycleHooks = PluginLifecycleHooks> = {
|
|
|
64
64
|
* console.log('Starting Kubb generation')
|
|
65
65
|
* })
|
|
66
66
|
*
|
|
67
|
-
* events.on('plugin:end', (plugin, duration) => {
|
|
67
|
+
* events.on('plugin:end', (plugin, { duration }) => {
|
|
68
68
|
* console.log(`Plugin ${plugin.name} completed in ${duration}ms`)
|
|
69
69
|
* })
|
|
70
70
|
* ```
|
|
@@ -133,21 +133,21 @@ interface KubbEvents {
|
|
|
133
133
|
*/
|
|
134
134
|
'hooks:end': [];
|
|
135
135
|
/**
|
|
136
|
-
* Emitted when a single hook execution starts.
|
|
137
|
-
*/
|
|
138
|
-
'hook:start': [command: string];
|
|
139
|
-
/**
|
|
140
|
-
* Emitted to execute a hook command (e.g., format or lint).
|
|
136
|
+
* Emitted when a single hook execution starts. (e.g., format or lint).
|
|
141
137
|
* The callback should be invoked when the command completes.
|
|
142
138
|
*/
|
|
143
|
-
'hook:
|
|
144
|
-
|
|
139
|
+
'hook:start': [{
|
|
140
|
+
id?: string;
|
|
141
|
+
command: string;
|
|
145
142
|
args?: readonly string[];
|
|
146
|
-
}
|
|
143
|
+
}];
|
|
147
144
|
/**
|
|
148
145
|
* Emitted when a single hook execution completes.
|
|
149
146
|
*/
|
|
150
|
-
'hook:end': [
|
|
147
|
+
'hook:end': [{
|
|
148
|
+
id?: string;
|
|
149
|
+
command: string;
|
|
150
|
+
}];
|
|
151
151
|
/**
|
|
152
152
|
* Emitted when a new version of Kubb is available.
|
|
153
153
|
*/
|
|
@@ -210,8 +210,13 @@ interface KubbEvents {
|
|
|
210
210
|
'plugin:start': [plugin: Plugin];
|
|
211
211
|
/**
|
|
212
212
|
* Emitted when a plugin completes execution.
|
|
213
|
+
* Duration in ms
|
|
213
214
|
*/
|
|
214
|
-
'plugin:end': [plugin: Plugin,
|
|
215
|
+
'plugin:end': [plugin: Plugin, meta: {
|
|
216
|
+
duration: number;
|
|
217
|
+
success: boolean;
|
|
218
|
+
error?: Error;
|
|
219
|
+
}];
|
|
215
220
|
/**
|
|
216
221
|
* Emitted when plugin hook progress tracking starts.
|
|
217
222
|
* Contains the hook name and list of plugins to execute.
|
|
@@ -990,4 +995,4 @@ type SchemaTree = {
|
|
|
990
995
|
declare function isKeyword<T extends Schema, K extends keyof SchemaKeywordMapper>(meta: T, keyword: K): meta is Extract<T, SchemaKeywordMapper[K]>;
|
|
991
996
|
//#endregion
|
|
992
997
|
export { Plugin as C, AsyncEventEmitter as D, UserPluginWithLifeCycle as E, KubbEvents as O, Output as S, ResolveNameParams as T, contentType as _, SchemaMapper as a, Config as b, schemaKeywords as c, HttpMethod as d, OasTypes as f, SchemaObject$1 as g, Operation$1 as h, SchemaKeywordMapper as i, BaseGenerator as k, isOptional as l, OpenAPIV3_1 as m, SchemaKeyword as n, SchemaTree as o, OpenAPIV3$1 as p, SchemaKeywordBase as r, isKeyword as s, Schema as t, Oas as u, FileMetaBase as v, PluginFactoryOptions as w, Group as x, PluginManager as y };
|
|
993
|
-
//# sourceMappingURL=SchemaMapper-
|
|
998
|
+
//# sourceMappingURL=SchemaMapper-DesnD5yL.d.ts.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { C as Plugin, D as AsyncEventEmitter, O as KubbEvents, S as Output, T as ResolveNameParams, _ as contentType, b as Config, d as HttpMethod, g as SchemaObject, h as Operation, i as SchemaKeywordMapper, k as BaseGenerator, t as Schema, u as Oas, v as FileMetaBase, w as PluginFactoryOptions, x as Group, y as PluginManager } from "./SchemaMapper-
|
|
1
|
+
import { C as Plugin, D as AsyncEventEmitter, O as KubbEvents, S as Output, T as ResolveNameParams, _ as contentType, b as Config, d as HttpMethod, g as SchemaObject, h as Operation, i as SchemaKeywordMapper, k as BaseGenerator, t as Schema, u as Oas, v as FileMetaBase, w as PluginFactoryOptions, x as Group, y as PluginManager } from "./SchemaMapper-DesnD5yL.js";
|
|
2
2
|
import { Fabric } from "@kubb/react-fabric";
|
|
3
3
|
import { KubbFile } from "@kubb/fabric-core/types";
|
|
4
4
|
import { KubbNode } from "@kubb/react-fabric/types";
|
|
@@ -36,8 +36,11 @@ type FunctionParamsASTWithType = {
|
|
|
36
36
|
type FunctionParamsAST = FunctionParamsASTWithoutType | FunctionParamsASTWithType;
|
|
37
37
|
//#endregion
|
|
38
38
|
//#region src/types.d.ts
|
|
39
|
+
type GetOasOptions = {
|
|
40
|
+
validate?: boolean;
|
|
41
|
+
};
|
|
39
42
|
type Context$2 = {
|
|
40
|
-
getOas(): Promise<Oas>;
|
|
43
|
+
getOas(options?: GetOasOptions): Promise<Oas>;
|
|
41
44
|
getBaseURL(): Promise<string | undefined>;
|
|
42
45
|
};
|
|
43
46
|
declare global {
|
|
@@ -350,4 +353,4 @@ type CoreGenerator<TOptions extends PluginFactoryOptions> = {
|
|
|
350
353
|
declare function createGenerator<TOptions extends PluginFactoryOptions>(generator: UserGenerator<TOptions>): CoreGenerator<TOptions>;
|
|
351
354
|
//#endregion
|
|
352
355
|
export { Resolver as C, ResolvePathOptions as S, Options as _, createReactGenerator as a, Ref as b, SchemaGeneratorBuildOptions as c, OperationGenerator as d, OperationMethodResult as f, OperationSchemas as g, OperationSchema as h, ReactGenerator as i, SchemaGeneratorOptions as l, Include as m, createGenerator as n, GetSchemaGeneratorOptions as o, Exclude as p, Generator as r, SchemaGenerator as s, CoreGenerator as t, SchemaMethodResult as u, Override as v, FunctionParamsAST as w, Refs as x, PluginOas as y };
|
|
353
|
-
//# sourceMappingURL=createGenerator-
|
|
356
|
+
//# sourceMappingURL=createGenerator-BpFur0uJ.d.ts.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { C as Plugin, D as AsyncEventEmitter, O as KubbEvents, S as Output, T as ResolveNameParams, _ as contentType, b as Config, d as HttpMethod, g as SchemaObject, h as Operation, i as SchemaKeywordMapper, k as BaseGenerator, t as Schema, u as Oas, v as FileMetaBase, w as PluginFactoryOptions, x as Group, y as PluginManager } from "./SchemaMapper-
|
|
1
|
+
import { C as Plugin, D as AsyncEventEmitter, O as KubbEvents, S as Output, T as ResolveNameParams, _ as contentType, b as Config, d as HttpMethod, g as SchemaObject, h as Operation, i as SchemaKeywordMapper, k as BaseGenerator, t as Schema, u as Oas, v as FileMetaBase, w as PluginFactoryOptions, x as Group, y as PluginManager } from "./SchemaMapper-B2a4K3r2.cjs";
|
|
2
2
|
import { KubbFile } from "@kubb/fabric-core/types";
|
|
3
3
|
import { Fabric } from "@kubb/react-fabric";
|
|
4
4
|
import { KubbNode } from "@kubb/react-fabric/types";
|
|
@@ -36,8 +36,11 @@ type FunctionParamsASTWithType = {
|
|
|
36
36
|
type FunctionParamsAST = FunctionParamsASTWithoutType | FunctionParamsASTWithType;
|
|
37
37
|
//#endregion
|
|
38
38
|
//#region src/types.d.ts
|
|
39
|
+
type GetOasOptions = {
|
|
40
|
+
validate?: boolean;
|
|
41
|
+
};
|
|
39
42
|
type Context$2 = {
|
|
40
|
-
getOas(): Promise<Oas>;
|
|
43
|
+
getOas(options?: GetOasOptions): Promise<Oas>;
|
|
41
44
|
getBaseURL(): Promise<string | undefined>;
|
|
42
45
|
};
|
|
43
46
|
declare global {
|
|
@@ -350,4 +353,4 @@ type CoreGenerator<TOptions extends PluginFactoryOptions> = {
|
|
|
350
353
|
declare function createGenerator<TOptions extends PluginFactoryOptions>(generator: UserGenerator<TOptions>): CoreGenerator<TOptions>;
|
|
351
354
|
//#endregion
|
|
352
355
|
export { Resolver as C, ResolvePathOptions as S, Options as _, createReactGenerator as a, Ref as b, SchemaGeneratorBuildOptions as c, OperationGenerator as d, OperationMethodResult as f, OperationSchemas as g, OperationSchema as h, ReactGenerator as i, SchemaGeneratorOptions as l, Include as m, createGenerator as n, GetSchemaGeneratorOptions as o, Exclude as p, Generator as r, SchemaGenerator as s, CoreGenerator as t, SchemaMethodResult as u, Override as v, FunctionParamsAST as w, Refs as x, PluginOas as y };
|
|
353
|
-
//# sourceMappingURL=createGenerator-
|
|
356
|
+
//# sourceMappingURL=createGenerator-DG5FCAfL.d.cts.map
|
package/dist/generators.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import "./SchemaMapper-
|
|
2
|
-
import { a as createReactGenerator, n as createGenerator, r as Generator, t as CoreGenerator, y as PluginOas } from "./createGenerator-
|
|
1
|
+
import "./SchemaMapper-B2a4K3r2.cjs";
|
|
2
|
+
import { a as createReactGenerator, n as createGenerator, r as Generator, t as CoreGenerator, y as PluginOas } from "./createGenerator-DG5FCAfL.cjs";
|
|
3
3
|
|
|
4
4
|
//#region src/generators/jsonGenerator.d.ts
|
|
5
5
|
declare const jsonGenerator: CoreGenerator<PluginOas>;
|
package/dist/generators.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import "./SchemaMapper-
|
|
2
|
-
import { a as createReactGenerator, n as createGenerator, r as Generator, t as CoreGenerator, y as PluginOas } from "./createGenerator-
|
|
1
|
+
import "./SchemaMapper-DesnD5yL.js";
|
|
2
|
+
import { a as createReactGenerator, n as createGenerator, r as Generator, t as CoreGenerator, y as PluginOas } from "./createGenerator-BpFur0uJ.js";
|
|
3
3
|
|
|
4
4
|
//#region src/generators/jsonGenerator.d.ts
|
|
5
5
|
declare const jsonGenerator: CoreGenerator<PluginOas>;
|
package/dist/hooks.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { C as Plugin, T as ResolveNameParams, h as Operation, t as Schema, u as Oas, v as FileMetaBase, w as PluginFactoryOptions } from "./SchemaMapper-
|
|
2
|
-
import { d as OperationGenerator, g as OperationSchemas } from "./createGenerator-
|
|
1
|
+
import { C as Plugin, T as ResolveNameParams, h as Operation, t as Schema, u as Oas, v as FileMetaBase, w as PluginFactoryOptions } from "./SchemaMapper-B2a4K3r2.cjs";
|
|
2
|
+
import { d as OperationGenerator, g as OperationSchemas } from "./createGenerator-DG5FCAfL.cjs";
|
|
3
3
|
import { KubbFile } from "@kubb/fabric-core/types";
|
|
4
4
|
|
|
5
5
|
//#region src/hooks/useOas.d.ts
|
package/dist/hooks.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { C as Plugin, T as ResolveNameParams, h as Operation, t as Schema, u as Oas, v as FileMetaBase, w as PluginFactoryOptions } from "./SchemaMapper-
|
|
2
|
-
import { d as OperationGenerator, g as OperationSchemas } from "./createGenerator-
|
|
1
|
+
import { C as Plugin, T as ResolveNameParams, h as Operation, t as Schema, u as Oas, v as FileMetaBase, w as PluginFactoryOptions } from "./SchemaMapper-DesnD5yL.js";
|
|
2
|
+
import { d as OperationGenerator, g as OperationSchemas } from "./createGenerator-BpFur0uJ.js";
|
|
3
3
|
import { KubbFile } from "@kubb/fabric-core/types";
|
|
4
4
|
|
|
5
5
|
//#region src/hooks/useOas.d.ts
|
package/dist/index.cjs
CHANGED
|
@@ -277,17 +277,23 @@ var OperationGenerator = class extends _kubb_core.BaseGenerator {
|
|
|
277
277
|
const pluginOasName = "plugin-oas";
|
|
278
278
|
const pluginOas = (0, _kubb_core.definePlugin)((options) => {
|
|
279
279
|
const { output = { path: "schemas" }, group, validate = true, generators = [require_generators.jsonGenerator], serverIndex, contentType, oasClass, discriminator = "strict" } = options;
|
|
280
|
-
const getOas = async ({ config }) => {
|
|
280
|
+
const getOas = async ({ validate: validate$1, config, events }) => {
|
|
281
281
|
const oas = await (0, _kubb_oas.parseFromConfig)(config, oasClass);
|
|
282
282
|
oas.setOptions({
|
|
283
283
|
contentType,
|
|
284
284
|
discriminator
|
|
285
285
|
});
|
|
286
286
|
try {
|
|
287
|
-
if (validate) await oas.valdiate();
|
|
288
|
-
} catch (
|
|
289
|
-
const
|
|
290
|
-
|
|
287
|
+
if (validate$1) await oas.valdiate();
|
|
288
|
+
} catch (er) {
|
|
289
|
+
const caughtError = er;
|
|
290
|
+
const errorTimestamp = /* @__PURE__ */ new Date();
|
|
291
|
+
const error = new Error("OAS Validation failed", { cause: caughtError });
|
|
292
|
+
events.emit("info", caughtError.message);
|
|
293
|
+
events.emit("debug", {
|
|
294
|
+
date: errorTimestamp,
|
|
295
|
+
logs: [`✗ ${error.message}`, caughtError.message]
|
|
296
|
+
});
|
|
291
297
|
}
|
|
292
298
|
return oas;
|
|
293
299
|
};
|
|
@@ -301,14 +307,23 @@ const pluginOas = (0, _kubb_core.definePlugin)((options) => {
|
|
|
301
307
|
},
|
|
302
308
|
inject() {
|
|
303
309
|
const config = this.config;
|
|
310
|
+
const events = this.events;
|
|
304
311
|
let oas;
|
|
305
312
|
return {
|
|
306
|
-
async getOas() {
|
|
307
|
-
if (!oas) oas = await getOas({
|
|
313
|
+
async getOas({ validate: validate$1 = false } = {}) {
|
|
314
|
+
if (!oas) oas = await getOas({
|
|
315
|
+
config,
|
|
316
|
+
events,
|
|
317
|
+
validate: validate$1
|
|
318
|
+
});
|
|
308
319
|
return oas;
|
|
309
320
|
},
|
|
310
321
|
async getBaseURL() {
|
|
311
|
-
const oas$1 = await getOas({
|
|
322
|
+
const oas$1 = await getOas({
|
|
323
|
+
config,
|
|
324
|
+
events,
|
|
325
|
+
validate: false
|
|
326
|
+
});
|
|
312
327
|
if (serverIndex !== void 0) return oas$1.api.servers?.at(serverIndex)?.url;
|
|
313
328
|
}
|
|
314
329
|
};
|
|
@@ -331,8 +346,8 @@ const pluginOas = (0, _kubb_core.definePlugin)((options) => {
|
|
|
331
346
|
return node_path.default.resolve(root, output.path, baseName);
|
|
332
347
|
},
|
|
333
348
|
async install() {
|
|
349
|
+
const oas = await this.getOas({ validate });
|
|
334
350
|
if (!output) return;
|
|
335
|
-
const oas = await this.getOas();
|
|
336
351
|
await oas.dereference();
|
|
337
352
|
const schemaFiles = await new require_SchemaGenerator.SchemaGenerator({
|
|
338
353
|
unknownType: "unknown",
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["context: HandlerContext<TOutput, TOptions>","SchemaGenerator","schemaKeywords","BaseGenerator","transformers","path","#isExcluded","#isIncluded","pLimit","#getOptions","buildOperation","buildOperations","jsonGenerator","oas: Oas","oas","path","options","groupName: Group['name']","SchemaGenerator","_createGenerator","_createReactGenerator"],"sources":["../src/createParser.ts","../src/OperationGenerator.ts","../src/plugin.ts","../src/index.ts"],"sourcesContent":["import { SchemaGenerator } from './SchemaGenerator.ts'\nimport type { Schema, SchemaKeywordMapper, SchemaMapper, SchemaTree } from './SchemaMapper.ts'\nimport { schemaKeywords } from './SchemaMapper.ts'\n\n/**\n * Handler context with parse method available via `this`\n */\nexport type HandlerContext<TOutput, TOptions> = {\n parse: (tree: SchemaTree, options: TOptions) => TOutput | null | undefined\n}\n\n/**\n * Handler function type for custom keyword processing\n * Handlers can access the parse function via `this.parse`\n */\nexport type KeywordHandler<TOutput, TOptions> = (this: HandlerContext<TOutput, TOptions>, tree: SchemaTree, options: TOptions) => TOutput | null | undefined\n\n/**\n * Configuration for createParser\n */\nexport type CreateParserConfig<TOutput, TOptions> = {\n /**\n * The keyword mapper that maps schema keywords to output generators\n */\n mapper: SchemaMapper<TOutput>\n\n /**\n * Custom handlers for specific schema keywords\n * These provide the implementation for complex types that need special processing\n *\n * Use function syntax (not arrow functions) to enable use of `this` keyword:\n * ```typescript\n * handlers: {\n * enum(tree, options, parse) {\n * // Implementation\n * }\n * }\n * ```\n *\n * Common keywords that typically need handlers:\n * - union: Combine multiple schemas into a union\n * - and: Combine multiple schemas into an intersection\n * - array: Handle array types with items\n * - object: Handle object types with properties\n * - enum: Handle enum types\n * - tuple: Handle tuple types\n * - const: Handle literal/const types\n * - ref: Handle references to other schemas\n * - string/number/integer: Handle primitives with constraints (min/max)\n * - matches: Handle regex patterns\n * - default/describe/optional/nullable: Handle modifiers\n */\n handlers: Partial<{\n [K in keyof SchemaKeywordMapper]: KeywordHandler<TOutput, TOptions>\n }>\n}\n\n/**\n * Creates a parser function that converts schema trees to output using the provided mapper and handlers\n *\n * This function provides a framework for building parsers by:\n * 1. Checking for custom handlers for each keyword\n * 2. Falling back to the mapper for simple keywords\n * 3. Providing utilities for common operations (finding siblings, etc.)\n *\n * The generated parser is recursive and can handle nested schemas.\n *\n * @template TOutput - The output type (e.g., string for Zod/Faker, ts.TypeNode for TypeScript)\n * @template TOptions - The parser options type\n * @param config - Configuration object containing mapper and handlers\n * @returns A parse function that converts SchemaTree to TOutput\n *\n * @example\n * ```ts\n * // Create a simple string-based parser\n * const parse = createParser({\n * mapper: zodKeywordMapper,\n * handlers: {\n * union(tree, options) {\n * const items = tree.current.args\n * .map(it => this.parse({ ...tree, current: it }, options))\n * .filter(Boolean)\n * return `z.union([${items.join(', ')}])`\n * },\n * string(tree, options) {\n * const minSchema = findSchemaKeyword(tree.siblings, 'min')\n * const maxSchema = findSchemaKeyword(tree.siblings, 'max')\n * return zodKeywordMapper.string(false, minSchema?.args, maxSchema?.args)\n * }\n * }\n * })\n * ```\n */\nexport function createParser<TOutput, TOptions extends Record<string, any>>(\n config: CreateParserConfig<TOutput, TOptions>,\n): (tree: SchemaTree, options: TOptions) => TOutput | null | undefined {\n const { mapper, handlers } = config\n\n function parse(tree: SchemaTree, options: TOptions): TOutput | null | undefined {\n const { current } = tree\n\n // Check if there's a custom handler for this keyword\n const handler = handlers[current.keyword as keyof SchemaKeywordMapper]\n if (handler) {\n // Create context object with parse method accessible via `this`\n const context: HandlerContext<TOutput, TOptions> = { parse }\n return handler.call(context, tree, options)\n }\n\n // Fall back to simple mapper lookup\n const value = mapper[current.keyword as keyof typeof mapper]\n\n if (!value) {\n return undefined\n }\n\n // For simple keywords without args, call the mapper directly\n if (current.keyword in mapper) {\n return value()\n }\n\n return undefined\n }\n\n return parse\n}\n\n/**\n * Helper to find a schema keyword in siblings\n * Useful in handlers when you need to find related schemas (e.g., min/max for string)\n *\n * @example\n * ```ts\n * const minSchema = findSchemaKeyword(tree.siblings, 'min')\n * const maxSchema = findSchemaKeyword(tree.siblings, 'max')\n * return zodKeywordMapper.string(false, minSchema?.args, maxSchema?.args)\n * ```\n */\nexport function findSchemaKeyword<K extends keyof SchemaKeywordMapper>(siblings: Schema[], keyword: K): SchemaKeywordMapper[K] | undefined {\n return SchemaGenerator.find(siblings, schemaKeywords[keyword]) as SchemaKeywordMapper[K] | undefined\n}\n","import type { KubbEvents, Plugin, PluginFactoryOptions, PluginManager } from '@kubb/core'\nimport { BaseGenerator, type FileMetaBase } from '@kubb/core'\nimport transformers from '@kubb/core/transformers'\nimport type { AsyncEventEmitter } from '@kubb/core/utils'\nimport type { KubbFile } from '@kubb/fabric-core/types'\nimport type { contentType, HttpMethod, Oas, OasTypes, Operation, SchemaObject } from '@kubb/oas'\nimport type { Fabric } from '@kubb/react-fabric'\nimport pLimit from 'p-limit'\nimport type { Generator } from './generators/types.ts'\nimport type { Exclude, Include, OperationSchemas, Override } from './types.ts'\nimport { buildOperation, buildOperations } from './utils.tsx'\n\nexport type OperationMethodResult<TFileMeta extends FileMetaBase> = Promise<KubbFile.File<TFileMeta> | Array<KubbFile.File<TFileMeta>> | null>\n\ntype Context<TOptions, TPluginOptions extends PluginFactoryOptions> = {\n fabric: Fabric\n oas: Oas\n exclude: Array<Exclude> | undefined\n include: Array<Include> | undefined\n override: Array<Override<TOptions>> | undefined\n contentType: contentType | undefined\n pluginManager: PluginManager\n events?: AsyncEventEmitter<KubbEvents>\n /**\n * Current plugin\n */\n plugin: Plugin<TPluginOptions>\n mode: KubbFile.Mode\n}\n\nexport class OperationGenerator<\n TPluginOptions extends PluginFactoryOptions = PluginFactoryOptions,\n TFileMeta extends FileMetaBase = FileMetaBase,\n> extends BaseGenerator<TPluginOptions['resolvedOptions'], Context<TPluginOptions['resolvedOptions'], TPluginOptions>> {\n #getOptions(operation: Operation, method: HttpMethod): Partial<TPluginOptions['resolvedOptions']> {\n const { override = [] } = this.context\n const operationId = operation.getOperationId({ friendlyCase: true })\n const contentType = operation.getContentType()\n\n return (\n override.find(({ pattern, type }) => {\n switch (type) {\n case 'tag':\n return operation.getTags().some((tag) => tag.name.match(pattern))\n case 'operationId':\n return !!operationId.match(pattern)\n case 'path':\n return !!operation.path.match(pattern)\n case 'method':\n return !!method.match(pattern)\n case 'contentType':\n return !!contentType.match(pattern)\n default:\n return false\n }\n })?.options || {}\n )\n }\n\n #isExcluded(operation: Operation, method: HttpMethod): boolean {\n const { exclude = [] } = this.context\n const operationId = operation.getOperationId({ friendlyCase: true })\n const contentType = operation.getContentType()\n\n return exclude.some(({ pattern, type }) => {\n switch (type) {\n case 'tag':\n return operation.getTags().some((tag) => tag.name.match(pattern))\n case 'operationId':\n return !!operationId.match(pattern)\n case 'path':\n return !!operation.path.match(pattern)\n case 'method':\n return !!method.match(pattern)\n case 'contentType':\n return !!contentType.match(pattern)\n default:\n return false\n }\n })\n }\n\n #isIncluded(operation: Operation, method: HttpMethod): boolean {\n const { include = [] } = this.context\n const operationId = operation.getOperationId({ friendlyCase: true })\n const contentType = operation.getContentType()\n\n return include.some(({ pattern, type }) => {\n switch (type) {\n case 'tag':\n return operation.getTags().some((tag) => tag.name.match(pattern))\n case 'operationId':\n return !!operationId.match(pattern)\n case 'path':\n return !!operation.path.match(pattern)\n case 'method':\n return !!method.match(pattern)\n case 'contentType':\n return !!contentType.match(pattern)\n default:\n return false\n }\n })\n }\n\n getSchemas(\n operation: Operation,\n {\n resolveName = (name) => name,\n }: {\n resolveName?: (name: string) => string\n } = {},\n ): OperationSchemas {\n const operationId = operation.getOperationId({ friendlyCase: true })\n const method = operation.method\n const operationName = transformers.pascalCase(operationId)\n\n const resolveKeys = (schema?: SchemaObject) => (schema?.properties ? Object.keys(schema.properties) : undefined)\n\n const pathParamsSchema = this.context.oas.getParametersSchema(operation, 'path')\n const queryParamsSchema = this.context.oas.getParametersSchema(operation, 'query')\n const headerParamsSchema = this.context.oas.getParametersSchema(operation, 'header')\n const requestSchema = this.context.oas.getRequestSchema(operation)\n const statusCodes = operation.getResponseStatusCodes().map((statusCode) => {\n const name = statusCode === 'default' ? 'error' : statusCode\n const schema = this.context.oas.getResponseSchema(operation, statusCode)\n const keys = resolveKeys(schema)\n\n return {\n name: resolveName(transformers.pascalCase(`${operationId} ${name}`)),\n description: (operation.getResponseByStatusCode(statusCode) as OasTypes.ResponseObject)?.description,\n schema,\n operation,\n operationName,\n statusCode: name === 'error' ? undefined : Number(statusCode),\n keys,\n keysToOmit: keys?.filter((key) => (schema?.properties?.[key] as OasTypes.SchemaObject)?.writeOnly),\n }\n })\n\n const successful = statusCodes.filter((item) => item.statusCode?.toString().startsWith('2'))\n const errors = statusCodes.filter((item) => item.statusCode?.toString().startsWith('4') || item.statusCode?.toString().startsWith('5'))\n\n return {\n pathParams: pathParamsSchema\n ? {\n name: resolveName(transformers.pascalCase(`${operationId} PathParams`)),\n operation,\n operationName,\n schema: pathParamsSchema,\n keys: resolveKeys(pathParamsSchema),\n }\n : undefined,\n queryParams: queryParamsSchema\n ? {\n name: resolveName(transformers.pascalCase(`${operationId} QueryParams`)),\n operation,\n operationName,\n schema: queryParamsSchema,\n keys: resolveKeys(queryParamsSchema) || [],\n }\n : undefined,\n headerParams: headerParamsSchema\n ? {\n name: resolveName(transformers.pascalCase(`${operationId} HeaderParams`)),\n operation,\n operationName,\n schema: headerParamsSchema,\n keys: resolveKeys(headerParamsSchema),\n }\n : undefined,\n request: requestSchema\n ? {\n name: resolveName(transformers.pascalCase(`${operationId} ${method === 'get' ? 'queryRequest' : 'mutationRequest'}`)),\n description: (operation.schema.requestBody as OasTypes.RequestBodyObject)?.description,\n operation,\n operationName,\n schema: requestSchema,\n keys: resolveKeys(requestSchema),\n keysToOmit: resolveKeys(requestSchema)?.filter((key) => (requestSchema.properties?.[key] as OasTypes.SchemaObject)?.readOnly),\n }\n : undefined,\n response: {\n name: resolveName(transformers.pascalCase(`${operationId} ${method === 'get' ? 'queryResponse' : 'mutationResponse'}`)),\n operation,\n operationName,\n schema: {\n oneOf: successful.map((item) => ({ ...item.schema, $ref: item.name })) || undefined,\n } as SchemaObject,\n },\n responses: successful,\n errors,\n statusCodes,\n }\n }\n\n async getOperations(): Promise<Array<{ path: string; method: HttpMethod; operation: Operation }>> {\n const { oas } = this.context\n\n const paths = oas.getPaths()\n\n return Object.entries(paths).flatMap(([path, methods]) =>\n Object.entries(methods)\n .map((values) => {\n const [method, operation] = values as [HttpMethod, Operation]\n if (this.#isExcluded(operation, method)) {\n return null\n }\n\n if (this.context.include && !this.#isIncluded(operation, method)) {\n return null\n }\n\n return operation ? { path, method: method as HttpMethod, operation } : null\n })\n .filter(Boolean),\n )\n }\n\n async build(...generators: Array<Generator<TPluginOptions>>): Promise<Array<KubbFile.File<TFileMeta>>> {\n const operations = await this.getOperations()\n\n const generatorLimit = pLimit(1)\n const operationLimit = pLimit(10)\n\n this.context.events?.emit('debug', {\n date: new Date(),\n logs: [`Building ${operations.length} operations`, ` • Generators: ${generators.length}`],\n })\n\n const writeTasks = generators.map((generator) =>\n generatorLimit(async () => {\n const operationTasks = operations.map(({ operation, method }) =>\n operationLimit(async () => {\n const options = this.#getOptions(operation, method)\n\n if (generator.type === 'react') {\n await buildOperation(operation, {\n config: this.context.pluginManager.config,\n fabric: this.context.fabric,\n Component: generator.Operation,\n generator: this,\n plugin: {\n ...this.context.plugin,\n options: {\n ...this.options,\n ...options,\n },\n },\n })\n\n return []\n }\n\n const result = await generator.operation?.({\n generator: this,\n config: this.context.pluginManager.config,\n operation,\n plugin: {\n ...this.context.plugin,\n options: {\n ...this.options,\n ...options,\n },\n },\n })\n\n return result ?? []\n }),\n )\n\n const operationResults = await Promise.all(operationTasks)\n const opResultsFlat = operationResults.flat()\n\n if (generator.type === 'react') {\n await buildOperations(\n operations.map((op) => op.operation),\n {\n fabric: this.context.fabric,\n config: this.context.pluginManager.config,\n Component: generator.Operations,\n generator: this,\n plugin: this.context.plugin,\n },\n )\n\n return []\n }\n\n const operationsResult = await generator.operations?.({\n generator: this,\n config: this.context.pluginManager.config,\n operations: operations.map((op) => op.operation),\n plugin: this.context.plugin,\n })\n\n return [...opResultsFlat, ...(operationsResult ?? [])] as unknown as KubbFile.File<TFileMeta>\n }),\n )\n\n const nestedResults = await Promise.all(writeTasks)\n\n return nestedResults.flat()\n }\n}\n","import path from 'node:path'\nimport { type Config, definePlugin, type Group, getMode } from '@kubb/core'\nimport { camelCase } from '@kubb/core/transformers'\nimport type { Oas } from '@kubb/oas'\nimport { parseFromConfig } from '@kubb/oas'\nimport { jsonGenerator } from './generators'\nimport { OperationGenerator } from './OperationGenerator.ts'\nimport { SchemaGenerator } from './SchemaGenerator.ts'\nimport type { PluginOas } from './types.ts'\n\nexport const pluginOasName = 'plugin-oas' satisfies PluginOas['name']\n\nexport const pluginOas = definePlugin<PluginOas>((options) => {\n const {\n output = {\n path: 'schemas',\n },\n group,\n validate = true,\n generators = [jsonGenerator],\n serverIndex,\n contentType,\n oasClass,\n discriminator = 'strict',\n } = options\n\n const getOas = async ({ config }: { config: Config }): Promise<Oas> => {\n // needs to be in a different variable or the catch here will not work(return of a promise instead)\n const oas = await parseFromConfig(config, oasClass)\n\n oas.setOptions({\n contentType,\n discriminator,\n })\n\n try {\n if (validate) {\n await oas.valdiate()\n }\n } catch (caughtError) {\n const error = caughtError as Error\n\n console.warn(error?.message)\n }\n\n return oas\n }\n\n return {\n name: pluginOasName,\n options: {\n output,\n validate,\n discriminator,\n ...options,\n },\n inject() {\n const config = this.config\n let oas: Oas\n\n return {\n async getOas() {\n if (!oas) {\n oas = await getOas({ config })\n }\n\n return oas\n },\n async getBaseURL() {\n const oas = await getOas({ config })\n if (serverIndex !== undefined) {\n return oas.api.servers?.at(serverIndex)?.url\n }\n\n return undefined\n },\n }\n },\n resolvePath(baseName, pathMode, options) {\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = pathMode ?? getMode(path.resolve(root, output.path))\n\n if (mode === 'single') {\n /**\n * when output is a file then we will always append to the same file(output file), see fileManager.addOrAppend\n * Other plugins then need to call addOrAppend instead of just add from the fileManager class\n */\n return path.resolve(root, output.path)\n }\n\n if (group && (options?.group?.path || options?.group?.tag)) {\n const groupName: Group['name'] = group?.name\n ? group.name\n : (ctx) => {\n if (group?.type === 'path') {\n return `${ctx.group.split('/')[1]}`\n }\n return `${camelCase(ctx.group)}Controller`\n }\n\n return path.resolve(\n root,\n output.path,\n groupName({\n group: group.type === 'path' ? options.group.path! : options.group.tag!,\n }),\n baseName,\n )\n }\n\n return path.resolve(root, output.path, baseName)\n },\n async install() {\n if (!output) {\n return\n }\n\n const oas = await this.getOas()\n await oas.dereference()\n\n const schemaGenerator = new SchemaGenerator(\n {\n unknownType: 'unknown',\n emptySchemaType: 'unknown',\n dateType: 'date',\n transformers: {},\n ...this.plugin.options,\n },\n {\n fabric: this.fabric,\n oas,\n pluginManager: this.pluginManager,\n events: this.events,\n plugin: this.plugin,\n contentType,\n include: undefined,\n override: undefined,\n mode: 'split',\n output: output.path,\n },\n )\n\n const schemaFiles = await schemaGenerator.build(...generators)\n await this.upsertFile(...schemaFiles)\n\n const operationGenerator = new OperationGenerator(this.plugin.options, {\n fabric: this.fabric,\n oas,\n pluginManager: this.pluginManager,\n events: this.events,\n plugin: this.plugin,\n contentType,\n exclude: undefined,\n include: undefined,\n override: undefined,\n mode: 'split',\n })\n\n const operationFiles = await operationGenerator.build(...generators)\n\n await this.upsertFile(...operationFiles)\n },\n }\n})\n","import type { PluginFactoryOptions } from '@kubb/core'\nimport { createGenerator as _createGenerator } from './generators/createGenerator.ts'\nimport { createReactGenerator as _createReactGenerator } from './generators/createReactGenerator.ts'\nimport type { Generator as _Generator } from './generators/types.ts'\n\nexport type { CreateParserConfig, KeywordHandler } from './createParser.ts'\nexport { createParser, findSchemaKeyword } from './createParser.ts'\nexport type { OperationMethodResult } from './OperationGenerator.ts'\nexport { OperationGenerator } from './OperationGenerator.ts'\nexport { pluginOas, pluginOasName } from './plugin.ts'\nexport type {\n GetSchemaGeneratorOptions,\n SchemaGeneratorBuildOptions,\n SchemaGeneratorOptions,\n SchemaMethodResult,\n} from './SchemaGenerator.ts'\nexport { SchemaGenerator } from './SchemaGenerator.ts'\nexport type {\n Schema,\n SchemaKeyword,\n SchemaKeywordBase,\n SchemaKeywordMapper,\n SchemaMapper,\n SchemaTree,\n} from './SchemaMapper.ts'\nexport { isKeyword, schemaKeywords } from './SchemaMapper.ts'\nexport type * from './types.ts'\nexport { buildOperation, buildOperations, buildSchema } from './utils.tsx'\n\n/**\n * @deprecated use `import { createGenerator } from '@kubb/plugin-oas/generators'`\n */\nexport const createGenerator = _createGenerator\n\n/**\n * @deprecated use `import { createReactGenerator } from '@kubb/plugin-oas/generators'`\n */\nexport const createReactGenerator = _createReactGenerator\n\n/**\n * @deprecated use `import { Generator } from '@kubb/plugin-oas/generators'`\n */\nexport type Generator<TOptions extends PluginFactoryOptions> = _Generator<TOptions>\n"],"mappings":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BAAK,QACV,MACA,OAAO,MACP,UAAU,EACR,OAAO,MAAM,SAAS,SAASC,UAAQ,MAAM,OAAQA,UAAQ,MAAM,KACpE,CAAC,EACF,SACD;;AAGH,UAAOD,kBAAK,QAAQ,MAAM,OAAO,MAAM,SAAS;;EAElD,MAAM,UAAU;AACd,OAAI,CAAC,OACH;GAGF,MAAM,MAAM,MAAM,KAAK,QAAQ;AAC/B,SAAM,IAAI,aAAa;GAwBvB,MAAM,cAAc,MAtBI,IAAIG,wCAC1B;IACE,aAAa;IACb,iBAAiB;IACjB,UAAU;IACV,cAAc,EAAE;IAChB,GAAG,KAAK,OAAO;IAChB,EACD;IACE,QAAQ,KAAK;IACb;IACA,eAAe,KAAK;IACpB,QAAQ,KAAK;IACb,QAAQ,KAAK;IACb;IACA,SAAS;IACT,UAAU;IACV,MAAM;IACN,QAAQ,OAAO;IAChB,CACF,CAEyC,MAAM,GAAG,WAAW;AAC9D,SAAM,KAAK,WAAW,GAAG,YAAY;GAerC,MAAM,iBAAiB,MAbI,IAAI,mBAAmB,KAAK,OAAO,SAAS;IACrE,QAAQ,KAAK;IACb;IACA,eAAe,KAAK;IACpB,QAAQ,KAAK;IACb,QAAQ,KAAK;IACb;IACA,SAAS;IACT,SAAS;IACT,UAAU;IACV,MAAM;IACP,CAAC,CAE8C,MAAM,GAAG,WAAW;AAEpE,SAAM,KAAK,WAAW,GAAG,eAAe;;EAE3C;EACD;;;;;;;ACnIF,MAAa,kBAAkBC;;;;AAK/B,MAAa,uBAAuBC"}
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["context: HandlerContext<TOutput, TOptions>","SchemaGenerator","schemaKeywords","BaseGenerator","transformers","path","#isExcluded","#isIncluded","pLimit","#getOptions","buildOperation","buildOperations","jsonGenerator","validate","oas: Oas","oas","path","options","groupName: Group['name']","SchemaGenerator","_createGenerator","_createReactGenerator"],"sources":["../src/createParser.ts","../src/OperationGenerator.ts","../src/plugin.ts","../src/index.ts"],"sourcesContent":["import { SchemaGenerator } from './SchemaGenerator.ts'\nimport type { Schema, SchemaKeywordMapper, SchemaMapper, SchemaTree } from './SchemaMapper.ts'\nimport { schemaKeywords } from './SchemaMapper.ts'\n\n/**\n * Handler context with parse method available via `this`\n */\nexport type HandlerContext<TOutput, TOptions> = {\n parse: (tree: SchemaTree, options: TOptions) => TOutput | null | undefined\n}\n\n/**\n * Handler function type for custom keyword processing\n * Handlers can access the parse function via `this.parse`\n */\nexport type KeywordHandler<TOutput, TOptions> = (this: HandlerContext<TOutput, TOptions>, tree: SchemaTree, options: TOptions) => TOutput | null | undefined\n\n/**\n * Configuration for createParser\n */\nexport type CreateParserConfig<TOutput, TOptions> = {\n /**\n * The keyword mapper that maps schema keywords to output generators\n */\n mapper: SchemaMapper<TOutput>\n\n /**\n * Custom handlers for specific schema keywords\n * These provide the implementation for complex types that need special processing\n *\n * Use function syntax (not arrow functions) to enable use of `this` keyword:\n * ```typescript\n * handlers: {\n * enum(tree, options, parse) {\n * // Implementation\n * }\n * }\n * ```\n *\n * Common keywords that typically need handlers:\n * - union: Combine multiple schemas into a union\n * - and: Combine multiple schemas into an intersection\n * - array: Handle array types with items\n * - object: Handle object types with properties\n * - enum: Handle enum types\n * - tuple: Handle tuple types\n * - const: Handle literal/const types\n * - ref: Handle references to other schemas\n * - string/number/integer: Handle primitives with constraints (min/max)\n * - matches: Handle regex patterns\n * - default/describe/optional/nullable: Handle modifiers\n */\n handlers: Partial<{\n [K in keyof SchemaKeywordMapper]: KeywordHandler<TOutput, TOptions>\n }>\n}\n\n/**\n * Creates a parser function that converts schema trees to output using the provided mapper and handlers\n *\n * This function provides a framework for building parsers by:\n * 1. Checking for custom handlers for each keyword\n * 2. Falling back to the mapper for simple keywords\n * 3. Providing utilities for common operations (finding siblings, etc.)\n *\n * The generated parser is recursive and can handle nested schemas.\n *\n * @template TOutput - The output type (e.g., string for Zod/Faker, ts.TypeNode for TypeScript)\n * @template TOptions - The parser options type\n * @param config - Configuration object containing mapper and handlers\n * @returns A parse function that converts SchemaTree to TOutput\n *\n * @example\n * ```ts\n * // Create a simple string-based parser\n * const parse = createParser({\n * mapper: zodKeywordMapper,\n * handlers: {\n * union(tree, options) {\n * const items = tree.current.args\n * .map(it => this.parse({ ...tree, current: it }, options))\n * .filter(Boolean)\n * return `z.union([${items.join(', ')}])`\n * },\n * string(tree, options) {\n * const minSchema = findSchemaKeyword(tree.siblings, 'min')\n * const maxSchema = findSchemaKeyword(tree.siblings, 'max')\n * return zodKeywordMapper.string(false, minSchema?.args, maxSchema?.args)\n * }\n * }\n * })\n * ```\n */\nexport function createParser<TOutput, TOptions extends Record<string, any>>(\n config: CreateParserConfig<TOutput, TOptions>,\n): (tree: SchemaTree, options: TOptions) => TOutput | null | undefined {\n const { mapper, handlers } = config\n\n function parse(tree: SchemaTree, options: TOptions): TOutput | null | undefined {\n const { current } = tree\n\n // Check if there's a custom handler for this keyword\n const handler = handlers[current.keyword as keyof SchemaKeywordMapper]\n if (handler) {\n // Create context object with parse method accessible via `this`\n const context: HandlerContext<TOutput, TOptions> = { parse }\n return handler.call(context, tree, options)\n }\n\n // Fall back to simple mapper lookup\n const value = mapper[current.keyword as keyof typeof mapper]\n\n if (!value) {\n return undefined\n }\n\n // For simple keywords without args, call the mapper directly\n if (current.keyword in mapper) {\n return value()\n }\n\n return undefined\n }\n\n return parse\n}\n\n/**\n * Helper to find a schema keyword in siblings\n * Useful in handlers when you need to find related schemas (e.g., min/max for string)\n *\n * @example\n * ```ts\n * const minSchema = findSchemaKeyword(tree.siblings, 'min')\n * const maxSchema = findSchemaKeyword(tree.siblings, 'max')\n * return zodKeywordMapper.string(false, minSchema?.args, maxSchema?.args)\n * ```\n */\nexport function findSchemaKeyword<K extends keyof SchemaKeywordMapper>(siblings: Schema[], keyword: K): SchemaKeywordMapper[K] | undefined {\n return SchemaGenerator.find(siblings, schemaKeywords[keyword]) as SchemaKeywordMapper[K] | undefined\n}\n","import type { KubbEvents, Plugin, PluginFactoryOptions, PluginManager } from '@kubb/core'\nimport { BaseGenerator, type FileMetaBase } from '@kubb/core'\nimport transformers from '@kubb/core/transformers'\nimport type { AsyncEventEmitter } from '@kubb/core/utils'\nimport type { KubbFile } from '@kubb/fabric-core/types'\nimport type { contentType, HttpMethod, Oas, OasTypes, Operation, SchemaObject } from '@kubb/oas'\nimport type { Fabric } from '@kubb/react-fabric'\nimport pLimit from 'p-limit'\nimport type { Generator } from './generators/types.ts'\nimport type { Exclude, Include, OperationSchemas, Override } from './types.ts'\nimport { buildOperation, buildOperations } from './utils.tsx'\n\nexport type OperationMethodResult<TFileMeta extends FileMetaBase> = Promise<KubbFile.File<TFileMeta> | Array<KubbFile.File<TFileMeta>> | null>\n\ntype Context<TOptions, TPluginOptions extends PluginFactoryOptions> = {\n fabric: Fabric\n oas: Oas\n exclude: Array<Exclude> | undefined\n include: Array<Include> | undefined\n override: Array<Override<TOptions>> | undefined\n contentType: contentType | undefined\n pluginManager: PluginManager\n events?: AsyncEventEmitter<KubbEvents>\n /**\n * Current plugin\n */\n plugin: Plugin<TPluginOptions>\n mode: KubbFile.Mode\n}\n\nexport class OperationGenerator<\n TPluginOptions extends PluginFactoryOptions = PluginFactoryOptions,\n TFileMeta extends FileMetaBase = FileMetaBase,\n> extends BaseGenerator<TPluginOptions['resolvedOptions'], Context<TPluginOptions['resolvedOptions'], TPluginOptions>> {\n #getOptions(operation: Operation, method: HttpMethod): Partial<TPluginOptions['resolvedOptions']> {\n const { override = [] } = this.context\n const operationId = operation.getOperationId({ friendlyCase: true })\n const contentType = operation.getContentType()\n\n return (\n override.find(({ pattern, type }) => {\n switch (type) {\n case 'tag':\n return operation.getTags().some((tag) => tag.name.match(pattern))\n case 'operationId':\n return !!operationId.match(pattern)\n case 'path':\n return !!operation.path.match(pattern)\n case 'method':\n return !!method.match(pattern)\n case 'contentType':\n return !!contentType.match(pattern)\n default:\n return false\n }\n })?.options || {}\n )\n }\n\n #isExcluded(operation: Operation, method: HttpMethod): boolean {\n const { exclude = [] } = this.context\n const operationId = operation.getOperationId({ friendlyCase: true })\n const contentType = operation.getContentType()\n\n return exclude.some(({ pattern, type }) => {\n switch (type) {\n case 'tag':\n return operation.getTags().some((tag) => tag.name.match(pattern))\n case 'operationId':\n return !!operationId.match(pattern)\n case 'path':\n return !!operation.path.match(pattern)\n case 'method':\n return !!method.match(pattern)\n case 'contentType':\n return !!contentType.match(pattern)\n default:\n return false\n }\n })\n }\n\n #isIncluded(operation: Operation, method: HttpMethod): boolean {\n const { include = [] } = this.context\n const operationId = operation.getOperationId({ friendlyCase: true })\n const contentType = operation.getContentType()\n\n return include.some(({ pattern, type }) => {\n switch (type) {\n case 'tag':\n return operation.getTags().some((tag) => tag.name.match(pattern))\n case 'operationId':\n return !!operationId.match(pattern)\n case 'path':\n return !!operation.path.match(pattern)\n case 'method':\n return !!method.match(pattern)\n case 'contentType':\n return !!contentType.match(pattern)\n default:\n return false\n }\n })\n }\n\n getSchemas(\n operation: Operation,\n {\n resolveName = (name) => name,\n }: {\n resolveName?: (name: string) => string\n } = {},\n ): OperationSchemas {\n const operationId = operation.getOperationId({ friendlyCase: true })\n const method = operation.method\n const operationName = transformers.pascalCase(operationId)\n\n const resolveKeys = (schema?: SchemaObject) => (schema?.properties ? Object.keys(schema.properties) : undefined)\n\n const pathParamsSchema = this.context.oas.getParametersSchema(operation, 'path')\n const queryParamsSchema = this.context.oas.getParametersSchema(operation, 'query')\n const headerParamsSchema = this.context.oas.getParametersSchema(operation, 'header')\n const requestSchema = this.context.oas.getRequestSchema(operation)\n const statusCodes = operation.getResponseStatusCodes().map((statusCode) => {\n const name = statusCode === 'default' ? 'error' : statusCode\n const schema = this.context.oas.getResponseSchema(operation, statusCode)\n const keys = resolveKeys(schema)\n\n return {\n name: resolveName(transformers.pascalCase(`${operationId} ${name}`)),\n description: (operation.getResponseByStatusCode(statusCode) as OasTypes.ResponseObject)?.description,\n schema,\n operation,\n operationName,\n statusCode: name === 'error' ? undefined : Number(statusCode),\n keys,\n keysToOmit: keys?.filter((key) => (schema?.properties?.[key] as OasTypes.SchemaObject)?.writeOnly),\n }\n })\n\n const successful = statusCodes.filter((item) => item.statusCode?.toString().startsWith('2'))\n const errors = statusCodes.filter((item) => item.statusCode?.toString().startsWith('4') || item.statusCode?.toString().startsWith('5'))\n\n return {\n pathParams: pathParamsSchema\n ? {\n name: resolveName(transformers.pascalCase(`${operationId} PathParams`)),\n operation,\n operationName,\n schema: pathParamsSchema,\n keys: resolveKeys(pathParamsSchema),\n }\n : undefined,\n queryParams: queryParamsSchema\n ? {\n name: resolveName(transformers.pascalCase(`${operationId} QueryParams`)),\n operation,\n operationName,\n schema: queryParamsSchema,\n keys: resolveKeys(queryParamsSchema) || [],\n }\n : undefined,\n headerParams: headerParamsSchema\n ? {\n name: resolveName(transformers.pascalCase(`${operationId} HeaderParams`)),\n operation,\n operationName,\n schema: headerParamsSchema,\n keys: resolveKeys(headerParamsSchema),\n }\n : undefined,\n request: requestSchema\n ? {\n name: resolveName(transformers.pascalCase(`${operationId} ${method === 'get' ? 'queryRequest' : 'mutationRequest'}`)),\n description: (operation.schema.requestBody as OasTypes.RequestBodyObject)?.description,\n operation,\n operationName,\n schema: requestSchema,\n keys: resolveKeys(requestSchema),\n keysToOmit: resolveKeys(requestSchema)?.filter((key) => (requestSchema.properties?.[key] as OasTypes.SchemaObject)?.readOnly),\n }\n : undefined,\n response: {\n name: resolveName(transformers.pascalCase(`${operationId} ${method === 'get' ? 'queryResponse' : 'mutationResponse'}`)),\n operation,\n operationName,\n schema: {\n oneOf: successful.map((item) => ({ ...item.schema, $ref: item.name })) || undefined,\n } as SchemaObject,\n },\n responses: successful,\n errors,\n statusCodes,\n }\n }\n\n async getOperations(): Promise<Array<{ path: string; method: HttpMethod; operation: Operation }>> {\n const { oas } = this.context\n\n const paths = oas.getPaths()\n\n return Object.entries(paths).flatMap(([path, methods]) =>\n Object.entries(methods)\n .map((values) => {\n const [method, operation] = values as [HttpMethod, Operation]\n if (this.#isExcluded(operation, method)) {\n return null\n }\n\n if (this.context.include && !this.#isIncluded(operation, method)) {\n return null\n }\n\n return operation ? { path, method: method as HttpMethod, operation } : null\n })\n .filter(Boolean),\n )\n }\n\n async build(...generators: Array<Generator<TPluginOptions>>): Promise<Array<KubbFile.File<TFileMeta>>> {\n const operations = await this.getOperations()\n\n const generatorLimit = pLimit(1)\n const operationLimit = pLimit(10)\n\n this.context.events?.emit('debug', {\n date: new Date(),\n logs: [`Building ${operations.length} operations`, ` • Generators: ${generators.length}`],\n })\n\n const writeTasks = generators.map((generator) =>\n generatorLimit(async () => {\n const operationTasks = operations.map(({ operation, method }) =>\n operationLimit(async () => {\n const options = this.#getOptions(operation, method)\n\n if (generator.type === 'react') {\n await buildOperation(operation, {\n config: this.context.pluginManager.config,\n fabric: this.context.fabric,\n Component: generator.Operation,\n generator: this,\n plugin: {\n ...this.context.plugin,\n options: {\n ...this.options,\n ...options,\n },\n },\n })\n\n return []\n }\n\n const result = await generator.operation?.({\n generator: this,\n config: this.context.pluginManager.config,\n operation,\n plugin: {\n ...this.context.plugin,\n options: {\n ...this.options,\n ...options,\n },\n },\n })\n\n return result ?? []\n }),\n )\n\n const operationResults = await Promise.all(operationTasks)\n const opResultsFlat = operationResults.flat()\n\n if (generator.type === 'react') {\n await buildOperations(\n operations.map((op) => op.operation),\n {\n fabric: this.context.fabric,\n config: this.context.pluginManager.config,\n Component: generator.Operations,\n generator: this,\n plugin: this.context.plugin,\n },\n )\n\n return []\n }\n\n const operationsResult = await generator.operations?.({\n generator: this,\n config: this.context.pluginManager.config,\n operations: operations.map((op) => op.operation),\n plugin: this.context.plugin,\n })\n\n return [...opResultsFlat, ...(operationsResult ?? [])] as unknown as KubbFile.File<TFileMeta>\n }),\n )\n\n const nestedResults = await Promise.all(writeTasks)\n\n return nestedResults.flat()\n }\n}\n","import path from 'node:path'\nimport { type Config, definePlugin, type Group, getMode, type KubbEvents } from '@kubb/core'\nimport { camelCase } from '@kubb/core/transformers'\nimport type { AsyncEventEmitter } from '@kubb/core/utils'\nimport type { Oas } from '@kubb/oas'\nimport { parseFromConfig } from '@kubb/oas'\nimport { jsonGenerator } from './generators'\nimport { OperationGenerator } from './OperationGenerator.ts'\nimport { SchemaGenerator } from './SchemaGenerator.ts'\nimport type { PluginOas } from './types.ts'\n\nexport const pluginOasName = 'plugin-oas' satisfies PluginOas['name']\n\nexport const pluginOas = definePlugin<PluginOas>((options) => {\n const {\n output = {\n path: 'schemas',\n },\n group,\n validate = true,\n generators = [jsonGenerator],\n serverIndex,\n contentType,\n oasClass,\n discriminator = 'strict',\n } = options\n\n const getOas = async ({ validate, config, events }: { validate: boolean; config: Config; events: AsyncEventEmitter<KubbEvents> }): Promise<Oas> => {\n // needs to be in a different variable or the catch here will not work(return of a promise instead)\n const oas = await parseFromConfig(config, oasClass)\n\n oas.setOptions({\n contentType,\n discriminator,\n })\n\n try {\n if (validate) {\n await oas.valdiate()\n }\n } catch (er) {\n const caughtError = er as Error\n const errorTimestamp = new Date()\n const error = new Error('OAS Validation failed', {\n cause: caughtError,\n })\n\n events.emit('info', caughtError.message)\n events.emit('debug', {\n date: errorTimestamp,\n logs: [`✗ ${error.message}`, caughtError.message],\n })\n }\n\n return oas\n }\n\n return {\n name: pluginOasName,\n options: {\n output,\n validate,\n discriminator,\n ...options,\n },\n inject() {\n const config = this.config\n const events = this.events\n\n let oas: Oas\n\n return {\n async getOas({ validate = false } = {}) {\n if (!oas) {\n oas = await getOas({ config, events, validate })\n }\n\n return oas\n },\n async getBaseURL() {\n const oas = await getOas({ config, events, validate: false })\n if (serverIndex !== undefined) {\n return oas.api.servers?.at(serverIndex)?.url\n }\n\n return undefined\n },\n }\n },\n resolvePath(baseName, pathMode, options) {\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = pathMode ?? getMode(path.resolve(root, output.path))\n\n if (mode === 'single') {\n /**\n * when output is a file then we will always append to the same file(output file), see fileManager.addOrAppend\n * Other plugins then need to call addOrAppend instead of just add from the fileManager class\n */\n return path.resolve(root, output.path)\n }\n\n if (group && (options?.group?.path || options?.group?.tag)) {\n const groupName: Group['name'] = group?.name\n ? group.name\n : (ctx) => {\n if (group?.type === 'path') {\n return `${ctx.group.split('/')[1]}`\n }\n return `${camelCase(ctx.group)}Controller`\n }\n\n return path.resolve(\n root,\n output.path,\n groupName({\n group: group.type === 'path' ? options.group.path! : options.group.tag!,\n }),\n baseName,\n )\n }\n\n return path.resolve(root, output.path, baseName)\n },\n async install() {\n const oas = await this.getOas({ validate })\n\n if (!output) {\n return\n }\n\n await oas.dereference()\n\n const schemaGenerator = new SchemaGenerator(\n {\n unknownType: 'unknown',\n emptySchemaType: 'unknown',\n dateType: 'date',\n transformers: {},\n ...this.plugin.options,\n },\n {\n fabric: this.fabric,\n oas,\n pluginManager: this.pluginManager,\n events: this.events,\n plugin: this.plugin,\n contentType,\n include: undefined,\n override: undefined,\n mode: 'split',\n output: output.path,\n },\n )\n\n const schemaFiles = await schemaGenerator.build(...generators)\n await this.upsertFile(...schemaFiles)\n\n const operationGenerator = new OperationGenerator(this.plugin.options, {\n fabric: this.fabric,\n oas,\n pluginManager: this.pluginManager,\n events: this.events,\n plugin: this.plugin,\n contentType,\n exclude: undefined,\n include: undefined,\n override: undefined,\n mode: 'split',\n })\n\n const operationFiles = await operationGenerator.build(...generators)\n\n await this.upsertFile(...operationFiles)\n },\n }\n})\n","import type { PluginFactoryOptions } from '@kubb/core'\nimport { createGenerator as _createGenerator } from './generators/createGenerator.ts'\nimport { createReactGenerator as _createReactGenerator } from './generators/createReactGenerator.ts'\nimport type { Generator as _Generator } from './generators/types.ts'\n\nexport type { CreateParserConfig, KeywordHandler } from './createParser.ts'\nexport { createParser, findSchemaKeyword } from './createParser.ts'\nexport type { OperationMethodResult } from './OperationGenerator.ts'\nexport { OperationGenerator } from './OperationGenerator.ts'\nexport { pluginOas, pluginOasName } from './plugin.ts'\nexport type {\n GetSchemaGeneratorOptions,\n SchemaGeneratorBuildOptions,\n SchemaGeneratorOptions,\n SchemaMethodResult,\n} from './SchemaGenerator.ts'\nexport { SchemaGenerator } from './SchemaGenerator.ts'\nexport type {\n Schema,\n SchemaKeyword,\n SchemaKeywordBase,\n SchemaKeywordMapper,\n SchemaMapper,\n SchemaTree,\n} from './SchemaMapper.ts'\nexport { isKeyword, schemaKeywords } from './SchemaMapper.ts'\nexport type * from './types.ts'\nexport { buildOperation, buildOperations, buildSchema } from './utils.tsx'\n\n/**\n * @deprecated use `import { createGenerator } from '@kubb/plugin-oas/generators'`\n */\nexport const createGenerator = _createGenerator\n\n/**\n * @deprecated use `import { createReactGenerator } from '@kubb/plugin-oas/generators'`\n */\nexport const createReactGenerator = _createReactGenerator\n\n/**\n * @deprecated use `import { Generator } from '@kubb/plugin-oas/generators'`\n */\nexport type Generator<TOptions extends PluginFactoryOptions> = _Generator<TOptions>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6FA,SAAgB,aACd,QACqE;CACrE,MAAM,EAAE,QAAQ,aAAa;CAE7B,SAAS,MAAM,MAAkB,SAA+C;EAC9E,MAAM,EAAE,YAAY;EAGpB,MAAM,UAAU,SAAS,QAAQ;AACjC,MAAI,SAAS;GAEX,MAAMA,UAA6C,EAAE,OAAO;AAC5D,UAAO,QAAQ,KAAK,SAAS,MAAM,QAAQ;;EAI7C,MAAM,QAAQ,OAAO,QAAQ;AAE7B,MAAI,CAAC,MACH;AAIF,MAAI,QAAQ,WAAW,OACrB,QAAO,OAAO;;AAMlB,QAAO;;;;;;;;;;;;;AAcT,SAAgB,kBAAuD,UAAoB,SAAgD;AACzI,QAAOC,wCAAgB,KAAK,UAAUC,oCAAe,SAAS;;;;;AC7GhE,IAAa,qBAAb,cAGUC,yBAA6G;CACrH,YAAY,WAAsB,QAAgE;EAChG,MAAM,EAAE,WAAW,EAAE,KAAK,KAAK;EAC/B,MAAM,cAAc,UAAU,eAAe,EAAE,cAAc,MAAM,CAAC;EACpE,MAAM,cAAc,UAAU,gBAAgB;AAE9C,SACE,SAAS,M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Q,KAAK;IACb;IACA,eAAe,KAAK;IACpB,QAAQ,KAAK;IACb,QAAQ,KAAK;IACb;IACA,SAAS;IACT,UAAU;IACV,MAAM;IACN,QAAQ,OAAO;IAChB,CACF,CAEyC,MAAM,GAAG,WAAW;AAC9D,SAAM,KAAK,WAAW,GAAG,YAAY;GAerC,MAAM,iBAAiB,MAbI,IAAI,mBAAmB,KAAK,OAAO,SAAS;IACrE,QAAQ,KAAK;IACb;IACA,eAAe,KAAK;IACpB,QAAQ,KAAK;IACb,QAAQ,KAAK;IACb;IACA,SAAS;IACT,SAAS;IACT,UAAU;IACV,MAAM;IACP,CAAC,CAE8C,MAAM,GAAG,WAAW;AAEpE,SAAM,KAAK,WAAW,GAAG,eAAe;;EAE3C;EACD;;;;;;;AC/IF,MAAa,kBAAkBC;;;;AAK/B,MAAa,uBAAuBC"}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { C as Plugin, E as UserPluginWithLifeCycle, a as SchemaMapper, b as Config, c as schemaKeywords, g as SchemaObject, h as Operation, i as SchemaKeywordMapper, n as SchemaKeyword, o as SchemaTree, r as SchemaKeywordBase, s as isKeyword, t as Schema, w as PluginFactoryOptions } from "./SchemaMapper-
|
|
2
|
-
import { C as Resolver, S as ResolvePathOptions, _ as Options, a as createReactGenerator$1, b as Ref, c as SchemaGeneratorBuildOptions, d as OperationGenerator, f as OperationMethodResult, g as OperationSchemas, h as OperationSchema, i as ReactGenerator, l as SchemaGeneratorOptions, m as Include, n as createGenerator$1, o as GetSchemaGeneratorOptions, p as Exclude, r as Generator$1, s as SchemaGenerator, u as SchemaMethodResult, v as Override, x as Refs, y as PluginOas } from "./createGenerator-
|
|
1
|
+
import { C as Plugin, E as UserPluginWithLifeCycle, a as SchemaMapper, b as Config, c as schemaKeywords, g as SchemaObject, h as Operation, i as SchemaKeywordMapper, n as SchemaKeyword, o as SchemaTree, r as SchemaKeywordBase, s as isKeyword, t as Schema, w as PluginFactoryOptions } from "./SchemaMapper-B2a4K3r2.cjs";
|
|
2
|
+
import { C as Resolver, S as ResolvePathOptions, _ as Options, a as createReactGenerator$1, b as Ref, c as SchemaGeneratorBuildOptions, d as OperationGenerator, f as OperationMethodResult, g as OperationSchemas, h as OperationSchema, i as ReactGenerator, l as SchemaGeneratorOptions, m as Include, n as createGenerator$1, o as GetSchemaGeneratorOptions, p as Exclude, r as Generator$1, s as SchemaGenerator, u as SchemaMethodResult, v as Override, x as Refs, y as PluginOas } from "./createGenerator-DG5FCAfL.cjs";
|
|
3
3
|
import { Fabric } from "@kubb/react-fabric";
|
|
4
4
|
|
|
5
5
|
//#region src/createParser.d.ts
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { C as Plugin, E as UserPluginWithLifeCycle, a as SchemaMapper, b as Config, c as schemaKeywords, g as SchemaObject, h as Operation, i as SchemaKeywordMapper, n as SchemaKeyword, o as SchemaTree, r as SchemaKeywordBase, s as isKeyword, t as Schema, w as PluginFactoryOptions } from "./SchemaMapper-
|
|
2
|
-
import { C as Resolver, S as ResolvePathOptions, _ as Options, a as createReactGenerator$1, b as Ref, c as SchemaGeneratorBuildOptions, d as OperationGenerator, f as OperationMethodResult, g as OperationSchemas, h as OperationSchema, i as ReactGenerator, l as SchemaGeneratorOptions, m as Include, n as createGenerator$1, o as GetSchemaGeneratorOptions, p as Exclude, r as Generator$1, s as SchemaGenerator, u as SchemaMethodResult, v as Override, x as Refs, y as PluginOas } from "./createGenerator-
|
|
1
|
+
import { C as Plugin, E as UserPluginWithLifeCycle, a as SchemaMapper, b as Config, c as schemaKeywords, g as SchemaObject, h as Operation, i as SchemaKeywordMapper, n as SchemaKeyword, o as SchemaTree, r as SchemaKeywordBase, s as isKeyword, t as Schema, w as PluginFactoryOptions } from "./SchemaMapper-DesnD5yL.js";
|
|
2
|
+
import { C as Resolver, S as ResolvePathOptions, _ as Options, a as createReactGenerator$1, b as Ref, c as SchemaGeneratorBuildOptions, d as OperationGenerator, f as OperationMethodResult, g as OperationSchemas, h as OperationSchema, i as ReactGenerator, l as SchemaGeneratorOptions, m as Include, n as createGenerator$1, o as GetSchemaGeneratorOptions, p as Exclude, r as Generator$1, s as SchemaGenerator, u as SchemaMethodResult, v as Override, x as Refs, y as PluginOas } from "./createGenerator-BpFur0uJ.js";
|
|
3
3
|
import { Fabric } from "@kubb/react-fabric";
|
|
4
4
|
|
|
5
5
|
//#region src/createParser.d.ts
|
package/dist/index.js
CHANGED
|
@@ -274,17 +274,23 @@ var OperationGenerator = class extends BaseGenerator {
|
|
|
274
274
|
const pluginOasName = "plugin-oas";
|
|
275
275
|
const pluginOas = definePlugin((options) => {
|
|
276
276
|
const { output = { path: "schemas" }, group, validate = true, generators = [jsonGenerator], serverIndex, contentType, oasClass, discriminator = "strict" } = options;
|
|
277
|
-
const getOas = async ({ config }) => {
|
|
277
|
+
const getOas = async ({ validate: validate$1, config, events }) => {
|
|
278
278
|
const oas = await parseFromConfig(config, oasClass);
|
|
279
279
|
oas.setOptions({
|
|
280
280
|
contentType,
|
|
281
281
|
discriminator
|
|
282
282
|
});
|
|
283
283
|
try {
|
|
284
|
-
if (validate) await oas.valdiate();
|
|
285
|
-
} catch (
|
|
286
|
-
const
|
|
287
|
-
|
|
284
|
+
if (validate$1) await oas.valdiate();
|
|
285
|
+
} catch (er) {
|
|
286
|
+
const caughtError = er;
|
|
287
|
+
const errorTimestamp = /* @__PURE__ */ new Date();
|
|
288
|
+
const error = new Error("OAS Validation failed", { cause: caughtError });
|
|
289
|
+
events.emit("info", caughtError.message);
|
|
290
|
+
events.emit("debug", {
|
|
291
|
+
date: errorTimestamp,
|
|
292
|
+
logs: [`✗ ${error.message}`, caughtError.message]
|
|
293
|
+
});
|
|
288
294
|
}
|
|
289
295
|
return oas;
|
|
290
296
|
};
|
|
@@ -298,14 +304,23 @@ const pluginOas = definePlugin((options) => {
|
|
|
298
304
|
},
|
|
299
305
|
inject() {
|
|
300
306
|
const config = this.config;
|
|
307
|
+
const events = this.events;
|
|
301
308
|
let oas;
|
|
302
309
|
return {
|
|
303
|
-
async getOas() {
|
|
304
|
-
if (!oas) oas = await getOas({
|
|
310
|
+
async getOas({ validate: validate$1 = false } = {}) {
|
|
311
|
+
if (!oas) oas = await getOas({
|
|
312
|
+
config,
|
|
313
|
+
events,
|
|
314
|
+
validate: validate$1
|
|
315
|
+
});
|
|
305
316
|
return oas;
|
|
306
317
|
},
|
|
307
318
|
async getBaseURL() {
|
|
308
|
-
const oas$1 = await getOas({
|
|
319
|
+
const oas$1 = await getOas({
|
|
320
|
+
config,
|
|
321
|
+
events,
|
|
322
|
+
validate: false
|
|
323
|
+
});
|
|
309
324
|
if (serverIndex !== void 0) return oas$1.api.servers?.at(serverIndex)?.url;
|
|
310
325
|
}
|
|
311
326
|
};
|
|
@@ -328,8 +343,8 @@ const pluginOas = definePlugin((options) => {
|
|
|
328
343
|
return path.resolve(root, output.path, baseName);
|
|
329
344
|
},
|
|
330
345
|
async install() {
|
|
346
|
+
const oas = await this.getOas({ validate });
|
|
331
347
|
if (!output) return;
|
|
332
|
-
const oas = await this.getOas();
|
|
333
348
|
await oas.dereference();
|
|
334
349
|
const schemaFiles = await new SchemaGenerator({
|
|
335
350
|
unknownType: "unknown",
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["context: HandlerContext<TOutput, TOptions>","path","#isExcluded","#isIncluded","#getOptions","oas: Oas","oas","options","groupName: Group['name']","_createGenerator","_createReactGenerator"],"sources":["../src/createParser.ts","../src/OperationGenerator.ts","../src/plugin.ts","../src/index.ts"],"sourcesContent":["import { SchemaGenerator } from './SchemaGenerator.ts'\nimport type { Schema, SchemaKeywordMapper, SchemaMapper, SchemaTree } from './SchemaMapper.ts'\nimport { schemaKeywords } from './SchemaMapper.ts'\n\n/**\n * Handler context with parse method available via `this`\n */\nexport type HandlerContext<TOutput, TOptions> = {\n parse: (tree: SchemaTree, options: TOptions) => TOutput | null | undefined\n}\n\n/**\n * Handler function type for custom keyword processing\n * Handlers can access the parse function via `this.parse`\n */\nexport type KeywordHandler<TOutput, TOptions> = (this: HandlerContext<TOutput, TOptions>, tree: SchemaTree, options: TOptions) => TOutput | null | undefined\n\n/**\n * Configuration for createParser\n */\nexport type CreateParserConfig<TOutput, TOptions> = {\n /**\n * The keyword mapper that maps schema keywords to output generators\n */\n mapper: SchemaMapper<TOutput>\n\n /**\n * Custom handlers for specific schema keywords\n * These provide the implementation for complex types that need special processing\n *\n * Use function syntax (not arrow functions) to enable use of `this` keyword:\n * ```typescript\n * handlers: {\n * enum(tree, options, parse) {\n * // Implementation\n * }\n * }\n * ```\n *\n * Common keywords that typically need handlers:\n * - union: Combine multiple schemas into a union\n * - and: Combine multiple schemas into an intersection\n * - array: Handle array types with items\n * - object: Handle object types with properties\n * - enum: Handle enum types\n * - tuple: Handle tuple types\n * - const: Handle literal/const types\n * - ref: Handle references to other schemas\n * - string/number/integer: Handle primitives with constraints (min/max)\n * - matches: Handle regex patterns\n * - default/describe/optional/nullable: Handle modifiers\n */\n handlers: Partial<{\n [K in keyof SchemaKeywordMapper]: KeywordHandler<TOutput, TOptions>\n }>\n}\n\n/**\n * Creates a parser function that converts schema trees to output using the provided mapper and handlers\n *\n * This function provides a framework for building parsers by:\n * 1. Checking for custom handlers for each keyword\n * 2. Falling back to the mapper for simple keywords\n * 3. Providing utilities for common operations (finding siblings, etc.)\n *\n * The generated parser is recursive and can handle nested schemas.\n *\n * @template TOutput - The output type (e.g., string for Zod/Faker, ts.TypeNode for TypeScript)\n * @template TOptions - The parser options type\n * @param config - Configuration object containing mapper and handlers\n * @returns A parse function that converts SchemaTree to TOutput\n *\n * @example\n * ```ts\n * // Create a simple string-based parser\n * const parse = createParser({\n * mapper: zodKeywordMapper,\n * handlers: {\n * union(tree, options) {\n * const items = tree.current.args\n * .map(it => this.parse({ ...tree, current: it }, options))\n * .filter(Boolean)\n * return `z.union([${items.join(', ')}])`\n * },\n * string(tree, options) {\n * const minSchema = findSchemaKeyword(tree.siblings, 'min')\n * const maxSchema = findSchemaKeyword(tree.siblings, 'max')\n * return zodKeywordMapper.string(false, minSchema?.args, maxSchema?.args)\n * }\n * }\n * })\n * ```\n */\nexport function createParser<TOutput, TOptions extends Record<string, any>>(\n config: CreateParserConfig<TOutput, TOptions>,\n): (tree: SchemaTree, options: TOptions) => TOutput | null | undefined {\n const { mapper, handlers } = config\n\n function parse(tree: SchemaTree, options: TOptions): TOutput | null | undefined {\n const { current } = tree\n\n // Check if there's a custom handler for this keyword\n const handler = handlers[current.keyword as keyof SchemaKeywordMapper]\n if (handler) {\n // Create context object with parse method accessible via `this`\n const context: HandlerContext<TOutput, TOptions> = { parse }\n return handler.call(context, tree, options)\n }\n\n // Fall back to simple mapper lookup\n const value = mapper[current.keyword as keyof typeof mapper]\n\n if (!value) {\n return undefined\n }\n\n // For simple keywords without args, call the mapper directly\n if (current.keyword in mapper) {\n return value()\n }\n\n return undefined\n }\n\n return parse\n}\n\n/**\n * Helper to find a schema keyword in siblings\n * Useful in handlers when you need to find related schemas (e.g., min/max for string)\n *\n * @example\n * ```ts\n * const minSchema = findSchemaKeyword(tree.siblings, 'min')\n * const maxSchema = findSchemaKeyword(tree.siblings, 'max')\n * return zodKeywordMapper.string(false, minSchema?.args, maxSchema?.args)\n * ```\n */\nexport function findSchemaKeyword<K extends keyof SchemaKeywordMapper>(siblings: Schema[], keyword: K): SchemaKeywordMapper[K] | undefined {\n return SchemaGenerator.find(siblings, schemaKeywords[keyword]) as SchemaKeywordMapper[K] | undefined\n}\n","import type { KubbEvents, Plugin, PluginFactoryOptions, PluginManager } from '@kubb/core'\nimport { BaseGenerator, type FileMetaBase } from '@kubb/core'\nimport transformers from '@kubb/core/transformers'\nimport type { AsyncEventEmitter } from '@kubb/core/utils'\nimport type { KubbFile } from '@kubb/fabric-core/types'\nimport type { contentType, HttpMethod, Oas, OasTypes, Operation, SchemaObject } from '@kubb/oas'\nimport type { Fabric } from '@kubb/react-fabric'\nimport pLimit from 'p-limit'\nimport type { Generator } from './generators/types.ts'\nimport type { Exclude, Include, OperationSchemas, Override } from './types.ts'\nimport { buildOperation, buildOperations } from './utils.tsx'\n\nexport type OperationMethodResult<TFileMeta extends FileMetaBase> = Promise<KubbFile.File<TFileMeta> | Array<KubbFile.File<TFileMeta>> | null>\n\ntype Context<TOptions, TPluginOptions extends PluginFactoryOptions> = {\n fabric: Fabric\n oas: Oas\n exclude: Array<Exclude> | undefined\n include: Array<Include> | undefined\n override: Array<Override<TOptions>> | undefined\n contentType: contentType | undefined\n pluginManager: PluginManager\n events?: AsyncEventEmitter<KubbEvents>\n /**\n * Current plugin\n */\n plugin: Plugin<TPluginOptions>\n mode: KubbFile.Mode\n}\n\nexport class OperationGenerator<\n TPluginOptions extends PluginFactoryOptions = PluginFactoryOptions,\n TFileMeta extends FileMetaBase = FileMetaBase,\n> extends BaseGenerator<TPluginOptions['resolvedOptions'], Context<TPluginOptions['resolvedOptions'], TPluginOptions>> {\n #getOptions(operation: Operation, method: HttpMethod): Partial<TPluginOptions['resolvedOptions']> {\n const { override = [] } = this.context\n const operationId = operation.getOperationId({ friendlyCase: true })\n const contentType = operation.getContentType()\n\n return (\n override.find(({ pattern, type }) => {\n switch (type) {\n case 'tag':\n return operation.getTags().some((tag) => tag.name.match(pattern))\n case 'operationId':\n return !!operationId.match(pattern)\n case 'path':\n return !!operation.path.match(pattern)\n case 'method':\n return !!method.match(pattern)\n case 'contentType':\n return !!contentType.match(pattern)\n default:\n return false\n }\n })?.options || {}\n )\n }\n\n #isExcluded(operation: Operation, method: HttpMethod): boolean {\n const { exclude = [] } = this.context\n const operationId = operation.getOperationId({ friendlyCase: true })\n const contentType = operation.getContentType()\n\n return exclude.some(({ pattern, type }) => {\n switch (type) {\n case 'tag':\n return operation.getTags().some((tag) => tag.name.match(pattern))\n case 'operationId':\n return !!operationId.match(pattern)\n case 'path':\n return !!operation.path.match(pattern)\n case 'method':\n return !!method.match(pattern)\n case 'contentType':\n return !!contentType.match(pattern)\n default:\n return false\n }\n })\n }\n\n #isIncluded(operation: Operation, method: HttpMethod): boolean {\n const { include = [] } = this.context\n const operationId = operation.getOperationId({ friendlyCase: true })\n const contentType = operation.getContentType()\n\n return include.some(({ pattern, type }) => {\n switch (type) {\n case 'tag':\n return operation.getTags().some((tag) => tag.name.match(pattern))\n case 'operationId':\n return !!operationId.match(pattern)\n case 'path':\n return !!operation.path.match(pattern)\n case 'method':\n return !!method.match(pattern)\n case 'contentType':\n return !!contentType.match(pattern)\n default:\n return false\n }\n })\n }\n\n getSchemas(\n operation: Operation,\n {\n resolveName = (name) => name,\n }: {\n resolveName?: (name: string) => string\n } = {},\n ): OperationSchemas {\n const operationId = operation.getOperationId({ friendlyCase: true })\n const method = operation.method\n const operationName = transformers.pascalCase(operationId)\n\n const resolveKeys = (schema?: SchemaObject) => (schema?.properties ? Object.keys(schema.properties) : undefined)\n\n const pathParamsSchema = this.context.oas.getParametersSchema(operation, 'path')\n const queryParamsSchema = this.context.oas.getParametersSchema(operation, 'query')\n const headerParamsSchema = this.context.oas.getParametersSchema(operation, 'header')\n const requestSchema = this.context.oas.getRequestSchema(operation)\n const statusCodes = operation.getResponseStatusCodes().map((statusCode) => {\n const name = statusCode === 'default' ? 'error' : statusCode\n const schema = this.context.oas.getResponseSchema(operation, statusCode)\n const keys = resolveKeys(schema)\n\n return {\n name: resolveName(transformers.pascalCase(`${operationId} ${name}`)),\n description: (operation.getResponseByStatusCode(statusCode) as OasTypes.ResponseObject)?.description,\n schema,\n operation,\n operationName,\n statusCode: name === 'error' ? undefined : Number(statusCode),\n keys,\n keysToOmit: keys?.filter((key) => (schema?.properties?.[key] as OasTypes.SchemaObject)?.writeOnly),\n }\n })\n\n const successful = statusCodes.filter((item) => item.statusCode?.toString().startsWith('2'))\n const errors = statusCodes.filter((item) => item.statusCode?.toString().startsWith('4') || item.statusCode?.toString().startsWith('5'))\n\n return {\n pathParams: pathParamsSchema\n ? {\n name: resolveName(transformers.pascalCase(`${operationId} PathParams`)),\n operation,\n operationName,\n schema: pathParamsSchema,\n keys: resolveKeys(pathParamsSchema),\n }\n : undefined,\n queryParams: queryParamsSchema\n ? {\n name: resolveName(transformers.pascalCase(`${operationId} QueryParams`)),\n operation,\n operationName,\n schema: queryParamsSchema,\n keys: resolveKeys(queryParamsSchema) || [],\n }\n : undefined,\n headerParams: headerParamsSchema\n ? {\n name: resolveName(transformers.pascalCase(`${operationId} HeaderParams`)),\n operation,\n operationName,\n schema: headerParamsSchema,\n keys: resolveKeys(headerParamsSchema),\n }\n : undefined,\n request: requestSchema\n ? {\n name: resolveName(transformers.pascalCase(`${operationId} ${method === 'get' ? 'queryRequest' : 'mutationRequest'}`)),\n description: (operation.schema.requestBody as OasTypes.RequestBodyObject)?.description,\n operation,\n operationName,\n schema: requestSchema,\n keys: resolveKeys(requestSchema),\n keysToOmit: resolveKeys(requestSchema)?.filter((key) => (requestSchema.properties?.[key] as OasTypes.SchemaObject)?.readOnly),\n }\n : undefined,\n response: {\n name: resolveName(transformers.pascalCase(`${operationId} ${method === 'get' ? 'queryResponse' : 'mutationResponse'}`)),\n operation,\n operationName,\n schema: {\n oneOf: successful.map((item) => ({ ...item.schema, $ref: item.name })) || undefined,\n } as SchemaObject,\n },\n responses: successful,\n errors,\n statusCodes,\n }\n }\n\n async getOperations(): Promise<Array<{ path: string; method: HttpMethod; operation: Operation }>> {\n const { oas } = this.context\n\n const paths = oas.getPaths()\n\n return Object.entries(paths).flatMap(([path, methods]) =>\n Object.entries(methods)\n .map((values) => {\n const [method, operation] = values as [HttpMethod, Operation]\n if (this.#isExcluded(operation, method)) {\n return null\n }\n\n if (this.context.include && !this.#isIncluded(operation, method)) {\n return null\n }\n\n return operation ? { path, method: method as HttpMethod, operation } : null\n })\n .filter(Boolean),\n )\n }\n\n async build(...generators: Array<Generator<TPluginOptions>>): Promise<Array<KubbFile.File<TFileMeta>>> {\n const operations = await this.getOperations()\n\n const generatorLimit = pLimit(1)\n const operationLimit = pLimit(10)\n\n this.context.events?.emit('debug', {\n date: new Date(),\n logs: [`Building ${operations.length} operations`, ` • Generators: ${generators.length}`],\n })\n\n const writeTasks = generators.map((generator) =>\n generatorLimit(async () => {\n const operationTasks = operations.map(({ operation, method }) =>\n operationLimit(async () => {\n const options = this.#getOptions(operation, method)\n\n if (generator.type === 'react') {\n await buildOperation(operation, {\n config: this.context.pluginManager.config,\n fabric: this.context.fabric,\n Component: generator.Operation,\n generator: this,\n plugin: {\n ...this.context.plugin,\n options: {\n ...this.options,\n ...options,\n },\n },\n })\n\n return []\n }\n\n const result = await generator.operation?.({\n generator: this,\n config: this.context.pluginManager.config,\n operation,\n plugin: {\n ...this.context.plugin,\n options: {\n ...this.options,\n ...options,\n },\n },\n })\n\n return result ?? []\n }),\n )\n\n const operationResults = await Promise.all(operationTasks)\n const opResultsFlat = operationResults.flat()\n\n if (generator.type === 'react') {\n await buildOperations(\n operations.map((op) => op.operation),\n {\n fabric: this.context.fabric,\n config: this.context.pluginManager.config,\n Component: generator.Operations,\n generator: this,\n plugin: this.context.plugin,\n },\n )\n\n return []\n }\n\n const operationsResult = await generator.operations?.({\n generator: this,\n config: this.context.pluginManager.config,\n operations: operations.map((op) => op.operation),\n plugin: this.context.plugin,\n })\n\n return [...opResultsFlat, ...(operationsResult ?? [])] as unknown as KubbFile.File<TFileMeta>\n }),\n )\n\n const nestedResults = await Promise.all(writeTasks)\n\n return nestedResults.flat()\n }\n}\n","import path from 'node:path'\nimport { type Config, definePlugin, type Group, getMode } from '@kubb/core'\nimport { camelCase } from '@kubb/core/transformers'\nimport type { Oas } from '@kubb/oas'\nimport { parseFromConfig } from '@kubb/oas'\nimport { jsonGenerator } from './generators'\nimport { OperationGenerator } from './OperationGenerator.ts'\nimport { SchemaGenerator } from './SchemaGenerator.ts'\nimport type { PluginOas } from './types.ts'\n\nexport const pluginOasName = 'plugin-oas' satisfies PluginOas['name']\n\nexport const pluginOas = definePlugin<PluginOas>((options) => {\n const {\n output = {\n path: 'schemas',\n },\n group,\n validate = true,\n generators = [jsonGenerator],\n serverIndex,\n contentType,\n oasClass,\n discriminator = 'strict',\n } = options\n\n const getOas = async ({ config }: { config: Config }): Promise<Oas> => {\n // needs to be in a different variable or the catch here will not work(return of a promise instead)\n const oas = await parseFromConfig(config, oasClass)\n\n oas.setOptions({\n contentType,\n discriminator,\n })\n\n try {\n if (validate) {\n await oas.valdiate()\n }\n } catch (caughtError) {\n const error = caughtError as Error\n\n console.warn(error?.message)\n }\n\n return oas\n }\n\n return {\n name: pluginOasName,\n options: {\n output,\n validate,\n discriminator,\n ...options,\n },\n inject() {\n const config = this.config\n let oas: Oas\n\n return {\n async getOas() {\n if (!oas) {\n oas = await getOas({ config })\n }\n\n return oas\n },\n async getBaseURL() {\n const oas = await getOas({ config })\n if (serverIndex !== undefined) {\n return oas.api.servers?.at(serverIndex)?.url\n }\n\n return undefined\n },\n }\n },\n resolvePath(baseName, pathMode, options) {\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = pathMode ?? getMode(path.resolve(root, output.path))\n\n if (mode === 'single') {\n /**\n * when output is a file then we will always append to the same file(output file), see fileManager.addOrAppend\n * Other plugins then need to call addOrAppend instead of just add from the fileManager class\n */\n return path.resolve(root, output.path)\n }\n\n if (group && (options?.group?.path || options?.group?.tag)) {\n const groupName: Group['name'] = group?.name\n ? group.name\n : (ctx) => {\n if (group?.type === 'path') {\n return `${ctx.group.split('/')[1]}`\n }\n return `${camelCase(ctx.group)}Controller`\n }\n\n return path.resolve(\n root,\n output.path,\n groupName({\n group: group.type === 'path' ? options.group.path! : options.group.tag!,\n }),\n baseName,\n )\n }\n\n return path.resolve(root, output.path, baseName)\n },\n async install() {\n if (!output) {\n return\n }\n\n const oas = await this.getOas()\n await oas.dereference()\n\n const schemaGenerator = new SchemaGenerator(\n {\n unknownType: 'unknown',\n emptySchemaType: 'unknown',\n dateType: 'date',\n transformers: {},\n ...this.plugin.options,\n },\n {\n fabric: this.fabric,\n oas,\n pluginManager: this.pluginManager,\n events: this.events,\n plugin: this.plugin,\n contentType,\n include: undefined,\n override: undefined,\n mode: 'split',\n output: output.path,\n },\n )\n\n const schemaFiles = await schemaGenerator.build(...generators)\n await this.upsertFile(...schemaFiles)\n\n const operationGenerator = new OperationGenerator(this.plugin.options, {\n fabric: this.fabric,\n oas,\n pluginManager: this.pluginManager,\n events: this.events,\n plugin: this.plugin,\n contentType,\n exclude: undefined,\n include: undefined,\n override: undefined,\n mode: 'split',\n })\n\n const operationFiles = await operationGenerator.build(...generators)\n\n await this.upsertFile(...operationFiles)\n },\n }\n})\n","import type { PluginFactoryOptions } from '@kubb/core'\nimport { createGenerator as _createGenerator } from './generators/createGenerator.ts'\nimport { createReactGenerator as _createReactGenerator } from './generators/createReactGenerator.ts'\nimport type { Generator as _Generator } from './generators/types.ts'\n\nexport type { CreateParserConfig, KeywordHandler } from './createParser.ts'\nexport { createParser, findSchemaKeyword } from './createParser.ts'\nexport type { OperationMethodResult } from './OperationGenerator.ts'\nexport { OperationGenerator } from './OperationGenerator.ts'\nexport { pluginOas, pluginOasName } from './plugin.ts'\nexport type {\n GetSchemaGeneratorOptions,\n SchemaGeneratorBuildOptions,\n SchemaGeneratorOptions,\n SchemaMethodResult,\n} from './SchemaGenerator.ts'\nexport { SchemaGenerator } from './SchemaGenerator.ts'\nexport type {\n Schema,\n SchemaKeyword,\n SchemaKeywordBase,\n SchemaKeywordMapper,\n SchemaMapper,\n SchemaTree,\n} from './SchemaMapper.ts'\nexport { isKeyword, schemaKeywords } from './SchemaMapper.ts'\nexport type * from './types.ts'\nexport { buildOperation, buildOperations, buildSchema } from './utils.tsx'\n\n/**\n * @deprecated use `import { createGenerator } from '@kubb/plugin-oas/generators'`\n */\nexport const createGenerator = _createGenerator\n\n/**\n * @deprecated use `import { createReactGenerator } from '@kubb/plugin-oas/generators'`\n */\nexport const createReactGenerator = _createReactGenerator\n\n/**\n * @deprecated use `import { Generator } from '@kubb/plugin-oas/generators'`\n */\nexport type Gener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,CAAC;;AAGrC,WAAO,KAAK,QACV,MACA,OAAO,MACP,UAAU,EACR,OAAO,MAAM,SAAS,SAASD,UAAQ,MAAM,OAAQA,UAAQ,MAAM,KACpE,CAAC,EACF,SACD;;AAGH,UAAO,KAAK,QAAQ,MAAM,OAAO,MAAM,SAAS;;EAElD,MAAM,UAAU;AACd,OAAI,CAAC,OACH;GAGF,MAAM,MAAM,MAAM,KAAK,QAAQ;AAC/B,SAAM,IAAI,aAAa;GAwBvB,MAAM,cAAc,MAtBI,IAAI,gBAC1B;IACE,aAAa;IACb,iBAAiB;IACjB,UAAU;IACV,cAAc,EAAE;IAChB,GAAG,KAAK,OAAO;IAChB,EACD;IACE,QAAQ,KAAK;IACb;IACA,eAAe,KAAK;IACpB,QAAQ,KAAK;IACb,QAAQ,KAAK;IACb;IACA,SAAS;IACT,UAAU;IACV,MAAM;IACN,QAAQ,OAAO;IAChB,CACF,CAEyC,MAAM,GAAG,WAAW;AAC9D,SAAM,KAAK,WAAW,GAAG,YAAY;GAerC,MAAM,iBAAiB,MAbI,IAAI,mBAAmB,KAAK,OAAO,SAAS;IACrE,QAAQ,KAAK;IACb;IACA,eAAe,KAAK;IACpB,QAAQ,KAAK;IACb,QAAQ,KAAK;IACb;IACA,SAAS;IACT,SAAS;IACT,UAAU;IACV,MAAM;IACP,CAAC,CAE8C,MAAM,GAAG,WAAW;AAEpE,SAAM,KAAK,WAAW,GAAG,eAAe;;EAE3C;EACD;;;;;;;ACnIF,MAAa,kBAAkBE;;;;AAK/B,MAAa,uBAAuBC"}
|
|
1
|
+
{"version":3,"file":"index.js","names":["context: HandlerContext<TOutput, TOptions>","path","#isExcluded","#isIncluded","#getOptions","validate","oas: Oas","oas","options","groupName: Group['name']","_createGenerator","_createReactGenerator"],"sources":["../src/createParser.ts","../src/OperationGenerator.ts","../src/plugin.ts","../src/index.ts"],"sourcesContent":["import { SchemaGenerator } from './SchemaGenerator.ts'\nimport type { Schema, SchemaKeywordMapper, SchemaMapper, SchemaTree } from './SchemaMapper.ts'\nimport { schemaKeywords } from './SchemaMapper.ts'\n\n/**\n * Handler context with parse method available via `this`\n */\nexport type HandlerContext<TOutput, TOptions> = {\n parse: (tree: SchemaTree, options: TOptions) => TOutput | null | undefined\n}\n\n/**\n * Handler function type for custom keyword processing\n * Handlers can access the parse function via `this.parse`\n */\nexport type KeywordHandler<TOutput, TOptions> = (this: HandlerContext<TOutput, TOptions>, tree: SchemaTree, options: TOptions) => TOutput | null | undefined\n\n/**\n * Configuration for createParser\n */\nexport type CreateParserConfig<TOutput, TOptions> = {\n /**\n * The keyword mapper that maps schema keywords to output generators\n */\n mapper: SchemaMapper<TOutput>\n\n /**\n * Custom handlers for specific schema keywords\n * These provide the implementation for complex types that need special processing\n *\n * Use function syntax (not arrow functions) to enable use of `this` keyword:\n * ```typescript\n * handlers: {\n * enum(tree, options, parse) {\n * // Implementation\n * }\n * }\n * ```\n *\n * Common keywords that typically need handlers:\n * - union: Combine multiple schemas into a union\n * - and: Combine multiple schemas into an intersection\n * - array: Handle array types with items\n * - object: Handle object types with properties\n * - enum: Handle enum types\n * - tuple: Handle tuple types\n * - const: Handle literal/const types\n * - ref: Handle references to other schemas\n * - string/number/integer: Handle primitives with constraints (min/max)\n * - matches: Handle regex patterns\n * - default/describe/optional/nullable: Handle modifiers\n */\n handlers: Partial<{\n [K in keyof SchemaKeywordMapper]: KeywordHandler<TOutput, TOptions>\n }>\n}\n\n/**\n * Creates a parser function that converts schema trees to output using the provided mapper and handlers\n *\n * This function provides a framework for building parsers by:\n * 1. Checking for custom handlers for each keyword\n * 2. Falling back to the mapper for simple keywords\n * 3. Providing utilities for common operations (finding siblings, etc.)\n *\n * The generated parser is recursive and can handle nested schemas.\n *\n * @template TOutput - The output type (e.g., string for Zod/Faker, ts.TypeNode for TypeScript)\n * @template TOptions - The parser options type\n * @param config - Configuration object containing mapper and handlers\n * @returns A parse function that converts SchemaTree to TOutput\n *\n * @example\n * ```ts\n * // Create a simple string-based parser\n * const parse = createParser({\n * mapper: zodKeywordMapper,\n * handlers: {\n * union(tree, options) {\n * const items = tree.current.args\n * .map(it => this.parse({ ...tree, current: it }, options))\n * .filter(Boolean)\n * return `z.union([${items.join(', ')}])`\n * },\n * string(tree, options) {\n * const minSchema = findSchemaKeyword(tree.siblings, 'min')\n * const maxSchema = findSchemaKeyword(tree.siblings, 'max')\n * return zodKeywordMapper.string(false, minSchema?.args, maxSchema?.args)\n * }\n * }\n * })\n * ```\n */\nexport function createParser<TOutput, TOptions extends Record<string, any>>(\n config: CreateParserConfig<TOutput, TOptions>,\n): (tree: SchemaTree, options: TOptions) => TOutput | null | undefined {\n const { mapper, handlers } = config\n\n function parse(tree: SchemaTree, options: TOptions): TOutput | null | undefined {\n const { current } = tree\n\n // Check if there's a custom handler for this keyword\n const handler = handlers[current.keyword as keyof SchemaKeywordMapper]\n if (handler) {\n // Create context object with parse method accessible via `this`\n const context: HandlerContext<TOutput, TOptions> = { parse }\n return handler.call(context, tree, options)\n }\n\n // Fall back to simple mapper lookup\n const value = mapper[current.keyword as keyof typeof mapper]\n\n if (!value) {\n return undefined\n }\n\n // For simple keywords without args, call the mapper directly\n if (current.keyword in mapper) {\n return value()\n }\n\n return undefined\n }\n\n return parse\n}\n\n/**\n * Helper to find a schema keyword in siblings\n * Useful in handlers when you need to find related schemas (e.g., min/max for string)\n *\n * @example\n * ```ts\n * const minSchema = findSchemaKeyword(tree.siblings, 'min')\n * const maxSchema = findSchemaKeyword(tree.siblings, 'max')\n * return zodKeywordMapper.string(false, minSchema?.args, maxSchema?.args)\n * ```\n */\nexport function findSchemaKeyword<K extends keyof SchemaKeywordMapper>(siblings: Schema[], keyword: K): SchemaKeywordMapper[K] | undefined {\n return SchemaGenerator.find(siblings, schemaKeywords[keyword]) as SchemaKeywordMapper[K] | undefined\n}\n","import type { KubbEvents, Plugin, PluginFactoryOptions, PluginManager } from '@kubb/core'\nimport { BaseGenerator, type FileMetaBase } from '@kubb/core'\nimport transformers from '@kubb/core/transformers'\nimport type { AsyncEventEmitter } from '@kubb/core/utils'\nimport type { KubbFile } from '@kubb/fabric-core/types'\nimport type { contentType, HttpMethod, Oas, OasTypes, Operation, SchemaObject } from '@kubb/oas'\nimport type { Fabric } from '@kubb/react-fabric'\nimport pLimit from 'p-limit'\nimport type { Generator } from './generators/types.ts'\nimport type { Exclude, Include, OperationSchemas, Override } from './types.ts'\nimport { buildOperation, buildOperations } from './utils.tsx'\n\nexport type OperationMethodResult<TFileMeta extends FileMetaBase> = Promise<KubbFile.File<TFileMeta> | Array<KubbFile.File<TFileMeta>> | null>\n\ntype Context<TOptions, TPluginOptions extends PluginFactoryOptions> = {\n fabric: Fabric\n oas: Oas\n exclude: Array<Exclude> | undefined\n include: Array<Include> | undefined\n override: Array<Override<TOptions>> | undefined\n contentType: contentType | undefined\n pluginManager: PluginManager\n events?: AsyncEventEmitter<KubbEvents>\n /**\n * Current plugin\n */\n plugin: Plugin<TPluginOptions>\n mode: KubbFile.Mode\n}\n\nexport class OperationGenerator<\n TPluginOptions extends PluginFactoryOptions = PluginFactoryOptions,\n TFileMeta extends FileMetaBase = FileMetaBase,\n> extends BaseGenerator<TPluginOptions['resolvedOptions'], Context<TPluginOptions['resolvedOptions'], TPluginOptions>> {\n #getOptions(operation: Operation, method: HttpMethod): Partial<TPluginOptions['resolvedOptions']> {\n const { override = [] } = this.context\n const operationId = operation.getOperationId({ friendlyCase: true })\n const contentType = operation.getContentType()\n\n return (\n override.find(({ pattern, type }) => {\n switch (type) {\n case 'tag':\n return operation.getTags().some((tag) => tag.name.match(pattern))\n case 'operationId':\n return !!operationId.match(pattern)\n case 'path':\n return !!operation.path.match(pattern)\n case 'method':\n return !!method.match(pattern)\n case 'contentType':\n return !!contentType.match(pattern)\n default:\n return false\n }\n })?.options || {}\n )\n }\n\n #isExcluded(operation: Operation, method: HttpMethod): boolean {\n const { exclude = [] } = this.context\n const operationId = operation.getOperationId({ friendlyCase: true })\n const contentType = operation.getContentType()\n\n return exclude.some(({ pattern, type }) => {\n switch (type) {\n case 'tag':\n return operation.getTags().some((tag) => tag.name.match(pattern))\n case 'operationId':\n return !!operationId.match(pattern)\n case 'path':\n return !!operation.path.match(pattern)\n case 'method':\n return !!method.match(pattern)\n case 'contentType':\n return !!contentType.match(pattern)\n default:\n return false\n }\n })\n }\n\n #isIncluded(operation: Operation, method: HttpMethod): boolean {\n const { include = [] } = this.context\n const operationId = operation.getOperationId({ friendlyCase: true })\n const contentType = operation.getContentType()\n\n return include.some(({ pattern, type }) => {\n switch (type) {\n case 'tag':\n return operation.getTags().some((tag) => tag.name.match(pattern))\n case 'operationId':\n return !!operationId.match(pattern)\n case 'path':\n return !!operation.path.match(pattern)\n case 'method':\n return !!method.match(pattern)\n case 'contentType':\n return !!contentType.match(pattern)\n default:\n return false\n }\n })\n }\n\n getSchemas(\n operation: Operation,\n {\n resolveName = (name) => name,\n }: {\n resolveName?: (name: string) => string\n } = {},\n ): OperationSchemas {\n const operationId = operation.getOperationId({ friendlyCase: true })\n const method = operation.method\n const operationName = transformers.pascalCase(operationId)\n\n const resolveKeys = (schema?: SchemaObject) => (schema?.properties ? Object.keys(schema.properties) : undefined)\n\n const pathParamsSchema = this.context.oas.getParametersSchema(operation, 'path')\n const queryParamsSchema = this.context.oas.getParametersSchema(operation, 'query')\n const headerParamsSchema = this.context.oas.getParametersSchema(operation, 'header')\n const requestSchema = this.context.oas.getRequestSchema(operation)\n const statusCodes = operation.getResponseStatusCodes().map((statusCode) => {\n const name = statusCode === 'default' ? 'error' : statusCode\n const schema = this.context.oas.getResponseSchema(operation, statusCode)\n const keys = resolveKeys(schema)\n\n return {\n name: resolveName(transformers.pascalCase(`${operationId} ${name}`)),\n description: (operation.getResponseByStatusCode(statusCode) as OasTypes.ResponseObject)?.description,\n schema,\n operation,\n operationName,\n statusCode: name === 'error' ? undefined : Number(statusCode),\n keys,\n keysToOmit: keys?.filter((key) => (schema?.properties?.[key] as OasTypes.SchemaObject)?.writeOnly),\n }\n })\n\n const successful = statusCodes.filter((item) => item.statusCode?.toString().startsWith('2'))\n const errors = statusCodes.filter((item) => item.statusCode?.toString().startsWith('4') || item.statusCode?.toString().startsWith('5'))\n\n return {\n pathParams: pathParamsSchema\n ? {\n name: resolveName(transformers.pascalCase(`${operationId} PathParams`)),\n operation,\n operationName,\n schema: pathParamsSchema,\n keys: resolveKeys(pathParamsSchema),\n }\n : undefined,\n queryParams: queryParamsSchema\n ? {\n name: resolveName(transformers.pascalCase(`${operationId} QueryParams`)),\n operation,\n operationName,\n schema: queryParamsSchema,\n keys: resolveKeys(queryParamsSchema) || [],\n }\n : undefined,\n headerParams: headerParamsSchema\n ? {\n name: resolveName(transformers.pascalCase(`${operationId} HeaderParams`)),\n operation,\n operationName,\n schema: headerParamsSchema,\n keys: resolveKeys(headerParamsSchema),\n }\n : undefined,\n request: requestSchema\n ? {\n name: resolveName(transformers.pascalCase(`${operationId} ${method === 'get' ? 'queryRequest' : 'mutationRequest'}`)),\n description: (operation.schema.requestBody as OasTypes.RequestBodyObject)?.description,\n operation,\n operationName,\n schema: requestSchema,\n keys: resolveKeys(requestSchema),\n keysToOmit: resolveKeys(requestSchema)?.filter((key) => (requestSchema.properties?.[key] as OasTypes.SchemaObject)?.readOnly),\n }\n : undefined,\n response: {\n name: resolveName(transformers.pascalCase(`${operationId} ${method === 'get' ? 'queryResponse' : 'mutationResponse'}`)),\n operation,\n operationName,\n schema: {\n oneOf: successful.map((item) => ({ ...item.schema, $ref: item.name })) || undefined,\n } as SchemaObject,\n },\n responses: successful,\n errors,\n statusCodes,\n }\n }\n\n async getOperations(): Promise<Array<{ path: string; method: HttpMethod; operation: Operation }>> {\n const { oas } = this.context\n\n const paths = oas.getPaths()\n\n return Object.entries(paths).flatMap(([path, methods]) =>\n Object.entries(methods)\n .map((values) => {\n const [method, operation] = values as [HttpMethod, Operation]\n if (this.#isExcluded(operation, method)) {\n return null\n }\n\n if (this.context.include && !this.#isIncluded(operation, method)) {\n return null\n }\n\n return operation ? { path, method: method as HttpMethod, operation } : null\n })\n .filter(Boolean),\n )\n }\n\n async build(...generators: Array<Generator<TPluginOptions>>): Promise<Array<KubbFile.File<TFileMeta>>> {\n const operations = await this.getOperations()\n\n const generatorLimit = pLimit(1)\n const operationLimit = pLimit(10)\n\n this.context.events?.emit('debug', {\n date: new Date(),\n logs: [`Building ${operations.length} operations`, ` • Generators: ${generators.length}`],\n })\n\n const writeTasks = generators.map((generator) =>\n generatorLimit(async () => {\n const operationTasks = operations.map(({ operation, method }) =>\n operationLimit(async () => {\n const options = this.#getOptions(operation, method)\n\n if (generator.type === 'react') {\n await buildOperation(operation, {\n config: this.context.pluginManager.config,\n fabric: this.context.fabric,\n Component: generator.Operation,\n generator: this,\n plugin: {\n ...this.context.plugin,\n options: {\n ...this.options,\n ...options,\n },\n },\n })\n\n return []\n }\n\n const result = await generator.operation?.({\n generator: this,\n config: this.context.pluginManager.config,\n operation,\n plugin: {\n ...this.context.plugin,\n options: {\n ...this.options,\n ...options,\n },\n },\n })\n\n return result ?? []\n }),\n )\n\n const operationResults = await Promise.all(operationTasks)\n const opResultsFlat = operationResults.flat()\n\n if (generator.type === 'react') {\n await buildOperations(\n operations.map((op) => op.operation),\n {\n fabric: this.context.fabric,\n config: this.context.pluginManager.config,\n Component: generator.Operations,\n generator: this,\n plugin: this.context.plugin,\n },\n )\n\n return []\n }\n\n const operationsResult = await generator.operations?.({\n generator: this,\n config: this.context.pluginManager.config,\n operations: operations.map((op) => op.operation),\n plugin: this.context.plugin,\n })\n\n return [...opResultsFlat, ...(operationsResult ?? [])] as unknown as KubbFile.File<TFileMeta>\n }),\n )\n\n const nestedResults = await Promise.all(writeTasks)\n\n return nestedResults.flat()\n }\n}\n","import path from 'node:path'\nimport { type Config, definePlugin, type Group, getMode, type KubbEvents } from '@kubb/core'\nimport { camelCase } from '@kubb/core/transformers'\nimport type { AsyncEventEmitter } from '@kubb/core/utils'\nimport type { Oas } from '@kubb/oas'\nimport { parseFromConfig } from '@kubb/oas'\nimport { jsonGenerator } from './generators'\nimport { OperationGenerator } from './OperationGenerator.ts'\nimport { SchemaGenerator } from './SchemaGenerator.ts'\nimport type { PluginOas } from './types.ts'\n\nexport const pluginOasName = 'plugin-oas' satisfies PluginOas['name']\n\nexport const pluginOas = definePlugin<PluginOas>((options) => {\n const {\n output = {\n path: 'schemas',\n },\n group,\n validate = true,\n generators = [jsonGenerator],\n serverIndex,\n contentType,\n oasClass,\n discriminator = 'strict',\n } = options\n\n const getOas = async ({ validate, config, events }: { validate: boolean; config: Config; events: AsyncEventEmitter<KubbEvents> }): Promise<Oas> => {\n // needs to be in a different variable or the catch here will not work(return of a promise instead)\n const oas = await parseFromConfig(config, oasClass)\n\n oas.setOptions({\n contentType,\n discriminator,\n })\n\n try {\n if (validate) {\n await oas.valdiate()\n }\n } catch (er) {\n const caughtError = er as Error\n const errorTimestamp = new Date()\n const error = new Error('OAS Validation failed', {\n cause: caughtError,\n })\n\n events.emit('info', caughtError.message)\n events.emit('debug', {\n date: errorTimestamp,\n logs: [`✗ ${error.message}`, caughtError.message],\n })\n }\n\n return oas\n }\n\n return {\n name: pluginOasName,\n options: {\n output,\n validate,\n discriminator,\n ...options,\n },\n inject() {\n const config = this.config\n const events = this.events\n\n let oas: Oas\n\n return {\n async getOas({ validate = false } = {}) {\n if (!oas) {\n oas = await getOas({ config, events, validate })\n }\n\n return oas\n },\n async getBaseURL() {\n const oas = await getOas({ config, events, validate: false })\n if (serverIndex !== undefined) {\n return oas.api.servers?.at(serverIndex)?.url\n }\n\n return undefined\n },\n }\n },\n resolvePath(baseName, pathMode, options) {\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = pathMode ?? getMode(path.resolve(root, output.path))\n\n if (mode === 'single') {\n /**\n * when output is a file then we will always append to the same file(output file), see fileManager.addOrAppend\n * Other plugins then need to call addOrAppend instead of just add from the fileManager class\n */\n return path.resolve(root, output.path)\n }\n\n if (group && (options?.group?.path || options?.group?.tag)) {\n const groupName: Group['name'] = group?.name\n ? group.name\n : (ctx) => {\n if (group?.type === 'path') {\n return `${ctx.group.split('/')[1]}`\n }\n return `${camelCase(ctx.group)}Controller`\n }\n\n return path.resolve(\n root,\n output.path,\n groupName({\n group: group.type === 'path' ? options.group.path! : options.group.tag!,\n }),\n baseName,\n )\n }\n\n return path.resolve(root, output.path, baseName)\n },\n async install() {\n const oas = await this.getOas({ validate })\n\n if (!output) {\n return\n }\n\n await oas.dereference()\n\n const schemaGenerator = new SchemaGenerator(\n {\n unknownType: 'unknown',\n emptySchemaType: 'unknown',\n dateType: 'date',\n transformers: {},\n ...this.plugin.options,\n },\n {\n fabric: this.fabric,\n oas,\n pluginManager: this.pluginManager,\n events: this.events,\n plugin: this.plugin,\n contentType,\n include: undefined,\n override: undefined,\n mode: 'split',\n output: output.path,\n },\n )\n\n const schemaFiles = await schemaGenerator.build(...generators)\n await this.upsertFile(...schemaFiles)\n\n const operationGenerator = new OperationGenerator(this.plugin.options, {\n fabric: this.fabric,\n oas,\n pluginManager: this.pluginManager,\n events: this.events,\n plugin: this.plugin,\n contentType,\n exclude: undefined,\n include: undefined,\n override: undefined,\n mode: 'split',\n })\n\n const operationFiles = await operationGenerator.build(...generators)\n\n await this.upsertFile(...operationFiles)\n },\n }\n})\n","import type { PluginFactoryOptions } from '@kubb/core'\nimport { createGenerator as _createGenerator } from './generators/createGenerator.ts'\nimport { createReactGenerator as _createReactGenerator } from './generators/createReactGenerator.ts'\nimport type { Generator as _Generator } from './generators/types.ts'\n\nexport type { CreateParserConfig, KeywordHandler } from './createParser.ts'\nexport { createParser, findSchemaKeyword } from './createParser.ts'\nexport type { OperationMethodResult } from './OperationGenerator.ts'\nexport { OperationGenerator } from './OperationGenerator.ts'\nexport { pluginOas, pluginOasName } from './plugin.ts'\nexport type {\n GetSchemaGeneratorOptions,\n SchemaGeneratorBuildOptions,\n SchemaGeneratorOptions,\n SchemaMethodResult,\n} from './SchemaGenerator.ts'\nexport { SchemaGenerator } from './SchemaGenerator.ts'\nexport type {\n Schema,\n SchemaKeyword,\n SchemaKeywordBase,\n SchemaKeywordMapper,\n SchemaMapper,\n SchemaTree,\n} from './SchemaMapper.ts'\nexport { isKeyword, schemaKeywords } from './SchemaMapper.ts'\nexport type * from './types.ts'\nexport { buildOperation, buildOperations, buildSchema } from './utils.tsx'\n\n/**\n * @deprecated use `import { createGenerator } from '@kubb/plugin-oas/generators'`\n */\nexport const createGenerator = _createGenerator\n\n/**\n * @deprecated use `import { createReactGenerator } from '@kubb/plugin-oas/generators'`\n */\nexport const createReactGenerator = _createReactGenerator\n\n/**\n * @deprecated use `import { Generator } from '@kubb/plugin-oas/generators'`\n */\nexport type Generator<TOptions extends PluginFactoryOptions> = _Generator<TOptions>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6FA,SAAgB,aACd,QACqE;CACrE,MAAM,EAAE,QAAQ,aAAa;CAE7B,SAAS,MAAM,MAAkB,SAA+C;EAC9E,MAAM,EAAE,YAAY;EAGpB,MAAM,UAAU,SAAS,QAAQ;AACjC,MAAI,SAAS;GAEX,MAAMA,UAA6C,EAAE,OAAO;AAC5D,UAAO,QAAQ,KAAK,SAAS,MAAM,QAAQ;;EAI7C,MAAM,QAAQ,OAAO,QAAQ;AAE7B,MAAI,CAAC,MACH;AAIF,MAAI,QAAQ,WAAW,OACrB,QAAO,OAAO;;AAMlB,QAAO;;;;;;;;;;;;;AAcT,SAAgB,kBAAuD,UAAoB,SAAgD;AACzI,QAAO,gBAAgB,KAAK,UAAU,eAAe,SAAS;;;;;AC7GhE,IAAa,qBAAb,cAGU,cAA6G;CACrH,YAAY,WAAsB,QAAgE;EAChG,MAAM,EAAE,WAAW,EAAE,KAAK,KAAK;EAC/B,MAAM,cAAc,UAAU,eAAe,EAAE,cAAc,MAAM,CAAC;EACpE,MAAM,cAAc,UAAU,gBAAgB;AAE9C,SACE,SAAS,MAAM,EAAE,SAAS,WAAW;AACnC,WAAQ,MAAR;IACE,KAAK,MACH,QAAO,UAAU,SA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AU;IACV,MAAM;IACN,QAAQ,OAAO;IAChB,CACF,CAEyC,MAAM,GAAG,WAAW;AAC9D,SAAM,KAAK,WAAW,GAAG,YAAY;GAerC,MAAM,iBAAiB,MAbI,IAAI,mBAAmB,KAAK,OAAO,SAAS;IACrE,QAAQ,KAAK;IACb;IACA,eAAe,KAAK;IACpB,QAAQ,KAAK;IACb,QAAQ,KAAK;IACb;IACA,SAAS;IACT,SAAS;IACT,UAAU;IACV,MAAM;IACP,CAAC,CAE8C,MAAM,GAAG,WAAW;AAEpE,SAAM,KAAK,WAAW,GAAG,eAAe;;EAE3C;EACD;;;;;;;AC/IF,MAAa,kBAAkBE;;;;AAK/B,MAAa,uBAAuBC"}
|
package/dist/mocks.d.cts
CHANGED
package/dist/mocks.d.ts
CHANGED
package/dist/utils.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { S as Output, _ as contentType, b as Config, f as OasTypes, g as SchemaObject, h as Operation, l as isOptional, m as OpenAPIV3_1, p as OpenAPIV3, u as Oas } from "./SchemaMapper-
|
|
2
|
-
import { h as OperationSchema, w as FunctionParamsAST } from "./createGenerator-
|
|
1
|
+
import { S as Output, _ as contentType, b as Config, f as OasTypes, g as SchemaObject, h as Operation, l as isOptional, m as OpenAPIV3_1, p as OpenAPIV3, u as Oas } from "./SchemaMapper-B2a4K3r2.cjs";
|
|
2
|
+
import { h as OperationSchema, w as FunctionParamsAST } from "./createGenerator-DG5FCAfL.cjs";
|
|
3
3
|
import { Params } from "@kubb/react-fabric/types";
|
|
4
4
|
|
|
5
5
|
//#region src/utils/getBanner.d.ts
|
package/dist/utils.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { S as Output, _ as contentType, b as Config, f as OasTypes, g as SchemaObject, h as Operation, l as isOptional, m as OpenAPIV3_1, p as OpenAPIV3, u as Oas } from "./SchemaMapper-
|
|
2
|
-
import { h as OperationSchema, w as FunctionParamsAST } from "./createGenerator-
|
|
1
|
+
import { S as Output, _ as contentType, b as Config, f as OasTypes, g as SchemaObject, h as Operation, l as isOptional, m as OpenAPIV3_1, p as OpenAPIV3, u as Oas } from "./SchemaMapper-DesnD5yL.js";
|
|
2
|
+
import { h as OperationSchema, w as FunctionParamsAST } from "./createGenerator-BpFur0uJ.js";
|
|
3
3
|
import { Params } from "@kubb/react-fabric/types";
|
|
4
4
|
|
|
5
5
|
//#region src/utils/getBanner.d.ts
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/plugin-oas",
|
|
3
|
-
"version": "4.12.
|
|
3
|
+
"version": "4.12.8",
|
|
4
4
|
"description": "OpenAPI Specification (OAS) plugin for Kubb, providing core functionality for parsing and processing OpenAPI/Swagger schemas for code generation.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"openapi",
|
|
@@ -79,15 +79,14 @@
|
|
|
79
79
|
}
|
|
80
80
|
],
|
|
81
81
|
"dependencies": {
|
|
82
|
-
"@kubb/react-fabric": "0.7.
|
|
83
|
-
"@stoplight/yaml": "^4.3.0",
|
|
82
|
+
"@kubb/react-fabric": "0.7.4",
|
|
84
83
|
"p-limit": "^7.2.0",
|
|
85
84
|
"remeda": "^2.32.0",
|
|
86
|
-
"@kubb/core": "4.12.
|
|
87
|
-
"@kubb/oas": "4.12.
|
|
85
|
+
"@kubb/core": "4.12.8",
|
|
86
|
+
"@kubb/oas": "4.12.8"
|
|
88
87
|
},
|
|
89
88
|
"peerDependencies": {
|
|
90
|
-
"@kubb/react-fabric": "0.7.
|
|
89
|
+
"@kubb/react-fabric": "0.7.4"
|
|
91
90
|
},
|
|
92
91
|
"engines": {
|
|
93
92
|
"node": ">=20"
|
package/src/plugin.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import path from 'node:path'
|
|
2
|
-
import { type Config, definePlugin, type Group, getMode } from '@kubb/core'
|
|
2
|
+
import { type Config, definePlugin, type Group, getMode, type KubbEvents } from '@kubb/core'
|
|
3
3
|
import { camelCase } from '@kubb/core/transformers'
|
|
4
|
+
import type { AsyncEventEmitter } from '@kubb/core/utils'
|
|
4
5
|
import type { Oas } from '@kubb/oas'
|
|
5
6
|
import { parseFromConfig } from '@kubb/oas'
|
|
6
7
|
import { jsonGenerator } from './generators'
|
|
@@ -24,7 +25,7 @@ export const pluginOas = definePlugin<PluginOas>((options) => {
|
|
|
24
25
|
discriminator = 'strict',
|
|
25
26
|
} = options
|
|
26
27
|
|
|
27
|
-
const getOas = async ({ config }: { config: Config }): Promise<Oas> => {
|
|
28
|
+
const getOas = async ({ validate, config, events }: { validate: boolean; config: Config; events: AsyncEventEmitter<KubbEvents> }): Promise<Oas> => {
|
|
28
29
|
// needs to be in a different variable or the catch here will not work(return of a promise instead)
|
|
29
30
|
const oas = await parseFromConfig(config, oasClass)
|
|
30
31
|
|
|
@@ -37,10 +38,18 @@ export const pluginOas = definePlugin<PluginOas>((options) => {
|
|
|
37
38
|
if (validate) {
|
|
38
39
|
await oas.valdiate()
|
|
39
40
|
}
|
|
40
|
-
} catch (
|
|
41
|
-
const
|
|
41
|
+
} catch (er) {
|
|
42
|
+
const caughtError = er as Error
|
|
43
|
+
const errorTimestamp = new Date()
|
|
44
|
+
const error = new Error('OAS Validation failed', {
|
|
45
|
+
cause: caughtError,
|
|
46
|
+
})
|
|
42
47
|
|
|
43
|
-
|
|
48
|
+
events.emit('info', caughtError.message)
|
|
49
|
+
events.emit('debug', {
|
|
50
|
+
date: errorTimestamp,
|
|
51
|
+
logs: [`✗ ${error.message}`, caughtError.message],
|
|
52
|
+
})
|
|
44
53
|
}
|
|
45
54
|
|
|
46
55
|
return oas
|
|
@@ -56,18 +65,20 @@ export const pluginOas = definePlugin<PluginOas>((options) => {
|
|
|
56
65
|
},
|
|
57
66
|
inject() {
|
|
58
67
|
const config = this.config
|
|
68
|
+
const events = this.events
|
|
69
|
+
|
|
59
70
|
let oas: Oas
|
|
60
71
|
|
|
61
72
|
return {
|
|
62
|
-
async getOas() {
|
|
73
|
+
async getOas({ validate = false } = {}) {
|
|
63
74
|
if (!oas) {
|
|
64
|
-
oas = await getOas({ config })
|
|
75
|
+
oas = await getOas({ config, events, validate })
|
|
65
76
|
}
|
|
66
77
|
|
|
67
78
|
return oas
|
|
68
79
|
},
|
|
69
80
|
async getBaseURL() {
|
|
70
|
-
const oas = await getOas({ config })
|
|
81
|
+
const oas = await getOas({ config, events, validate: false })
|
|
71
82
|
if (serverIndex !== undefined) {
|
|
72
83
|
return oas.api.servers?.at(serverIndex)?.url
|
|
73
84
|
}
|
|
@@ -111,11 +122,12 @@ export const pluginOas = definePlugin<PluginOas>((options) => {
|
|
|
111
122
|
return path.resolve(root, output.path, baseName)
|
|
112
123
|
},
|
|
113
124
|
async install() {
|
|
125
|
+
const oas = await this.getOas({ validate })
|
|
126
|
+
|
|
114
127
|
if (!output) {
|
|
115
128
|
return
|
|
116
129
|
}
|
|
117
130
|
|
|
118
|
-
const oas = await this.getOas()
|
|
119
131
|
await oas.dereference()
|
|
120
132
|
|
|
121
133
|
const schemaGenerator = new SchemaGenerator(
|
package/src/types.ts
CHANGED
|
@@ -4,8 +4,12 @@ import type { KubbFile } from '@kubb/fabric-core/types'
|
|
|
4
4
|
import type { contentType, HttpMethod, Oas, Operation, SchemaObject } from '@kubb/oas'
|
|
5
5
|
import type { Generator } from './generators/types.ts'
|
|
6
6
|
|
|
7
|
+
type GetOasOptions = {
|
|
8
|
+
validate?: boolean
|
|
9
|
+
}
|
|
10
|
+
|
|
7
11
|
type Context = {
|
|
8
|
-
getOas(): Promise<Oas>
|
|
12
|
+
getOas(options?: GetOasOptions): Promise<Oas>
|
|
9
13
|
getBaseURL(): Promise<string | undefined>
|
|
10
14
|
}
|
|
11
15
|
|