@kubb/plugin-oas 0.0.0-canary-20240509211223
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/LICENSE +21 -0
- package/README.md +44 -0
- package/dist/OperationGenerator-DvnXUUp4.d.ts +56 -0
- package/dist/OperationGenerator-X6CTMfhG.d.cts +56 -0
- package/dist/Schema-BWPWyiQO.d.cts +39 -0
- package/dist/Schema-DFZBfjF2.d.ts +39 -0
- package/dist/SchemaGenerator-hK5SHxTI.d.ts +316 -0
- package/dist/SchemaGenerator-z_7YrAAB.d.cts +316 -0
- package/dist/chunk-2MJ2CQMI.js +61 -0
- package/dist/chunk-2MJ2CQMI.js.map +1 -0
- package/dist/chunk-3RCQ2LNT.js +81 -0
- package/dist/chunk-3RCQ2LNT.js.map +1 -0
- package/dist/chunk-55NUFNT6.cjs +68 -0
- package/dist/chunk-55NUFNT6.cjs.map +1 -0
- package/dist/chunk-ECXSQTMV.cjs +81 -0
- package/dist/chunk-ECXSQTMV.cjs.map +1 -0
- package/dist/chunk-EPTOYYAP.js +3312 -0
- package/dist/chunk-EPTOYYAP.js.map +1 -0
- package/dist/chunk-H52M2RUX.cjs +3312 -0
- package/dist/chunk-H52M2RUX.cjs.map +1 -0
- package/dist/chunk-LQ6IAWRX.js +68 -0
- package/dist/chunk-LQ6IAWRX.js.map +1 -0
- package/dist/chunk-VNFSHGSN.cjs +61 -0
- package/dist/chunk-VNFSHGSN.cjs.map +1 -0
- package/dist/components.cjs +18 -0
- package/dist/components.cjs.map +1 -0
- package/dist/components.d.cts +41 -0
- package/dist/components.d.ts +41 -0
- package/dist/components.js +18 -0
- package/dist/components.js.map +1 -0
- package/dist/hooks.cjs +152 -0
- package/dist/hooks.cjs.map +1 -0
- package/dist/hooks.d.cts +76 -0
- package/dist/hooks.d.ts +76 -0
- package/dist/hooks.js +152 -0
- package/dist/hooks.js.map +1 -0
- package/dist/index.cjs +985 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +17 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.js +985 -0
- package/dist/index.js.map +1 -0
- package/dist/types-n5zV4Q3s.d.cts +146 -0
- package/dist/types-n5zV4Q3s.d.ts +146 -0
- package/dist/utils.cjs +126 -0
- package/dist/utils.cjs.map +1 -0
- package/dist/utils.d.cts +80 -0
- package/dist/utils.d.ts +80 -0
- package/dist/utils.js +126 -0
- package/dist/utils.js.map +1 -0
- package/package.json +107 -0
- package/src/OperationGenerator.ts +328 -0
- package/src/SchemaGenerator.ts +827 -0
- package/src/SchemaMapper.ts +145 -0
- package/src/components/Oas.tsx +31 -0
- package/src/components/Operation.tsx +21 -0
- package/src/components/Schema.tsx +156 -0
- package/src/components/index.ts +3 -0
- package/src/hooks/index.ts +5 -0
- package/src/hooks/useOas.ts +15 -0
- package/src/hooks/useOperation.ts +18 -0
- package/src/hooks/useOperationManager.ts +142 -0
- package/src/hooks/useOperations.ts +40 -0
- package/src/hooks/useSchema.ts +23 -0
- package/src/index.ts +30 -0
- package/src/plugin.ts +133 -0
- package/src/types.ts +147 -0
- package/src/utils/getComments.ts +15 -0
- package/src/utils/getGroupedByTagFiles.ts +81 -0
- package/src/utils/getParams.ts +57 -0
- package/src/utils/getSchemaFactory.ts +33 -0
- package/src/utils/getSchemas.ts +45 -0
- package/src/utils/index.ts +8 -0
- package/src/utils/parseFromConfig.ts +36 -0
- package/src/utils/refSorter.ts +13 -0
|
@@ -0,0 +1,316 @@
|
|
|
1
|
+
import { KubbFile, ResolveNameParams, PluginFactoryOptions, Generator, PluginManager, Plugin } from '@kubb/core';
|
|
2
|
+
import { SchemaObject, Oas, contentType } from '@kubb/oas';
|
|
3
|
+
import { d as OperationSchema, b as Refs, g as Override } from './types-n5zV4Q3s.cjs';
|
|
4
|
+
|
|
5
|
+
type SchemaKeywordMapper = {
|
|
6
|
+
object: {
|
|
7
|
+
keyword: 'object';
|
|
8
|
+
args: {
|
|
9
|
+
properties: {
|
|
10
|
+
[x: string]: Schema[];
|
|
11
|
+
};
|
|
12
|
+
additionalProperties: Schema[];
|
|
13
|
+
strict?: boolean;
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
strict: {
|
|
17
|
+
keyword: 'strict';
|
|
18
|
+
};
|
|
19
|
+
url: {
|
|
20
|
+
keyword: 'url';
|
|
21
|
+
};
|
|
22
|
+
readOnly: {
|
|
23
|
+
keyword: 'readOnly';
|
|
24
|
+
};
|
|
25
|
+
uuid: {
|
|
26
|
+
keyword: 'uuid';
|
|
27
|
+
};
|
|
28
|
+
email: {
|
|
29
|
+
keyword: 'email';
|
|
30
|
+
};
|
|
31
|
+
firstName: {
|
|
32
|
+
keyword: 'firstName';
|
|
33
|
+
};
|
|
34
|
+
lastName: {
|
|
35
|
+
keyword: 'lastName';
|
|
36
|
+
};
|
|
37
|
+
phone: {
|
|
38
|
+
keyword: 'phone';
|
|
39
|
+
};
|
|
40
|
+
password: {
|
|
41
|
+
keyword: 'password';
|
|
42
|
+
};
|
|
43
|
+
date: {
|
|
44
|
+
keyword: 'date';
|
|
45
|
+
args: {
|
|
46
|
+
type?: 'date' | 'string';
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
time: {
|
|
50
|
+
keyword: 'time';
|
|
51
|
+
args: {
|
|
52
|
+
type?: 'date' | 'string';
|
|
53
|
+
};
|
|
54
|
+
};
|
|
55
|
+
datetime: {
|
|
56
|
+
keyword: 'datetime';
|
|
57
|
+
args: {
|
|
58
|
+
offset?: boolean;
|
|
59
|
+
local?: boolean;
|
|
60
|
+
};
|
|
61
|
+
};
|
|
62
|
+
tuple: {
|
|
63
|
+
keyword: 'tuple';
|
|
64
|
+
args: Schema[];
|
|
65
|
+
};
|
|
66
|
+
array: {
|
|
67
|
+
keyword: 'array';
|
|
68
|
+
args: {
|
|
69
|
+
items: Schema[];
|
|
70
|
+
min?: number;
|
|
71
|
+
max?: number;
|
|
72
|
+
};
|
|
73
|
+
};
|
|
74
|
+
enum: {
|
|
75
|
+
keyword: 'enum';
|
|
76
|
+
args: {
|
|
77
|
+
name: string;
|
|
78
|
+
typeName: string;
|
|
79
|
+
asConst: boolean;
|
|
80
|
+
items: Array<{
|
|
81
|
+
name: string | number;
|
|
82
|
+
format: 'string' | 'number';
|
|
83
|
+
value?: string | number;
|
|
84
|
+
}>;
|
|
85
|
+
};
|
|
86
|
+
};
|
|
87
|
+
and: {
|
|
88
|
+
keyword: 'and';
|
|
89
|
+
args: Schema[];
|
|
90
|
+
};
|
|
91
|
+
const: {
|
|
92
|
+
keyword: 'const';
|
|
93
|
+
args: {
|
|
94
|
+
name: string | number;
|
|
95
|
+
format: 'string' | 'number';
|
|
96
|
+
value?: string | number;
|
|
97
|
+
};
|
|
98
|
+
};
|
|
99
|
+
union: {
|
|
100
|
+
keyword: 'union';
|
|
101
|
+
args: Schema[];
|
|
102
|
+
};
|
|
103
|
+
ref: {
|
|
104
|
+
keyword: 'ref';
|
|
105
|
+
args: {
|
|
106
|
+
name: string;
|
|
107
|
+
path: KubbFile.OptionalPath;
|
|
108
|
+
isTypeOnly?: boolean;
|
|
109
|
+
};
|
|
110
|
+
};
|
|
111
|
+
matches: {
|
|
112
|
+
keyword: 'matches';
|
|
113
|
+
args?: string;
|
|
114
|
+
};
|
|
115
|
+
boolean: {
|
|
116
|
+
keyword: 'boolean';
|
|
117
|
+
};
|
|
118
|
+
default: {
|
|
119
|
+
keyword: 'default';
|
|
120
|
+
args: string | number | boolean;
|
|
121
|
+
};
|
|
122
|
+
string: {
|
|
123
|
+
keyword: 'string';
|
|
124
|
+
};
|
|
125
|
+
integer: {
|
|
126
|
+
keyword: 'integer';
|
|
127
|
+
};
|
|
128
|
+
number: {
|
|
129
|
+
keyword: 'number';
|
|
130
|
+
};
|
|
131
|
+
max: {
|
|
132
|
+
keyword: 'max';
|
|
133
|
+
args: number;
|
|
134
|
+
};
|
|
135
|
+
min: {
|
|
136
|
+
keyword: 'min';
|
|
137
|
+
args: number;
|
|
138
|
+
};
|
|
139
|
+
describe: {
|
|
140
|
+
keyword: 'describe';
|
|
141
|
+
args: string;
|
|
142
|
+
};
|
|
143
|
+
example: {
|
|
144
|
+
keyword: 'example';
|
|
145
|
+
args: string;
|
|
146
|
+
};
|
|
147
|
+
deprecated: {
|
|
148
|
+
keyword: 'deprecated';
|
|
149
|
+
};
|
|
150
|
+
optional: {
|
|
151
|
+
keyword: 'optional';
|
|
152
|
+
};
|
|
153
|
+
undefined: {
|
|
154
|
+
keyword: 'undefined';
|
|
155
|
+
};
|
|
156
|
+
nullish: {
|
|
157
|
+
keyword: 'nullish';
|
|
158
|
+
};
|
|
159
|
+
nullable: {
|
|
160
|
+
keyword: 'nullable';
|
|
161
|
+
};
|
|
162
|
+
null: {
|
|
163
|
+
keyword: 'null';
|
|
164
|
+
};
|
|
165
|
+
any: {
|
|
166
|
+
keyword: 'any';
|
|
167
|
+
};
|
|
168
|
+
unknown: {
|
|
169
|
+
keyword: 'unknown';
|
|
170
|
+
};
|
|
171
|
+
blob: {
|
|
172
|
+
keyword: 'blob';
|
|
173
|
+
};
|
|
174
|
+
schema: {
|
|
175
|
+
keyword: 'schema';
|
|
176
|
+
args: {
|
|
177
|
+
type: 'string' | 'number' | 'integer' | 'boolean' | 'array' | 'object';
|
|
178
|
+
format?: string;
|
|
179
|
+
};
|
|
180
|
+
};
|
|
181
|
+
name: {
|
|
182
|
+
keyword: 'name';
|
|
183
|
+
args: string;
|
|
184
|
+
};
|
|
185
|
+
catchall: {
|
|
186
|
+
keyword: 'catchall';
|
|
187
|
+
};
|
|
188
|
+
};
|
|
189
|
+
declare const schemaKeywords: {
|
|
190
|
+
any: "any";
|
|
191
|
+
strict: "strict";
|
|
192
|
+
unknown: "unknown";
|
|
193
|
+
number: "number";
|
|
194
|
+
integer: "integer";
|
|
195
|
+
string: "string";
|
|
196
|
+
boolean: "boolean";
|
|
197
|
+
undefined: "undefined";
|
|
198
|
+
nullable: "nullable";
|
|
199
|
+
null: "null";
|
|
200
|
+
nullish: "nullish";
|
|
201
|
+
array: "array";
|
|
202
|
+
tuple: "tuple";
|
|
203
|
+
enum: "enum";
|
|
204
|
+
union: "union";
|
|
205
|
+
datetime: "datetime";
|
|
206
|
+
date: "date";
|
|
207
|
+
email: "email";
|
|
208
|
+
uuid: "uuid";
|
|
209
|
+
url: "url";
|
|
210
|
+
default: "default";
|
|
211
|
+
const: "const";
|
|
212
|
+
and: "and";
|
|
213
|
+
describe: "describe";
|
|
214
|
+
min: "min";
|
|
215
|
+
max: "max";
|
|
216
|
+
optional: "optional";
|
|
217
|
+
readOnly: "readOnly";
|
|
218
|
+
object: "object";
|
|
219
|
+
ref: "ref";
|
|
220
|
+
matches: "matches";
|
|
221
|
+
firstName: "firstName";
|
|
222
|
+
lastName: "lastName";
|
|
223
|
+
password: "password";
|
|
224
|
+
phone: "phone";
|
|
225
|
+
blob: "blob";
|
|
226
|
+
deprecated: "deprecated";
|
|
227
|
+
example: "example";
|
|
228
|
+
schema: "schema";
|
|
229
|
+
catchall: "catchall";
|
|
230
|
+
time: "time";
|
|
231
|
+
name: "name";
|
|
232
|
+
};
|
|
233
|
+
type SchemaKeyword = keyof SchemaKeywordMapper;
|
|
234
|
+
type SchemaMapper<T = string | null | undefined> = {
|
|
235
|
+
[K in keyof SchemaKeywordMapper]: (() => T | undefined) | undefined;
|
|
236
|
+
};
|
|
237
|
+
type SchemaKeywordBase<T> = {
|
|
238
|
+
keyword: SchemaKeyword;
|
|
239
|
+
args: T;
|
|
240
|
+
};
|
|
241
|
+
type Schema = {
|
|
242
|
+
keyword: string;
|
|
243
|
+
} | SchemaKeywordMapper[keyof SchemaKeywordMapper];
|
|
244
|
+
declare function isKeyword<T extends Schema, K extends keyof SchemaKeywordMapper>(meta: T, keyword: K): meta is Extract<T, SchemaKeywordMapper[K]>;
|
|
245
|
+
|
|
246
|
+
type SchemaMethodResult<TFileMeta extends KubbFile.FileMetaBase> = Promise<KubbFile.File<TFileMeta> | Array<KubbFile.File<TFileMeta>> | null>;
|
|
247
|
+
type Context<TOptions, TPluginOptions extends PluginFactoryOptions> = {
|
|
248
|
+
oas: Oas;
|
|
249
|
+
pluginManager: PluginManager;
|
|
250
|
+
/**
|
|
251
|
+
* Current plugin
|
|
252
|
+
*/
|
|
253
|
+
plugin: Plugin<TPluginOptions>;
|
|
254
|
+
mode: KubbFile.Mode;
|
|
255
|
+
include?: Array<'schemas' | 'responses' | 'requestBodies'>;
|
|
256
|
+
override: Array<Override<TOptions>> | undefined;
|
|
257
|
+
contentType?: contentType;
|
|
258
|
+
output?: string;
|
|
259
|
+
};
|
|
260
|
+
type SchemaGeneratorOptions = {
|
|
261
|
+
dateType: false | 'string' | 'stringOffset' | 'stringLocal' | 'date';
|
|
262
|
+
unknownType: 'any' | 'unknown';
|
|
263
|
+
enumType?: 'enum' | 'asConst' | 'asPascalConst' | 'constEnum' | 'literal';
|
|
264
|
+
enumSuffix?: string;
|
|
265
|
+
usedEnumNames?: Record<string, number>;
|
|
266
|
+
mapper?: Record<string, string>;
|
|
267
|
+
typed?: boolean;
|
|
268
|
+
transformers: {
|
|
269
|
+
/**
|
|
270
|
+
* Customize the names based on the type that is provided by the plugin.
|
|
271
|
+
*/
|
|
272
|
+
name?: (name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string;
|
|
273
|
+
/**
|
|
274
|
+
* Receive schema and name(propertName) and return FakerMeta array
|
|
275
|
+
* TODO TODO add docs
|
|
276
|
+
* @beta
|
|
277
|
+
*/
|
|
278
|
+
schema?: (schemaProps: SchemaProps, defaultSchemas: Schema[]) => Schema[] | undefined;
|
|
279
|
+
};
|
|
280
|
+
};
|
|
281
|
+
type SchemaGeneratorBuildOptions = Omit<OperationSchema, 'name' | 'schema'>;
|
|
282
|
+
type SchemaProps = {
|
|
283
|
+
schema?: SchemaObject;
|
|
284
|
+
name?: string;
|
|
285
|
+
parentName?: string;
|
|
286
|
+
};
|
|
287
|
+
declare abstract class SchemaGenerator<TOptions extends SchemaGeneratorOptions = SchemaGeneratorOptions, TPluginOptions extends PluginFactoryOptions = PluginFactoryOptions, TFileMeta extends KubbFile.FileMetaBase = KubbFile.FileMetaBase> extends Generator<TOptions, Context<TOptions, TPluginOptions>> {
|
|
288
|
+
#private;
|
|
289
|
+
refs: Refs;
|
|
290
|
+
/**
|
|
291
|
+
* Creates a type node from a given schema.
|
|
292
|
+
* Delegates to getBaseTypeFromSchema internally and
|
|
293
|
+
* optionally adds a union with null.
|
|
294
|
+
*/
|
|
295
|
+
buildSchemas(props: SchemaProps): Schema[];
|
|
296
|
+
deepSearch<T extends keyof SchemaKeywordMapper>(schemas: Schema[] | undefined, keyword: T): SchemaKeywordMapper[T][];
|
|
297
|
+
find<T extends keyof SchemaKeywordMapper>(schemas: Schema[] | undefined, keyword: T): SchemaKeywordMapper[T] | undefined;
|
|
298
|
+
static deepSearch<T extends keyof SchemaKeywordMapper>(schemas: Schema[] | undefined, keyword: T): SchemaKeywordMapper[T][];
|
|
299
|
+
static findInObject<T extends keyof SchemaKeywordMapper>(schemas: Schema[] | undefined, keyword: T): SchemaKeywordMapper[T] | undefined;
|
|
300
|
+
static find<T extends keyof SchemaKeywordMapper>(schemas: Schema[] | undefined, keyword: T): SchemaKeywordMapper[T] | undefined;
|
|
301
|
+
build(): Promise<Array<KubbFile.File<TFileMeta>>>;
|
|
302
|
+
/**
|
|
303
|
+
* Schema
|
|
304
|
+
*/
|
|
305
|
+
abstract schema(name: string, object: SchemaObject): SchemaMethodResult<TFileMeta>;
|
|
306
|
+
/**
|
|
307
|
+
* Returns the source, in the future it will return a React component
|
|
308
|
+
*/
|
|
309
|
+
abstract getSource<TOptions extends SchemaGeneratorBuildOptions = SchemaGeneratorBuildOptions>(name: string, schemas: Schema[], options?: TOptions): string[];
|
|
310
|
+
/**
|
|
311
|
+
* @deprecated only used for testing
|
|
312
|
+
*/
|
|
313
|
+
abstract buildSource(name: string, object: SchemaObject | undefined, options?: SchemaGeneratorBuildOptions): string[];
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
export { type SchemaGeneratorBuildOptions as S, type SchemaGeneratorOptions as a, type SchemaMethodResult as b, SchemaGenerator as c, type Schema as d, type SchemaKeyword as e, type SchemaKeywordBase as f, type SchemaKeywordMapper as g, type SchemaMapper as h, isKeyword as i, schemaKeywords as s };
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import {
|
|
2
|
+
init_esm_shims
|
|
3
|
+
} from "./chunk-LQ6IAWRX.js";
|
|
4
|
+
|
|
5
|
+
// src/SchemaMapper.ts
|
|
6
|
+
init_esm_shims();
|
|
7
|
+
var schemaKeywords = {
|
|
8
|
+
any: "any",
|
|
9
|
+
strict: "strict",
|
|
10
|
+
unknown: "unknown",
|
|
11
|
+
number: "number",
|
|
12
|
+
integer: "integer",
|
|
13
|
+
string: "string",
|
|
14
|
+
boolean: "boolean",
|
|
15
|
+
undefined: "undefined",
|
|
16
|
+
nullable: "nullable",
|
|
17
|
+
null: "null",
|
|
18
|
+
nullish: "nullish",
|
|
19
|
+
array: "array",
|
|
20
|
+
tuple: "tuple",
|
|
21
|
+
enum: "enum",
|
|
22
|
+
union: "union",
|
|
23
|
+
datetime: "datetime",
|
|
24
|
+
date: "date",
|
|
25
|
+
email: "email",
|
|
26
|
+
uuid: "uuid",
|
|
27
|
+
url: "url",
|
|
28
|
+
/* intersection */
|
|
29
|
+
default: "default",
|
|
30
|
+
const: "const",
|
|
31
|
+
and: "and",
|
|
32
|
+
describe: "describe",
|
|
33
|
+
min: "min",
|
|
34
|
+
max: "max",
|
|
35
|
+
optional: "optional",
|
|
36
|
+
readOnly: "readOnly",
|
|
37
|
+
// custom ones
|
|
38
|
+
object: "object",
|
|
39
|
+
ref: "ref",
|
|
40
|
+
matches: "matches",
|
|
41
|
+
firstName: "firstName",
|
|
42
|
+
lastName: "lastName",
|
|
43
|
+
password: "password",
|
|
44
|
+
phone: "phone",
|
|
45
|
+
blob: "blob",
|
|
46
|
+
deprecated: "deprecated",
|
|
47
|
+
example: "example",
|
|
48
|
+
schema: "schema",
|
|
49
|
+
catchall: "catchall",
|
|
50
|
+
time: "time",
|
|
51
|
+
name: "name"
|
|
52
|
+
};
|
|
53
|
+
function isKeyword(meta, keyword) {
|
|
54
|
+
return meta.keyword === keyword;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export {
|
|
58
|
+
schemaKeywords,
|
|
59
|
+
isKeyword
|
|
60
|
+
};
|
|
61
|
+
//# sourceMappingURL=chunk-2MJ2CQMI.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/SchemaMapper.ts"],"sourcesContent":["import type { KubbFile } from '@kubb/core'\n\nexport type SchemaKeywordMapper = {\n object: {\n keyword: 'object'\n args: {\n properties: { [x: string]: Schema[] }\n additionalProperties: Schema[]\n strict?: boolean\n }\n }\n strict: { keyword: 'strict' }\n url: { keyword: 'url' }\n readOnly: { keyword: 'readOnly' }\n uuid: { keyword: 'uuid' }\n email: { keyword: 'email' }\n firstName: { keyword: 'firstName' }\n lastName: { keyword: 'lastName' }\n phone: { keyword: 'phone' }\n password: { keyword: 'password' }\n date: { keyword: 'date'; args: { type?: 'date' | 'string' } }\n time: { keyword: 'time'; args: { type?: 'date' | 'string' } }\n datetime: { keyword: 'datetime'; args: { offset?: boolean; local?: boolean } }\n tuple: { keyword: 'tuple'; args: Schema[] }\n array: {\n keyword: 'array'\n args: { items: Schema[]; min?: number; max?: number }\n }\n enum: {\n keyword: 'enum'\n args: {\n name: string\n typeName: string\n asConst: boolean\n items: Array<{\n name: string | number\n format: 'string' | 'number'\n value?: string | number\n }>\n }\n }\n and: { keyword: 'and'; args: Schema[] }\n const: {\n keyword: 'const'\n args: {\n name: string | number\n format: 'string' | 'number'\n value?: string | number\n }\n }\n union: { keyword: 'union'; args: Schema[] }\n ref: {\n keyword: 'ref'\n args: { name: string; path: KubbFile.OptionalPath; isTypeOnly?: boolean }\n }\n matches: { keyword: 'matches'; args?: string }\n boolean: { keyword: 'boolean' }\n default: { keyword: 'default'; args: string | number | boolean }\n string: { keyword: 'string' }\n integer: { keyword: 'integer' }\n number: { keyword: 'number' }\n max: { keyword: 'max'; args: number }\n min: { keyword: 'min'; args: number }\n describe: { keyword: 'describe'; args: string }\n example: { keyword: 'example'; args: string }\n deprecated: { keyword: 'deprecated' }\n optional: { keyword: 'optional' }\n undefined: { keyword: 'undefined' }\n nullish: { keyword: 'nullish' }\n nullable: { keyword: 'nullable' }\n null: { keyword: 'null' }\n any: { keyword: 'any' }\n unknown: { keyword: 'unknown' }\n blob: { keyword: 'blob' }\n schema: { keyword: 'schema'; args: { type: 'string' | 'number' | 'integer' | 'boolean' | 'array' | 'object'; format?: string } }\n name: { keyword: 'name'; args: string }\n catchall: { keyword: 'catchall' }\n}\n\nexport const schemaKeywords = {\n any: 'any',\n strict: 'strict',\n unknown: 'unknown',\n number: 'number',\n integer: 'integer',\n string: 'string',\n boolean: 'boolean',\n undefined: 'undefined',\n nullable: 'nullable',\n null: 'null',\n nullish: 'nullish',\n array: 'array',\n tuple: 'tuple',\n enum: 'enum',\n union: 'union',\n datetime: 'datetime',\n date: 'date',\n email: 'email',\n uuid: 'uuid',\n url: 'url',\n /* intersection */\n default: 'default',\n const: 'const',\n and: 'and',\n describe: 'describe',\n min: 'min',\n max: 'max',\n optional: 'optional',\n readOnly: 'readOnly',\n\n // custom ones\n object: 'object',\n ref: 'ref',\n matches: 'matches',\n firstName: 'firstName',\n lastName: 'lastName',\n password: 'password',\n phone: 'phone',\n blob: 'blob',\n deprecated: 'deprecated',\n example: 'example',\n schema: 'schema',\n catchall: 'catchall',\n time: 'time',\n name: 'name',\n} satisfies {\n [K in keyof SchemaKeywordMapper]: SchemaKeywordMapper[K]['keyword']\n}\n\nexport type SchemaKeyword = keyof SchemaKeywordMapper\n\nexport type SchemaMapper<T = string | null | undefined> = {\n [K in keyof SchemaKeywordMapper]: (() => T | undefined) | undefined\n}\n\nexport type SchemaKeywordBase<T> = {\n keyword: SchemaKeyword\n args: T\n}\n\nexport type Schema = { keyword: string } | SchemaKeywordMapper[keyof SchemaKeywordMapper]\n\nexport function isKeyword<T extends Schema, K extends keyof SchemaKeywordMapper>(meta: T, keyword: K): meta is Extract<T, SchemaKeywordMapper[K]> {\n return meta.keyword === keyword\n}\n"],"mappings":";;;;;AAAA;AA+EO,IAAM,iBAAiB;AAAA,EAC5B,KAAK;AAAA,EACL,QAAQ;AAAA,EACR,SAAS;AAAA,EACT,QAAQ;AAAA,EACR,SAAS;AAAA,EACT,QAAQ;AAAA,EACR,SAAS;AAAA,EACT,WAAW;AAAA,EACX,UAAU;AAAA,EACV,MAAM;AAAA,EACN,SAAS;AAAA,EACT,OAAO;AAAA,EACP,OAAO;AAAA,EACP,MAAM;AAAA,EACN,OAAO;AAAA,EACP,UAAU;AAAA,EACV,MAAM;AAAA,EACN,OAAO;AAAA,EACP,MAAM;AAAA,EACN,KAAK;AAAA;AAAA,EAEL,SAAS;AAAA,EACT,OAAO;AAAA,EACP,KAAK;AAAA,EACL,UAAU;AAAA,EACV,KAAK;AAAA,EACL,KAAK;AAAA,EACL,UAAU;AAAA,EACV,UAAU;AAAA;AAAA,EAGV,QAAQ;AAAA,EACR,KAAK;AAAA,EACL,SAAS;AAAA,EACT,WAAW;AAAA,EACX,UAAU;AAAA,EACV,UAAU;AAAA,EACV,OAAO;AAAA,EACP,MAAM;AAAA,EACN,YAAY;AAAA,EACZ,SAAS;AAAA,EACT,QAAQ;AAAA,EACR,UAAU;AAAA,EACV,MAAM;AAAA,EACN,MAAM;AACR;AAiBO,SAAS,UAAiE,MAAS,SAAwD;AAChJ,SAAO,KAAK,YAAY;AAC1B;","names":[]}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import {
|
|
2
|
+
init_esm_shims
|
|
3
|
+
} from "./chunk-LQ6IAWRX.js";
|
|
4
|
+
|
|
5
|
+
// src/utils/getSchemas.ts
|
|
6
|
+
init_esm_shims();
|
|
7
|
+
function getSchemas({ oas, contentType, includes = ["schemas", "requestBodies", "responses"] }) {
|
|
8
|
+
const components = oas.getDefinition().components;
|
|
9
|
+
let schemas = {};
|
|
10
|
+
if (includes.includes("schemas")) {
|
|
11
|
+
schemas = {
|
|
12
|
+
...schemas,
|
|
13
|
+
...components?.schemas || {}
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
const requestBodies = components?.requestBodies || {};
|
|
17
|
+
if (includes.includes("responses")) {
|
|
18
|
+
const responses = components?.responses || {};
|
|
19
|
+
Object.entries(responses).forEach(([name, response]) => {
|
|
20
|
+
if (response.content && !schemas[name]) {
|
|
21
|
+
const firstContentType = Object.keys(response.content)[0] || "application/json";
|
|
22
|
+
schemas[name] = response.content?.[contentType || firstContentType]?.schema;
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
if (includes.includes("requestBodies")) {
|
|
27
|
+
Object.entries(requestBodies).forEach(([name, request]) => {
|
|
28
|
+
if (request.content && !schemas[name]) {
|
|
29
|
+
const firstContentType = Object.keys(request.content)[0] || "application/json";
|
|
30
|
+
schemas[name] = request.content?.[contentType || firstContentType]?.schema;
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
return schemas;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// src/utils/parseFromConfig.ts
|
|
38
|
+
init_esm_shims();
|
|
39
|
+
import { resolve } from "path";
|
|
40
|
+
import { URLPath } from "@kubb/core/utils";
|
|
41
|
+
import { parse } from "@kubb/oas/parser";
|
|
42
|
+
import yaml from "@stoplight/yaml";
|
|
43
|
+
function parseFromConfig(config, options = {}) {
|
|
44
|
+
if ("data" in config.input) {
|
|
45
|
+
if (typeof config.input.data === "object") {
|
|
46
|
+
const api2 = JSON.parse(JSON.stringify(config.input.data));
|
|
47
|
+
return parse(api2, options);
|
|
48
|
+
}
|
|
49
|
+
try {
|
|
50
|
+
const api2 = yaml.parse(config.input.data);
|
|
51
|
+
return parse(api2, options);
|
|
52
|
+
} catch (e) {
|
|
53
|
+
}
|
|
54
|
+
const api = JSON.parse(JSON.stringify(config.input.data));
|
|
55
|
+
return parse(api, options);
|
|
56
|
+
}
|
|
57
|
+
if (new URLPath(config.input.path).isURL) {
|
|
58
|
+
return parse(config.input.path, options);
|
|
59
|
+
}
|
|
60
|
+
return parse(resolve(config.root, config.input.path), options);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// src/utils/getSchemaFactory.ts
|
|
64
|
+
init_esm_shims();
|
|
65
|
+
import { isOpenApiV3_1Document } from "@kubb/oas";
|
|
66
|
+
function getSchemaFactory(oas) {
|
|
67
|
+
return (schema) => {
|
|
68
|
+
const version = isOpenApiV3_1Document(oas.api) ? "3.1" : "3.0";
|
|
69
|
+
return {
|
|
70
|
+
schema,
|
|
71
|
+
version
|
|
72
|
+
};
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export {
|
|
77
|
+
getSchemas,
|
|
78
|
+
parseFromConfig,
|
|
79
|
+
getSchemaFactory
|
|
80
|
+
};
|
|
81
|
+
//# sourceMappingURL=chunk-3RCQ2LNT.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/utils/getSchemas.ts","../src/utils/parseFromConfig.ts","../src/utils/getSchemaFactory.ts"],"sourcesContent":["import type { Oas, OasTypes, contentType } from '@kubb/oas'\n\ntype Mode = 'schemas' | 'responses' | 'requestBodies'\n\nexport type GetSchemasProps = {\n oas: Oas\n contentType?: contentType\n includes?: Mode[]\n}\n\nexport function getSchemas({ oas, contentType, includes = ['schemas', 'requestBodies', 'responses'] }: GetSchemasProps): Record<string, OasTypes.SchemaObject> {\n const components = oas.getDefinition().components\n\n let schemas: Record<string, OasTypes.SchemaObject> = {}\n\n if (includes.includes('schemas')) {\n schemas = {\n ...schemas,\n ...((components?.schemas as Record<string, OasTypes.SchemaObject>) || {}),\n }\n }\n\n const requestBodies = components?.requestBodies || {}\n if (includes.includes('responses')) {\n const responses = components?.responses || {}\n\n Object.entries(responses).forEach(([name, response]: [string, OasTypes.ResponseObject]) => {\n if (response.content && !schemas[name]) {\n const firstContentType = Object.keys(response.content)[0] || 'application/json'\n schemas[name] = response.content?.[contentType || firstContentType]?.schema as OasTypes.SchemaObject\n }\n })\n }\n\n if (includes.includes('requestBodies')) {\n Object.entries(requestBodies).forEach(([name, request]: [string, OasTypes.RequestBodyObject]) => {\n if (request.content && !schemas[name]) {\n const firstContentType = Object.keys(request.content)[0] || 'application/json'\n schemas[name] = request.content?.[contentType || firstContentType]?.schema as OasTypes.SchemaObject\n }\n })\n }\n\n return schemas\n}\n","import { resolve } from 'node:path'\n\nimport { URLPath } from '@kubb/core/utils'\n\nimport { type FormatOptions, parse } from '@kubb/oas/parser'\n\nimport type { Config } from '@kubb/core'\nimport type { Oas, OasTypes } from '@kubb/oas'\nimport yaml from '@stoplight/yaml'\n\nexport function parseFromConfig(config: Config, options: FormatOptions = {}): 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, options)\n }\n\n try {\n const api: string = yaml.parse(config.input.data as string) as string\n\n return parse(api, options)\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, options)\n }\n\n if (new URLPath(config.input.path).isURL) {\n return parse(config.input.path, options)\n }\n\n return parse(resolve(config.root, config.input.path), options)\n}\n","import { isOpenApiV3_1Document } from '@kubb/oas'\n\nimport type { Oas, OpenAPIV3, OpenAPIV3_1, SchemaObject } from '@kubb/oas'\n\n/**\n * Make it possible to narrow down the schema based on a specific version(3 or 3.1)\n */\ntype SchemaResult<TWithRef extends boolean = false> =\n | {\n schema?: (TWithRef extends true ? OpenAPIV3.SchemaObject | OpenAPIV3.ReferenceObject : OpenAPIV3.SchemaObject) & {\n nullable?: boolean\n 'x-nullable'?: boolean\n }\n version: '3.0'\n }\n | {\n schema?: (TWithRef extends true ? OpenAPIV3_1.SchemaObject | OpenAPIV3_1.ReferenceObject : OpenAPIV3_1.SchemaObject) & {\n nullable?: boolean\n 'x-nullable'?: boolean\n }\n version: '3.1'\n }\n\nexport function getSchemaFactory<TWithRef extends boolean = false>(oas: Oas): (schema?: SchemaObject) => SchemaResult<TWithRef> {\n return (schema?: SchemaObject) => {\n const version = isOpenApiV3_1Document(oas.api) ? '3.1' : '3.0'\n\n return {\n schema,\n version,\n } as SchemaResult<TWithRef>\n }\n}\n"],"mappings":";;;;;AAAA;AAUO,SAAS,WAAW,EAAE,KAAK,aAAa,WAAW,CAAC,WAAW,iBAAiB,WAAW,EAAE,GAA2D;AAC7J,QAAM,aAAa,IAAI,cAAc,EAAE;AAEvC,MAAI,UAAiD,CAAC;AAEtD,MAAI,SAAS,SAAS,SAAS,GAAG;AAChC,cAAU;AAAA,MACR,GAAG;AAAA,MACH,GAAK,YAAY,WAAqD,CAAC;AAAA,IACzE;AAAA,EACF;AAEA,QAAM,gBAAgB,YAAY,iBAAiB,CAAC;AACpD,MAAI,SAAS,SAAS,WAAW,GAAG;AAClC,UAAM,YAAY,YAAY,aAAa,CAAC;AAE5C,WAAO,QAAQ,SAAS,EAAE,QAAQ,CAAC,CAAC,MAAM,QAAQ,MAAyC;AACzF,UAAI,SAAS,WAAW,CAAC,QAAQ,IAAI,GAAG;AACtC,cAAM,mBAAmB,OAAO,KAAK,SAAS,OAAO,EAAE,CAAC,KAAK;AAC7D,gBAAQ,IAAI,IAAI,SAAS,UAAU,eAAe,gBAAgB,GAAG;AAAA,MACvE;AAAA,IACF,CAAC;AAAA,EACH;AAEA,MAAI,SAAS,SAAS,eAAe,GAAG;AACtC,WAAO,QAAQ,aAAa,EAAE,QAAQ,CAAC,CAAC,MAAM,OAAO,MAA4C;AAC/F,UAAI,QAAQ,WAAW,CAAC,QAAQ,IAAI,GAAG;AACrC,cAAM,mBAAmB,OAAO,KAAK,QAAQ,OAAO,EAAE,CAAC,KAAK;AAC5D,gBAAQ,IAAI,IAAI,QAAQ,UAAU,eAAe,gBAAgB,GAAG;AAAA,MACtE;AAAA,IACF,CAAC;AAAA,EACH;AAEA,SAAO;AACT;;;AC5CA;AAAA,SAAS,eAAe;AAExB,SAAS,eAAe;AAExB,SAA6B,aAAa;AAI1C,OAAO,UAAU;AAEV,SAAS,gBAAgB,QAAgB,UAAyB,CAAC,GAAiB;AACzF,MAAI,UAAU,OAAO,OAAO;AAC1B,QAAI,OAAO,OAAO,MAAM,SAAS,UAAU;AACzC,YAAMA,OAA4B,KAAK,MAAM,KAAK,UAAU,OAAO,MAAM,IAAI,CAAC;AAC9E,aAAO,MAAMA,MAAK,OAAO;AAAA,IAC3B;AAEA,QAAI;AACF,YAAMA,OAAc,KAAK,MAAM,OAAO,MAAM,IAAc;AAE1D,aAAO,MAAMA,MAAK,OAAO;AAAA,IAC3B,SAAS,GAAG;AAAA,IAEZ;AAEA,UAAM,MAA4B,KAAK,MAAM,KAAK,UAAU,OAAO,MAAM,IAAI,CAAC;AAE9E,WAAO,MAAM,KAAK,OAAO;AAAA,EAC3B;AAEA,MAAI,IAAI,QAAQ,OAAO,MAAM,IAAI,EAAE,OAAO;AACxC,WAAO,MAAM,OAAO,MAAM,MAAM,OAAO;AAAA,EACzC;AAEA,SAAO,MAAM,QAAQ,OAAO,MAAM,OAAO,MAAM,IAAI,GAAG,OAAO;AAC/D;;;ACnCA;AAAA,SAAS,6BAA6B;AAuB/B,SAAS,iBAAmD,KAA6D;AAC9H,SAAO,CAAC,WAA0B;AAChC,UAAM,UAAU,sBAAsB,IAAI,GAAG,IAAI,QAAQ;AAEzD,WAAO;AAAA,MACL;AAAA,MACA;AAAA,IACF;AAAA,EACF;AACF;","names":["api"]}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __esm = (fn, res) => function __init() {
|
|
8
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
9
|
+
};
|
|
10
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
11
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
12
|
+
};
|
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from))
|
|
16
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
17
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
18
|
+
}
|
|
19
|
+
return to;
|
|
20
|
+
};
|
|
21
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
22
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
23
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
24
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
25
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
26
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
27
|
+
mod
|
|
28
|
+
));
|
|
29
|
+
var __accessCheck = (obj, member, msg) => {
|
|
30
|
+
if (!member.has(obj))
|
|
31
|
+
throw TypeError("Cannot " + msg);
|
|
32
|
+
};
|
|
33
|
+
var __privateGet = (obj, member, getter) => {
|
|
34
|
+
__accessCheck(obj, member, "read from private field");
|
|
35
|
+
return getter ? getter.call(obj) : member.get(obj);
|
|
36
|
+
};
|
|
37
|
+
var __privateAdd = (obj, member, value) => {
|
|
38
|
+
if (member.has(obj))
|
|
39
|
+
throw TypeError("Cannot add the same private member more than once");
|
|
40
|
+
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
41
|
+
};
|
|
42
|
+
var __privateSet = (obj, member, value, setter) => {
|
|
43
|
+
__accessCheck(obj, member, "write to private field");
|
|
44
|
+
setter ? setter.call(obj, value) : member.set(obj, value);
|
|
45
|
+
return value;
|
|
46
|
+
};
|
|
47
|
+
var __privateMethod = (obj, member, method) => {
|
|
48
|
+
__accessCheck(obj, member, "access private method");
|
|
49
|
+
return method;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
// ../../node_modules/.pnpm/tsup@8.0.2_@microsoft+api-extractor@7.43.3_@types+node@20.12.11__postcss@8.4.38_ts-node@10.9._m3ved7kneisj6uq6vsf2lw6r5q/node_modules/tsup/assets/cjs_shims.js
|
|
53
|
+
var init_cjs_shims = __esm({
|
|
54
|
+
"../../node_modules/.pnpm/tsup@8.0.2_@microsoft+api-extractor@7.43.3_@types+node@20.12.11__postcss@8.4.38_ts-node@10.9._m3ved7kneisj6uq6vsf2lw6r5q/node_modules/tsup/assets/cjs_shims.js"() {
|
|
55
|
+
"use strict";
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
exports.__commonJS = __commonJS; exports.__toESM = __toESM; exports.__privateGet = __privateGet; exports.__privateAdd = __privateAdd; exports.__privateSet = __privateSet; exports.__privateMethod = __privateMethod; exports.init_cjs_shims = init_cjs_shims;
|
|
68
|
+
//# sourceMappingURL=chunk-55NUFNT6.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../node_modules/.pnpm/tsup@8.0.2_@microsoft+api-extractor@7.43.3_@types+node@20.12.11__postcss@8.4.38_ts-node@10.9._m3ved7kneisj6uq6vsf2lw6r5q/node_modules/tsup/assets/cjs_shims.js"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA","sourcesContent":["// Shim globals in cjs bundle\n// There's a weird bug that esbuild will always inject importMetaUrl\n// if we export it as `const importMetaUrl = ... __filename ...`\n// But using a function will not cause this issue\n\nconst getImportMetaUrl = () =>\n typeof document === 'undefined'\n ? new URL('file:' + __filename).href\n : (document.currentScript && document.currentScript.src) ||\n new URL('main.js', document.baseURI).href\n\nexport const importMetaUrl = /* @__PURE__ */ getImportMetaUrl()\n"]}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
|
+
|
|
3
|
+
var _chunk55NUFNT6cjs = require('./chunk-55NUFNT6.cjs');
|
|
4
|
+
|
|
5
|
+
// src/utils/getSchemas.ts
|
|
6
|
+
_chunk55NUFNT6cjs.init_cjs_shims.call(void 0, );
|
|
7
|
+
function getSchemas({ oas, contentType, includes = ["schemas", "requestBodies", "responses"] }) {
|
|
8
|
+
const components = oas.getDefinition().components;
|
|
9
|
+
let schemas = {};
|
|
10
|
+
if (includes.includes("schemas")) {
|
|
11
|
+
schemas = {
|
|
12
|
+
...schemas,
|
|
13
|
+
..._optionalChain([components, 'optionalAccess', _ => _.schemas]) || {}
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
const requestBodies = _optionalChain([components, 'optionalAccess', _2 => _2.requestBodies]) || {};
|
|
17
|
+
if (includes.includes("responses")) {
|
|
18
|
+
const responses = _optionalChain([components, 'optionalAccess', _3 => _3.responses]) || {};
|
|
19
|
+
Object.entries(responses).forEach(([name, response]) => {
|
|
20
|
+
if (response.content && !schemas[name]) {
|
|
21
|
+
const firstContentType = Object.keys(response.content)[0] || "application/json";
|
|
22
|
+
schemas[name] = _optionalChain([response, 'access', _4 => _4.content, 'optionalAccess', _5 => _5[contentType || firstContentType], 'optionalAccess', _6 => _6.schema]);
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
if (includes.includes("requestBodies")) {
|
|
27
|
+
Object.entries(requestBodies).forEach(([name, request]) => {
|
|
28
|
+
if (request.content && !schemas[name]) {
|
|
29
|
+
const firstContentType = Object.keys(request.content)[0] || "application/json";
|
|
30
|
+
schemas[name] = _optionalChain([request, 'access', _7 => _7.content, 'optionalAccess', _8 => _8[contentType || firstContentType], 'optionalAccess', _9 => _9.schema]);
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
return schemas;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// src/utils/parseFromConfig.ts
|
|
38
|
+
_chunk55NUFNT6cjs.init_cjs_shims.call(void 0, );
|
|
39
|
+
var _path = require('path');
|
|
40
|
+
var _utils = require('@kubb/core/utils');
|
|
41
|
+
var _parser = require('@kubb/oas/parser');
|
|
42
|
+
var _yaml = require('@stoplight/yaml'); var _yaml2 = _interopRequireDefault(_yaml);
|
|
43
|
+
function parseFromConfig(config, options = {}) {
|
|
44
|
+
if ("data" in config.input) {
|
|
45
|
+
if (typeof config.input.data === "object") {
|
|
46
|
+
const api2 = JSON.parse(JSON.stringify(config.input.data));
|
|
47
|
+
return _parser.parse.call(void 0, api2, options);
|
|
48
|
+
}
|
|
49
|
+
try {
|
|
50
|
+
const api2 = _yaml2.default.parse(config.input.data);
|
|
51
|
+
return _parser.parse.call(void 0, api2, options);
|
|
52
|
+
} catch (e) {
|
|
53
|
+
}
|
|
54
|
+
const api = JSON.parse(JSON.stringify(config.input.data));
|
|
55
|
+
return _parser.parse.call(void 0, api, options);
|
|
56
|
+
}
|
|
57
|
+
if (new (0, _utils.URLPath)(config.input.path).isURL) {
|
|
58
|
+
return _parser.parse.call(void 0, config.input.path, options);
|
|
59
|
+
}
|
|
60
|
+
return _parser.parse.call(void 0, _path.resolve.call(void 0, config.root, config.input.path), options);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// src/utils/getSchemaFactory.ts
|
|
64
|
+
_chunk55NUFNT6cjs.init_cjs_shims.call(void 0, );
|
|
65
|
+
var _oas = require('@kubb/oas');
|
|
66
|
+
function getSchemaFactory(oas) {
|
|
67
|
+
return (schema) => {
|
|
68
|
+
const version = _oas.isOpenApiV3_1Document.call(void 0, oas.api) ? "3.1" : "3.0";
|
|
69
|
+
return {
|
|
70
|
+
schema,
|
|
71
|
+
version
|
|
72
|
+
};
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
exports.getSchemas = getSchemas; exports.parseFromConfig = parseFromConfig; exports.getSchemaFactory = getSchemaFactory;
|
|
81
|
+
//# sourceMappingURL=chunk-ECXSQTMV.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/utils/getSchemas.ts","../src/utils/parseFromConfig.ts","../src/utils/getSchemaFactory.ts"],"names":["api"],"mappings":";;;;;AAAA;AAUO,SAAS,WAAW,EAAE,KAAK,aAAa,WAAW,CAAC,WAAW,iBAAiB,WAAW,EAAE,GAA2D;AAC7J,QAAM,aAAa,IAAI,cAAc,EAAE;AAEvC,MAAI,UAAiD,CAAC;AAEtD,MAAI,SAAS,SAAS,SAAS,GAAG;AAChC,cAAU;AAAA,MACR,GAAG;AAAA,MACH,GAAK,YAAY,WAAqD,CAAC;AAAA,IACzE;AAAA,EACF;AAEA,QAAM,gBAAgB,YAAY,iBAAiB,CAAC;AACpD,MAAI,SAAS,SAAS,WAAW,GAAG;AAClC,UAAM,YAAY,YAAY,aAAa,CAAC;AAE5C,WAAO,QAAQ,SAAS,EAAE,QAAQ,CAAC,CAAC,MAAM,QAAQ,MAAyC;AACzF,UAAI,SAAS,WAAW,CAAC,QAAQ,IAAI,GAAG;AACtC,cAAM,mBAAmB,OAAO,KAAK,SAAS,OAAO,EAAE,CAAC,KAAK;AAC7D,gBAAQ,IAAI,IAAI,SAAS,UAAU,eAAe,gBAAgB,GAAG;AAAA,MACvE;AAAA,IACF,CAAC;AAAA,EACH;AAEA,MAAI,SAAS,SAAS,eAAe,GAAG;AACtC,WAAO,QAAQ,aAAa,EAAE,QAAQ,CAAC,CAAC,MAAM,OAAO,MAA4C;AAC/F,UAAI,QAAQ,WAAW,CAAC,QAAQ,IAAI,GAAG;AACrC,cAAM,mBAAmB,OAAO,KAAK,QAAQ,OAAO,EAAE,CAAC,KAAK;AAC5D,gBAAQ,IAAI,IAAI,QAAQ,UAAU,eAAe,gBAAgB,GAAG;AAAA,MACtE;AAAA,IACF,CAAC;AAAA,EACH;AAEA,SAAO;AACT;;;AC5CA;AAAA,SAAS,eAAe;AAExB,SAAS,eAAe;AAExB,SAA6B,aAAa;AAI1C,OAAO,UAAU;AAEV,SAAS,gBAAgB,QAAgB,UAAyB,CAAC,GAAiB;AACzF,MAAI,UAAU,OAAO,OAAO;AAC1B,QAAI,OAAO,OAAO,MAAM,SAAS,UAAU;AACzC,YAAMA,OAA4B,KAAK,MAAM,KAAK,UAAU,OAAO,MAAM,IAAI,CAAC;AAC9E,aAAO,MAAMA,MAAK,OAAO;AAAA,IAC3B;AAEA,QAAI;AACF,YAAMA,OAAc,KAAK,MAAM,OAAO,MAAM,IAAc;AAE1D,aAAO,MAAMA,MAAK,OAAO;AAAA,IAC3B,SAAS,GAAG;AAAA,IAEZ;AAEA,UAAM,MAA4B,KAAK,MAAM,KAAK,UAAU,OAAO,MAAM,IAAI,CAAC;AAE9E,WAAO,MAAM,KAAK,OAAO;AAAA,EAC3B;AAEA,MAAI,IAAI,QAAQ,OAAO,MAAM,IAAI,EAAE,OAAO;AACxC,WAAO,MAAM,OAAO,MAAM,MAAM,OAAO;AAAA,EACzC;AAEA,SAAO,MAAM,QAAQ,OAAO,MAAM,OAAO,MAAM,IAAI,GAAG,OAAO;AAC/D;;;ACnCA;AAAA,SAAS,6BAA6B;AAuB/B,SAAS,iBAAmD,KAA6D;AAC9H,SAAO,CAAC,WAA0B;AAChC,UAAM,UAAU,sBAAsB,IAAI,GAAG,IAAI,QAAQ;AAEzD,WAAO;AAAA,MACL;AAAA,MACA;AAAA,IACF;AAAA,EACF;AACF","sourcesContent":["import type { Oas, OasTypes, contentType } from '@kubb/oas'\n\ntype Mode = 'schemas' | 'responses' | 'requestBodies'\n\nexport type GetSchemasProps = {\n oas: Oas\n contentType?: contentType\n includes?: Mode[]\n}\n\nexport function getSchemas({ oas, contentType, includes = ['schemas', 'requestBodies', 'responses'] }: GetSchemasProps): Record<string, OasTypes.SchemaObject> {\n const components = oas.getDefinition().components\n\n let schemas: Record<string, OasTypes.SchemaObject> = {}\n\n if (includes.includes('schemas')) {\n schemas = {\n ...schemas,\n ...((components?.schemas as Record<string, OasTypes.SchemaObject>) || {}),\n }\n }\n\n const requestBodies = components?.requestBodies || {}\n if (includes.includes('responses')) {\n const responses = components?.responses || {}\n\n Object.entries(responses).forEach(([name, response]: [string, OasTypes.ResponseObject]) => {\n if (response.content && !schemas[name]) {\n const firstContentType = Object.keys(response.content)[0] || 'application/json'\n schemas[name] = response.content?.[contentType || firstContentType]?.schema as OasTypes.SchemaObject\n }\n })\n }\n\n if (includes.includes('requestBodies')) {\n Object.entries(requestBodies).forEach(([name, request]: [string, OasTypes.RequestBodyObject]) => {\n if (request.content && !schemas[name]) {\n const firstContentType = Object.keys(request.content)[0] || 'application/json'\n schemas[name] = request.content?.[contentType || firstContentType]?.schema as OasTypes.SchemaObject\n }\n })\n }\n\n return schemas\n}\n","import { resolve } from 'node:path'\n\nimport { URLPath } from '@kubb/core/utils'\n\nimport { type FormatOptions, parse } from '@kubb/oas/parser'\n\nimport type { Config } from '@kubb/core'\nimport type { Oas, OasTypes } from '@kubb/oas'\nimport yaml from '@stoplight/yaml'\n\nexport function parseFromConfig(config: Config, options: FormatOptions = {}): 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, options)\n }\n\n try {\n const api: string = yaml.parse(config.input.data as string) as string\n\n return parse(api, options)\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, options)\n }\n\n if (new URLPath(config.input.path).isURL) {\n return parse(config.input.path, options)\n }\n\n return parse(resolve(config.root, config.input.path), options)\n}\n","import { isOpenApiV3_1Document } from '@kubb/oas'\n\nimport type { Oas, OpenAPIV3, OpenAPIV3_1, SchemaObject } from '@kubb/oas'\n\n/**\n * Make it possible to narrow down the schema based on a specific version(3 or 3.1)\n */\ntype SchemaResult<TWithRef extends boolean = false> =\n | {\n schema?: (TWithRef extends true ? OpenAPIV3.SchemaObject | OpenAPIV3.ReferenceObject : OpenAPIV3.SchemaObject) & {\n nullable?: boolean\n 'x-nullable'?: boolean\n }\n version: '3.0'\n }\n | {\n schema?: (TWithRef extends true ? OpenAPIV3_1.SchemaObject | OpenAPIV3_1.ReferenceObject : OpenAPIV3_1.SchemaObject) & {\n nullable?: boolean\n 'x-nullable'?: boolean\n }\n version: '3.1'\n }\n\nexport function getSchemaFactory<TWithRef extends boolean = false>(oas: Oas): (schema?: SchemaObject) => SchemaResult<TWithRef> {\n return (schema?: SchemaObject) => {\n const version = isOpenApiV3_1Document(oas.api) ? '3.1' : '3.0'\n\n return {\n schema,\n version,\n } as SchemaResult<TWithRef>\n }\n}\n"]}
|