@kubb/plugin-oas 3.0.0-alpha.8 → 3.0.0-beta.1

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.
Files changed (100) hide show
  1. package/README.md +14 -5
  2. package/dist/OperationGenerator-BgQeGRzk.d.cts +550 -0
  3. package/dist/OperationGenerator-BgQeGRzk.d.ts +550 -0
  4. package/dist/{Schema-B1vcPGiK.d.ts → Schema-1iM2I0dK.d.ts} +1 -12
  5. package/dist/{Schema-DoSFh7Qd.d.cts → Schema-5o-c5UOy.d.cts} +1 -12
  6. package/dist/chunk-ABOQ73FL.cjs +36 -0
  7. package/dist/chunk-ABOQ73FL.cjs.map +1 -0
  8. package/dist/chunk-BG77DP54.js +30 -0
  9. package/dist/chunk-BG77DP54.js.map +1 -0
  10. package/dist/chunk-GF26SDHQ.js +28 -0
  11. package/dist/chunk-GF26SDHQ.js.map +1 -0
  12. package/dist/chunk-PADR76WZ.cjs +4 -0
  13. package/dist/chunk-PADR76WZ.cjs.map +1 -0
  14. package/dist/chunk-QAFBZLJA.cjs +48 -0
  15. package/dist/chunk-QAFBZLJA.cjs.map +1 -0
  16. package/dist/chunk-QT6ZFRNJ.cjs +752 -0
  17. package/dist/chunk-QT6ZFRNJ.cjs.map +1 -0
  18. package/dist/chunk-QWO5NQGQ.js +88 -0
  19. package/dist/chunk-QWO5NQGQ.js.map +1 -0
  20. package/dist/chunk-R47XMJ32.js +3 -0
  21. package/dist/chunk-R47XMJ32.js.map +1 -0
  22. package/dist/chunk-SR63CBLH.cjs +92 -0
  23. package/dist/chunk-SR63CBLH.cjs.map +1 -0
  24. package/dist/chunk-V2JO6RHI.js +744 -0
  25. package/dist/chunk-V2JO6RHI.js.map +1 -0
  26. package/dist/chunk-XNCEFOE6.js +45 -0
  27. package/dist/chunk-XNCEFOE6.js.map +1 -0
  28. package/dist/chunk-ZWHQ54JM.cjs +32 -0
  29. package/dist/chunk-ZWHQ54JM.cjs.map +1 -0
  30. package/dist/components.cjs +20 -12
  31. package/dist/components.cjs.map +1 -1
  32. package/dist/components.d.cts +3 -6
  33. package/dist/components.d.ts +3 -6
  34. package/dist/components.js +3 -12
  35. package/dist/components.js.map +1 -1
  36. package/dist/generators.cjs +14 -0
  37. package/dist/generators.cjs.map +1 -0
  38. package/dist/generators.d.cts +9 -0
  39. package/dist/generators.d.ts +9 -0
  40. package/dist/generators.js +5 -0
  41. package/dist/generators.js.map +1 -0
  42. package/dist/hooks.cjs +102 -57
  43. package/dist/hooks.cjs.map +1 -1
  44. package/dist/hooks.d.cts +41 -10
  45. package/dist/hooks.d.ts +41 -10
  46. package/dist/hooks.js +91 -53
  47. package/dist/hooks.js.map +1 -1
  48. package/dist/index.cjs +137 -187
  49. package/dist/index.cjs.map +1 -1
  50. package/dist/index.d.cts +2 -5
  51. package/dist/index.d.ts +2 -5
  52. package/dist/index.js +76 -153
  53. package/dist/index.js.map +1 -1
  54. package/dist/utils.cjs +32 -41
  55. package/dist/utils.cjs.map +1 -1
  56. package/dist/utils.d.cts +5 -13
  57. package/dist/utils.d.ts +5 -13
  58. package/dist/utils.js +8 -40
  59. package/dist/utils.js.map +1 -1
  60. package/package.json +20 -14
  61. package/src/OperationGenerator.ts +23 -30
  62. package/src/SchemaGenerator.ts +79 -22
  63. package/src/SchemaMapper.ts +6 -4
  64. package/src/components/Schema.tsx +1 -99
  65. package/src/{parser.tsx → generator.tsx} +30 -22
  66. package/src/generators/index.ts +1 -0
  67. package/src/generators/jsonGenerator.ts +32 -0
  68. package/src/hooks/index.ts +2 -0
  69. package/src/hooks/useOperationManager.ts +77 -30
  70. package/src/hooks/useSchemaManager.ts +77 -0
  71. package/src/index.ts +3 -3
  72. package/src/plugin.ts +69 -56
  73. package/src/types.ts +24 -18
  74. package/src/utils/getParams.ts +1 -1
  75. package/src/utils/getSchemaFactory.ts +1 -1
  76. package/src/utils/index.ts +2 -1
  77. package/src/utils/parseFromConfig.ts +7 -7
  78. package/dist/OperationGenerator-DeXrfGDC.d.ts +0 -158
  79. package/dist/OperationGenerator-DhJ0MBKc.d.cts +0 -158
  80. package/dist/SchemaMapper-sGcY1xL5.d.cts +0 -247
  81. package/dist/SchemaMapper-sGcY1xL5.d.ts +0 -247
  82. package/dist/chunk-75BIOXB7.cjs +0 -7
  83. package/dist/chunk-75BIOXB7.cjs.map +0 -1
  84. package/dist/chunk-MUI5DWM3.js +0 -3966
  85. package/dist/chunk-MUI5DWM3.js.map +0 -1
  86. package/dist/chunk-N7EEVJA6.js +0 -35
  87. package/dist/chunk-N7EEVJA6.js.map +0 -1
  88. package/dist/chunk-NU4F7G47.cjs +0 -89
  89. package/dist/chunk-NU4F7G47.cjs.map +0 -1
  90. package/dist/chunk-O76YQFZB.cjs +0 -35
  91. package/dist/chunk-O76YQFZB.cjs.map +0 -1
  92. package/dist/chunk-SQ64ESS4.js +0 -7
  93. package/dist/chunk-SQ64ESS4.js.map +0 -1
  94. package/dist/chunk-SZDO532A.js +0 -89
  95. package/dist/chunk-SZDO532A.js.map +0 -1
  96. package/dist/chunk-VSVVTCQB.cjs +0 -3966
  97. package/dist/chunk-VSVVTCQB.cjs.map +0 -1
  98. package/dist/types-CZTUCaE5.d.cts +0 -145
  99. package/dist/types-CZTUCaE5.d.ts +0 -145
  100. package/src/utils/refSorter.ts +0 -13
