@kubb/plugin-oas 3.16.2 → 3.16.4
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/Oas-CuqAnIw-.js +60 -0
- package/dist/Oas-CuqAnIw-.js.map +1 -0
- package/dist/Oas-Cv_pyXRM.cjs +78 -0
- package/dist/Oas-Cv_pyXRM.cjs.map +1 -0
- package/dist/OperationGenerator-CgbXErhW.d.cts +900 -0
- package/dist/OperationGenerator-OtLcGk2y.d.ts +900 -0
- package/dist/Schema-DJshqHto.d.cts +38 -0
- package/dist/Schema-DOXGUW1m.d.ts +38 -0
- package/dist/SchemaGenerator-8205BXCp.cjs +942 -0
- package/dist/SchemaGenerator-8205BXCp.cjs.map +1 -0
- package/dist/SchemaGenerator-B8Io6kky.js +930 -0
- package/dist/SchemaGenerator-B8Io6kky.js.map +1 -0
- package/dist/SchemaMapper-BaZQKrQB.js +54 -0
- package/dist/SchemaMapper-BaZQKrQB.js.map +1 -0
- package/dist/SchemaMapper-BiagBQN4.d.cts +388 -0
- package/dist/SchemaMapper-C2J2d3o4.d.ts +388 -0
- package/dist/SchemaMapper-D8J0V9Pj.cjs +66 -0
- package/dist/SchemaMapper-D8J0V9Pj.cjs.map +1 -0
- package/dist/chunk-CUT6urMc.cjs +30 -0
- package/dist/components.cjs +4 -19
- package/dist/components.d.cts +42 -35
- package/dist/components.d.ts +42 -35
- package/dist/components.js +3 -3
- package/dist/generators-BhLMlRNk.js +137 -0
- package/dist/generators-BhLMlRNk.js.map +1 -0
- package/dist/generators-DLH2kvlh.cjs +155 -0
- package/dist/generators-DLH2kvlh.cjs.map +1 -0
- package/dist/generators.cjs +4 -13
- package/dist/generators.d.cts +5 -7
- package/dist/generators.d.ts +5 -7
- package/dist/generators.js +5 -5
- package/dist/getFooter-BChY2kC1.cjs +43 -0
- package/dist/getFooter-BChY2kC1.cjs.map +1 -0
- package/dist/getFooter-T7_pZ6f8.js +31 -0
- package/dist/getFooter-T7_pZ6f8.js.map +1 -0
- package/dist/getSchemas-D8mP129c.cjs +67 -0
- package/dist/getSchemas-D8mP129c.cjs.map +1 -0
- package/dist/getSchemas-WoSBIxG8.js +55 -0
- package/dist/getSchemas-WoSBIxG8.js.map +1 -0
- package/dist/hooks.cjs +213 -195
- package/dist/hooks.cjs.map +1 -1
- package/dist/hooks.d.cts +91 -86
- package/dist/hooks.d.ts +91 -86
- package/dist/hooks.js +212 -193
- package/dist/hooks.js.map +1 -1
- package/dist/index.cjs +280 -342
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +7 -10
- package/dist/index.d.ts +7 -10
- package/dist/index.js +274 -318
- package/dist/index.js.map +1 -1
- package/dist/mocks.cjs +802 -737
- package/dist/mocks.cjs.map +1 -1
- package/dist/mocks.d.cts +12 -11
- package/dist/mocks.d.ts +12 -11
- package/dist/mocks.js +802 -735
- package/dist/mocks.js.map +1 -1
- package/dist/parseFromConfig-CMNGsef2.cjs +33 -0
- package/dist/parseFromConfig-CMNGsef2.cjs.map +1 -0
- package/dist/parseFromConfig-yAiFK03V.js +27 -0
- package/dist/parseFromConfig-yAiFK03V.js.map +1 -0
- package/dist/utils.cjs +58 -74
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.d.cts +96 -42
- package/dist/utils.d.ts +96 -42
- package/dist/utils.js +47 -46
- package/dist/utils.js.map +1 -1
- package/package.json +26 -34
- package/src/components/Operation.tsx +1 -2
- package/src/mocks/schemas.ts +39 -0
- package/src/utils/getBanner.ts +5 -5
- package/src/utils/getFooter.ts +4 -4
- package/dist/OperationGenerator-C7NPZtOM.d.ts +0 -288
- package/dist/OperationGenerator-DJE2XQ83.d.cts +0 -288
- package/dist/Schema-AjebpeVY.d.ts +0 -32
- package/dist/Schema-M6983FL1.d.cts +0 -32
- package/dist/SchemaMapper-B21ZmWag.d.cts +0 -275
- package/dist/SchemaMapper-B21ZmWag.d.ts +0 -275
- package/dist/chunk-6S7YFY6F.js +0 -33
- package/dist/chunk-6S7YFY6F.js.map +0 -1
- package/dist/chunk-76E35IZ2.js +0 -56
- package/dist/chunk-76E35IZ2.js.map +0 -1
- package/dist/chunk-7RFNM43R.cjs +0 -41
- package/dist/chunk-7RFNM43R.cjs.map +0 -1
- package/dist/chunk-DTD4ZUDA.cjs +0 -36
- package/dist/chunk-DTD4ZUDA.cjs.map +0 -1
- package/dist/chunk-G3FDK7YW.js +0 -35
- package/dist/chunk-G3FDK7YW.js.map +0 -1
- package/dist/chunk-JNN4JPWK.js +0 -28
- package/dist/chunk-JNN4JPWK.js.map +0 -1
- package/dist/chunk-MBX66JAT.js +0 -93
- package/dist/chunk-MBX66JAT.js.map +0 -1
- package/dist/chunk-NC5PWNEF.js +0 -866
- package/dist/chunk-NC5PWNEF.js.map +0 -1
- package/dist/chunk-PORSNYI5.js +0 -47
- package/dist/chunk-PORSNYI5.js.map +0 -1
- package/dist/chunk-QJMOOF2A.cjs +0 -97
- package/dist/chunk-QJMOOF2A.cjs.map +0 -1
- package/dist/chunk-RKHCI3WI.cjs +0 -1002
- package/dist/chunk-RKHCI3WI.cjs.map +0 -1
- package/dist/chunk-YWMMI3MO.cjs +0 -59
- package/dist/chunk-YWMMI3MO.cjs.map +0 -1
- package/dist/chunk-Z2NREI4X.cjs +0 -32
- package/dist/chunk-Z2NREI4X.cjs.map +0 -1
- package/dist/chunk-ZVFL3NXX.cjs +0 -50
- package/dist/chunk-ZVFL3NXX.cjs.map +0 -1
- package/dist/components.cjs.map +0 -1
- package/dist/components.js.map +0 -1
- package/dist/generators.cjs.map +0 -1
- package/dist/generators.js.map +0 -1
|
@@ -0,0 +1,900 @@
|
|
|
1
|
+
import { BaseName, Extname, File, Mode, OptionalPath, Path, ResolvedFile, Schema, SchemaKeywordMapper } from "./SchemaMapper-BiagBQN4.cjs";
|
|
2
|
+
import { Key, ReactNode } from "react";
|
|
3
|
+
import * as OasTypes from "oas/types";
|
|
4
|
+
import { HttpMethods as HttpMethod, OASDocument, SchemaObject, User } from "oas/types";
|
|
5
|
+
import { Operation, Operation as Operation$1 } from "oas/operation";
|
|
6
|
+
import { OpenAPIV3, OpenAPIV3 as OpenAPIV3$1, OpenAPIV3_1 } from "openapi-types";
|
|
7
|
+
import * as oas_normalize_lib_types0 from "oas-normalize/lib/types";
|
|
8
|
+
import BaseOas from "oas";
|
|
9
|
+
import { ConsolaInstance, LogLevel } from "consola";
|
|
10
|
+
|
|
11
|
+
//#region ../oas/src/types.d.ts
|
|
12
|
+
type contentType = 'application/json' | (string & {});
|
|
13
|
+
type SchemaObject$1 = OasTypes.SchemaObject & {
|
|
14
|
+
'x-nullable'?: boolean;
|
|
15
|
+
$ref?: string;
|
|
16
|
+
};
|
|
17
|
+
//#endregion
|
|
18
|
+
//#region ../oas/src/Oas.d.ts
|
|
19
|
+
type Options$3 = {
|
|
20
|
+
contentType?: contentType;
|
|
21
|
+
discriminator?: 'strict' | 'inherit';
|
|
22
|
+
};
|
|
23
|
+
declare class Oas<const TOAS = unknown> extends BaseOas {
|
|
24
|
+
#private;
|
|
25
|
+
document: TOAS;
|
|
26
|
+
constructor({
|
|
27
|
+
oas,
|
|
28
|
+
user
|
|
29
|
+
}: {
|
|
30
|
+
oas: TOAS | OASDocument | string;
|
|
31
|
+
user?: User;
|
|
32
|
+
});
|
|
33
|
+
setOptions(options: Options$3): void;
|
|
34
|
+
get options(): Options$3;
|
|
35
|
+
get($ref: string): any;
|
|
36
|
+
getKey($ref: string): string | undefined;
|
|
37
|
+
set($ref: string, value: unknown): false | undefined;
|
|
38
|
+
getDiscriminator(schema: OasTypes.SchemaObject): OpenAPIV3.DiscriminatorObject | undefined;
|
|
39
|
+
dereferenceWithRef(schema?: unknown): any;
|
|
40
|
+
getResponseSchema(operation: Operation, statusCode: string | number): SchemaObject;
|
|
41
|
+
getRequestSchema(operation: Operation): SchemaObject | undefined;
|
|
42
|
+
getParametersSchema(operation: Operation, inKey: 'path' | 'query' | 'header'): SchemaObject | null;
|
|
43
|
+
valdiate(): Promise<oas_normalize_lib_types0.ValidationResult>;
|
|
44
|
+
}
|
|
45
|
+
//#endregion
|
|
46
|
+
//#region ../react/src/utils/getFunctionParams.d.ts
|
|
47
|
+
type Param = {
|
|
48
|
+
/**
|
|
49
|
+
* `object` will return the pathParams as an object.
|
|
50
|
+
*
|
|
51
|
+
* `inline` will return the pathParams as comma separated params.
|
|
52
|
+
* @default `'inline'`
|
|
53
|
+
* @private
|
|
54
|
+
*/
|
|
55
|
+
mode?: 'object' | 'inline' | 'inlineSpread';
|
|
56
|
+
type?: 'string' | 'number' | (string & {});
|
|
57
|
+
optional?: boolean;
|
|
58
|
+
/**
|
|
59
|
+
* @example test = "default"
|
|
60
|
+
*/
|
|
61
|
+
default?: string;
|
|
62
|
+
/**
|
|
63
|
+
* Used for no TypeScript(with mode object)
|
|
64
|
+
* @example test: "default"
|
|
65
|
+
*/
|
|
66
|
+
value?: string;
|
|
67
|
+
children?: Params;
|
|
68
|
+
};
|
|
69
|
+
type Params = Record<string, Param | undefined>;
|
|
70
|
+
//#endregion
|
|
71
|
+
//#region ../react/src/types.d.ts
|
|
72
|
+
type KubbNode = ReactNode;
|
|
73
|
+
//#endregion
|
|
74
|
+
//#region ../core/src/BaseGenerator.d.ts
|
|
75
|
+
/**
|
|
76
|
+
* Abstract class that contains the building blocks for plugins to create their own Generator
|
|
77
|
+
* @link idea based on https://github.com/colinhacks/zod/blob/master/src/types.ts#L137
|
|
78
|
+
*/
|
|
79
|
+
declare abstract class BaseGenerator<TOptions = unknown, TContext = unknown> {
|
|
80
|
+
#private;
|
|
81
|
+
constructor(options?: TOptions, context?: TContext);
|
|
82
|
+
get options(): TOptions;
|
|
83
|
+
get context(): TContext;
|
|
84
|
+
set options(options: TOptions);
|
|
85
|
+
abstract build(...params: unknown[]): unknown;
|
|
86
|
+
}
|
|
87
|
+
//#endregion
|
|
88
|
+
//#region ../core/src/utils/EventEmitter.d.ts
|
|
89
|
+
declare class EventEmitter<TEvents extends Record<string, any>> {
|
|
90
|
+
#private;
|
|
91
|
+
constructor();
|
|
92
|
+
emit<TEventName extends keyof TEvents & string>(eventName: TEventName, ...eventArg: TEvents[TEventName]): void;
|
|
93
|
+
on<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: (...eventArg: TEvents[TEventName]) => void): void;
|
|
94
|
+
off<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: (...eventArg: TEvents[TEventName]) => void): void;
|
|
95
|
+
removeAll(): void;
|
|
96
|
+
}
|
|
97
|
+
//#endregion
|
|
98
|
+
//#region ../core/src/logger.d.ts
|
|
99
|
+
type DebugEvent = {
|
|
100
|
+
date: Date;
|
|
101
|
+
logs: string[];
|
|
102
|
+
fileName?: string;
|
|
103
|
+
};
|
|
104
|
+
type Events$1 = {
|
|
105
|
+
start: [message: string];
|
|
106
|
+
success: [message: string];
|
|
107
|
+
error: [message: string, cause: Error];
|
|
108
|
+
warning: [message: string];
|
|
109
|
+
debug: [DebugEvent];
|
|
110
|
+
info: [message: string];
|
|
111
|
+
progress_start: [{
|
|
112
|
+
id: string;
|
|
113
|
+
size: number;
|
|
114
|
+
message?: string;
|
|
115
|
+
}];
|
|
116
|
+
progressed: [{
|
|
117
|
+
id: string;
|
|
118
|
+
message?: string;
|
|
119
|
+
}];
|
|
120
|
+
progress_stop: [{
|
|
121
|
+
id: string;
|
|
122
|
+
}];
|
|
123
|
+
};
|
|
124
|
+
type Logger = {
|
|
125
|
+
/**
|
|
126
|
+
* Optional config name to show in CLI output
|
|
127
|
+
*/
|
|
128
|
+
name?: string;
|
|
129
|
+
logLevel: LogLevel;
|
|
130
|
+
consola?: ConsolaInstance;
|
|
131
|
+
on: EventEmitter<Events$1>['on'];
|
|
132
|
+
emit: EventEmitter<Events$1>['emit'];
|
|
133
|
+
writeLogs: () => Promise<string[]>;
|
|
134
|
+
};
|
|
135
|
+
//#endregion
|
|
136
|
+
//#region ../core/src/utils/types.d.ts
|
|
137
|
+
type PossiblePromise<T> = Promise<T> | T;
|
|
138
|
+
type ArrayWithLength<T extends number, U extends any[] = []> = U['length'] extends T ? U : ArrayWithLength<T, [true, ...U]>;
|
|
139
|
+
type GreaterThan<T extends number, U extends number> = ArrayWithLength<U> extends [...ArrayWithLength<T>, ...infer _] ? false : true;
|
|
140
|
+
//#endregion
|
|
141
|
+
//#region ../core/src/types.d.ts
|
|
142
|
+
type InputPath = {
|
|
143
|
+
/**
|
|
144
|
+
* Specify your Swagger/OpenAPI file, either as an absolute path or a path relative to the root.
|
|
145
|
+
*/
|
|
146
|
+
path: string;
|
|
147
|
+
};
|
|
148
|
+
type InputData = {
|
|
149
|
+
/**
|
|
150
|
+
* A `string` or `object` that contains your Swagger/OpenAPI data.
|
|
151
|
+
*/
|
|
152
|
+
data: string | unknown;
|
|
153
|
+
};
|
|
154
|
+
type Input = InputPath | InputData | Array<InputPath>;
|
|
155
|
+
type BarrelType = 'all' | 'named' | 'propagate';
|
|
156
|
+
/**
|
|
157
|
+
* @private
|
|
158
|
+
*/
|
|
159
|
+
type Config<TInput = Input> = {
|
|
160
|
+
/**
|
|
161
|
+
* The name to display in the CLI output.
|
|
162
|
+
*/
|
|
163
|
+
name?: string;
|
|
164
|
+
/**
|
|
165
|
+
* The project root directory, which can be either an absolute path or a path relative to the location of your `kubb.config.ts` file.
|
|
166
|
+
* @default process.cwd()
|
|
167
|
+
*/
|
|
168
|
+
root: string;
|
|
169
|
+
/**
|
|
170
|
+
* You can use either `input.path` or `input.data`, depending on your specific needs.
|
|
171
|
+
*/
|
|
172
|
+
input: TInput;
|
|
173
|
+
output: {
|
|
174
|
+
/**
|
|
175
|
+
* The path where all generated files will be exported.
|
|
176
|
+
* This can be an absolute path or a path relative to the specified root option.
|
|
177
|
+
*/
|
|
178
|
+
path: string;
|
|
179
|
+
/**
|
|
180
|
+
* Clean the output directory before each build.
|
|
181
|
+
*/
|
|
182
|
+
clean?: boolean;
|
|
183
|
+
/**
|
|
184
|
+
* Save files to the file system.
|
|
185
|
+
* @default true
|
|
186
|
+
*/
|
|
187
|
+
write?: boolean;
|
|
188
|
+
/**
|
|
189
|
+
* Override the extension to the generated imports and exports, by default each plugin will add an extension
|
|
190
|
+
* @default { '.ts': '.ts'}
|
|
191
|
+
*/
|
|
192
|
+
extension?: Record<Extname, Extname | ''>;
|
|
193
|
+
/**
|
|
194
|
+
* Specify how `index.ts` files should be created. You can also disable the generation of barrel files here. While each plugin has its own `barrelType` option, this setting controls the creation of the root barrel file, such as` src/gen/index.ts`.
|
|
195
|
+
* @default 'named'
|
|
196
|
+
*/
|
|
197
|
+
barrelType?: Exclude<BarrelType, 'propagate'> | false;
|
|
198
|
+
/**
|
|
199
|
+
* Add a default banner to the beginning of every generated file. This makes it clear that the file was generated by Kubb.
|
|
200
|
+
* - 'simple': will only add banner with link to Kubb
|
|
201
|
+
* - 'full': will add source, title, description and the OpenAPI version used
|
|
202
|
+
* @default 'simple'
|
|
203
|
+
*/
|
|
204
|
+
defaultBanner?: 'simple' | 'full' | false;
|
|
205
|
+
};
|
|
206
|
+
/**
|
|
207
|
+
* An array of Kubb plugins that will be used in the generation.
|
|
208
|
+
* Each plugin may include additional configurable options(defined in the plugin itself).
|
|
209
|
+
* If a plugin depends on another plugin, an error will be returned if the required dependency is missing. See pre for more details.
|
|
210
|
+
*/
|
|
211
|
+
plugins?: Array<Plugin>;
|
|
212
|
+
/**
|
|
213
|
+
* Hooks that will be called when a specific action is triggered in Kubb.
|
|
214
|
+
*/
|
|
215
|
+
hooks?: {
|
|
216
|
+
/**
|
|
217
|
+
* Hook that will be triggered at the end of all executions.
|
|
218
|
+
* Useful for running Prettier or ESLint to format/lint your code.
|
|
219
|
+
*/
|
|
220
|
+
done?: string | Array<string>;
|
|
221
|
+
};
|
|
222
|
+
};
|
|
223
|
+
type PluginFactoryOptions<
|
|
224
|
+
/**
|
|
225
|
+
* Name to be used for the plugin, this will also be used for they key.
|
|
226
|
+
*/
|
|
227
|
+
TName extends string = string,
|
|
228
|
+
/**
|
|
229
|
+
* Options of the plugin.
|
|
230
|
+
*/
|
|
231
|
+
TOptions extends object = object,
|
|
232
|
+
/**
|
|
233
|
+
* Options of the plugin that can be used later on, see `options` inside your plugin config.
|
|
234
|
+
*/
|
|
235
|
+
TResolvedOptions extends object = TOptions,
|
|
236
|
+
/**
|
|
237
|
+
* Context that you want to expose to other plugins.
|
|
238
|
+
*/
|
|
239
|
+
TContext = any,
|
|
240
|
+
/**
|
|
241
|
+
* When calling `resolvePath` you can specify better types.
|
|
242
|
+
*/
|
|
243
|
+
TResolvePathOptions extends object = object> = {
|
|
244
|
+
name: TName;
|
|
245
|
+
/**
|
|
246
|
+
* Same behaviour like what has been done with `QueryKey` in `@tanstack/react-query`
|
|
247
|
+
*/
|
|
248
|
+
key: PluginKey<TName | string>;
|
|
249
|
+
options: TOptions;
|
|
250
|
+
resolvedOptions: TResolvedOptions;
|
|
251
|
+
context: TContext;
|
|
252
|
+
resolvePathOptions: TResolvePathOptions;
|
|
253
|
+
};
|
|
254
|
+
type PluginKey<TName> = [name: TName, identifier?: string | number];
|
|
255
|
+
type UserPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
256
|
+
/**
|
|
257
|
+
* Unique name used for the plugin
|
|
258
|
+
* The name of the plugin follows the format scope:foo-bar or foo-bar, adding scope: can avoid naming conflicts with other plugins.
|
|
259
|
+
* @example @kubb/typescript
|
|
260
|
+
*/
|
|
261
|
+
name: TOptions['name'];
|
|
262
|
+
/**
|
|
263
|
+
* Options set for a specific plugin(see kubb.config.js), passthrough of options.
|
|
264
|
+
*/
|
|
265
|
+
options: TOptions['resolvedOptions'];
|
|
266
|
+
/**
|
|
267
|
+
* Specifies the preceding plugins for the current plugin. You can pass an array of preceding plugin names, and the current plugin will be executed after these plugins.
|
|
268
|
+
* Can be used to validate dependent plugins.
|
|
269
|
+
*/
|
|
270
|
+
pre?: Array<string>;
|
|
271
|
+
/**
|
|
272
|
+
* Specifies the succeeding plugins for the current plugin. You can pass an array of succeeding plugin names, and the current plugin will be executed before these plugins.
|
|
273
|
+
*/
|
|
274
|
+
post?: Array<string>;
|
|
275
|
+
} & (TOptions['context'] extends never ? {
|
|
276
|
+
context?: never;
|
|
277
|
+
} : {
|
|
278
|
+
context: (this: TOptions['name'] extends 'core' ? null : Omit<PluginContext<TOptions>, 'addFile'>) => TOptions['context'];
|
|
279
|
+
});
|
|
280
|
+
type UserPluginWithLifeCycle<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = UserPlugin<TOptions> & PluginLifecycle<TOptions>;
|
|
281
|
+
type Plugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
282
|
+
/**
|
|
283
|
+
* Unique name used for the plugin
|
|
284
|
+
* @example @kubb/typescript
|
|
285
|
+
*/
|
|
286
|
+
name: TOptions['name'];
|
|
287
|
+
/**
|
|
288
|
+
* Internal key used when a developer uses more than one of the same plugin
|
|
289
|
+
* @private
|
|
290
|
+
*/
|
|
291
|
+
key: TOptions['key'];
|
|
292
|
+
/**
|
|
293
|
+
* Specifies the preceding plugins for the current plugin. You can pass an array of preceding plugin names, and the current plugin will be executed after these plugins.
|
|
294
|
+
* Can be used to validate dependent plugins.
|
|
295
|
+
*/
|
|
296
|
+
pre?: Array<string>;
|
|
297
|
+
/**
|
|
298
|
+
* Specifies the succeeding plugins for the current plugin. You can pass an array of succeeding plugin names, and the current plugin will be executed before these plugins.
|
|
299
|
+
*/
|
|
300
|
+
post?: Array<string>;
|
|
301
|
+
/**
|
|
302
|
+
* Options set for a specific plugin(see kubb.config.js), passthrough of options.
|
|
303
|
+
*/
|
|
304
|
+
options: TOptions['resolvedOptions'];
|
|
305
|
+
} & (TOptions['context'] extends never ? {
|
|
306
|
+
context?: never;
|
|
307
|
+
} : {
|
|
308
|
+
context: TOptions['context'];
|
|
309
|
+
});
|
|
310
|
+
type PluginWithLifeCycle<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = Plugin<TOptions> & PluginLifecycle<TOptions>;
|
|
311
|
+
type PluginLifecycle<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
312
|
+
/**
|
|
313
|
+
* Start of the lifecycle of a plugin.
|
|
314
|
+
* @type hookParallel
|
|
315
|
+
*/
|
|
316
|
+
buildStart?: (this: PluginContext<TOptions>, Config: Config) => PossiblePromise<void>;
|
|
317
|
+
/**
|
|
318
|
+
* Resolve to a Path based on a baseName(example: `./Pet.ts`) and directory(example: `./models`).
|
|
319
|
+
* Options can als be included.
|
|
320
|
+
* @type hookFirst
|
|
321
|
+
* @example ('./Pet.ts', './src/gen/') => '/src/gen/Pet.ts'
|
|
322
|
+
*/
|
|
323
|
+
resolvePath?: (this: PluginContext<TOptions>, baseName: BaseName, mode?: Mode, options?: TOptions['resolvePathOptions']) => OptionalPath;
|
|
324
|
+
/**
|
|
325
|
+
* Resolve to a name based on a string.
|
|
326
|
+
* Useful when converting to PascalCase or camelCase.
|
|
327
|
+
* @type hookFirst
|
|
328
|
+
* @example ('pet') => 'Pet'
|
|
329
|
+
*/
|
|
330
|
+
resolveName?: (this: PluginContext<TOptions>, name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string;
|
|
331
|
+
/**
|
|
332
|
+
* End of the plugin lifecycle.
|
|
333
|
+
* @type hookParallel
|
|
334
|
+
*/
|
|
335
|
+
buildEnd?: (this: PluginContext<TOptions>) => PossiblePromise<void>;
|
|
336
|
+
};
|
|
337
|
+
type PluginLifecycleHooks = keyof PluginLifecycle;
|
|
338
|
+
type PluginParameter<H extends PluginLifecycleHooks> = Parameters<Required<PluginLifecycle>[H]>;
|
|
339
|
+
type ResolvePathParams<TOptions = object> = {
|
|
340
|
+
pluginKey?: Plugin['key'];
|
|
341
|
+
baseName: BaseName;
|
|
342
|
+
mode?: Mode;
|
|
343
|
+
/**
|
|
344
|
+
* Options to be passed to 'resolvePath' 3th parameter
|
|
345
|
+
*/
|
|
346
|
+
options?: TOptions;
|
|
347
|
+
};
|
|
348
|
+
type ResolveNameParams = {
|
|
349
|
+
name: string;
|
|
350
|
+
pluginKey?: Plugin['key'];
|
|
351
|
+
/**
|
|
352
|
+
* `file` will be used to customize the name of the created file(use of camelCase)
|
|
353
|
+
* `function` can be used to customize the exported functions(use of camelCase)
|
|
354
|
+
* `type` is a special type for TypeScript(use of PascalCase)
|
|
355
|
+
* `const` can be used for variables(use of camelCase)
|
|
356
|
+
*/
|
|
357
|
+
type?: 'file' | 'function' | 'type' | 'const';
|
|
358
|
+
};
|
|
359
|
+
type PluginContext<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
360
|
+
config: Config;
|
|
361
|
+
fileManager: FileManager;
|
|
362
|
+
pluginManager: PluginManager;
|
|
363
|
+
addFile: (...file: Array<File>) => Promise<Array<ResolvedFile>>;
|
|
364
|
+
resolvePath: (params: ResolvePathParams<TOptions['resolvePathOptions']>) => OptionalPath;
|
|
365
|
+
resolveName: (params: ResolveNameParams) => string;
|
|
366
|
+
logger: Logger;
|
|
367
|
+
/**
|
|
368
|
+
* All plugins
|
|
369
|
+
*/
|
|
370
|
+
plugins: Plugin[];
|
|
371
|
+
/**
|
|
372
|
+
* Current plugin
|
|
373
|
+
*/
|
|
374
|
+
plugin: Plugin<TOptions>;
|
|
375
|
+
};
|
|
376
|
+
/**
|
|
377
|
+
* Specify the export location for the files and define the behavior of the output
|
|
378
|
+
*/
|
|
379
|
+
type Output<TOptions> = {
|
|
380
|
+
/**
|
|
381
|
+
* Path to the output folder or file that will contain the generated code
|
|
382
|
+
*/
|
|
383
|
+
path: string;
|
|
384
|
+
/**
|
|
385
|
+
* Define what needs to be exported, here you can also disable the export of barrel files
|
|
386
|
+
* @default 'named'
|
|
387
|
+
*/
|
|
388
|
+
barrelType?: BarrelType | false;
|
|
389
|
+
/**
|
|
390
|
+
* Add a banner text in the beginning of every file
|
|
391
|
+
*/
|
|
392
|
+
banner?: string | ((options: TOptions) => string);
|
|
393
|
+
/**
|
|
394
|
+
* Add a footer text in the beginning of every file
|
|
395
|
+
*/
|
|
396
|
+
footer?: string | ((options: TOptions) => string);
|
|
397
|
+
};
|
|
398
|
+
type GroupContext = {
|
|
399
|
+
group: string;
|
|
400
|
+
};
|
|
401
|
+
type Group = {
|
|
402
|
+
/**
|
|
403
|
+
* Define a type where to group the files on
|
|
404
|
+
*/
|
|
405
|
+
type: 'tag' | 'path';
|
|
406
|
+
/**
|
|
407
|
+
* Return the name of a group based on the group name, this will be used for the file and name generation
|
|
408
|
+
*/
|
|
409
|
+
name?: (context: GroupContext) => string;
|
|
410
|
+
};
|
|
411
|
+
//#endregion
|
|
412
|
+
//#region ../core/src/FileManager.d.ts
|
|
413
|
+
type FileMetaBase = {
|
|
414
|
+
pluginKey?: Plugin['key'];
|
|
415
|
+
};
|
|
416
|
+
type AddResult<T extends Array<File>> = Promise<Awaited<GreaterThan<T['length'], 1> extends true ? Promise<ResolvedFile[]> : Promise<ResolvedFile>>>;
|
|
417
|
+
type AddIndexesProps = {
|
|
418
|
+
type: BarrelType | false | undefined;
|
|
419
|
+
/**
|
|
420
|
+
* Root based on root and output.path specified in the config
|
|
421
|
+
*/
|
|
422
|
+
root: string;
|
|
423
|
+
/**
|
|
424
|
+
* Output for plugin
|
|
425
|
+
*/
|
|
426
|
+
output: {
|
|
427
|
+
path: string;
|
|
428
|
+
};
|
|
429
|
+
group?: {
|
|
430
|
+
output: string;
|
|
431
|
+
exportAs: string;
|
|
432
|
+
};
|
|
433
|
+
logger?: Logger;
|
|
434
|
+
meta?: FileMetaBase;
|
|
435
|
+
};
|
|
436
|
+
type WriteFilesProps = {
|
|
437
|
+
root: Config['root'];
|
|
438
|
+
extension?: Record<Extname, Extname | ''>;
|
|
439
|
+
logger?: Logger;
|
|
440
|
+
dryRun?: boolean;
|
|
441
|
+
};
|
|
442
|
+
declare class FileManager {
|
|
443
|
+
#private;
|
|
444
|
+
constructor();
|
|
445
|
+
add<T extends Array<File> = Array<File>>(...files: T): AddResult<T>;
|
|
446
|
+
getByPath(path: Path): Promise<ResolvedFile | null>;
|
|
447
|
+
deleteByPath(path: Path): Promise<void>;
|
|
448
|
+
clear(): Promise<void>;
|
|
449
|
+
getFiles(): Promise<Array<ResolvedFile>>;
|
|
450
|
+
processFiles({
|
|
451
|
+
dryRun,
|
|
452
|
+
root,
|
|
453
|
+
extension,
|
|
454
|
+
logger
|
|
455
|
+
}: WriteFilesProps): Promise<Array<ResolvedFile>>;
|
|
456
|
+
getBarrelFiles({
|
|
457
|
+
type,
|
|
458
|
+
meta,
|
|
459
|
+
root,
|
|
460
|
+
output,
|
|
461
|
+
logger
|
|
462
|
+
}: AddIndexesProps): Promise<File[]>;
|
|
463
|
+
static getMode(path: string | undefined | null): Mode;
|
|
464
|
+
}
|
|
465
|
+
//#endregion
|
|
466
|
+
//#region ../core/src/PluginManager.d.ts
|
|
467
|
+
type RequiredPluginLifecycle = Required<PluginLifecycle>;
|
|
468
|
+
type Strategy = 'hookFirst' | 'hookForPlugin' | 'hookParallel' | 'hookSeq';
|
|
469
|
+
type Executer<H extends PluginLifecycleHooks = PluginLifecycleHooks> = {
|
|
470
|
+
message: string;
|
|
471
|
+
strategy: Strategy;
|
|
472
|
+
hookName: H;
|
|
473
|
+
plugin: Plugin;
|
|
474
|
+
parameters?: unknown[] | undefined;
|
|
475
|
+
output?: unknown;
|
|
476
|
+
};
|
|
477
|
+
type ParseResult<H extends PluginLifecycleHooks> = RequiredPluginLifecycle[H];
|
|
478
|
+
type SafeParseResult<H extends PluginLifecycleHooks, Result = ReturnType<ParseResult<H>>> = {
|
|
479
|
+
result: Result;
|
|
480
|
+
plugin: Plugin;
|
|
481
|
+
};
|
|
482
|
+
type Options$2 = {
|
|
483
|
+
logger: Logger;
|
|
484
|
+
/**
|
|
485
|
+
* @default Number.POSITIVE_INFINITY
|
|
486
|
+
*/
|
|
487
|
+
concurrency?: number;
|
|
488
|
+
};
|
|
489
|
+
type Events = {
|
|
490
|
+
executing: [executer: Executer];
|
|
491
|
+
executed: [executer: Executer];
|
|
492
|
+
error: [error: Error];
|
|
493
|
+
};
|
|
494
|
+
type GetFileProps<TOptions = object> = {
|
|
495
|
+
name: string;
|
|
496
|
+
mode?: Mode;
|
|
497
|
+
extname: Extname;
|
|
498
|
+
pluginKey: Plugin['key'];
|
|
499
|
+
options?: TOptions;
|
|
500
|
+
};
|
|
501
|
+
declare class PluginManager {
|
|
502
|
+
#private;
|
|
503
|
+
readonly plugins: Set<Plugin<PluginFactoryOptions<string, object, object, any, object>>>;
|
|
504
|
+
readonly fileManager: FileManager;
|
|
505
|
+
readonly events: EventEmitter<Events>;
|
|
506
|
+
readonly config: Config;
|
|
507
|
+
readonly executed: Array<Executer>;
|
|
508
|
+
readonly logger: Logger;
|
|
509
|
+
readonly options: Options$2;
|
|
510
|
+
constructor(config: Config, options: Options$2);
|
|
511
|
+
getFile<TOptions = object>({
|
|
512
|
+
name,
|
|
513
|
+
mode,
|
|
514
|
+
extname,
|
|
515
|
+
pluginKey,
|
|
516
|
+
options
|
|
517
|
+
}: GetFileProps<TOptions>): File<{
|
|
518
|
+
pluginKey: Plugin['key'];
|
|
519
|
+
}>;
|
|
520
|
+
resolvePath: <TOptions = object>(params: ResolvePathParams<TOptions>) => OptionalPath;
|
|
521
|
+
resolveName: (params: ResolveNameParams) => string;
|
|
522
|
+
/**
|
|
523
|
+
* Instead of calling `pluginManager.events.on` you can use `pluginManager.on`. This one also has better types.
|
|
524
|
+
*/
|
|
525
|
+
on<TEventName extends keyof Events & string>(eventName: TEventName, handler: (...eventArg: Events[TEventName]) => void): void;
|
|
526
|
+
/**
|
|
527
|
+
* Run a specific hookName for plugin x.
|
|
528
|
+
*/
|
|
529
|
+
hookForPlugin<H extends PluginLifecycleHooks>({
|
|
530
|
+
pluginKey,
|
|
531
|
+
hookName,
|
|
532
|
+
parameters,
|
|
533
|
+
message
|
|
534
|
+
}: {
|
|
535
|
+
pluginKey: Plugin['key'];
|
|
536
|
+
hookName: H;
|
|
537
|
+
parameters: PluginParameter<H>;
|
|
538
|
+
message: string;
|
|
539
|
+
}): Promise<Array<ReturnType<ParseResult<H>> | null>>;
|
|
540
|
+
/**
|
|
541
|
+
* Run a specific hookName for plugin x.
|
|
542
|
+
*/
|
|
543
|
+
hookForPluginSync<H extends PluginLifecycleHooks>({
|
|
544
|
+
pluginKey,
|
|
545
|
+
hookName,
|
|
546
|
+
parameters,
|
|
547
|
+
message
|
|
548
|
+
}: {
|
|
549
|
+
pluginKey: Plugin['key'];
|
|
550
|
+
hookName: H;
|
|
551
|
+
parameters: PluginParameter<H>;
|
|
552
|
+
message: string;
|
|
553
|
+
}): Array<ReturnType<ParseResult<H>>> | null;
|
|
554
|
+
/**
|
|
555
|
+
* First non-null result stops and will return it's value.
|
|
556
|
+
*/
|
|
557
|
+
hookFirst<H extends PluginLifecycleHooks>({
|
|
558
|
+
hookName,
|
|
559
|
+
parameters,
|
|
560
|
+
skipped,
|
|
561
|
+
message
|
|
562
|
+
}: {
|
|
563
|
+
hookName: H;
|
|
564
|
+
parameters: PluginParameter<H>;
|
|
565
|
+
skipped?: ReadonlySet<Plugin> | null;
|
|
566
|
+
message: string;
|
|
567
|
+
}): Promise<SafeParseResult<H>>;
|
|
568
|
+
/**
|
|
569
|
+
* First non-null result stops and will return it's value.
|
|
570
|
+
*/
|
|
571
|
+
hookFirstSync<H extends PluginLifecycleHooks>({
|
|
572
|
+
hookName,
|
|
573
|
+
parameters,
|
|
574
|
+
skipped,
|
|
575
|
+
message
|
|
576
|
+
}: {
|
|
577
|
+
hookName: H;
|
|
578
|
+
parameters: PluginParameter<H>;
|
|
579
|
+
skipped?: ReadonlySet<Plugin> | null;
|
|
580
|
+
message: string;
|
|
581
|
+
}): SafeParseResult<H>;
|
|
582
|
+
/**
|
|
583
|
+
* Run all plugins in parallel(order will be based on `this.plugin` and if `pre` or `post` is set).
|
|
584
|
+
*/
|
|
585
|
+
hookParallel<H extends PluginLifecycleHooks, TOuput = void>({
|
|
586
|
+
hookName,
|
|
587
|
+
parameters,
|
|
588
|
+
message
|
|
589
|
+
}: {
|
|
590
|
+
hookName: H;
|
|
591
|
+
parameters?: Parameters<RequiredPluginLifecycle[H]> | undefined;
|
|
592
|
+
message: string;
|
|
593
|
+
}): Promise<Awaited<TOuput>[]>;
|
|
594
|
+
/**
|
|
595
|
+
* Chains plugins
|
|
596
|
+
*/
|
|
597
|
+
hookSeq<H extends PluginLifecycleHooks>({
|
|
598
|
+
hookName,
|
|
599
|
+
parameters,
|
|
600
|
+
message
|
|
601
|
+
}: {
|
|
602
|
+
hookName: H;
|
|
603
|
+
parameters?: PluginParameter<H>;
|
|
604
|
+
message: string;
|
|
605
|
+
}): Promise<void>;
|
|
606
|
+
getPluginByKey(pluginKey: Plugin['key']): Plugin | undefined;
|
|
607
|
+
getPluginsByKey(hookName: keyof PluginWithLifeCycle, pluginKey: Plugin['key']): Plugin[];
|
|
608
|
+
static getDependedPlugins<T1 extends PluginFactoryOptions, T2 extends PluginFactoryOptions = never, T3 extends PluginFactoryOptions = never, TOutput = (T3 extends never ? (T2 extends never ? [T1: Plugin<T1>] : [T1: Plugin<T1>, T2: Plugin<T2>]) : [T1: Plugin<T1>, T2: Plugin<T2>, T3: Plugin<T3>])>(plugins: Array<Plugin>, dependedPluginNames: string | string[]): TOutput;
|
|
609
|
+
static get hooks(): readonly ["buildStart", "resolvePath", "resolveName", "buildEnd"];
|
|
610
|
+
}
|
|
611
|
+
//#endregion
|
|
612
|
+
//#region src/types.d.ts
|
|
613
|
+
type ResolvePathOptions = {
|
|
614
|
+
pluginKey?: Plugin['key'];
|
|
615
|
+
group?: {
|
|
616
|
+
tag?: string;
|
|
617
|
+
path?: string;
|
|
618
|
+
};
|
|
619
|
+
type?: ResolveNameParams['type'];
|
|
620
|
+
};
|
|
621
|
+
type API = {
|
|
622
|
+
getOas: () => Promise<Oas>;
|
|
623
|
+
getBaseURL: () => Promise<string | undefined>;
|
|
624
|
+
};
|
|
625
|
+
type Options$1 = {
|
|
626
|
+
/**
|
|
627
|
+
* Validate your input(see kubb.config) based on '@readme/openapi-parser'.
|
|
628
|
+
* @default true
|
|
629
|
+
*/
|
|
630
|
+
validate?: boolean;
|
|
631
|
+
/**
|
|
632
|
+
* Specify the export location for the files and define the behavior of the output
|
|
633
|
+
* @default { path: 'schemas', barrelType: 'named' }
|
|
634
|
+
*/
|
|
635
|
+
output?: Output<Oas>;
|
|
636
|
+
/**
|
|
637
|
+
* Group the JSON files based on the provided name.
|
|
638
|
+
*/
|
|
639
|
+
group?: Group;
|
|
640
|
+
/**
|
|
641
|
+
* Which server to use from the array of `servers.url[serverIndex]`
|
|
642
|
+
* @example
|
|
643
|
+
* - `0` will return `http://petstore.swagger.io/api`
|
|
644
|
+
* - `1` will return `http://localhost:3000`
|
|
645
|
+
*/
|
|
646
|
+
serverIndex?: number;
|
|
647
|
+
/**
|
|
648
|
+
* Define which contentType should be used.
|
|
649
|
+
* By default, the first JSON valid mediaType will be used
|
|
650
|
+
*/
|
|
651
|
+
contentType?: contentType;
|
|
652
|
+
/**
|
|
653
|
+
* Defines how the discriminator value should be interpreted during processing.
|
|
654
|
+
*
|
|
655
|
+
* @default 'strict'
|
|
656
|
+
*
|
|
657
|
+
* @example
|
|
658
|
+
* - `inherit`: Replaces the `oneOf` schema with the schema referenced by `discriminator.mapping[key]`.
|
|
659
|
+
* - `strict`: Uses the `oneOf` schemas as defined, without modification.
|
|
660
|
+
*
|
|
661
|
+
* @see https://github.com/kubb-labs/kubb/issues/1736
|
|
662
|
+
*/
|
|
663
|
+
discriminator?: 'strict' | 'inherit';
|
|
664
|
+
/**
|
|
665
|
+
* Override some behaviour of the Oas class instance, see '@kubb/oas'
|
|
666
|
+
*/
|
|
667
|
+
oasClass?: typeof Oas;
|
|
668
|
+
/**
|
|
669
|
+
* Define some generators next to the JSON generation
|
|
670
|
+
*/
|
|
671
|
+
generators?: Array<Generator<PluginOas>>;
|
|
672
|
+
};
|
|
673
|
+
/**
|
|
674
|
+
* `propertyName` is the ref name + resolved with the nameResolver
|
|
675
|
+
* @example import { Pet } from './Pet'
|
|
676
|
+
*
|
|
677
|
+
* `originalName` is the original name used(in PascalCase), only used to remove duplicates
|
|
678
|
+
*
|
|
679
|
+
* `pluginKey` can be used to override the current plugin being used, handy when you want to import a type/schema out of another plugin
|
|
680
|
+
* @example import a type(plugin-ts) for a mock file(swagger-faker)
|
|
681
|
+
*/
|
|
682
|
+
type Ref = {
|
|
683
|
+
propertyName: string;
|
|
684
|
+
originalName: string;
|
|
685
|
+
path: OptionalPath;
|
|
686
|
+
pluginKey?: Plugin['key'];
|
|
687
|
+
};
|
|
688
|
+
type Refs = Record<string, Ref>;
|
|
689
|
+
type Resolver = {
|
|
690
|
+
/**
|
|
691
|
+
* Original name or name resolved by `resolveName({ name: operation?.getOperationId() as string, pluginName })`
|
|
692
|
+
*/
|
|
693
|
+
name: string;
|
|
694
|
+
baseName: BaseName;
|
|
695
|
+
path: Path;
|
|
696
|
+
};
|
|
697
|
+
type OperationSchema = {
|
|
698
|
+
/**
|
|
699
|
+
* Converted name, contains already `PathParams`, `QueryParams`, ...
|
|
700
|
+
*/
|
|
701
|
+
name: string;
|
|
702
|
+
schema: SchemaObject$1;
|
|
703
|
+
operation?: Operation$1;
|
|
704
|
+
/**
|
|
705
|
+
* OperationName in PascalCase, only being used in OperationGenerator
|
|
706
|
+
*/
|
|
707
|
+
operationName: string;
|
|
708
|
+
description?: string;
|
|
709
|
+
statusCode?: number;
|
|
710
|
+
keys?: string[];
|
|
711
|
+
keysToOmit?: string[];
|
|
712
|
+
withData?: boolean;
|
|
713
|
+
};
|
|
714
|
+
type OperationSchemas = {
|
|
715
|
+
pathParams?: OperationSchema & {
|
|
716
|
+
keysToOmit?: never;
|
|
717
|
+
};
|
|
718
|
+
queryParams?: OperationSchema & {
|
|
719
|
+
keysToOmit?: never;
|
|
720
|
+
};
|
|
721
|
+
headerParams?: OperationSchema & {
|
|
722
|
+
keysToOmit?: never;
|
|
723
|
+
};
|
|
724
|
+
request?: OperationSchema;
|
|
725
|
+
response: OperationSchema;
|
|
726
|
+
responses: Array<OperationSchema>;
|
|
727
|
+
statusCodes?: Array<OperationSchema>;
|
|
728
|
+
errors?: Array<OperationSchema>;
|
|
729
|
+
};
|
|
730
|
+
type ByTag = {
|
|
731
|
+
type: 'tag';
|
|
732
|
+
pattern: string | RegExp;
|
|
733
|
+
};
|
|
734
|
+
type ByOperationId = {
|
|
735
|
+
type: 'operationId';
|
|
736
|
+
pattern: string | RegExp;
|
|
737
|
+
};
|
|
738
|
+
type ByPath = {
|
|
739
|
+
type: 'path';
|
|
740
|
+
pattern: string | RegExp;
|
|
741
|
+
};
|
|
742
|
+
type ByMethod = {
|
|
743
|
+
type: 'method';
|
|
744
|
+
pattern: HttpMethod | RegExp;
|
|
745
|
+
};
|
|
746
|
+
type BySchemaName = {
|
|
747
|
+
type: 'schemaName';
|
|
748
|
+
pattern: string | RegExp;
|
|
749
|
+
};
|
|
750
|
+
type ByContentType = {
|
|
751
|
+
type: 'contentType';
|
|
752
|
+
pattern: string | RegExp;
|
|
753
|
+
};
|
|
754
|
+
type Exclude$1 = ByTag | ByOperationId | ByPath | ByMethod | ByContentType;
|
|
755
|
+
type Include = ByTag | ByOperationId | ByPath | ByMethod | ByContentType;
|
|
756
|
+
type Override<TOptions> = (ByTag | ByOperationId | ByPath | ByMethod | BySchemaName | ByContentType) & {
|
|
757
|
+
options: Partial<TOptions>;
|
|
758
|
+
};
|
|
759
|
+
type ResolvedOptions = Options$1 & {
|
|
760
|
+
output: Output<Oas>;
|
|
761
|
+
};
|
|
762
|
+
type PluginOas = PluginFactoryOptions<'plugin-oas', Options$1, ResolvedOptions, API, ResolvePathOptions>;
|
|
763
|
+
//#endregion
|
|
764
|
+
//#region src/SchemaGenerator.d.ts
|
|
765
|
+
type GetSchemaGeneratorOptions<T extends SchemaGenerator<any, any, any>> = T extends SchemaGenerator<infer Options, any, any> ? Options : never;
|
|
766
|
+
type SchemaMethodResult<TFileMeta extends FileMetaBase> = Promise<File<TFileMeta> | Array<File<TFileMeta>> | null>;
|
|
767
|
+
type Context$1<TOptions, TPluginOptions extends PluginFactoryOptions> = {
|
|
768
|
+
oas: Oas;
|
|
769
|
+
pluginManager: PluginManager;
|
|
770
|
+
/**
|
|
771
|
+
* Current plugin
|
|
772
|
+
*/
|
|
773
|
+
plugin: Plugin<TPluginOptions>;
|
|
774
|
+
mode: Mode;
|
|
775
|
+
include?: Array<'schemas' | 'responses' | 'requestBodies'>;
|
|
776
|
+
override: Array<Override<TOptions>> | undefined;
|
|
777
|
+
contentType?: contentType;
|
|
778
|
+
output?: string;
|
|
779
|
+
};
|
|
780
|
+
type SchemaGeneratorOptions = {
|
|
781
|
+
dateType: false | 'string' | 'stringOffset' | 'stringLocal' | 'date';
|
|
782
|
+
unknownType: 'any' | 'unknown' | 'void';
|
|
783
|
+
emptySchemaType: 'any' | 'unknown' | 'void';
|
|
784
|
+
enumType?: 'enum' | 'asConst' | 'asPascalConst' | 'constEnum' | 'literal';
|
|
785
|
+
enumSuffix?: string;
|
|
786
|
+
usedEnumNames?: Record<string, number>;
|
|
787
|
+
mapper?: Record<string, string>;
|
|
788
|
+
typed?: boolean;
|
|
789
|
+
transformers: {
|
|
790
|
+
/**
|
|
791
|
+
* Customize the names based on the type that is provided by the plugin.
|
|
792
|
+
*/
|
|
793
|
+
name?: (name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string;
|
|
794
|
+
/**
|
|
795
|
+
* Receive schema and name(propertName) and return FakerMeta array
|
|
796
|
+
* TODO TODO add docs
|
|
797
|
+
* @beta
|
|
798
|
+
*/
|
|
799
|
+
schema?: (schemaProps: SchemaProps$1, defaultSchemas: Schema[]) => Schema[] | undefined;
|
|
800
|
+
};
|
|
801
|
+
};
|
|
802
|
+
type SchemaGeneratorBuildOptions = Omit<OperationSchema, 'name' | 'schema'>;
|
|
803
|
+
type SchemaProps$1 = {
|
|
804
|
+
schemaObject?: SchemaObject$1;
|
|
805
|
+
name?: string;
|
|
806
|
+
parentName?: string;
|
|
807
|
+
};
|
|
808
|
+
declare class SchemaGenerator<TOptions extends SchemaGeneratorOptions = SchemaGeneratorOptions, TPluginOptions extends PluginFactoryOptions = PluginFactoryOptions, TFileMeta extends FileMetaBase = FileMetaBase> extends BaseGenerator<TOptions, Context$1<TOptions, TPluginOptions>> {
|
|
809
|
+
#private;
|
|
810
|
+
refs: Refs;
|
|
811
|
+
/**
|
|
812
|
+
* Creates a type node from a given schema.
|
|
813
|
+
* Delegates to getBaseTypeFromSchema internally and
|
|
814
|
+
* optionally adds a union with null.
|
|
815
|
+
*/
|
|
816
|
+
parse(props: SchemaProps$1): Schema[];
|
|
817
|
+
deepSearch<T extends keyof SchemaKeywordMapper>(tree: Schema[] | undefined, keyword: T): Array<SchemaKeywordMapper[T]>;
|
|
818
|
+
find<T extends keyof SchemaKeywordMapper>(tree: Schema[] | undefined, keyword: T): SchemaKeywordMapper[T] | undefined;
|
|
819
|
+
static deepSearch<T extends keyof SchemaKeywordMapper>(tree: Schema[] | undefined, keyword: T): Array<SchemaKeywordMapper[T]>;
|
|
820
|
+
static findInObject<T extends keyof SchemaKeywordMapper>(tree: Schema[] | undefined, keyword: T): SchemaKeywordMapper[T] | undefined;
|
|
821
|
+
static find<T extends keyof SchemaKeywordMapper>(tree: Schema[] | undefined, keyword: T): SchemaKeywordMapper[T] | undefined;
|
|
822
|
+
static combineObjects(tree: Schema[] | undefined): Schema[];
|
|
823
|
+
build(...generators: Array<Generator<TPluginOptions>>): Promise<Array<File<TFileMeta>>>;
|
|
824
|
+
}
|
|
825
|
+
//#endregion
|
|
826
|
+
//#region src/generator.d.ts
|
|
827
|
+
type OperationsProps<TOptions extends PluginFactoryOptions> = {
|
|
828
|
+
instance: Omit<OperationGenerator<TOptions>, 'build'>;
|
|
829
|
+
options: TOptions['resolvedOptions'];
|
|
830
|
+
operations: Array<Operation$1>;
|
|
831
|
+
};
|
|
832
|
+
type OperationProps<TOptions extends PluginFactoryOptions> = {
|
|
833
|
+
instance: Omit<OperationGenerator<TOptions>, 'build'>;
|
|
834
|
+
options: TOptions['resolvedOptions'];
|
|
835
|
+
operation: Operation$1;
|
|
836
|
+
};
|
|
837
|
+
type SchemaProps<TOptions extends PluginFactoryOptions> = {
|
|
838
|
+
instance: Omit<SchemaGenerator<SchemaGeneratorOptions, TOptions>, 'build'>;
|
|
839
|
+
options: TOptions['resolvedOptions'];
|
|
840
|
+
schema: {
|
|
841
|
+
name: string;
|
|
842
|
+
tree: Array<Schema>;
|
|
843
|
+
value: SchemaObject$1;
|
|
844
|
+
};
|
|
845
|
+
};
|
|
846
|
+
type GeneratorOptions<TOptions extends PluginFactoryOptions> = {
|
|
847
|
+
name: string;
|
|
848
|
+
operations?: (this: GeneratorOptions<TOptions>, props: OperationsProps<TOptions>) => Promise<File[]>;
|
|
849
|
+
operation?: (this: GeneratorOptions<TOptions>, props: OperationProps<TOptions>) => Promise<File[]>;
|
|
850
|
+
schema?: (this: GeneratorOptions<TOptions>, props: SchemaProps<TOptions>) => Promise<File[]>;
|
|
851
|
+
};
|
|
852
|
+
type Generator<TOptions extends PluginFactoryOptions> = GeneratorOptions<TOptions>;
|
|
853
|
+
declare function createGenerator<TOptions extends PluginFactoryOptions>(parseOptions: GeneratorOptions<TOptions>): Generator<TOptions>;
|
|
854
|
+
type ReactGeneratorOptions<TOptions extends PluginFactoryOptions> = {
|
|
855
|
+
name: string;
|
|
856
|
+
Operations?: (this: ReactGeneratorOptions<TOptions>, props: OperationsProps<TOptions>) => KubbNode;
|
|
857
|
+
Operation?: (this: ReactGeneratorOptions<TOptions>, props: OperationProps<TOptions>) => KubbNode;
|
|
858
|
+
Schema?: (this: ReactGeneratorOptions<TOptions>, props: SchemaProps<TOptions>) => KubbNode;
|
|
859
|
+
};
|
|
860
|
+
/****
|
|
861
|
+
* Creates a generator that uses React component functions to generate files for OpenAPI operations and schemas.
|
|
862
|
+
*
|
|
863
|
+
* 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.
|
|
864
|
+
*
|
|
865
|
+
* @returns A generator object with async methods for operations, operation, and schema file generation.
|
|
866
|
+
*/
|
|
867
|
+
declare function createReactGenerator<TOptions extends PluginFactoryOptions>(parseOptions: ReactGeneratorOptions<TOptions>): Generator<TOptions>;
|
|
868
|
+
//#endregion
|
|
869
|
+
//#region src/OperationGenerator.d.ts
|
|
870
|
+
type OperationMethodResult<TFileMeta extends FileMetaBase> = Promise<File<TFileMeta> | Array<File<TFileMeta>> | null>;
|
|
871
|
+
type Context<TOptions, TPluginOptions extends PluginFactoryOptions> = {
|
|
872
|
+
oas: Oas;
|
|
873
|
+
exclude: Array<Exclude$1> | undefined;
|
|
874
|
+
include: Array<Include> | undefined;
|
|
875
|
+
override: Array<Override<TOptions>> | undefined;
|
|
876
|
+
contentType: contentType | undefined;
|
|
877
|
+
pluginManager: PluginManager;
|
|
878
|
+
/**
|
|
879
|
+
* Current plugin
|
|
880
|
+
*/
|
|
881
|
+
plugin: Plugin<TPluginOptions>;
|
|
882
|
+
mode: Mode;
|
|
883
|
+
};
|
|
884
|
+
declare class OperationGenerator<TPluginOptions extends PluginFactoryOptions = PluginFactoryOptions, TFileMeta extends FileMetaBase = FileMetaBase> extends BaseGenerator<TPluginOptions['resolvedOptions'], Context<TPluginOptions['resolvedOptions'], TPluginOptions>> {
|
|
885
|
+
#private;
|
|
886
|
+
getSchemas(operation: Operation$1, {
|
|
887
|
+
resolveName
|
|
888
|
+
}?: {
|
|
889
|
+
resolveName?: (name: string) => string;
|
|
890
|
+
}): OperationSchemas;
|
|
891
|
+
getOperations(): Promise<Array<{
|
|
892
|
+
path: string;
|
|
893
|
+
method: HttpMethod;
|
|
894
|
+
operation: Operation$1;
|
|
895
|
+
}>>;
|
|
896
|
+
build(...generators: Array<Generator<TPluginOptions>>): Promise<Array<File<TFileMeta>>>;
|
|
897
|
+
}
|
|
898
|
+
//#endregion
|
|
899
|
+
export { API, Config, Exclude$1 as Exclude, FileMetaBase, Generator, GeneratorOptions, GetSchemaGeneratorOptions, type HttpMethod, Include, type Key, KubbNode, Oas, type OasTypes, type OpenAPIV3$1 as OpenAPIV3, type OpenAPIV3_1, type Operation$1 as Operation, OperationGenerator, OperationMethodResult, OperationSchema, OperationSchemas, Options$1 as Options, Output, Override, type Params, Plugin, PluginOas, ReactGeneratorOptions, Ref, Refs, ResolveNameParams, ResolvePathOptions, Resolver, SchemaGenerator, SchemaGeneratorBuildOptions, SchemaGeneratorOptions, SchemaMethodResult, SchemaObject$1 as SchemaObject, UserPluginWithLifeCycle, contentType, createGenerator, createReactGenerator };
|
|
900
|
+
//# sourceMappingURL=OperationGenerator-CgbXErhW.d.cts.map
|