@kubb/plugin-oas 5.0.0-alpha.2 → 5.0.0-alpha.21
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/{createGenerator-B8BypXNu.d.ts → createGenerator-BiZ9IsdY.d.ts} +106 -58
- package/dist/{generators-vAAte6w6.cjs → generators-85sP4GIS.cjs} +7 -7
- package/dist/generators-85sP4GIS.cjs.map +1 -0
- package/dist/{generators-B8HiBWvT.js → generators-hPE06pZB.js} +7 -7
- package/dist/generators-hPE06pZB.js.map +1 -0
- package/dist/generators.cjs +1 -1
- package/dist/generators.d.ts +4 -3
- package/dist/generators.js +1 -1
- package/dist/{getFooter-Pw3tLCiV.js → getFooter-Dz4u5Mg4.js} +5 -2
- package/dist/getFooter-Dz4u5Mg4.js.map +1 -0
- package/dist/{getFooter-BBzsC616.cjs → getFooter-gshcRE1-.cjs} +5 -2
- package/dist/getFooter-gshcRE1-.cjs.map +1 -0
- package/dist/hooks.cjs +26 -45
- package/dist/hooks.cjs.map +1 -1
- package/dist/hooks.d.ts +6 -23
- package/dist/hooks.js +29 -47
- package/dist/hooks.js.map +1 -1
- package/dist/index.cjs +15 -15
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +22 -38
- package/dist/index.js +14 -14
- package/dist/index.js.map +1 -1
- package/dist/{requestBody-FpiwLR1p.cjs → requestBody-BHEEK1Z3.cjs} +87 -126
- package/dist/requestBody-BHEEK1Z3.cjs.map +1 -0
- package/dist/{requestBody-DQMKhTin.js → requestBody-bs_SwfEj.js} +77 -116
- package/dist/requestBody-bs_SwfEj.js.map +1 -0
- package/dist/utils.cjs +61 -11
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.d.ts +1 -1
- package/dist/utils.js +61 -11
- package/dist/utils.js.map +1 -1
- package/package.json +7 -7
- package/src/OperationGenerator.ts +15 -15
- package/src/SchemaGenerator.ts +17 -20
- package/src/generators/createGenerator.ts +12 -15
- package/src/generators/createReactGenerator.ts +12 -15
- package/src/generators/index.ts +2 -2
- package/src/generators/jsonGenerator.ts +3 -3
- package/src/generators/types.ts +5 -40
- package/src/hooks/index.ts +0 -1
- package/src/hooks/useOas.ts +5 -2
- package/src/hooks/useOperationManager.ts +19 -18
- package/src/hooks/useSchemaManager.ts +5 -4
- package/src/index.ts +2 -2
- package/src/plugin.ts +5 -5
- package/src/types.ts +3 -2
- package/src/utils/getBanner.ts +1 -1
- package/src/utils/getFooter.ts +1 -1
- package/src/utils/getParams.ts +2 -2
- package/src/utils.tsx +50 -137
- package/dist/generators-B8HiBWvT.js.map +0 -1
- package/dist/generators-vAAte6w6.cjs.map +0 -1
- package/dist/getFooter-BBzsC616.cjs.map +0 -1
- package/dist/getFooter-Pw3tLCiV.js.map +0 -1
- package/dist/requestBody-DQMKhTin.js.map +0 -1
- package/dist/requestBody-FpiwLR1p.cjs.map +0 -1
- package/src/hooks/useRootNode.ts +0 -25
|
@@ -1,12 +1,81 @@
|
|
|
1
1
|
import { t as __name } from "./chunk--u3MIqq1.js";
|
|
2
2
|
import { i as SchemaKeywordMapper, t as Schema } from "./SchemaMapper-SneuY1wg.js";
|
|
3
3
|
import { HttpMethod, Oas, Operation, SchemaObject, contentType } from "@kubb/oas";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { KubbFile } from "@kubb/fabric-core/types";
|
|
7
|
-
import { OperationNode, SchemaNode } from "@kubb/ast/types";
|
|
4
|
+
import { Config, FileMetaBase, Generator, Group, KubbEvents, Output, Plugin, PluginDriver, PluginFactoryOptions, ResolveNameParams } from "@kubb/core";
|
|
5
|
+
import { Fabric, KubbFile } from "@kubb/fabric-core/types";
|
|
8
6
|
import { FabricReactNode } from "@kubb/react-fabric/types";
|
|
9
7
|
|
|
8
|
+
//#region ../../internals/utils/src/asyncEventEmitter.d.ts
|
|
9
|
+
/**
|
|
10
|
+
* A function that can be registered as an event listener, synchronous or async.
|
|
11
|
+
*/
|
|
12
|
+
type AsyncListener<TArgs extends unknown[]> = (...args: TArgs) => void | Promise<void>;
|
|
13
|
+
/**
|
|
14
|
+
* Typed `EventEmitter` that awaits all async listeners before resolving.
|
|
15
|
+
* Wraps Node's `EventEmitter` with full TypeScript event-map inference.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* const emitter = new AsyncEventEmitter<{ build: [name: string] }>()
|
|
20
|
+
* emitter.on('build', async (name) => { console.log(name) })
|
|
21
|
+
* await emitter.emit('build', 'petstore') // all listeners awaited
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
declare class AsyncEventEmitter<TEvents extends { [K in keyof TEvents]: unknown[] }> {
|
|
25
|
+
#private;
|
|
26
|
+
/**
|
|
27
|
+
* Maximum number of listeners per event before Node emits a memory-leak warning.
|
|
28
|
+
* @default 10
|
|
29
|
+
*/
|
|
30
|
+
constructor(maxListener?: number);
|
|
31
|
+
/**
|
|
32
|
+
* Emits `eventName` and awaits all registered listeners in parallel.
|
|
33
|
+
* Throws if any listener rejects, wrapping the cause with the event name and serialized arguments.
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```ts
|
|
37
|
+
* await emitter.emit('build', 'petstore')
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
emit<TEventName extends keyof TEvents & string>(eventName: TEventName, ...eventArgs: TEvents[TEventName]): Promise<void>;
|
|
41
|
+
/**
|
|
42
|
+
* Registers a persistent listener for `eventName`.
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```ts
|
|
46
|
+
* emitter.on('build', async (name) => { console.log(name) })
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
on<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: AsyncListener<TEvents[TEventName]>): void;
|
|
50
|
+
/**
|
|
51
|
+
* Registers a one-shot listener that removes itself after the first invocation.
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```ts
|
|
55
|
+
* emitter.onOnce('build', async (name) => { console.log(name) })
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
onOnce<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: AsyncListener<TEvents[TEventName]>): void;
|
|
59
|
+
/**
|
|
60
|
+
* Removes a previously registered listener.
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* ```ts
|
|
64
|
+
* emitter.off('build', handler)
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
67
|
+
off<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: AsyncListener<TEvents[TEventName]>): void;
|
|
68
|
+
/**
|
|
69
|
+
* Removes all listeners from every event channel.
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* ```ts
|
|
73
|
+
* emitter.removeAll()
|
|
74
|
+
* ```
|
|
75
|
+
*/
|
|
76
|
+
removeAll(): void;
|
|
77
|
+
}
|
|
78
|
+
//#endregion
|
|
10
79
|
//#region src/types.d.ts
|
|
11
80
|
type GetOasOptions = {
|
|
12
81
|
validate?: boolean;
|
|
@@ -97,7 +166,7 @@ type Options = {
|
|
|
97
166
|
/**
|
|
98
167
|
* Define some generators next to the JSON generation
|
|
99
168
|
*/
|
|
100
|
-
generators?: Array<Generator<PluginOas>>;
|
|
169
|
+
generators?: Array<Generator$1<PluginOas>>;
|
|
101
170
|
/**
|
|
102
171
|
* Resolve name collisions when schemas from different components share the same name (case-insensitive).
|
|
103
172
|
*
|
|
@@ -210,8 +279,8 @@ type ByContentType = {
|
|
|
210
279
|
type: 'contentType';
|
|
211
280
|
pattern: string | RegExp;
|
|
212
281
|
};
|
|
213
|
-
type Exclude = ByTag | ByOperationId | ByPath | ByMethod | ByContentType;
|
|
214
|
-
type Include = ByTag | ByOperationId | ByPath | ByMethod | ByContentType;
|
|
282
|
+
type Exclude = ByTag | ByOperationId | ByPath | ByMethod | ByContentType | BySchemaName;
|
|
283
|
+
type Include = ByTag | ByOperationId | ByPath | ByMethod | ByContentType | BySchemaName;
|
|
215
284
|
type Override<TOptions> = (ByTag | ByOperationId | ByPath | ByMethod | BySchemaName | ByContentType) & {
|
|
216
285
|
options: Partial<TOptions>;
|
|
217
286
|
};
|
|
@@ -229,7 +298,7 @@ type Context$1<TOptions, TPluginOptions extends PluginFactoryOptions> = {
|
|
|
229
298
|
include: Array<Include> | undefined;
|
|
230
299
|
override: Array<Override<TOptions>> | undefined;
|
|
231
300
|
contentType: contentType | undefined;
|
|
232
|
-
|
|
301
|
+
driver: PluginDriver;
|
|
233
302
|
events?: AsyncEventEmitter<KubbEvents>;
|
|
234
303
|
/**
|
|
235
304
|
* Current plugin
|
|
@@ -255,7 +324,7 @@ declare class OperationGenerator<TPluginOptions extends PluginFactoryOptions = P
|
|
|
255
324
|
method: HttpMethod;
|
|
256
325
|
operation: Operation;
|
|
257
326
|
}>>;
|
|
258
|
-
build(...generators: Array<Generator<TPluginOptions
|
|
327
|
+
build(...generators: Array<Generator$1<TPluginOptions>>): Promise<Array<KubbFile.File<TFileMeta>>>;
|
|
259
328
|
}
|
|
260
329
|
//#endregion
|
|
261
330
|
//#region src/SchemaGenerator.d.ts
|
|
@@ -264,7 +333,7 @@ type SchemaMethodResult<TFileMeta extends FileMetaBase> = Promise<KubbFile.File<
|
|
|
264
333
|
type Context<TOptions, TPluginOptions extends PluginFactoryOptions> = {
|
|
265
334
|
fabric: Fabric;
|
|
266
335
|
oas: Oas;
|
|
267
|
-
|
|
336
|
+
driver: PluginDriver;
|
|
268
337
|
events?: AsyncEventEmitter<KubbEvents>;
|
|
269
338
|
/**
|
|
270
339
|
* Current plugin
|
|
@@ -327,24 +396,23 @@ declare class SchemaGenerator<TOptions extends SchemaGeneratorOptions = SchemaGe
|
|
|
327
396
|
static deepSearch<T extends keyof SchemaKeywordMapper>(tree: Schema[] | undefined, keyword: T): Array<SchemaKeywordMapper[T]>;
|
|
328
397
|
static find<T extends keyof SchemaKeywordMapper>(tree: Schema[] | undefined, keyword: T): SchemaKeywordMapper[T] | undefined;
|
|
329
398
|
static combineObjects(tree: Schema[] | undefined): Schema[];
|
|
330
|
-
build(...generators: Array<Generator<TPluginOptions
|
|
399
|
+
build(...generators: Array<Generator$1<TPluginOptions>>): Promise<Array<KubbFile.File<TFileMeta>>>;
|
|
331
400
|
}
|
|
332
401
|
//#endregion
|
|
333
402
|
//#region src/generators/createReactGenerator.d.ts
|
|
334
|
-
type UserGenerator$1<TOptions extends PluginFactoryOptions
|
|
403
|
+
type UserGenerator$1<TOptions extends PluginFactoryOptions> = {
|
|
335
404
|
name: string;
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
Schema?: (props: SchemaProps<TOptions, TVersion>) => FabricReactNode;
|
|
405
|
+
Operations?: (props: OperationsProps<TOptions>) => FabricReactNode;
|
|
406
|
+
Operation?: (props: OperationProps<TOptions>) => FabricReactNode;
|
|
407
|
+
Schema?: (props: SchemaProps<TOptions>) => FabricReactNode;
|
|
340
408
|
};
|
|
341
|
-
type ReactGenerator<TOptions extends PluginFactoryOptions
|
|
409
|
+
type ReactGenerator<TOptions extends PluginFactoryOptions> = {
|
|
342
410
|
name: string;
|
|
343
411
|
type: 'react';
|
|
344
|
-
version:
|
|
345
|
-
Operations: (props: OperationsProps<TOptions
|
|
346
|
-
Operation: (props: OperationProps<TOptions
|
|
347
|
-
Schema: (props: SchemaProps<TOptions
|
|
412
|
+
version: '1';
|
|
413
|
+
Operations: (props: OperationsProps<TOptions>) => FabricReactNode;
|
|
414
|
+
Operation: (props: OperationProps<TOptions>) => FabricReactNode;
|
|
415
|
+
Schema: (props: SchemaProps<TOptions>) => FabricReactNode;
|
|
348
416
|
};
|
|
349
417
|
/****
|
|
350
418
|
* Creates a generator that uses React component functions to generate files for OpenAPI operations and schemas.
|
|
@@ -353,35 +421,22 @@ type ReactGenerator<TOptions extends PluginFactoryOptions, TVersion extends Vers
|
|
|
353
421
|
*
|
|
354
422
|
* @returns A generator object with async methods for operations, operation, and schema file generation.
|
|
355
423
|
*/
|
|
356
|
-
declare function createReactGenerator<TOptions extends PluginFactoryOptions
|
|
424
|
+
declare function createReactGenerator<TOptions extends PluginFactoryOptions>(generator: UserGenerator$1<TOptions>): ReactGenerator<TOptions>;
|
|
357
425
|
//#endregion
|
|
358
426
|
//#region src/generators/types.d.ts
|
|
359
|
-
type
|
|
360
|
-
type OperationsV1Props<TOptions extends PluginFactoryOptions> = {
|
|
427
|
+
type OperationsProps<TOptions extends PluginFactoryOptions> = {
|
|
361
428
|
config: Config;
|
|
362
429
|
generator: Omit<OperationGenerator<TOptions>, 'build'>;
|
|
363
430
|
plugin: Plugin<TOptions>;
|
|
364
431
|
operations: Array<Operation>;
|
|
365
432
|
};
|
|
366
|
-
type
|
|
367
|
-
config: Config;
|
|
368
|
-
plugin: Plugin<TOptions>;
|
|
369
|
-
nodes: Array<OperationNode>;
|
|
370
|
-
};
|
|
371
|
-
type OperationV1Props<TOptions extends PluginFactoryOptions> = {
|
|
433
|
+
type OperationProps<TOptions extends PluginFactoryOptions> = {
|
|
372
434
|
config: Config;
|
|
373
435
|
generator: Omit<OperationGenerator<TOptions>, 'build'>;
|
|
374
436
|
plugin: Plugin<TOptions>;
|
|
375
437
|
operation: Operation;
|
|
376
438
|
};
|
|
377
|
-
type
|
|
378
|
-
config: Config;
|
|
379
|
-
plugin: Plugin<TOptions>;
|
|
380
|
-
node: OperationNode;
|
|
381
|
-
};
|
|
382
|
-
type OperationsProps<TOptions extends PluginFactoryOptions, TVersion extends Version = '1'> = TVersion extends '2' ? OperationsV2Props<TOptions> : OperationsV1Props<TOptions>;
|
|
383
|
-
type OperationProps<TOptions extends PluginFactoryOptions, TVersion extends Version = '1'> = TVersion extends '2' ? OperationV2Props<TOptions> : OperationV1Props<TOptions>;
|
|
384
|
-
type SchemaV1Props<TOptions extends PluginFactoryOptions> = {
|
|
439
|
+
type SchemaProps<TOptions extends PluginFactoryOptions> = {
|
|
385
440
|
config: Config;
|
|
386
441
|
generator: Omit<SchemaGenerator<SchemaGeneratorOptions, TOptions>, 'build'>;
|
|
387
442
|
plugin: Plugin<TOptions>;
|
|
@@ -391,31 +446,24 @@ type SchemaV1Props<TOptions extends PluginFactoryOptions> = {
|
|
|
391
446
|
value: SchemaObject;
|
|
392
447
|
};
|
|
393
448
|
};
|
|
394
|
-
type
|
|
395
|
-
config: Config;
|
|
396
|
-
plugin: Plugin<TOptions>;
|
|
397
|
-
node: SchemaNode;
|
|
398
|
-
};
|
|
399
|
-
type SchemaProps<TOptions extends PluginFactoryOptions, TVersion extends Version = '1'> = TVersion extends '2' ? SchemaV2Props<TOptions> : SchemaV1Props<TOptions>;
|
|
400
|
-
type Generator<TOptions extends PluginFactoryOptions, TVersion extends Version = Version> = CoreGenerator<TOptions, TVersion> | ReactGenerator<TOptions, TVersion>;
|
|
449
|
+
type Generator$1<TOptions extends PluginFactoryOptions> = CoreGenerator<TOptions> | ReactGenerator<TOptions> | Generator<TOptions>;
|
|
401
450
|
//#endregion
|
|
402
451
|
//#region src/generators/createGenerator.d.ts
|
|
403
|
-
type UserGenerator<TOptions extends PluginFactoryOptions
|
|
452
|
+
type UserGenerator<TOptions extends PluginFactoryOptions> = {
|
|
404
453
|
name: string;
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
schema?: (props: SchemaProps<TOptions, TVersion>) => Promise<KubbFile.File[]>;
|
|
454
|
+
operations?: (props: OperationsProps<TOptions>) => Promise<KubbFile.File[]>;
|
|
455
|
+
operation?: (props: OperationProps<TOptions>) => Promise<KubbFile.File[]>;
|
|
456
|
+
schema?: (props: SchemaProps<TOptions>) => Promise<KubbFile.File[]>;
|
|
409
457
|
};
|
|
410
|
-
type CoreGenerator<TOptions extends PluginFactoryOptions
|
|
458
|
+
type CoreGenerator<TOptions extends PluginFactoryOptions> = {
|
|
411
459
|
name: string;
|
|
412
460
|
type: 'core';
|
|
413
|
-
version:
|
|
414
|
-
operations: (props: OperationsProps<TOptions
|
|
415
|
-
operation: (props: OperationProps<TOptions
|
|
416
|
-
schema: (props: SchemaProps<TOptions
|
|
461
|
+
version: '1';
|
|
462
|
+
operations: (props: OperationsProps<TOptions>) => Promise<KubbFile.File[]>;
|
|
463
|
+
operation: (props: OperationProps<TOptions>) => Promise<KubbFile.File[]>;
|
|
464
|
+
schema: (props: SchemaProps<TOptions>) => Promise<KubbFile.File[]>;
|
|
417
465
|
};
|
|
418
|
-
declare function createGenerator<TOptions extends PluginFactoryOptions
|
|
466
|
+
declare function createGenerator<TOptions extends PluginFactoryOptions>(generator: UserGenerator<TOptions>): CoreGenerator<TOptions>;
|
|
419
467
|
//#endregion
|
|
420
|
-
export {
|
|
421
|
-
//# sourceMappingURL=createGenerator-
|
|
468
|
+
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$1 as r, SchemaGenerator as s, CoreGenerator as t, SchemaMethodResult as u, Override as v, Refs as x, PluginOas as y };
|
|
469
|
+
//# sourceMappingURL=createGenerator-BiZ9IsdY.d.ts.map
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
require("./chunk-ByKO4r7w.cjs");
|
|
2
|
-
const require_getFooter = require("./getFooter-
|
|
2
|
+
const require_getFooter = require("./getFooter-gshcRE1-.cjs");
|
|
3
3
|
//#region src/generators/createGenerator.ts
|
|
4
4
|
function createGenerator(generator) {
|
|
5
5
|
return {
|
|
6
6
|
type: "core",
|
|
7
|
-
version:
|
|
7
|
+
version: "1",
|
|
8
8
|
async operations() {
|
|
9
9
|
return [];
|
|
10
10
|
},
|
|
@@ -29,7 +29,7 @@ function createGenerator(generator) {
|
|
|
29
29
|
function createReactGenerator(generator) {
|
|
30
30
|
return {
|
|
31
31
|
type: "react",
|
|
32
|
-
version:
|
|
32
|
+
version: "1",
|
|
33
33
|
Operations() {
|
|
34
34
|
return null;
|
|
35
35
|
},
|
|
@@ -47,9 +47,9 @@ function createReactGenerator(generator) {
|
|
|
47
47
|
const jsonGenerator = createGenerator({
|
|
48
48
|
name: "plugin-oas",
|
|
49
49
|
async schema({ schema, generator }) {
|
|
50
|
-
const {
|
|
50
|
+
const { driver, plugin } = generator.context;
|
|
51
51
|
return [{
|
|
52
|
-
...
|
|
52
|
+
...driver.getFile({
|
|
53
53
|
name: require_getFooter.camelCase(schema.name),
|
|
54
54
|
extname: ".json",
|
|
55
55
|
mode: "split",
|
|
@@ -64,7 +64,7 @@ const jsonGenerator = createGenerator({
|
|
|
64
64
|
banner: require_getFooter.getBanner({
|
|
65
65
|
oas: generator.context.oas,
|
|
66
66
|
output: plugin.options.output,
|
|
67
|
-
config:
|
|
67
|
+
config: driver.config
|
|
68
68
|
}),
|
|
69
69
|
format: require_getFooter.getFooter({
|
|
70
70
|
oas: generator.context.oas,
|
|
@@ -93,4 +93,4 @@ Object.defineProperty(exports, "jsonGenerator", {
|
|
|
93
93
|
}
|
|
94
94
|
});
|
|
95
95
|
|
|
96
|
-
//# sourceMappingURL=generators-
|
|
96
|
+
//# sourceMappingURL=generators-85sP4GIS.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generators-85sP4GIS.cjs","names":["camelCase","getBanner","getFooter"],"sources":["../src/generators/createGenerator.ts","../src/generators/createReactGenerator.ts","../src/generators/jsonGenerator.ts"],"sourcesContent":["import type { PluginFactoryOptions } from '@kubb/core'\nimport type { KubbFile } from '@kubb/fabric-core/types'\nimport type { OperationProps, OperationsProps, SchemaProps } from './types.ts'\n\ntype UserGenerator<TOptions extends PluginFactoryOptions> = {\n name: string\n operations?: (props: OperationsProps<TOptions>) => Promise<KubbFile.File[]>\n operation?: (props: OperationProps<TOptions>) => Promise<KubbFile.File[]>\n schema?: (props: SchemaProps<TOptions>) => Promise<KubbFile.File[]>\n}\n\nexport type CoreGenerator<TOptions extends PluginFactoryOptions> = {\n name: string\n type: 'core'\n version: '1'\n operations: (props: OperationsProps<TOptions>) => Promise<KubbFile.File[]>\n operation: (props: OperationProps<TOptions>) => Promise<KubbFile.File[]>\n schema: (props: SchemaProps<TOptions>) => Promise<KubbFile.File[]>\n}\n\nexport function createGenerator<TOptions extends PluginFactoryOptions>(generator: UserGenerator<TOptions>): CoreGenerator<TOptions> {\n return {\n type: 'core',\n version: '1',\n async operations() {\n return []\n },\n async operation() {\n return []\n },\n async schema() {\n return []\n },\n ...generator,\n }\n}\n","import type { PluginFactoryOptions } from '@kubb/core'\nimport type { FabricReactNode } from '@kubb/react-fabric/types'\nimport type { OperationProps, OperationsProps, SchemaProps } from './types.ts'\n\ntype UserGenerator<TOptions extends PluginFactoryOptions> = {\n name: string\n Operations?: (props: OperationsProps<TOptions>) => FabricReactNode\n Operation?: (props: OperationProps<TOptions>) => FabricReactNode\n Schema?: (props: SchemaProps<TOptions>) => FabricReactNode\n}\n\nexport type ReactGenerator<TOptions extends PluginFactoryOptions> = {\n name: string\n type: 'react'\n version: '1'\n Operations: (props: OperationsProps<TOptions>) => FabricReactNode\n Operation: (props: OperationProps<TOptions>) => FabricReactNode\n Schema: (props: SchemaProps<TOptions>) => FabricReactNode\n}\n\n/****\n * Creates a generator that uses React component functions to generate files for OpenAPI operations and schemas.\n *\n * The returned generator exposes async methods for generating files from operations, a single operation, or a schema, using the corresponding React components if provided. If a component is not defined, the method returns an empty array.\n *\n * @returns A generator object with async methods for operations, operation, and schema file generation.\n */\nexport function createReactGenerator<TOptions extends PluginFactoryOptions>(generator: UserGenerator<TOptions>): ReactGenerator<TOptions> {\n return {\n type: 'react',\n version: '1',\n Operations() {\n return null\n },\n Operation() {\n return null\n },\n Schema() {\n return null\n },\n ...generator,\n }\n}\n","import { camelCase } from '@internals/utils'\nimport type { PluginOas } from '../types.ts'\nimport { getBanner } from '../utils/getBanner.ts'\nimport { getFooter } from '../utils/getFooter.ts'\nimport { createGenerator } from './createGenerator.ts'\n\nexport const jsonGenerator = createGenerator<PluginOas>({\n name: 'plugin-oas',\n async schema({ schema, generator }) {\n const { driver, plugin } = generator.context\n const file = driver.getFile({\n name: camelCase(schema.name),\n extname: '.json',\n mode: 'split',\n pluginName: plugin.name,\n })\n\n return [\n {\n ...file,\n sources: [\n {\n name: camelCase(schema.name),\n isExportable: false,\n isIndexable: false,\n value: JSON.stringify(schema.value),\n },\n ],\n banner: getBanner({\n oas: generator.context.oas,\n output: plugin.options.output,\n config: driver.config,\n }),\n format: getFooter({ oas: generator.context.oas, output: plugin.options.output }),\n },\n ]\n },\n})\n"],"mappings":";;;AAoBA,SAAgB,gBAAuD,WAA6D;AAClI,QAAO;EACL,MAAM;EACN,SAAS;EACT,MAAM,aAAa;AACjB,UAAO,EAAE;;EAEX,MAAM,YAAY;AAChB,UAAO,EAAE;;EAEX,MAAM,SAAS;AACb,UAAO,EAAE;;EAEX,GAAG;EACJ;;;;;;;;;;;ACPH,SAAgB,qBAA4D,WAA8D;AACxI,QAAO;EACL,MAAM;EACN,SAAS;EACT,aAAa;AACX,UAAO;;EAET,YAAY;AACV,UAAO;;EAET,SAAS;AACP,UAAO;;EAET,GAAG;EACJ;;;;ACnCH,MAAa,gBAAgB,gBAA2B;CACtD,MAAM;CACN,MAAM,OAAO,EAAE,QAAQ,aAAa;EAClC,MAAM,EAAE,QAAQ,WAAW,UAAU;AAQrC,SAAO,CACL;GACE,GATS,OAAO,QAAQ;IAC1B,MAAMA,kBAAAA,UAAU,OAAO,KAAK;IAC5B,SAAS;IACT,MAAM;IACN,YAAY,OAAO;IACpB,CAAC;GAKE,SAAS,CACP;IACE,MAAMA,kBAAAA,UAAU,OAAO,KAAK;IAC5B,cAAc;IACd,aAAa;IACb,OAAO,KAAK,UAAU,OAAO,MAAM;IACpC,CACF;GACD,QAAQC,kBAAAA,UAAU;IAChB,KAAK,UAAU,QAAQ;IACvB,QAAQ,OAAO,QAAQ;IACvB,QAAQ,OAAO;IAChB,CAAC;GACF,QAAQC,kBAAAA,UAAU;IAAE,KAAK,UAAU,QAAQ;IAAK,QAAQ,OAAO,QAAQ;IAAQ,CAAC;GACjF,CACF;;CAEJ,CAAC"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import "./chunk--u3MIqq1.js";
|
|
2
|
-
import { n as getBanner, r as camelCase, t as getFooter } from "./getFooter-
|
|
2
|
+
import { n as getBanner, r as camelCase, t as getFooter } from "./getFooter-Dz4u5Mg4.js";
|
|
3
3
|
//#region src/generators/createGenerator.ts
|
|
4
4
|
function createGenerator(generator) {
|
|
5
5
|
return {
|
|
6
6
|
type: "core",
|
|
7
|
-
version:
|
|
7
|
+
version: "1",
|
|
8
8
|
async operations() {
|
|
9
9
|
return [];
|
|
10
10
|
},
|
|
@@ -29,7 +29,7 @@ function createGenerator(generator) {
|
|
|
29
29
|
function createReactGenerator(generator) {
|
|
30
30
|
return {
|
|
31
31
|
type: "react",
|
|
32
|
-
version:
|
|
32
|
+
version: "1",
|
|
33
33
|
Operations() {
|
|
34
34
|
return null;
|
|
35
35
|
},
|
|
@@ -47,9 +47,9 @@ function createReactGenerator(generator) {
|
|
|
47
47
|
const jsonGenerator = createGenerator({
|
|
48
48
|
name: "plugin-oas",
|
|
49
49
|
async schema({ schema, generator }) {
|
|
50
|
-
const {
|
|
50
|
+
const { driver, plugin } = generator.context;
|
|
51
51
|
return [{
|
|
52
|
-
...
|
|
52
|
+
...driver.getFile({
|
|
53
53
|
name: camelCase(schema.name),
|
|
54
54
|
extname: ".json",
|
|
55
55
|
mode: "split",
|
|
@@ -64,7 +64,7 @@ const jsonGenerator = createGenerator({
|
|
|
64
64
|
banner: getBanner({
|
|
65
65
|
oas: generator.context.oas,
|
|
66
66
|
output: plugin.options.output,
|
|
67
|
-
config:
|
|
67
|
+
config: driver.config
|
|
68
68
|
}),
|
|
69
69
|
format: getFooter({
|
|
70
70
|
oas: generator.context.oas,
|
|
@@ -76,4 +76,4 @@ const jsonGenerator = createGenerator({
|
|
|
76
76
|
//#endregion
|
|
77
77
|
export { createReactGenerator as n, createGenerator as r, jsonGenerator as t };
|
|
78
78
|
|
|
79
|
-
//# sourceMappingURL=generators-
|
|
79
|
+
//# sourceMappingURL=generators-hPE06pZB.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generators-hPE06pZB.js","names":[],"sources":["../src/generators/createGenerator.ts","../src/generators/createReactGenerator.ts","../src/generators/jsonGenerator.ts"],"sourcesContent":["import type { PluginFactoryOptions } from '@kubb/core'\nimport type { KubbFile } from '@kubb/fabric-core/types'\nimport type { OperationProps, OperationsProps, SchemaProps } from './types.ts'\n\ntype UserGenerator<TOptions extends PluginFactoryOptions> = {\n name: string\n operations?: (props: OperationsProps<TOptions>) => Promise<KubbFile.File[]>\n operation?: (props: OperationProps<TOptions>) => Promise<KubbFile.File[]>\n schema?: (props: SchemaProps<TOptions>) => Promise<KubbFile.File[]>\n}\n\nexport type CoreGenerator<TOptions extends PluginFactoryOptions> = {\n name: string\n type: 'core'\n version: '1'\n operations: (props: OperationsProps<TOptions>) => Promise<KubbFile.File[]>\n operation: (props: OperationProps<TOptions>) => Promise<KubbFile.File[]>\n schema: (props: SchemaProps<TOptions>) => Promise<KubbFile.File[]>\n}\n\nexport function createGenerator<TOptions extends PluginFactoryOptions>(generator: UserGenerator<TOptions>): CoreGenerator<TOptions> {\n return {\n type: 'core',\n version: '1',\n async operations() {\n return []\n },\n async operation() {\n return []\n },\n async schema() {\n return []\n },\n ...generator,\n }\n}\n","import type { PluginFactoryOptions } from '@kubb/core'\nimport type { FabricReactNode } from '@kubb/react-fabric/types'\nimport type { OperationProps, OperationsProps, SchemaProps } from './types.ts'\n\ntype UserGenerator<TOptions extends PluginFactoryOptions> = {\n name: string\n Operations?: (props: OperationsProps<TOptions>) => FabricReactNode\n Operation?: (props: OperationProps<TOptions>) => FabricReactNode\n Schema?: (props: SchemaProps<TOptions>) => FabricReactNode\n}\n\nexport type ReactGenerator<TOptions extends PluginFactoryOptions> = {\n name: string\n type: 'react'\n version: '1'\n Operations: (props: OperationsProps<TOptions>) => FabricReactNode\n Operation: (props: OperationProps<TOptions>) => FabricReactNode\n Schema: (props: SchemaProps<TOptions>) => FabricReactNode\n}\n\n/****\n * Creates a generator that uses React component functions to generate files for OpenAPI operations and schemas.\n *\n * The returned generator exposes async methods for generating files from operations, a single operation, or a schema, using the corresponding React components if provided. If a component is not defined, the method returns an empty array.\n *\n * @returns A generator object with async methods for operations, operation, and schema file generation.\n */\nexport function createReactGenerator<TOptions extends PluginFactoryOptions>(generator: UserGenerator<TOptions>): ReactGenerator<TOptions> {\n return {\n type: 'react',\n version: '1',\n Operations() {\n return null\n },\n Operation() {\n return null\n },\n Schema() {\n return null\n },\n ...generator,\n }\n}\n","import { camelCase } from '@internals/utils'\nimport type { PluginOas } from '../types.ts'\nimport { getBanner } from '../utils/getBanner.ts'\nimport { getFooter } from '../utils/getFooter.ts'\nimport { createGenerator } from './createGenerator.ts'\n\nexport const jsonGenerator = createGenerator<PluginOas>({\n name: 'plugin-oas',\n async schema({ schema, generator }) {\n const { driver, plugin } = generator.context\n const file = driver.getFile({\n name: camelCase(schema.name),\n extname: '.json',\n mode: 'split',\n pluginName: plugin.name,\n })\n\n return [\n {\n ...file,\n sources: [\n {\n name: camelCase(schema.name),\n isExportable: false,\n isIndexable: false,\n value: JSON.stringify(schema.value),\n },\n ],\n banner: getBanner({\n oas: generator.context.oas,\n output: plugin.options.output,\n config: driver.config,\n }),\n format: getFooter({ oas: generator.context.oas, output: plugin.options.output }),\n },\n ]\n },\n})\n"],"mappings":";;;AAoBA,SAAgB,gBAAuD,WAA6D;AAClI,QAAO;EACL,MAAM;EACN,SAAS;EACT,MAAM,aAAa;AACjB,UAAO,EAAE;;EAEX,MAAM,YAAY;AAChB,UAAO,EAAE;;EAEX,MAAM,SAAS;AACb,UAAO,EAAE;;EAEX,GAAG;EACJ;;;;;;;;;;;ACPH,SAAgB,qBAA4D,WAA8D;AACxI,QAAO;EACL,MAAM;EACN,SAAS;EACT,aAAa;AACX,UAAO;;EAET,YAAY;AACV,UAAO;;EAET,SAAS;AACP,UAAO;;EAET,GAAG;EACJ;;;;ACnCH,MAAa,gBAAgB,gBAA2B;CACtD,MAAM;CACN,MAAM,OAAO,EAAE,QAAQ,aAAa;EAClC,MAAM,EAAE,QAAQ,WAAW,UAAU;AAQrC,SAAO,CACL;GACE,GATS,OAAO,QAAQ;IAC1B,MAAM,UAAU,OAAO,KAAK;IAC5B,SAAS;IACT,MAAM;IACN,YAAY,OAAO;IACpB,CAAC;GAKE,SAAS,CACP;IACE,MAAM,UAAU,OAAO,KAAK;IAC5B,cAAc;IACd,aAAa;IACb,OAAO,KAAK,UAAU,OAAO,MAAM;IACpC,CACF;GACD,QAAQ,UAAU;IAChB,KAAK,UAAU,QAAQ;IACvB,QAAQ,OAAO,QAAQ;IACvB,QAAQ,OAAO;IAChB,CAAC;GACF,QAAQ,UAAU;IAAE,KAAK,UAAU,QAAQ;IAAK,QAAQ,OAAO,QAAQ;IAAQ,CAAC;GACjF,CACF;;CAEJ,CAAC"}
|
package/dist/generators.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_generators = require("./generators-
|
|
2
|
+
const require_generators = require("./generators-85sP4GIS.cjs");
|
|
3
3
|
exports.createGenerator = require_generators.createGenerator;
|
|
4
4
|
exports.createReactGenerator = require_generators.createReactGenerator;
|
|
5
5
|
exports.jsonGenerator = require_generators.jsonGenerator;
|
package/dist/generators.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { t as __name } from "./chunk--u3MIqq1.js";
|
|
2
|
-
import {
|
|
2
|
+
import { a as createReactGenerator, i as ReactGenerator, n as createGenerator, r as Generator, t as CoreGenerator, y as PluginOas } from "./createGenerator-BiZ9IsdY.js";
|
|
3
|
+
|
|
3
4
|
//#region src/generators/jsonGenerator.d.ts
|
|
4
|
-
declare const jsonGenerator: CoreGenerator<PluginOas
|
|
5
|
+
declare const jsonGenerator: CoreGenerator<PluginOas>;
|
|
5
6
|
//#endregion
|
|
6
|
-
export { type Generator, createGenerator, createReactGenerator, jsonGenerator };
|
|
7
|
+
export { type CoreGenerator, type Generator, type ReactGenerator, createGenerator, createReactGenerator, jsonGenerator };
|
|
7
8
|
//# sourceMappingURL=generators.d.ts.map
|
package/dist/generators.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as createReactGenerator, r as createGenerator, t as jsonGenerator } from "./generators-
|
|
1
|
+
import { n as createReactGenerator, r as createGenerator, t as jsonGenerator } from "./generators-hPE06pZB.js";
|
|
2
2
|
export { createGenerator, createReactGenerator, jsonGenerator };
|
|
@@ -20,9 +20,12 @@ function toCamelOrPascal(text, pascal) {
|
|
|
20
20
|
* Splits `text` on `.` and applies `transformPart` to each segment.
|
|
21
21
|
* The last segment receives `isLast = true`, all earlier segments receive `false`.
|
|
22
22
|
* Segments are joined with `/` to form a file path.
|
|
23
|
+
*
|
|
24
|
+
* Only splits on dots followed by a letter so that version numbers
|
|
25
|
+
* embedded in operationIds (e.g. `v2025.0`) are kept intact.
|
|
23
26
|
*/
|
|
24
27
|
function applyToFileParts(text, transformPart) {
|
|
25
|
-
const parts = text.split(
|
|
28
|
+
const parts = text.split(/\.(?=[a-zA-Z])/);
|
|
26
29
|
return parts.map((part, i) => transformPart(part, i === parts.length - 1)).join("/");
|
|
27
30
|
}
|
|
28
31
|
/**
|
|
@@ -109,4 +112,4 @@ function getFooter({ output, oas }) {
|
|
|
109
112
|
//#endregion
|
|
110
113
|
export { pascalCase as i, getBanner as n, camelCase as r, getFooter as t };
|
|
111
114
|
|
|
112
|
-
//# sourceMappingURL=getFooter-
|
|
115
|
+
//# sourceMappingURL=getFooter-Dz4u5Mg4.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getFooter-Dz4u5Mg4.js","names":[],"sources":["../../../internals/utils/src/casing.ts","../src/utils/getBanner.ts","../src/utils/getFooter.ts"],"sourcesContent":["type Options = {\n /**\n * When `true`, dot-separated segments are split on `.` and joined with `/` after casing.\n */\n isFile?: boolean\n /**\n * Text prepended before casing is applied.\n */\n prefix?: string\n /**\n * Text appended before casing is applied.\n */\n suffix?: string\n}\n\n/**\n * Shared implementation for camelCase and PascalCase conversion.\n * Splits on common word boundaries (spaces, hyphens, underscores, dots, slashes, colons)\n * and capitalizes each word according to `pascal`.\n *\n * When `pascal` is `true` the first word is also capitalized (PascalCase), otherwise only subsequent words are.\n */\nfunction toCamelOrPascal(text: string, pascal: boolean): string {\n const normalized = text\n .trim()\n .replace(/([a-z\\d])([A-Z])/g, '$1 $2')\n .replace(/([A-Z]+)([A-Z][a-z])/g, '$1 $2')\n .replace(/(\\d)([a-z])/g, '$1 $2')\n\n const words = normalized.split(/[\\s\\-_./\\\\:]+/).filter(Boolean)\n\n return words\n .map((word, i) => {\n const allUpper = word.length > 1 && word === word.toUpperCase()\n if (allUpper) return word\n if (i === 0 && !pascal) return word.charAt(0).toLowerCase() + word.slice(1)\n return word.charAt(0).toUpperCase() + word.slice(1)\n })\n .join('')\n .replace(/[^a-zA-Z0-9]/g, '')\n}\n\n/**\n * Splits `text` on `.` and applies `transformPart` to each segment.\n * The last segment receives `isLast = true`, all earlier segments receive `false`.\n * Segments are joined with `/` to form a file path.\n *\n * Only splits on dots followed by a letter so that version numbers\n * embedded in operationIds (e.g. `v2025.0`) are kept intact.\n */\nfunction applyToFileParts(text: string, transformPart: (part: string, isLast: boolean) => string): string {\n const parts = text.split(/\\.(?=[a-zA-Z])/)\n return parts.map((part, i) => transformPart(part, i === parts.length - 1)).join('/')\n}\n\n/**\n * Converts `text` to camelCase.\n * When `isFile` is `true`, dot-separated segments are each cased independently and joined with `/`.\n *\n * @example\n * camelCase('hello-world') // 'helloWorld'\n * camelCase('pet.petId', { isFile: true }) // 'pet/petId'\n */\nexport function camelCase(text: string, { isFile, prefix = '', suffix = '' }: Options = {}): string {\n if (isFile) {\n return applyToFileParts(text, (part, isLast) => camelCase(part, isLast ? { prefix, suffix } : {}))\n }\n\n return toCamelOrPascal(`${prefix} ${text} ${suffix}`, false)\n}\n\n/**\n * Converts `text` to PascalCase.\n * When `isFile` is `true`, the last dot-separated segment is PascalCased and earlier segments are camelCased.\n *\n * @example\n * pascalCase('hello-world') // 'HelloWorld'\n * pascalCase('pet.petId', { isFile: true }) // 'pet/PetId'\n */\nexport function pascalCase(text: string, { isFile, prefix = '', suffix = '' }: Options = {}): string {\n if (isFile) {\n return applyToFileParts(text, (part, isLast) => (isLast ? pascalCase(part, { prefix, suffix }) : camelCase(part)))\n }\n\n return toCamelOrPascal(`${prefix} ${text} ${suffix}`, true)\n}\n\n/**\n * Converts `text` to snake_case.\n *\n * @example\n * snakeCase('helloWorld') // 'hello_world'\n * snakeCase('Hello-World') // 'hello_world'\n */\nexport function snakeCase(text: string, { prefix = '', suffix = '' }: Omit<Options, 'isFile'> = {}): string {\n const processed = `${prefix} ${text} ${suffix}`.trim()\n return processed\n .replace(/([a-z])([A-Z])/g, '$1_$2')\n .replace(/[\\s\\-.]+/g, '_')\n .replace(/[^a-zA-Z0-9_]/g, '')\n .toLowerCase()\n .split('_')\n .filter(Boolean)\n .join('_')\n}\n\n/**\n * Converts `text` to SCREAMING_SNAKE_CASE.\n *\n * @example\n * screamingSnakeCase('helloWorld') // 'HELLO_WORLD'\n */\nexport function screamingSnakeCase(text: string, { prefix = '', suffix = '' }: Omit<Options, 'isFile'> = {}): string {\n return snakeCase(text, { prefix, suffix }).toUpperCase()\n}\n","import path from 'node:path'\nimport type { Config, Output } from '@kubb/core'\nimport type { Oas } from '@kubb/oas'\nimport { isFunction } from 'remeda'\n\ntype Props<TOas extends Oas> = {\n oas: TOas\n output: Output<any>\n config?: Config\n}\n\n/**\n * Generate a default banner for files created by Kubb\n * @returns A string with the default banner\n */\nfunction getDefaultBanner({ title, description, version, config }: { title?: string; description?: string; version?: string; config: Config }): string {\n try {\n let source = ''\n if ('path' in config.input) {\n source = path.basename(config.input.path)\n } else if ('data' in config.input) {\n source = 'text content'\n }\n\n let banner = '/**\\n* Generated by Kubb (https://kubb.dev/).\\n* Do not edit manually.\\n'\n\n if (config.output.defaultBanner === 'simple') {\n banner += '*/\\n'\n return banner\n }\n\n if (source) {\n banner += `* Source: ${source}\\n`\n }\n\n if (title) {\n banner += `* Title: ${title}\\n`\n }\n\n if (description) {\n const formattedDescription = description.replace(/\\n/gm, '\\n* ')\n banner += `* Description: ${formattedDescription}\\n`\n }\n\n if (version) {\n banner += `* OpenAPI spec version: ${version}\\n`\n }\n\n banner += '*/\\n'\n return banner\n } catch (_error) {\n // If there's any error in parsing the Oas data, return a simpler banner\n return '/**\\n* Generated by Kubb (https://kubb.dev/).\\n* Do not edit manually.\\n*/'\n }\n}\n\nexport function getBanner<TOas extends Oas>({ output, oas, config }: Props<TOas>): string {\n let banner = ''\n if (config?.output?.defaultBanner !== false && config) {\n const { title, description, version } = oas.api?.info || {}\n\n banner = getDefaultBanner({ title, description, version, config })\n }\n\n if (!output.banner) {\n return banner\n }\n\n if (isFunction(output.banner)) {\n return `${output.banner(oas as any)}\\n${banner}`\n }\n\n return `${output.banner}\\n${banner}`\n}\n","import type { Output } from '@kubb/core'\nimport type { Oas } from '@kubb/oas'\nimport { isFunction } from 'remeda'\n\ntype Props<TOas extends Oas> = {\n oas: TOas\n output: Output<any>\n}\n\nexport function getFooter<TOas extends Oas>({ output, oas }: Props<TOas>) {\n if (!output.footer) {\n return undefined\n }\n\n if (isFunction(output.footer)) {\n return output.footer(oas as any)\n }\n\n return output.footer\n}\n"],"mappings":";;;;;;;;;;;AAsBA,SAAS,gBAAgB,MAAc,QAAyB;AAS9D,QARmB,KAChB,MAAM,CACN,QAAQ,qBAAqB,QAAQ,CACrC,QAAQ,yBAAyB,QAAQ,CACzC,QAAQ,gBAAgB,QAAQ,CAEV,MAAM,gBAAgB,CAAC,OAAO,QAAQ,CAG5D,KAAK,MAAM,MAAM;AAEhB,MADiB,KAAK,SAAS,KAAK,SAAS,KAAK,aAAa,CACjD,QAAO;AACrB,MAAI,MAAM,KAAK,CAAC,OAAQ,QAAO,KAAK,OAAO,EAAE,CAAC,aAAa,GAAG,KAAK,MAAM,EAAE;AAC3E,SAAO,KAAK,OAAO,EAAE,CAAC,aAAa,GAAG,KAAK,MAAM,EAAE;GACnD,CACD,KAAK,GAAG,CACR,QAAQ,iBAAiB,GAAG;;;;;;;;;;AAWjC,SAAS,iBAAiB,MAAc,eAAkE;CACxG,MAAM,QAAQ,KAAK,MAAM,iBAAiB;AAC1C,QAAO,MAAM,KAAK,MAAM,MAAM,cAAc,MAAM,MAAM,MAAM,SAAS,EAAE,CAAC,CAAC,KAAK,IAAI;;;;;;;;;;AAWtF,SAAgB,UAAU,MAAc,EAAE,QAAQ,SAAS,IAAI,SAAS,OAAgB,EAAE,EAAU;AAClG,KAAI,OACF,QAAO,iBAAiB,OAAO,MAAM,WAAW,UAAU,MAAM,SAAS;EAAE;EAAQ;EAAQ,GAAG,EAAE,CAAC,CAAC;AAGpG,QAAO,gBAAgB,GAAG,OAAO,GAAG,KAAK,GAAG,UAAU,MAAM;;;;;;;;;;AAW9D,SAAgB,WAAW,MAAc,EAAE,QAAQ,SAAS,IAAI,SAAS,OAAgB,EAAE,EAAU;AACnG,KAAI,OACF,QAAO,iBAAiB,OAAO,MAAM,WAAY,SAAS,WAAW,MAAM;EAAE;EAAQ;EAAQ,CAAC,GAAG,UAAU,KAAK,CAAE;AAGpH,QAAO,gBAAgB,GAAG,OAAO,GAAG,KAAK,GAAG,UAAU,KAAK;;;;;;;;ACrE7D,SAAS,iBAAiB,EAAE,OAAO,aAAa,SAAS,UAA8F;AACrJ,KAAI;EACF,IAAI,SAAS;AACb,MAAI,UAAU,OAAO,MACnB,UAAS,KAAK,SAAS,OAAO,MAAM,KAAK;WAChC,UAAU,OAAO,MAC1B,UAAS;EAGX,IAAI,SAAS;AAEb,MAAI,OAAO,OAAO,kBAAkB,UAAU;AAC5C,aAAU;AACV,UAAO;;AAGT,MAAI,OACF,WAAU,aAAa,OAAO;AAGhC,MAAI,MACF,WAAU,YAAY,MAAM;AAG9B,MAAI,aAAa;GACf,MAAM,uBAAuB,YAAY,QAAQ,QAAQ,OAAO;AAChE,aAAU,kBAAkB,qBAAqB;;AAGnD,MAAI,QACF,WAAU,2BAA2B,QAAQ;AAG/C,YAAU;AACV,SAAO;UACA,QAAQ;AAEf,SAAO;;;AAIX,SAAgB,UAA4B,EAAE,QAAQ,KAAK,UAA+B;CACxF,IAAI,SAAS;AACb,KAAI,QAAQ,QAAQ,kBAAkB,SAAS,QAAQ;EACrD,MAAM,EAAE,OAAO,aAAa,YAAY,IAAI,KAAK,QAAQ,EAAE;AAE3D,WAAS,iBAAiB;GAAE;GAAO;GAAa;GAAS;GAAQ,CAAC;;AAGpE,KAAI,CAAC,OAAO,OACV,QAAO;AAGT,KAAI,WAAW,OAAO,OAAO,CAC3B,QAAO,GAAG,OAAO,OAAO,IAAW,CAAC,IAAI;AAG1C,QAAO,GAAG,OAAO,OAAO,IAAI;;;;AC/D9B,SAAgB,UAA4B,EAAE,QAAQ,OAAoB;AACxE,KAAI,CAAC,OAAO,OACV;AAGF,KAAI,WAAW,OAAO,OAAO,CAC3B,QAAO,OAAO,OAAO,IAAW;AAGlC,QAAO,OAAO"}
|
|
@@ -21,9 +21,12 @@ function toCamelOrPascal(text, pascal) {
|
|
|
21
21
|
* Splits `text` on `.` and applies `transformPart` to each segment.
|
|
22
22
|
* The last segment receives `isLast = true`, all earlier segments receive `false`.
|
|
23
23
|
* Segments are joined with `/` to form a file path.
|
|
24
|
+
*
|
|
25
|
+
* Only splits on dots followed by a letter so that version numbers
|
|
26
|
+
* embedded in operationIds (e.g. `v2025.0`) are kept intact.
|
|
24
27
|
*/
|
|
25
28
|
function applyToFileParts(text, transformPart) {
|
|
26
|
-
const parts = text.split(
|
|
29
|
+
const parts = text.split(/\.(?=[a-zA-Z])/);
|
|
27
30
|
return parts.map((part, i) => transformPart(part, i === parts.length - 1)).join("/");
|
|
28
31
|
}
|
|
29
32
|
/**
|
|
@@ -133,4 +136,4 @@ Object.defineProperty(exports, "pascalCase", {
|
|
|
133
136
|
}
|
|
134
137
|
});
|
|
135
138
|
|
|
136
|
-
//# sourceMappingURL=getFooter-
|
|
139
|
+
//# sourceMappingURL=getFooter-gshcRE1-.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getFooter-gshcRE1-.cjs","names":["path"],"sources":["../../../internals/utils/src/casing.ts","../src/utils/getBanner.ts","../src/utils/getFooter.ts"],"sourcesContent":["type Options = {\n /**\n * When `true`, dot-separated segments are split on `.` and joined with `/` after casing.\n */\n isFile?: boolean\n /**\n * Text prepended before casing is applied.\n */\n prefix?: string\n /**\n * Text appended before casing is applied.\n */\n suffix?: string\n}\n\n/**\n * Shared implementation for camelCase and PascalCase conversion.\n * Splits on common word boundaries (spaces, hyphens, underscores, dots, slashes, colons)\n * and capitalizes each word according to `pascal`.\n *\n * When `pascal` is `true` the first word is also capitalized (PascalCase), otherwise only subsequent words are.\n */\nfunction toCamelOrPascal(text: string, pascal: boolean): string {\n const normalized = text\n .trim()\n .replace(/([a-z\\d])([A-Z])/g, '$1 $2')\n .replace(/([A-Z]+)([A-Z][a-z])/g, '$1 $2')\n .replace(/(\\d)([a-z])/g, '$1 $2')\n\n const words = normalized.split(/[\\s\\-_./\\\\:]+/).filter(Boolean)\n\n return words\n .map((word, i) => {\n const allUpper = word.length > 1 && word === word.toUpperCase()\n if (allUpper) return word\n if (i === 0 && !pascal) return word.charAt(0).toLowerCase() + word.slice(1)\n return word.charAt(0).toUpperCase() + word.slice(1)\n })\n .join('')\n .replace(/[^a-zA-Z0-9]/g, '')\n}\n\n/**\n * Splits `text` on `.` and applies `transformPart` to each segment.\n * The last segment receives `isLast = true`, all earlier segments receive `false`.\n * Segments are joined with `/` to form a file path.\n *\n * Only splits on dots followed by a letter so that version numbers\n * embedded in operationIds (e.g. `v2025.0`) are kept intact.\n */\nfunction applyToFileParts(text: string, transformPart: (part: string, isLast: boolean) => string): string {\n const parts = text.split(/\\.(?=[a-zA-Z])/)\n return parts.map((part, i) => transformPart(part, i === parts.length - 1)).join('/')\n}\n\n/**\n * Converts `text` to camelCase.\n * When `isFile` is `true`, dot-separated segments are each cased independently and joined with `/`.\n *\n * @example\n * camelCase('hello-world') // 'helloWorld'\n * camelCase('pet.petId', { isFile: true }) // 'pet/petId'\n */\nexport function camelCase(text: string, { isFile, prefix = '', suffix = '' }: Options = {}): string {\n if (isFile) {\n return applyToFileParts(text, (part, isLast) => camelCase(part, isLast ? { prefix, suffix } : {}))\n }\n\n return toCamelOrPascal(`${prefix} ${text} ${suffix}`, false)\n}\n\n/**\n * Converts `text` to PascalCase.\n * When `isFile` is `true`, the last dot-separated segment is PascalCased and earlier segments are camelCased.\n *\n * @example\n * pascalCase('hello-world') // 'HelloWorld'\n * pascalCase('pet.petId', { isFile: true }) // 'pet/PetId'\n */\nexport function pascalCase(text: string, { isFile, prefix = '', suffix = '' }: Options = {}): string {\n if (isFile) {\n return applyToFileParts(text, (part, isLast) => (isLast ? pascalCase(part, { prefix, suffix }) : camelCase(part)))\n }\n\n return toCamelOrPascal(`${prefix} ${text} ${suffix}`, true)\n}\n\n/**\n * Converts `text` to snake_case.\n *\n * @example\n * snakeCase('helloWorld') // 'hello_world'\n * snakeCase('Hello-World') // 'hello_world'\n */\nexport function snakeCase(text: string, { prefix = '', suffix = '' }: Omit<Options, 'isFile'> = {}): string {\n const processed = `${prefix} ${text} ${suffix}`.trim()\n return processed\n .replace(/([a-z])([A-Z])/g, '$1_$2')\n .replace(/[\\s\\-.]+/g, '_')\n .replace(/[^a-zA-Z0-9_]/g, '')\n .toLowerCase()\n .split('_')\n .filter(Boolean)\n .join('_')\n}\n\n/**\n * Converts `text` to SCREAMING_SNAKE_CASE.\n *\n * @example\n * screamingSnakeCase('helloWorld') // 'HELLO_WORLD'\n */\nexport function screamingSnakeCase(text: string, { prefix = '', suffix = '' }: Omit<Options, 'isFile'> = {}): string {\n return snakeCase(text, { prefix, suffix }).toUpperCase()\n}\n","import path from 'node:path'\nimport type { Config, Output } from '@kubb/core'\nimport type { Oas } from '@kubb/oas'\nimport { isFunction } from 'remeda'\n\ntype Props<TOas extends Oas> = {\n oas: TOas\n output: Output<any>\n config?: Config\n}\n\n/**\n * Generate a default banner for files created by Kubb\n * @returns A string with the default banner\n */\nfunction getDefaultBanner({ title, description, version, config }: { title?: string; description?: string; version?: string; config: Config }): string {\n try {\n let source = ''\n if ('path' in config.input) {\n source = path.basename(config.input.path)\n } else if ('data' in config.input) {\n source = 'text content'\n }\n\n let banner = '/**\\n* Generated by Kubb (https://kubb.dev/).\\n* Do not edit manually.\\n'\n\n if (config.output.defaultBanner === 'simple') {\n banner += '*/\\n'\n return banner\n }\n\n if (source) {\n banner += `* Source: ${source}\\n`\n }\n\n if (title) {\n banner += `* Title: ${title}\\n`\n }\n\n if (description) {\n const formattedDescription = description.replace(/\\n/gm, '\\n* ')\n banner += `* Description: ${formattedDescription}\\n`\n }\n\n if (version) {\n banner += `* OpenAPI spec version: ${version}\\n`\n }\n\n banner += '*/\\n'\n return banner\n } catch (_error) {\n // If there's any error in parsing the Oas data, return a simpler banner\n return '/**\\n* Generated by Kubb (https://kubb.dev/).\\n* Do not edit manually.\\n*/'\n }\n}\n\nexport function getBanner<TOas extends Oas>({ output, oas, config }: Props<TOas>): string {\n let banner = ''\n if (config?.output?.defaultBanner !== false && config) {\n const { title, description, version } = oas.api?.info || {}\n\n banner = getDefaultBanner({ title, description, version, config })\n }\n\n if (!output.banner) {\n return banner\n }\n\n if (isFunction(output.banner)) {\n return `${output.banner(oas as any)}\\n${banner}`\n }\n\n return `${output.banner}\\n${banner}`\n}\n","import type { Output } from '@kubb/core'\nimport type { Oas } from '@kubb/oas'\nimport { isFunction } from 'remeda'\n\ntype Props<TOas extends Oas> = {\n oas: TOas\n output: Output<any>\n}\n\nexport function getFooter<TOas extends Oas>({ output, oas }: Props<TOas>) {\n if (!output.footer) {\n return undefined\n }\n\n if (isFunction(output.footer)) {\n return output.footer(oas as any)\n }\n\n return output.footer\n}\n"],"mappings":";;;;;;;;;;;;AAsBA,SAAS,gBAAgB,MAAc,QAAyB;AAS9D,QARmB,KAChB,MAAM,CACN,QAAQ,qBAAqB,QAAQ,CACrC,QAAQ,yBAAyB,QAAQ,CACzC,QAAQ,gBAAgB,QAAQ,CAEV,MAAM,gBAAgB,CAAC,OAAO,QAAQ,CAG5D,KAAK,MAAM,MAAM;AAEhB,MADiB,KAAK,SAAS,KAAK,SAAS,KAAK,aAAa,CACjD,QAAO;AACrB,MAAI,MAAM,KAAK,CAAC,OAAQ,QAAO,KAAK,OAAO,EAAE,CAAC,aAAa,GAAG,KAAK,MAAM,EAAE;AAC3E,SAAO,KAAK,OAAO,EAAE,CAAC,aAAa,GAAG,KAAK,MAAM,EAAE;GACnD,CACD,KAAK,GAAG,CACR,QAAQ,iBAAiB,GAAG;;;;;;;;;;AAWjC,SAAS,iBAAiB,MAAc,eAAkE;CACxG,MAAM,QAAQ,KAAK,MAAM,iBAAiB;AAC1C,QAAO,MAAM,KAAK,MAAM,MAAM,cAAc,MAAM,MAAM,MAAM,SAAS,EAAE,CAAC,CAAC,KAAK,IAAI;;;;;;;;;;AAWtF,SAAgB,UAAU,MAAc,EAAE,QAAQ,SAAS,IAAI,SAAS,OAAgB,EAAE,EAAU;AAClG,KAAI,OACF,QAAO,iBAAiB,OAAO,MAAM,WAAW,UAAU,MAAM,SAAS;EAAE;EAAQ;EAAQ,GAAG,EAAE,CAAC,CAAC;AAGpG,QAAO,gBAAgB,GAAG,OAAO,GAAG,KAAK,GAAG,UAAU,MAAM;;;;;;;;;;AAW9D,SAAgB,WAAW,MAAc,EAAE,QAAQ,SAAS,IAAI,SAAS,OAAgB,EAAE,EAAU;AACnG,KAAI,OACF,QAAO,iBAAiB,OAAO,MAAM,WAAY,SAAS,WAAW,MAAM;EAAE;EAAQ;EAAQ,CAAC,GAAG,UAAU,KAAK,CAAE;AAGpH,QAAO,gBAAgB,GAAG,OAAO,GAAG,KAAK,GAAG,UAAU,KAAK;;;;;;;;ACrE7D,SAAS,iBAAiB,EAAE,OAAO,aAAa,SAAS,UAA8F;AACrJ,KAAI;EACF,IAAI,SAAS;AACb,MAAI,UAAU,OAAO,MACnB,UAASA,UAAAA,QAAK,SAAS,OAAO,MAAM,KAAK;WAChC,UAAU,OAAO,MAC1B,UAAS;EAGX,IAAI,SAAS;AAEb,MAAI,OAAO,OAAO,kBAAkB,UAAU;AAC5C,aAAU;AACV,UAAO;;AAGT,MAAI,OACF,WAAU,aAAa,OAAO;AAGhC,MAAI,MACF,WAAU,YAAY,MAAM;AAG9B,MAAI,aAAa;GACf,MAAM,uBAAuB,YAAY,QAAQ,QAAQ,OAAO;AAChE,aAAU,kBAAkB,qBAAqB;;AAGnD,MAAI,QACF,WAAU,2BAA2B,QAAQ;AAG/C,YAAU;AACV,SAAO;UACA,QAAQ;AAEf,SAAO;;;AAIX,SAAgB,UAA4B,EAAE,QAAQ,KAAK,UAA+B;CACxF,IAAI,SAAS;AACb,KAAI,QAAQ,QAAQ,kBAAkB,SAAS,QAAQ;EACrD,MAAM,EAAE,OAAO,aAAa,YAAY,IAAI,KAAK,QAAQ,EAAE;AAE3D,WAAS,iBAAiB;GAAE;GAAO;GAAa;GAAS;GAAQ,CAAC;;AAGpE,KAAI,CAAC,OAAO,OACV,QAAO;AAGT,MAAA,GAAA,OAAA,YAAe,OAAO,OAAO,CAC3B,QAAO,GAAG,OAAO,OAAO,IAAW,CAAC,IAAI;AAG1C,QAAO,GAAG,OAAO,OAAO,IAAI;;;;AC/D9B,SAAgB,UAA4B,EAAE,QAAQ,OAAoB;AACxE,KAAI,CAAC,OAAO,OACV;AAGF,MAAA,GAAA,OAAA,YAAe,OAAO,OAAO,CAC3B,QAAO,OAAO,OAAO,IAAW;AAGlC,QAAO,OAAO"}
|