@@ -0,0 +1,550 @@
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
+ declare function createReactGenerator<TOptions extends PluginFactoryOptions>(parseOptions: ReactGeneratorOptions<TOptions>): Generator<TOptions>;
493
+
494
+ /**
495
+ * @deprecated
496
+ */
497
+ type GetOperationGeneratorOptions<T = any> = any;
498
+ type OperationMethodResult<TFileMeta extends FileMetaBase> = Promise<KubbFile.File<TFileMeta> | Array<KubbFile.File<TFileMeta>> | null>;
499
+ type Context<TOptions, TPluginOptions extends PluginFactoryOptions> = {
500
+ oas: Oas;
501
+ exclude: Array<Exclude> | undefined;
502
+ include: Array<Include> | undefined;
503
+ override: Array<Override<TOptions>> | undefined;
504
+ contentType: contentType | undefined;
505
+ pluginManager: PluginManager;
506
+ /**
507
+ * Current plugin
508
+ */
509
+ plugin: Plugin<TPluginOptions>;
510
+ mode: KubbFile.Mode;
511
+ };
512
+ declare class OperationGenerator<TPluginOptions extends PluginFactoryOptions = PluginFactoryOptions, TFileMeta extends FileMetaBase = FileMetaBase> extends BaseGenerator<TPluginOptions['resolvedOptions'], Context<TPluginOptions['resolvedOptions'], TPluginOptions>> {
513
+ #private;
514
+ get operationsByMethod(): OperationsByMethod;
515
+ set operationsByMethod(paths: OperationsByMethod);
516
+ getSchemas(operation: Operation, { resolveName, }?: {
517
+ resolveName?: (name: string) => string;
518
+ }): OperationSchemas;
519
+ build(...generators: Array<Generator<TPluginOptions>>): Promise<Array<KubbFile.File<TFileMeta>>>;
520
+ /**
521
+ * Operation
522
+ */
523
+ operation(operation: Operation, options: TPluginOptions['resolvedOptions']): OperationMethodResult<TFileMeta>;
524
+ /**
525
+ * GET
526
+ */
527
+ get(operation: Operation, options: TPluginOptions['resolvedOptions']): OperationMethodResult<TFileMeta>;
528
+ /**
529
+ * POST
530
+ */
531
+ post(operation: Operation, options: TPluginOptions['resolvedOptions']): OperationMethodResult<TFileMeta>;
532
+ /**
533
+ * PATCH
534
+ */
535
+ patch(operation: Operation, options: TPluginOptions['resolvedOptions']): OperationMethodResult<TFileMeta>;
536
+ /**
537
+ * PUT
538
+ */
539
+ put(operation: Operation, options: TPluginOptions['resolvedOptions']): OperationMethodResult<TFileMeta>;
540
+ /**
541
+ * DELETE
542
+ */
543
+ delete(operation: Operation, options: TPluginOptions['resolvedOptions']): OperationMethodResult<TFileMeta>;
544
+ /**
545
+ * Combination of GET, POST, PATCH, PUT, DELETE
546
+ */
547
+ all(operations: Operation[], paths: OperationsByMethod): OperationMethodResult<TFileMeta>;
548
+ }
549
+
550
+ 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 };
@@ -1,8 +1,7 @@
1
1
  import * as react from 'react';
