@kubb/plugin-oas 3.0.0-alpha.3 → 3.0.0-alpha.30
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/README.md +13 -4
- package/dist/OperationGenerator-DhPriVDJ.d.cts +554 -0
- package/dist/OperationGenerator-DhPriVDJ.d.ts +554 -0
- package/dist/Schema-BfZVq77f.d.cts +22 -0
- package/dist/Schema-IlDbvlbP.d.ts +22 -0
- package/dist/chunk-4H2KTGZM.cjs +92 -0
- package/dist/chunk-4H2KTGZM.cjs.map +1 -0
- package/dist/chunk-ABIWUCV7.js +88 -0
- package/dist/chunk-ABIWUCV7.js.map +1 -0
- package/dist/chunk-ABOQ73FL.cjs +36 -0
- package/dist/chunk-ABOQ73FL.cjs.map +1 -0
- package/dist/chunk-BG77DP54.js +30 -0
- package/dist/chunk-BG77DP54.js.map +1 -0
- package/dist/chunk-GF26SDHQ.js +28 -0
- package/dist/chunk-GF26SDHQ.js.map +1 -0
- package/dist/chunk-PADR76WZ.cjs +4 -0
- package/dist/chunk-PADR76WZ.cjs.map +1 -0
- package/dist/chunk-QAFBZLJA.cjs +48 -0
- package/dist/chunk-QAFBZLJA.cjs.map +1 -0
- package/dist/chunk-QT6ZFRNJ.cjs +752 -0
- package/dist/chunk-QT6ZFRNJ.cjs.map +1 -0
- package/dist/chunk-R47XMJ32.js +3 -0
- package/dist/chunk-R47XMJ32.js.map +1 -0
- package/dist/chunk-V2JO6RHI.js +744 -0
- package/dist/chunk-V2JO6RHI.js.map +1 -0
- package/dist/chunk-XNCEFOE6.js +45 -0
- package/dist/chunk-XNCEFOE6.js.map +1 -0
- package/dist/chunk-ZWHQ54JM.cjs +32 -0
- package/dist/chunk-ZWHQ54JM.cjs.map +1 -0
- package/dist/components.cjs +20 -12
- package/dist/components.cjs.map +1 -1
- package/dist/components.d.cts +4 -7
- package/dist/components.d.ts +4 -7
- package/dist/components.js +3 -12
- package/dist/components.js.map +1 -1
- package/dist/generators.cjs +14 -0
- package/dist/generators.cjs.map +1 -0
- package/dist/generators.d.cts +9 -0
- package/dist/generators.d.ts +9 -0
- package/dist/generators.js +5 -0
- package/dist/generators.js.map +1 -0
- package/dist/hooks.cjs +102 -57
- package/dist/hooks.cjs.map +1 -1
- package/dist/hooks.d.cts +41 -10
- package/dist/hooks.d.ts +41 -10
- package/dist/hooks.js +91 -53
- package/dist/hooks.js.map +1 -1
- package/dist/index.cjs +192 -258
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -6
- package/dist/index.d.ts +3 -6
- package/dist/index.js +135 -228
- package/dist/index.js.map +1 -1
- package/dist/utils.cjs +32 -87
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.d.cts +8 -43
- package/dist/utils.d.ts +8 -43
- package/dist/utils.js +8 -86
- package/dist/utils.js.map +1 -1
- package/package.json +20 -14
- package/src/OperationGenerator.ts +23 -30
- package/src/SchemaGenerator.ts +80 -23
- package/src/SchemaMapper.ts +7 -5
- package/src/components/Oas.tsx +1 -1
- package/src/components/Operation.tsx +1 -1
- package/src/components/Schema.tsx +2 -102
- package/src/{parser.tsx → generator.tsx} +35 -22
- package/src/generators/index.ts +1 -0
- package/src/generators/jsonGenerator.ts +32 -0
- package/src/hooks/index.ts +2 -0
- package/src/hooks/useOperationManager.ts +77 -29
- package/src/hooks/useSchemaManager.ts +77 -0
- package/src/index.ts +3 -3
- package/src/plugin.ts +67 -59
- package/src/types.ts +24 -16
- package/src/utils/getParams.ts +2 -2
- package/src/utils/getSchemaFactory.ts +1 -1
- package/src/utils/index.ts +2 -2
- package/src/utils/parseFromConfig.ts +7 -7
- package/dist/OperationGenerator-D7rSlflc.d.cts +0 -158
- package/dist/OperationGenerator-vw0Zf-Mi.d.ts +0 -158
- package/dist/Schema-DxyOIX7q.d.cts +0 -35
- package/dist/Schema-gHgN14i2.d.ts +0 -35
- package/dist/SchemaMapper-BM1IGWqD.d.cts +0 -248
- package/dist/SchemaMapper-BM1IGWqD.d.ts +0 -248
- package/dist/chunk-264TCCJF.cjs +0 -3973
- package/dist/chunk-264TCCJF.cjs.map +0 -1
- package/dist/chunk-7KIEQOVZ.cjs +0 -7
- package/dist/chunk-7KIEQOVZ.cjs.map +0 -1
- package/dist/chunk-FZN3PBEK.js +0 -3973
- package/dist/chunk-FZN3PBEK.js.map +0 -1
- package/dist/chunk-P42X362U.cjs +0 -101
- package/dist/chunk-P42X362U.cjs.map +0 -1
- package/dist/chunk-QLJIL3U5.cjs +0 -35
- package/dist/chunk-QLJIL3U5.cjs.map +0 -1
- package/dist/chunk-TWKZEVSM.js +0 -7
- package/dist/chunk-TWKZEVSM.js.map +0 -1
- package/dist/chunk-UB552H4J.js +0 -101
- package/dist/chunk-UB552H4J.js.map +0 -1
- package/dist/chunk-Y4V7HHX7.js +0 -35
- package/dist/chunk-Y4V7HHX7.js.map +0 -1
- package/dist/types-C2RXaY0_.d.cts +0 -143
- package/dist/types-C2RXaY0_.d.ts +0 -143
- package/src/utils/getGroupedByTagFiles.ts +0 -82
- package/src/utils/refSorter.ts +0 -13
package/README.md
CHANGED
|
@@ -13,10 +13,6 @@
|
|
|
13
13
|
[![Coverage][coverage-src]][coverage-href]
|
|
14
14
|
[![License][license-src]][license-href]
|
|
15
15
|
|
|
16
|
-
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
|
|
17
|
-
<!-- ALL-CONTRIBUTORS-BADGE:END -->
|
|
18
|
-
</p>
|
|
19
|
-
|
|
20
16
|
<h4>
|
|
21
17
|
<a href="https://codesandbox.io/s/github/kubb-labs/kubb/tree/alpha/examples/typescript" target="_blank">View Demo</a>
|
|
22
18
|
<span> · </span>
|
|
@@ -28,6 +24,19 @@
|
|
|
28
24
|
</h4>
|
|
29
25
|
</div>
|
|
30
26
|
|
|
27
|
+
## Supporting Kubb
|
|
28
|
+
|
|
29
|
+
Kubb uses an MIT-licensed open source project with its ongoing development made possible entirely by the support of Sponsors. If you would like to become a sponsor, please consider:
|
|
30
|
+
|
|
31
|
+
- [Become a Sponsor on GitHub](https://github.com/sponsors/stijnvanhulle)
|
|
32
|
+
|
|
33
|
+
<p align="center">
|
|
34
|
+
<a href="https://github.com/sponsors/stijnvanhulle">
|
|
35
|
+
<img src="https://raw.githubusercontent.com/stijnvanhulle/sponsors/main/sponsors.svg" alt="My sponsors" />
|
|
36
|
+
</a>
|
|
37
|
+
</p>
|
|
38
|
+
|
|
39
|
+
|
|
31
40
|
<!-- Badges -->
|
|
32
41
|
|
|
33
42
|
[npm-version-src]: https://img.shields.io/npm/v/@kubb/plugin-oas?flat&colorA=18181B&colorB=f58517
|
|
@@ -0,0 +1,554 @@
|
|
|
1
|
+
import { Plugin, ResolveNameParams, Output, PluginFactoryOptions, FileMetaBase, BaseGenerator, PluginManager } from '@kubb/core';
|
|
2
|
+
import * as KubbFile from '@kubb/fs/types';
|
|
3
|
+
import { Oas, contentType, OasTypes, SchemaObject, Operation, HttpMethod } from '@kubb/oas';
|
|
4
|
+
import { KubbNode } from '@kubb/react/types';
|
|
5
|
+
|
|
6
|
+
type SchemaKeywordMapper = {
|
|
7
|
+
object: {
|
|
8
|
+
keyword: 'object';
|
|
9
|
+
args: {
|
|
10
|
+
properties: {
|
|
11
|
+
[x: string]: Schema[];
|
|
12
|
+
};
|
|
13
|
+
additionalProperties: Schema[];
|
|
14
|
+
strict?: boolean;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
strict: {
|
|
18
|
+
keyword: 'strict';
|
|
19
|
+
};
|
|
20
|
+
url: {
|
|
21
|
+
keyword: 'url';
|
|
22
|
+
};
|
|
23
|
+
readOnly: {
|
|
24
|
+
keyword: 'readOnly';
|
|
25
|
+
};
|
|
26
|
+
writeOnly: {
|
|
27
|
+
keyword: 'writeOnly';
|
|
28
|
+
};
|
|
29
|
+
uuid: {
|
|
30
|
+
keyword: 'uuid';
|
|
31
|
+
};
|
|
32
|
+
email: {
|
|
33
|
+
keyword: 'email';
|
|
34
|
+
};
|
|
35
|
+
firstName: {
|
|
36
|
+
keyword: 'firstName';
|
|
37
|
+
};
|
|
38
|
+
lastName: {
|
|
39
|
+
keyword: 'lastName';
|
|
40
|
+
};
|
|
41
|
+
phone: {
|
|
42
|
+
keyword: 'phone';
|
|
43
|
+
};
|
|
44
|
+
password: {
|
|
45
|
+
keyword: 'password';
|
|
46
|
+
};
|
|
47
|
+
date: {
|
|
48
|
+
keyword: 'date';
|
|
49
|
+
args: {
|
|
50
|
+
type?: 'date' | 'string';
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
time: {
|
|
54
|
+
keyword: 'time';
|
|
55
|
+
args: {
|
|
56
|
+
type?: 'date' | 'string';
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
datetime: {
|
|
60
|
+
keyword: 'datetime';
|
|
61
|
+
args: {
|
|
62
|
+
offset?: boolean;
|
|
63
|
+
local?: boolean;
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
tuple: {
|
|
67
|
+
keyword: 'tuple';
|
|
68
|
+
args: {
|
|
69
|
+
items: Schema[];
|
|
70
|
+
min?: number;
|
|
71
|
+
max?: number;
|
|
72
|
+
};
|
|
73
|
+
};
|
|
74
|
+
array: {
|
|
75
|
+
keyword: 'array';
|
|
76
|
+
args: {
|
|
77
|
+
items: Schema[];
|
|
78
|
+
min?: number;
|
|
79
|
+
max?: number;
|
|
80
|
+
};
|
|
81
|
+
};
|
|
82
|
+
enum: {
|
|
83
|
+
keyword: 'enum';
|
|
84
|
+
args: {
|
|
85
|
+
name: string;
|
|
86
|
+
typeName: string;
|
|
87
|
+
asConst: boolean;
|
|
88
|
+
items: Array<{
|
|
89
|
+
name: string | number;
|
|
90
|
+
format: 'string' | 'number' | 'boolean';
|
|
91
|
+
value?: string | number | boolean;
|
|
92
|
+
}>;
|
|
93
|
+
};
|
|
94
|
+
};
|
|
95
|
+
and: {
|
|
96
|
+
keyword: 'and';
|
|
97
|
+
args: Schema[];
|
|
98
|
+
};
|
|
99
|
+
const: {
|
|
100
|
+
keyword: 'const';
|
|
101
|
+
args: {
|
|
102
|
+
name: string | number;
|
|
103
|
+
format: 'string' | 'number' | 'boolean';
|
|
104
|
+
value?: string | number | boolean;
|
|
105
|
+
};
|
|
106
|
+
};
|
|
107
|
+
union: {
|
|
108
|
+
keyword: 'union';
|
|
109
|
+
args: Schema[];
|
|
110
|
+
};
|
|
111
|
+
ref: {
|
|
112
|
+
keyword: 'ref';
|
|
113
|
+
args: {
|
|
114
|
+
name: string;
|
|
115
|
+
path: KubbFile.OptionalPath;
|
|
116
|
+
};
|
|
117
|
+
};
|
|
118
|
+
matches: {
|
|
119
|
+
keyword: 'matches';
|
|
120
|
+
args?: string;
|
|
121
|
+
};
|
|
122
|
+
boolean: {
|
|
123
|
+
keyword: 'boolean';
|
|
124
|
+
};
|
|
125
|
+
default: {
|
|
126
|
+
keyword: 'default';
|
|
127
|
+
args: string | number | boolean;
|
|
128
|
+
};
|
|
129
|
+
string: {
|
|
130
|
+
keyword: 'string';
|
|
131
|
+
};
|
|
132
|
+
integer: {
|
|
133
|
+
keyword: 'integer';
|
|
134
|
+
};
|
|
135
|
+
number: {
|
|
136
|
+
keyword: 'number';
|
|
137
|
+
};
|
|
138
|
+
max: {
|
|
139
|
+
keyword: 'max';
|
|
140
|
+
args: number;
|
|
141
|
+
};
|
|
142
|
+
min: {
|
|
143
|
+
keyword: 'min';
|
|
144
|
+
args: number;
|
|
145
|
+
};
|
|
146
|
+
describe: {
|
|
147
|
+
keyword: 'describe';
|
|
148
|
+
args: string;
|
|
149
|
+
};
|
|
150
|
+
example: {
|
|
151
|
+
keyword: 'example';
|
|
152
|
+
args: string;
|
|
153
|
+
};
|
|
154
|
+
deprecated: {
|
|
155
|
+
keyword: 'deprecated';
|
|
156
|
+
};
|
|
157
|
+
optional: {
|
|
158
|
+
keyword: 'optional';
|
|
159
|
+
};
|
|
160
|
+
undefined: {
|
|
161
|
+
keyword: 'undefined';
|
|
162
|
+
};
|
|
163
|
+
nullish: {
|
|
164
|
+
keyword: 'nullish';
|
|
165
|
+
};
|
|
166
|
+
nullable: {
|
|
167
|
+
keyword: 'nullable';
|
|
168
|
+
};
|
|
169
|
+
null: {
|
|
170
|
+
keyword: 'null';
|
|
171
|
+
};
|
|
172
|
+
any: {
|
|
173
|
+
keyword: 'any';
|
|
174
|
+
};
|
|
175
|
+
unknown: {
|
|
176
|
+
keyword: 'unknown';
|
|
177
|
+
};
|
|
178
|
+
blob: {
|
|
179
|
+
keyword: 'blob';
|
|
180
|
+
};
|
|
181
|
+
schema: {
|
|
182
|
+
keyword: 'schema';
|
|
183
|
+
args: {
|
|
184
|
+
type: 'string' | 'number' | 'integer' | 'boolean' | 'array' | 'object';
|
|
185
|
+
format?: string;
|
|
186
|
+
};
|
|
187
|
+
};
|
|
188
|
+
name: {
|
|
189
|
+
keyword: 'name';
|
|
190
|
+
args: string;
|
|
191
|
+
};
|
|
192
|
+
catchall: {
|
|
193
|
+
keyword: 'catchall';
|
|
194
|
+
};
|
|
195
|
+
};
|
|
196
|
+
declare const schemaKeywords: {
|
|
197
|
+
any: "any";
|
|
198
|
+
strict: "strict";
|
|
199
|
+
unknown: "unknown";
|
|
200
|
+
number: "number";
|
|
201
|
+
integer: "integer";
|
|
202
|
+
string: "string";
|
|
203
|
+
boolean: "boolean";
|
|
204
|
+
undefined: "undefined";
|
|
205
|
+
nullable: "nullable";
|
|
206
|
+
null: "null";
|
|
207
|
+
nullish: "nullish";
|
|
208
|
+
array: "array";
|
|
209
|
+
tuple: "tuple";
|
|
210
|
+
enum: "enum";
|
|
211
|
+
union: "union";
|
|
212
|
+
datetime: "datetime";
|
|
213
|
+
date: "date";
|
|
214
|
+
email: "email";
|
|
215
|
+
uuid: "uuid";
|
|
216
|
+
url: "url";
|
|
217
|
+
default: "default";
|
|
218
|
+
const: "const";
|
|
219
|
+
and: "and";
|
|
220
|
+
describe: "describe";
|
|
221
|
+
min: "min";
|
|
222
|
+
max: "max";
|
|
223
|
+
optional: "optional";
|
|
224
|
+
readOnly: "readOnly";
|
|
225
|
+
writeOnly: "writeOnly";
|
|
226
|
+
object: "object";
|
|
227
|
+
ref: "ref";
|
|
228
|
+
matches: "matches";
|
|
229
|
+
firstName: "firstName";
|
|
230
|
+
lastName: "lastName";
|
|
231
|
+
password: "password";
|
|
232
|
+
phone: "phone";
|
|
233
|
+
blob: "blob";
|
|
234
|
+
deprecated: "deprecated";
|
|
235
|
+
example: "example";
|
|
236
|
+
schema: "schema";
|
|
237
|
+
catchall: "catchall";
|
|
238
|
+
time: "time";
|
|
239
|
+
name: "name";
|
|
240
|
+
};
|
|
241
|
+
type SchemaKeyword = keyof SchemaKeywordMapper;
|
|
242
|
+
type SchemaMapper<T = string | null | undefined> = {
|
|
243
|
+
[K in keyof SchemaKeywordMapper]: (() => T | undefined) | undefined;
|
|
244
|
+
};
|
|
245
|
+
type SchemaKeywordBase<T> = {
|
|
246
|
+
keyword: SchemaKeyword;
|
|
247
|
+
args: T;
|
|
248
|
+
};
|
|
249
|
+
type Schema = {
|
|
250
|
+
keyword: string;
|
|
251
|
+
} | SchemaKeywordMapper[keyof SchemaKeywordMapper];
|
|
252
|
+
declare function isKeyword<T extends Schema, K extends keyof SchemaKeywordMapper>(meta: T, keyword: K): meta is Extract<T, SchemaKeywordMapper[K]>;
|
|
253
|
+
|
|
254
|
+
type Mode = 'schemas' | 'responses' | 'requestBodies';
|
|
255
|
+
type GetSchemasProps = {
|
|
256
|
+
oas: Oas;
|
|
257
|
+
contentType?: contentType;
|
|
258
|
+
includes?: Mode[];
|
|
259
|
+
};
|
|
260
|
+
declare function getSchemas({ oas, contentType, includes }: GetSchemasProps): Record<string, OasTypes.SchemaObject>;
|
|
261
|
+
|
|
262
|
+
type ResolvePathOptions = {
|
|
263
|
+
pluginKey?: Plugin['key'];
|
|
264
|
+
tag?: string;
|
|
265
|
+
type?: ResolveNameParams['type'];
|
|
266
|
+
};
|
|
267
|
+
type API = {
|
|
268
|
+
getOas: () => Promise<Oas>;
|
|
269
|
+
getSchemas: (options?: Pick<GetSchemasProps, 'includes'>) => Promise<Record<string, SchemaObject>>;
|
|
270
|
+
getBaseURL: () => Promise<string | undefined>;
|
|
271
|
+
contentType?: contentType;
|
|
272
|
+
};
|
|
273
|
+
type Options = {
|
|
274
|
+
/**
|
|
275
|
+
* Validate your input(see kubb.config) based on '@readme/openapi-parser'.
|
|
276
|
+
* @default true
|
|
277
|
+
*/
|
|
278
|
+
validate?: boolean;
|
|
279
|
+
/**
|
|
280
|
+
* @default 'schemas'
|
|
281
|
+
*/
|
|
282
|
+
output?: Output;
|
|
283
|
+
/**
|
|
284
|
+
* Which server to use from the array of `servers.url[serverIndex]`
|
|
285
|
+
* @example
|
|
286
|
+
* - `0` will return `http://petstore.swagger.io/api`
|
|
287
|
+
* - `1` will return `http://localhost:3000`
|
|
288
|
+
* @default 0
|
|
289
|
+
*/
|
|
290
|
+
serverIndex?: number;
|
|
291
|
+
/**
|
|
292
|
+
* Define which contentType should be used.
|
|
293
|
+
* By default, this is set based on the first used contentType..
|
|
294
|
+
*/
|
|
295
|
+
contentType?: contentType;
|
|
296
|
+
/**
|
|
297
|
+
* Override some behaviour of the Oas class instance, see '@kubb/oas'
|
|
298
|
+
*/
|
|
299
|
+
oasClass?: typeof Oas;
|
|
300
|
+
/**
|
|
301
|
+
* Define some generators next to the JSON generation
|
|
302
|
+
*/
|
|
303
|
+
generators?: Array<Generator<PluginOas>>;
|
|
304
|
+
};
|
|
305
|
+
/**
|
|
306
|
+
* `propertyName` is the ref name + resolved with the nameResolver
|
|
307
|
+
* @example `import { Pet } from './Pet'`
|
|
308
|
+
*
|
|
309
|
+
* `originalName` is the original name used(in PascalCase), only used to remove duplicates
|
|
310
|
+
*
|
|
311
|
+
* `pluginKey` can be used to override the current plugin being used, handy when you want to import a type/schema out of another plugin
|
|
312
|
+
* @example import a type(plugin-ts) for a mock file(swagger-faker)
|
|
313
|
+
*/
|
|
314
|
+
type Ref = {
|
|
315
|
+
propertyName: string;
|
|
316
|
+
originalName: string;
|
|
317
|
+
path: KubbFile.OptionalPath;
|
|
318
|
+
pluginKey?: Plugin['key'];
|
|
319
|
+
};
|
|
320
|
+
type Refs = Record<string, Ref>;
|
|
321
|
+
type Resolver = {
|
|
322
|
+
/**
|
|
323
|
+
* Original name or name resolved by `resolveName({ name: operation?.getOperationId() as string, pluginName })`
|
|
324
|
+
*/
|
|
325
|
+
name: string;
|
|
326
|
+
baseName: KubbFile.BaseName;
|
|
327
|
+
path: KubbFile.Path;
|
|
328
|
+
};
|
|
329
|
+
type OperationSchema = {
|
|
330
|
+
/**
|
|
331
|
+
* Converted name, contains already `PathParams`, `QueryParams`, ...
|
|
332
|
+
*/
|
|
333
|
+
name: string;
|
|
334
|
+
schema: SchemaObject;
|
|
335
|
+
operation?: Operation;
|
|
336
|
+
/**
|
|
337
|
+
* OperationName in PascalCase, only being used in OperationGenerator
|
|
338
|
+
*/
|
|
339
|
+
operationName?: string;
|
|
340
|
+
description?: string;
|
|
341
|
+
statusCode?: number;
|
|
342
|
+
keys?: string[];
|
|
343
|
+
keysToOmit?: string[];
|
|
344
|
+
withData?: boolean;
|
|
345
|
+
};
|
|
346
|
+
type OperationSchemas = {
|
|
347
|
+
pathParams?: OperationSchema & {
|
|
348
|
+
keysToOmit?: never;
|
|
349
|
+
};
|
|
350
|
+
queryParams?: OperationSchema & {
|
|
351
|
+
keysToOmit?: never;
|
|
352
|
+
};
|
|
353
|
+
headerParams?: OperationSchema & {
|
|
354
|
+
keysToOmit?: never;
|
|
355
|
+
};
|
|
356
|
+
request?: OperationSchema;
|
|
357
|
+
response: OperationSchema;
|
|
358
|
+
statusCodes?: Array<OperationSchema>;
|
|
359
|
+
errors?: Array<OperationSchema>;
|
|
360
|
+
};
|
|
361
|
+
type OperationsByMethod = Record<string, Record<HttpMethod, {
|
|
362
|
+
operation: Operation;
|
|
363
|
+
schemas: OperationSchemas;
|
|
364
|
+
}>>;
|
|
365
|
+
type ByTag = {
|
|
366
|
+
type: 'tag';
|
|
367
|
+
pattern: string | RegExp;
|
|
368
|
+
};
|
|
369
|
+
type ByOperationId = {
|
|
370
|
+
type: 'operationId';
|
|
371
|
+
pattern: string | RegExp;
|
|
372
|
+
};
|
|
373
|
+
type ByPath = {
|
|
374
|
+
type: 'path';
|
|
375
|
+
pattern: string | RegExp;
|
|
376
|
+
};
|
|
377
|
+
type ByMethod = {
|
|
378
|
+
type: 'method';
|
|
379
|
+
pattern: HttpMethod | RegExp;
|
|
380
|
+
};
|
|
381
|
+
type BySchemaName = {
|
|
382
|
+
type: 'schemaName';
|
|
383
|
+
pattern: string | RegExp;
|
|
384
|
+
};
|
|
385
|
+
type Exclude = ByTag | ByOperationId | ByPath | ByMethod;
|
|
386
|
+
type Include = ByTag | ByOperationId | ByPath | ByMethod;
|
|
387
|
+
type Override<TOptions> = (ByTag | ByOperationId | ByPath | ByMethod | BySchemaName) & {
|
|
388
|
+
options: Partial<TOptions>;
|
|
389
|
+
};
|
|
390
|
+
type ResolvedOptions = Options & {
|
|
391
|
+
output: Output;
|
|
392
|
+
};
|
|
393
|
+
type PluginOas = PluginFactoryOptions<'plugin-oas', Options, ResolvedOptions, API, never>;
|
|
394
|
+
|
|
395
|
+
type GetSchemaGeneratorOptions<T extends SchemaGenerator<any, any, any>> = T extends SchemaGenerator<infer Options, any, any> ? Options : never;
|
|
396
|
+
type SchemaMethodResult<TFileMeta extends FileMetaBase> = Promise<KubbFile.File<TFileMeta> | Array<KubbFile.File<TFileMeta>> | null>;
|
|
397
|
+
type Context$1<TOptions, TPluginOptions extends PluginFactoryOptions> = {
|
|
398
|
+
oas: Oas;
|
|
399
|
+
pluginManager: PluginManager;
|
|
400
|
+
/**
|
|
401
|
+
* Current plugin
|
|
402
|
+
*/
|
|
403
|
+
plugin: Plugin<TPluginOptions>;
|
|
404
|
+
mode: KubbFile.Mode;
|
|
405
|
+
include?: Array<'schemas' | 'responses' | 'requestBodies'>;
|
|
406
|
+
override: Array<Override<TOptions>> | undefined;
|
|
407
|
+
contentType?: contentType;
|
|
408
|
+
output?: string;
|
|
409
|
+
};
|
|
410
|
+
type SchemaGeneratorOptions = {
|
|
411
|
+
dateType: false | 'string' | 'stringOffset' | 'stringLocal' | 'date';
|
|
412
|
+
unknownType: 'any' | 'unknown';
|
|
413
|
+
enumType?: 'enum' | 'asConst' | 'asPascalConst' | 'constEnum' | 'literal';
|
|
414
|
+
enumSuffix?: string;
|
|
415
|
+
usedEnumNames?: Record<string, number>;
|
|
416
|
+
mapper?: Record<string, string>;
|
|
417
|
+
typed?: boolean;
|
|
418
|
+
transformers: {
|
|
419
|
+
/**
|
|
420
|
+
* Customize the names based on the type that is provided by the plugin.
|
|
421
|
+
*/
|
|
422
|
+
name?: (name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string;
|
|
423
|
+
/**
|
|
424
|
+
* Receive schema and name(propertName) and return FakerMeta array
|
|
425
|
+
* TODO TODO add docs
|
|
426
|
+
* @beta
|
|
427
|
+
*/
|
|
428
|
+
schema?: (schemaProps: SchemaProps$1, defaultSchemas: Schema[]) => Schema[] | undefined;
|
|
429
|
+
};
|
|
430
|
+
};
|
|
431
|
+
type SchemaGeneratorBuildOptions = Omit<OperationSchema, 'name' | 'schema'>;
|
|
432
|
+
type SchemaProps$1 = {
|
|
433
|
+
schema?: SchemaObject;
|
|
434
|
+
name?: string;
|
|
435
|
+
parentName?: string;
|
|
436
|
+
};
|
|
437
|
+
declare class SchemaGenerator<TOptions extends SchemaGeneratorOptions = SchemaGeneratorOptions, TPluginOptions extends PluginFactoryOptions = PluginFactoryOptions, TFileMeta extends FileMetaBase = FileMetaBase> extends BaseGenerator<TOptions, Context$1<TOptions, TPluginOptions>> {
|
|
438
|
+
#private;
|
|
439
|
+
refs: Refs;
|
|
440
|
+
/**
|
|
441
|
+
* Creates a type node from a given schema.
|
|
442
|
+
* Delegates to getBaseTypeFromSchema internally and
|
|
443
|
+
* optionally adds a union with null.
|
|
444
|
+
*/
|
|
445
|
+
parse(props: SchemaProps$1): Schema[];
|
|
446
|
+
deepSearch<T extends keyof SchemaKeywordMapper>(tree: Schema[] | undefined, keyword: T): SchemaKeywordMapper[T][];
|
|
447
|
+
find<T extends keyof SchemaKeywordMapper>(tree: Schema[] | undefined, keyword: T): SchemaKeywordMapper[T] | undefined;
|
|
448
|
+
static deepSearch<T extends keyof SchemaKeywordMapper>(tree: Schema[] | undefined, keyword: T): SchemaKeywordMapper[T][];
|
|
449
|
+
static findInObject<T extends keyof SchemaKeywordMapper>(tree: Schema[] | undefined, keyword: T): SchemaKeywordMapper[T] | undefined;
|
|
450
|
+
static find<T extends keyof SchemaKeywordMapper>(tree: Schema[] | undefined, keyword: T): SchemaKeywordMapper[T] | undefined;
|
|
451
|
+
build(...generators: Array<Generator<TPluginOptions>>): Promise<Array<KubbFile.File<TFileMeta>>>;
|
|
452
|
+
/**
|
|
453
|
+
* Schema
|
|
454
|
+
*/
|
|
455
|
+
schema(name: string, object: SchemaObject, options: TOptions): SchemaMethodResult<TFileMeta>;
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
type OperationsProps<TOptions extends PluginFactoryOptions> = {
|
|
459
|
+
instance: Omit<OperationGenerator<TOptions>, 'build'>;
|
|
460
|
+
options: TOptions['resolvedOptions'];
|
|
461
|
+
operations: Array<Operation>;
|
|
462
|
+
operationsByMethod: OperationsByMethod;
|
|
463
|
+
};
|
|
464
|
+
type OperationProps<TOptions extends PluginFactoryOptions> = {
|
|
465
|
+
instance: Omit<OperationGenerator<TOptions>, 'build'>;
|
|
466
|
+
options: TOptions['resolvedOptions'];
|
|
467
|
+
operation: Operation;
|
|
468
|
+
};
|
|
469
|
+
type SchemaProps<TOptions extends PluginFactoryOptions> = {
|
|
470
|
+
instance: Omit<SchemaGenerator<SchemaGeneratorOptions, TOptions>, 'build'>;
|
|
471
|
+
schema: {
|
|
472
|
+
name: string;
|
|
473
|
+
tree: Array<Schema>;
|
|
474
|
+
value: SchemaObject;
|
|
475
|
+
};
|
|
476
|
+
options: TOptions['resolvedOptions'];
|
|
477
|
+
};
|
|
478
|
+
type GeneratorOptions<TOptions extends PluginFactoryOptions> = {
|
|
479
|
+
name: string;
|
|
480
|
+
operations?: (this: GeneratorOptions<TOptions>, props: OperationsProps<TOptions>) => Promise<KubbFile.File[]>;
|
|
481
|
+
operation?: (this: GeneratorOptions<TOptions>, props: OperationProps<TOptions>) => Promise<KubbFile.File[]>;
|
|
482
|
+
schema?: (this: GeneratorOptions<TOptions>, props: SchemaProps<TOptions>) => Promise<KubbFile.File[]>;
|
|
483
|
+
};
|
|
484
|
+
type Generator<TOptions extends PluginFactoryOptions> = GeneratorOptions<TOptions>;
|
|
485
|
+
declare function createGenerator<TOptions extends PluginFactoryOptions>(parseOptions: GeneratorOptions<TOptions>): Generator<TOptions>;
|
|
486
|
+
type ReactGeneratorOptions<TOptions extends PluginFactoryOptions> = {
|
|
487
|
+
name: string;
|
|
488
|
+
Operations?: (this: ReactGeneratorOptions<TOptions>, props: OperationsProps<TOptions>) => KubbNode;
|
|
489
|
+
Operation?: (this: ReactGeneratorOptions<TOptions>, props: OperationProps<TOptions>) => KubbNode;
|
|
490
|
+
Schema?: (this: ReactGeneratorOptions<TOptions>, props: SchemaProps<TOptions>) => KubbNode;
|
|
491
|
+
/**
|
|
492
|
+
* Combine all react nodes and only render ones(to string or render)
|
|
493
|
+
*/
|
|
494
|
+
render?: () => any;
|
|
495
|
+
};
|
|
496
|
+
declare function createReactGenerator<TOptions extends PluginFactoryOptions>(parseOptions: ReactGeneratorOptions<TOptions>): Generator<TOptions>;
|
|
497
|
+
|
|
498
|
+
/**
|
|
499
|
+
* @deprecated
|
|
500
|
+
*/
|
|
501
|
+
type GetOperationGeneratorOptions<T = any> = any;
|
|
502
|
+
type OperationMethodResult<TFileMeta extends FileMetaBase> = Promise<KubbFile.File<TFileMeta> | Array<KubbFile.File<TFileMeta>> | null>;
|
|
503
|
+
type Context<TOptions, TPluginOptions extends PluginFactoryOptions> = {
|
|
504
|
+
oas: Oas;
|
|
505
|
+
exclude: Array<Exclude> | undefined;
|
|
506
|
+
include: Array<Include> | undefined;
|
|
507
|
+
override: Array<Override<TOptions>> | undefined;
|
|
508
|
+
contentType: contentType | undefined;
|
|
509
|
+
pluginManager: PluginManager;
|
|
510
|
+
/**
|
|
511
|
+
* Current plugin
|
|
512
|
+
*/
|
|
513
|
+
plugin: Plugin<TPluginOptions>;
|
|
514
|
+
mode: KubbFile.Mode;
|
|
515
|
+
};
|
|
516
|
+
declare class OperationGenerator<TPluginOptions extends PluginFactoryOptions = PluginFactoryOptions, TFileMeta extends FileMetaBase = FileMetaBase> extends BaseGenerator<TPluginOptions['resolvedOptions'], Context<TPluginOptions['resolvedOptions'], TPluginOptions>> {
|
|
517
|
+
#private;
|
|
518
|
+
get operationsByMethod(): OperationsByMethod;
|
|
519
|
+
set operationsByMethod(paths: OperationsByMethod);
|
|
520
|
+
getSchemas(operation: Operation, { resolveName, }?: {
|
|
521
|
+
resolveName?: (name: string) => string;
|
|
522
|
+
}): OperationSchemas;
|
|
523
|
+
build(...generators: Array<Generator<TPluginOptions>>): Promise<Array<KubbFile.File<TFileMeta>>>;
|
|
524
|
+
/**
|
|
525
|
+
* Operation
|
|
526
|
+
*/
|
|
527
|
+
operation(operation: Operation, options: TPluginOptions['resolvedOptions']): OperationMethodResult<TFileMeta>;
|
|
528
|
+
/**
|
|
529
|
+
* GET
|
|
530
|
+
*/
|
|
531
|
+
get(operation: Operation, options: TPluginOptions['resolvedOptions']): OperationMethodResult<TFileMeta>;
|
|
532
|
+
/**
|
|
533
|
+
* POST
|
|
534
|
+
*/
|
|
535
|
+
post(operation: Operation, options: TPluginOptions['resolvedOptions']): OperationMethodResult<TFileMeta>;
|
|
536
|
+
/**
|
|
537
|
+
* PATCH
|
|
538
|
+
*/
|
|
539
|
+
patch(operation: Operation, options: TPluginOptions['resolvedOptions']): OperationMethodResult<TFileMeta>;
|
|
540
|
+
/**
|
|
541
|
+
* PUT
|
|
542
|
+
*/
|
|
543
|
+
put(operation: Operation, options: TPluginOptions['resolvedOptions']): OperationMethodResult<TFileMeta>;
|
|
544
|
+
/**
|
|
545
|
+
* DELETE
|
|
546
|
+
*/
|
|
547
|
+
delete(operation: Operation, options: TPluginOptions['resolvedOptions']): OperationMethodResult<TFileMeta>;
|
|
548
|
+
/**
|
|
549
|
+
* Combination of GET, POST, PATCH, PUT, DELETE
|
|
550
|
+
*/
|
|
551
|
+
all(operations: Operation[], paths: OperationsByMethod): OperationMethodResult<TFileMeta>;
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
export { type API as A, getSchemas as B, type Exclude as E, type GetOperationGeneratorOptions as G, type Include as I, type Options as O, type PluginOas as P, type ReactGeneratorOptions as R, type SchemaGeneratorBuildOptions as S, type OperationMethodResult as a, OperationGenerator as b, type GetSchemaGeneratorOptions as c, type SchemaGeneratorOptions as d, type SchemaMethodResult as e, SchemaGenerator as f, type Schema as g, type SchemaKeyword as h, type SchemaKeywordBase as i, type SchemaKeywordMapper as j, type SchemaMapper as k, isKeyword as l, createGenerator as m, createReactGenerator as n, type Generator as o, type GeneratorOptions as p, type ResolvePathOptions as q, type Ref as r, schemaKeywords as s, type Refs as t, type Resolver as u, type OperationSchema as v, type OperationSchemas as w, type OperationsByMethod as x, type Override as y, type GetSchemasProps as z };
|