2
- import { ReactNode } from 'react';
3
2
  import { SchemaObject } from '@kubb/oas';
4
3
  import { KubbNode } from '@kubb/react/types';
5
- import { S as Schema$1 } from './SchemaMapper-sGcY1xL5.js';
4
+ import { g as Schema$1 } from './OperationGenerator-BgQeGRzk.js';
6
5
 
7
6
  type SchemaContextProps = {
8
7
  name: string;
@@ -17,17 +16,7 @@ type Props = {
17
16
  };
18
17
  declare function Schema({ name, value, tree, children }: Props): KubbNode;
19
18
  declare namespace Schema {
20
- var File: ({ output, isTypeOnly, children }: FileProps) => ReactNode;
21
- var Imports: ({ isTypeOnly }: SchemaImportsProps) => ReactNode;
22
19
  var Context: react.Context<SchemaContextProps>;
23
20
  }
24
- type FileProps = {
25
- isTypeOnly?: boolean;
26
- output: string | undefined;
27
- children?: KubbNode;
28
- };
29
- type SchemaImportsProps = {
30
- isTypeOnly?: boolean;
31
- };
32
21
 
33
22
  export { Schema as S, type SchemaContextProps as a };
@@ -1,8 +1,7 @@
1
1
  import * as react from 'react';
2
- import { ReactNode } from 'react';
3
2
  import { SchemaObject } from '@kubb/oas';
4
3
  import { KubbNode } from '@kubb/react/types';
5
- import { S as Schema$1 } from './SchemaMapper-sGcY1xL5.cjs';
4
+ import { g as Schema$1 } from './OperationGenerator-BgQeGRzk.cjs';
6
5
 
7
6
  type SchemaContextProps = {
8
7
  name: string;
@@ -17,17 +16,7 @@ type Props = {
17
16
  };
18
17
  declare function Schema({ name, value, tree, children }: Props): KubbNode;
19
18
  declare namespace Schema {
20
- var File: ({ output, isTypeOnly, children }: FileProps) => ReactNode;
21
- var Imports: ({ isTypeOnly }: SchemaImportsProps) => ReactNode;
22
19
  var Context: react.Context<SchemaContextProps>;
23
20
  }
24
- type FileProps = {
25
- isTypeOnly?: boolean;
26
- output: string | undefined;
27
- children?: KubbNode;
28
- };
29
- type SchemaImportsProps = {
30
- isTypeOnly?: boolean;
31
- };
32
21
 
33
22
  export { Schema as S, type SchemaContextProps as a };
@@ -0,0 +1,36 @@
1
+ 'use strict';
2
+
3
+ var path = require('path');
4
+ var utils = require('@kubb/core/utils');
5
+ var parser = require('@kubb/oas/parser');
6
+ var oas = require('@kubb/oas');
7
+ var yaml = require('@stoplight/yaml');
8
+
9
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
10
+
11
+ var yaml__default = /*#__PURE__*/_interopDefault(yaml);
12
+
13
+ // src/utils/parseFromConfig.ts
14
+ function parseFromConfig(config, oasClass = oas.Oas) {
15
+ if ("data" in config.input) {
16
+ if (typeof config.input.data === "object") {
17
+ const api2 = JSON.parse(JSON.stringify(config.input.data));
18
+ return parser.parse(api2, oasClass);
19
+ }
20
+ try {
21
+ const api2 = yaml__default.default.parse(config.input.data);
22
+ return parser.parse(api2, oasClass);
23
+ } catch (e) {
24
+ }
25
+ const api = JSON.parse(JSON.stringify(config.input.data));
26
+ return parser.parse(api, oasClass);
27
+ }
28
+ if (new utils.URLPath(config.input.path).isURL) {
29
+ return parser.parse(config.input.path, oasClass);
30
+ }
31
+ return parser.parse(path.resolve(config.root, config.input.path), oasClass);
32
+ }
33
+
34
+ exports.parseFromConfig = parseFromConfig;
35
+ //# sourceMappingURL=chunk-ABOQ73FL.cjs.map
36
+ //# sourceMappingURL=chunk-ABOQ73FL.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/utils/parseFromConfig.ts"],"names":["Oas","api","parse","yaml","URLPath","resolve"],"mappings":";;;;;;;;;;;;;AAUO,SAAS,eAAA,CAAgB,MAAgB,EAAA,QAAA,GAAuBA,OAAmB,EAAA;AACxF,EAAI,IAAA,MAAA,IAAU,OAAO,KAAO,EAAA;AAC1B,IAAA,IAAI,OAAO,MAAA,CAAO,KAAM,CAAA,IAAA,KAAS,QAAU,EAAA;AACzC,MAAMC,MAAAA,IAAAA,GAA4B,KAAK,KAAM,CAAA,IAAA,CAAK,UAAU,MAAO,CAAA,KAAA,CAAM,IAAI,CAAC,CAAA,CAAA;AAC9E,MAAO,OAAAC,YAAA,CAAMD,MAAK,QAAQ,CAAA,CAAA;AAAA,KAC5B;AAEA,IAAI,IAAA;AACF,MAAA,MAAMA,IAAc,GAAAE,qBAAA,CAAK,KAAM,CAAA,MAAA,CAAO,MAAM,IAAc,CAAA,CAAA;AAE1D,MAAO,OAAAD,YAAA,CAAMD,MAAK,QAAQ,CAAA,CAAA;AAAA,aACnB,CAAG,EAAA;AAAA,KAEZ;AAEA,IAAM,MAAA,GAAA,GAA4B,KAAK,KAAM,CAAA,IAAA,CAAK,UAAU,MAAO,CAAA,KAAA,CAAM,IAAI,CAAC,CAAA,CAAA;AAE9E,IAAO,OAAAC,YAAA,CAAM,KAAK,QAAQ,CAAA,CAAA;AAAA,GAC5B;AAEA,EAAA,IAAI,IAAIE,aAAQ,CAAA,MAAA,CAAO,KAAM,CAAA,IAAI,EAAE,KAAO,EAAA;AACxC,IAAA,OAAOF,YAAM,CAAA,MAAA,CAAO,KAAM,CAAA,IAAA,EAAM,QAAQ,CAAA,CAAA;AAAA,GAC1C;AAEA,EAAO,OAAAA,YAAA,CAAMG,aAAQ,MAAO,CAAA,IAAA,EAAM,OAAO,KAAM,CAAA,IAAI,GAAG,QAAQ,CAAA,CAAA;AAChE","file":"chunk-ABOQ73FL.cjs","sourcesContent":["import { resolve } from 'node:path'\n\nimport { URLPath } from '@kubb/core/utils'\n\nimport { parse } from '@kubb/oas/parser'\n\nimport type { Config } from '@kubb/core'\nimport { Oas, type OasTypes } from '@kubb/oas'\nimport yaml from '@stoplight/yaml'\n\nexport function parseFromConfig(config: Config, oasClass: typeof Oas = Oas): Promise<Oas> {\n if ('data' in config.input) {\n if (typeof config.input.data === 'object') {\n const api: OasTypes.OASDocument = JSON.parse(JSON.stringify(config.input.data)) as OasTypes.OASDocument\n return parse(api, oasClass)\n }\n\n try {\n const api: string = yaml.parse(config.input.data as string) as string\n\n return parse(api, oasClass)\n } catch (e) {\n /* empty */\n }\n\n const api: OasTypes.OASDocument = JSON.parse(JSON.stringify(config.input.data)) as OasTypes.OASDocument\n\n return parse(api, oasClass)\n }\n\n if (new URLPath(config.input.path).isURL) {\n return parse(config.input.path, oasClass)\n }\n\n return parse(resolve(config.root, config.input.path), oasClass)\n}\n"]}
@@ -0,0 +1,30 @@
1
+ import { resolve } from 'node:path';
2
+ import { URLPath } from '@kubb/core/utils';
3
+ import { parse } from '@kubb/oas/parser';
4
+ import { Oas } from '@kubb/oas';
5
+ import yaml from '@stoplight/yaml';
6
+
7
+ // src/utils/parseFromConfig.ts
8
+ function parseFromConfig(config, oasClass = Oas) {
9
+ if ("data" in config.input) {
10
+ if (typeof config.input.data === "object") {
11
+ const api2 = JSON.parse(JSON.stringify(config.input.data));
12
+ return parse(api2, oasClass);
13
+ }
14
+ try {
15
+ const api2 = yaml.parse(config.input.data);
16
+ return parse(api2, oasClass);
17
+ } catch (e) {
18
+ }
19
+ const api = JSON.parse(JSON.stringify(config.input.data));
20
+ return parse(api, oasClass);
21
+ }
22
+ if (new URLPath(config.input.path).isURL) {
23
+ return parse(config.input.path, oasClass);
24
+ }
25
+ return parse(resolve(config.root, config.input.path), oasClass);
26
+ }
27
+
28
+ export { parseFromConfig };
29
+ //# sourceMappingURL=chunk-BG77DP54.js.map
30
+ //# sourceMappingURL=chunk-BG77DP54.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/utils/parseFromConfig.ts"],"names":["api"],"mappings":";;;;;;;AAUO,SAAS,eAAA,CAAgB,MAAgB,EAAA,QAAA,GAAuB,GAAmB,EAAA;AACxF,EAAI,IAAA,MAAA,IAAU,OAAO,KAAO,EAAA;AAC1B,IAAA,IAAI,OAAO,MAAA,CAAO,KAAM,CAAA,IAAA,KAAS,QAAU,EAAA;AACzC,MAAMA,MAAAA,IAAAA,GAA4B,KAAK,KAAM,CAAA,IAAA,CAAK,UAAU,MAAO,CAAA,KAAA,CAAM,IAAI,CAAC,CAAA,CAAA;AAC9E,MAAO,OAAA,KAAA,CAAMA,MAAK,QAAQ,CAAA,CAAA;AAAA,KAC5B;AAEA,IAAI,IAAA;AACF,MAAA,MAAMA,IAAc,GAAA,IAAA,CAAK,KAAM,CAAA,MAAA,CAAO,MAAM,IAAc,CAAA,CAAA;AAE1D,MAAO,OAAA,KAAA,CAAMA,MAAK,QAAQ,CAAA,CAAA;AAAA,aACnB,CAAG,EAAA;AAAA,KAEZ;AAEA,IAAM,MAAA,GAAA,GAA4B,KAAK,KAAM,CAAA,IAAA,CAAK,UAAU,MAAO,CAAA,KAAA,CAAM,IAAI,CAAC,CAAA,CAAA;AAE9E,IAAO,OAAA,KAAA,CAAM,KAAK,QAAQ,CAAA,CAAA;AAAA,GAC5B;AAEA,EAAA,IAAI,IAAI,OAAQ,CAAA,MAAA,CAAO,KAAM,CAAA,IAAI,EAAE,KAAO,EAAA;AACxC,IAAA,OAAO,KAAM,CAAA,MAAA,CAAO,KAAM,CAAA,IAAA,EAAM,QAAQ,CAAA,CAAA;AAAA,GAC1C;AAEA,EAAO,OAAA,KAAA,CAAM,QAAQ,MAAO,CAAA,IAAA,EAAM,OAAO,KAAM,CAAA,IAAI,GAAG,QAAQ,CAAA,CAAA;AAChE","file":"chunk-BG77DP54.js","sourcesContent":["import { resolve } from 'node:path'\n\nimport { URLPath } from '@kubb/core/utils'\n\nimport { parse } from '@kubb/oas/parser'\n\nimport type { Config } from '@kubb/core'\nimport { Oas, type OasTypes } from '@kubb/oas'\nimport yaml from '@stoplight/yaml'\n\nexport function parseFromConfig(config: Config, oasClass: typeof Oas = Oas): Promise<Oas> {\n if ('data' in config.input) {\n if (typeof config.input.data === 'object') {\n const api: OasTypes.OASDocument = JSON.parse(JSON.stringify(config.input.data)) as OasTypes.OASDocument\n return parse(api, oasClass)\n }\n\n try {\n const api: string = yaml.parse(config.input.data as string) as string\n\n return parse(api, oasClass)\n } catch (e) {\n /* empty */\n }\n\n const api: OasTypes.OASDocument = JSON.parse(JSON.stringify(config.input.data)) as OasTypes.OASDocument\n\n return parse(api, oasClass)\n }\n\n if (new URLPath(config.input.path).isURL) {\n return parse(config.input.path, oasClass)\n }\n\n return parse(resolve(config.root, config.input.path), oasClass)\n}\n"]}