@kubb/plugin-oas 3.0.0-alpha.0 → 3.0.0-alpha.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/OperationGenerator-By5WOmWB.d.ts +165 -0
- package/dist/OperationGenerator-Gd1X7wUz.d.cts +165 -0
- package/dist/{Schema-DefwBJMc.d.ts → Schema-B1vcPGiK.d.ts} +3 -5
- package/dist/{Schema-an5hOrjZ.d.cts → Schema-DoSFh7Qd.d.cts} +3 -5
- package/dist/{SchemaMapper-CsBQ6eEx.d.cts → SchemaMapper-sGcY1xL5.d.cts} +1 -2
- package/dist/{SchemaMapper-CsBQ6eEx.d.ts → SchemaMapper-sGcY1xL5.d.ts} +1 -2
- package/dist/chunk-75BIOXB7.cjs +7 -0
- package/dist/chunk-75BIOXB7.cjs.map +1 -0
- package/dist/{chunk-UKUEVTRB.cjs → chunk-IAUV3UKH.cjs} +735 -35
- package/dist/chunk-IAUV3UKH.cjs.map +1 -0
- package/dist/{chunk-QSM6A5QX.js → chunk-M347763D.js} +714 -14
- package/dist/chunk-M347763D.js.map +1 -0
- package/dist/{chunk-GUPCIAYT.js → chunk-N7EEVJA6.js} +3 -3
- package/dist/{chunk-J7IF3KA3.cjs → chunk-NU4F7G47.cjs} +4 -16
- package/dist/chunk-NU4F7G47.cjs.map +1 -0
- package/dist/{chunk-3UN2S6P2.cjs → chunk-O76YQFZB.cjs} +3 -3
- package/dist/{chunk-3UN2S6P2.cjs.map → chunk-O76YQFZB.cjs.map} +1 -1
- package/dist/chunk-SQ64ESS4.js +7 -0
- package/dist/chunk-SQ64ESS4.js.map +1 -0
- package/dist/{chunk-Y272OQMW.js → chunk-SZDO532A.js} +3 -15
- package/dist/chunk-SZDO532A.js.map +1 -0
- package/dist/components.cjs +4 -9
- package/dist/components.cjs.map +1 -1
- package/dist/components.d.cts +13 -7
- package/dist/components.d.ts +13 -7
- package/dist/components.js +3 -8
- package/dist/components.js.map +1 -1
- package/dist/hooks.cjs +12 -13
- package/dist/hooks.cjs.map +1 -1
- package/dist/hooks.d.cts +4 -4
- package/dist/hooks.d.ts +4 -4
- package/dist/hooks.js +2 -3
- package/dist/hooks.js.map +1 -1
- package/dist/index.cjs +282 -231
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +8 -77
- package/dist/index.d.ts +8 -77
- package/dist/index.js +274 -223
- package/dist/index.js.map +1 -1
- package/dist/{types-BP45TdiW.d.cts → types-CZTUCaE5.d.cts} +3 -6
- package/dist/{types-BP45TdiW.d.ts → types-CZTUCaE5.d.ts} +3 -6
- package/dist/utils.cjs +12 -54
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.d.cts +7 -33
- package/dist/utils.d.ts +7 -33
- package/dist/utils.js +6 -48
- package/dist/utils.js.map +1 -1
- package/package.json +12 -11
- package/src/OperationGenerator.ts +68 -32
- package/src/SchemaGenerator.ts +32 -15
- package/src/SchemaMapper.ts +1 -1
- package/src/components/Oas.tsx +9 -3
- package/src/components/Operation.tsx +1 -1
- package/src/components/Schema.tsx +29 -31
- package/src/generator.tsx +125 -0
- package/src/hooks/useOperationManager.ts +1 -0
- package/src/index.ts +3 -9
- package/src/plugin.ts +25 -38
- package/src/types.ts +2 -6
- package/src/utils/getParams.ts +1 -1
- package/src/utils/index.ts +2 -1
- package/dist/OperationGenerator-B0RLFu4P.d.ts +0 -60
- package/dist/OperationGenerator-CrCcKl3S.d.cts +0 -60
- package/dist/chunk-J7IF3KA3.cjs.map +0 -1
- package/dist/chunk-K4GEQ3C2.cjs +0 -698
- package/dist/chunk-K4GEQ3C2.cjs.map +0 -1
- package/dist/chunk-QSM6A5QX.js.map +0 -1
- package/dist/chunk-UKUEVTRB.cjs.map +0 -1
- package/dist/chunk-Y272OQMW.js.map +0 -1
- package/dist/chunk-ZZ7ZC4TT.js +0 -698
- package/dist/chunk-ZZ7ZC4TT.js.map +0 -1
- package/src/utils/getGroupedByTagFiles.ts +0 -82
- /package/dist/{chunk-GUPCIAYT.js.map → chunk-N7EEVJA6.js.map} +0 -0
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
SchemaGenerator,
|
|
3
|
-
schemaKeywords
|
|
4
|
-
} from "./chunk-ZZ7ZC4TT.js";
|
|
5
1
|
import {
|
|
6
2
|
__commonJS,
|
|
7
3
|
__toESM,
|
|
4
|
+
getSchemaFactory,
|
|
5
|
+
getSchemas,
|
|
8
6
|
init_esm_shims
|
|
9
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-SZDO532A.js";
|
|
10
8
|
|
|
11
9
|
// ../../node_modules/.pnpm/react@18.3.1/node_modules/react/cjs/react.production.min.js
|
|
12
10
|
var require_react_production_min = __commonJS({
|
|
@@ -3103,6 +3101,700 @@ var require_jsx_runtime = __commonJS({
|
|
|
3103
3101
|
}
|
|
3104
3102
|
});
|
|
3105
3103
|
|
|
3104
|
+
// src/SchemaMapper.ts
|
|
3105
|
+
init_esm_shims();
|
|
3106
|
+
var schemaKeywords = {
|
|
3107
|
+
any: "any",
|
|
3108
|
+
strict: "strict",
|
|
3109
|
+
unknown: "unknown",
|
|
3110
|
+
number: "number",
|
|
3111
|
+
integer: "integer",
|
|
3112
|
+
string: "string",
|
|
3113
|
+
boolean: "boolean",
|
|
3114
|
+
undefined: "undefined",
|
|
3115
|
+
nullable: "nullable",
|
|
3116
|
+
null: "null",
|
|
3117
|
+
nullish: "nullish",
|
|
3118
|
+
array: "array",
|
|
3119
|
+
tuple: "tuple",
|
|
3120
|
+
enum: "enum",
|
|
3121
|
+
union: "union",
|
|
3122
|
+
datetime: "datetime",
|
|
3123
|
+
date: "date",
|
|
3124
|
+
email: "email",
|
|
3125
|
+
uuid: "uuid",
|
|
3126
|
+
url: "url",
|
|
3127
|
+
/* intersection */
|
|
3128
|
+
default: "default",
|
|
3129
|
+
const: "const",
|
|
3130
|
+
and: "and",
|
|
3131
|
+
describe: "describe",
|
|
3132
|
+
min: "min",
|
|
3133
|
+
max: "max",
|
|
3134
|
+
optional: "optional",
|
|
3135
|
+
readOnly: "readOnly",
|
|
3136
|
+
// custom ones
|
|
3137
|
+
object: "object",
|
|
3138
|
+
ref: "ref",
|
|
3139
|
+
matches: "matches",
|
|
3140
|
+
firstName: "firstName",
|
|
3141
|
+
lastName: "lastName",
|
|
3142
|
+
password: "password",
|
|
3143
|
+
phone: "phone",
|
|
3144
|
+
blob: "blob",
|
|
3145
|
+
deprecated: "deprecated",
|
|
3146
|
+
example: "example",
|
|
3147
|
+
schema: "schema",
|
|
3148
|
+
catchall: "catchall",
|
|
3149
|
+
time: "time",
|
|
3150
|
+
name: "name"
|
|
3151
|
+
};
|
|
3152
|
+
function isKeyword(meta, keyword) {
|
|
3153
|
+
return meta.keyword === keyword;
|
|
3154
|
+
}
|
|
3155
|
+
|
|
3156
|
+
// src/SchemaGenerator.ts
|
|
3157
|
+
init_esm_shims();
|
|
3158
|
+
import { BaseGenerator } from "@kubb/core";
|
|
3159
|
+
import transformers, { pascalCase } from "@kubb/core/transformers";
|
|
3160
|
+
import { getUniqueName } from "@kubb/core/utils";
|
|
3161
|
+
import { isReference } from "@kubb/oas";
|
|
3162
|
+
import { isDeepEqual, isNumber, uniqueWith } from "remeda";
|
|
3163
|
+
var SchemaGenerator = class _SchemaGenerator extends BaseGenerator {
|
|
3164
|
+
// Collect the types of all referenced schemas, so we can export them later
|
|
3165
|
+
refs = {};
|
|
3166
|
+
// Keep track of already used type aliases
|
|
3167
|
+
#usedAliasNames = {};
|
|
3168
|
+
/**
|
|
3169
|
+
* Creates a type node from a given schema.
|
|
3170
|
+
* Delegates to getBaseTypeFromSchema internally and
|
|
3171
|
+
* optionally adds a union with null.
|
|
3172
|
+
*/
|
|
3173
|
+
parse(props) {
|
|
3174
|
+
const options = this.#getOptions(props);
|
|
3175
|
+
const defaultSchemas = this.#parseSchemaObject(props);
|
|
3176
|
+
const schemas = options.transformers?.schema?.(props, defaultSchemas) || defaultSchemas || [];
|
|
3177
|
+
return uniqueWith(schemas, isDeepEqual);
|
|
3178
|
+
}
|
|
3179
|
+
deepSearch(tree, keyword) {
|
|
3180
|
+
return _SchemaGenerator.deepSearch(tree, keyword);
|
|
3181
|
+
}
|
|
3182
|
+
find(tree, keyword) {
|
|
3183
|
+
return _SchemaGenerator.find(tree, keyword);
|
|
3184
|
+
}
|
|
3185
|
+
static deepSearch(tree, keyword) {
|
|
3186
|
+
const foundItems = [];
|
|
3187
|
+
tree?.forEach((schema) => {
|
|
3188
|
+
if (schema.keyword === keyword) {
|
|
3189
|
+
foundItems.push(schema);
|
|
3190
|
+
}
|
|
3191
|
+
if (schema.keyword === schemaKeywords.object) {
|
|
3192
|
+
const subItem = schema;
|
|
3193
|
+
Object.values(subItem.args?.properties || {}).forEach((entrySchema) => {
|
|
3194
|
+
foundItems.push(..._SchemaGenerator.deepSearch(entrySchema, keyword));
|
|
3195
|
+
});
|
|
3196
|
+
Object.values(subItem.args?.additionalProperties || {}).forEach((entrySchema) => {
|
|
3197
|
+
foundItems.push(..._SchemaGenerator.deepSearch([entrySchema], keyword));
|
|
3198
|
+
});
|
|
3199
|
+
}
|
|
3200
|
+
if (schema.keyword === schemaKeywords.array) {
|
|
3201
|
+
const subItem = schema;
|
|
3202
|
+
subItem.args.items.forEach((entrySchema) => {
|
|
3203
|
+
foundItems.push(..._SchemaGenerator.deepSearch([entrySchema], keyword));
|
|
3204
|
+
});
|
|
3205
|
+
}
|
|
3206
|
+
if (schema.keyword === schemaKeywords.and) {
|
|
3207
|
+
const subItem = schema;
|
|
3208
|
+
subItem.args.forEach((entrySchema) => {
|
|
3209
|
+
foundItems.push(..._SchemaGenerator.deepSearch([entrySchema], keyword));
|
|
3210
|
+
});
|
|
3211
|
+
}
|
|
3212
|
+
if (schema.keyword === schemaKeywords.tuple) {
|
|
3213
|
+
const subItem = schema;
|
|
3214
|
+
subItem.args.items.forEach((entrySchema) => {
|
|
3215
|
+
foundItems.push(..._SchemaGenerator.deepSearch([entrySchema], keyword));
|
|
3216
|
+
});
|
|
3217
|
+
}
|
|
3218
|
+
if (schema.keyword === schemaKeywords.union) {
|
|
3219
|
+
const subItem = schema;
|
|
3220
|
+
subItem.args.forEach((entrySchema) => {
|
|
3221
|
+
foundItems.push(..._SchemaGenerator.deepSearch([entrySchema], keyword));
|
|
3222
|
+
});
|
|
3223
|
+
}
|
|
3224
|
+
});
|
|
3225
|
+
return foundItems;
|
|
3226
|
+
}
|
|
3227
|
+
static findInObject(tree, keyword) {
|
|
3228
|
+
let foundItem = void 0;
|
|
3229
|
+
tree?.forEach((schema) => {
|
|
3230
|
+
if (!foundItem && schema.keyword === keyword) {
|
|
3231
|
+
foundItem = schema;
|
|
3232
|
+
}
|
|
3233
|
+
if (schema.keyword === schemaKeywords.object) {
|
|
3234
|
+
const subItem = schema;
|
|
3235
|
+
Object.values(subItem.args?.properties || {}).forEach((entrySchema) => {
|
|
3236
|
+
if (!foundItem) {
|
|
3237
|
+
foundItem = _SchemaGenerator.find(entrySchema, keyword);
|
|
3238
|
+
}
|
|
3239
|
+
});
|
|
3240
|
+
Object.values(subItem.args?.additionalProperties || {}).forEach((entrySchema) => {
|
|
3241
|
+
if (!foundItem) {
|
|
3242
|
+
foundItem = _SchemaGenerator.find([entrySchema], keyword);
|
|
3243
|
+
}
|
|
3244
|
+
});
|
|
3245
|
+
}
|
|
3246
|
+
});
|
|
3247
|
+
return foundItem;
|
|
3248
|
+
}
|
|
3249
|
+
static find(tree, keyword) {
|
|
3250
|
+
let foundItem = void 0;
|
|
3251
|
+
tree?.forEach((schema) => {
|
|
3252
|
+
if (!foundItem && schema.keyword === keyword) {
|
|
3253
|
+
foundItem = schema;
|
|
3254
|
+
}
|
|
3255
|
+
if (schema.keyword === schemaKeywords.array) {
|
|
3256
|
+
const subItem = schema;
|
|
3257
|
+
subItem.args.items.forEach((entrySchema) => {
|
|
3258
|
+
if (!foundItem) {
|
|
3259
|
+
foundItem = _SchemaGenerator.find([entrySchema], keyword);
|
|
3260
|
+
}
|
|
3261
|
+
});
|
|
3262
|
+
}
|
|
3263
|
+
if (schema.keyword === schemaKeywords.and) {
|
|
3264
|
+
const subItem = schema;
|
|
3265
|
+
subItem.args.forEach((entrySchema) => {
|
|
3266
|
+
if (!foundItem) {
|
|
3267
|
+
foundItem = _SchemaGenerator.find([entrySchema], keyword);
|
|
3268
|
+
}
|
|
3269
|
+
});
|
|
3270
|
+
}
|
|
3271
|
+
if (schema.keyword === schemaKeywords.tuple) {
|
|
3272
|
+
const subItem = schema;
|
|
3273
|
+
subItem.args.items.forEach((entrySchema) => {
|
|
3274
|
+
if (!foundItem) {
|
|
3275
|
+
foundItem = _SchemaGenerator.find([entrySchema], keyword);
|
|
3276
|
+
}
|
|
3277
|
+
});
|
|
3278
|
+
}
|
|
3279
|
+
if (schema.keyword === schemaKeywords.union) {
|
|
3280
|
+
const subItem = schema;
|
|
3281
|
+
subItem.args.forEach((entrySchema) => {
|
|
3282
|
+
if (!foundItem) {
|
|
3283
|
+
foundItem = _SchemaGenerator.find([entrySchema], keyword);
|
|
3284
|
+
}
|
|
3285
|
+
});
|
|
3286
|
+
}
|
|
3287
|
+
});
|
|
3288
|
+
return foundItem;
|
|
3289
|
+
}
|
|
3290
|
+
#getUsedEnumNames(props) {
|
|
3291
|
+
const options = this.#getOptions(props);
|
|
3292
|
+
return options.usedEnumNames || {};
|
|
3293
|
+
}
|
|
3294
|
+
#getOptions({ name }) {
|
|
3295
|
+
const { override = [] } = this.context;
|
|
3296
|
+
return {
|
|
3297
|
+
...this.options,
|
|
3298
|
+
...override.find(({ pattern, type }) => {
|
|
3299
|
+
if (name && type === "schemaName") {
|
|
3300
|
+
return !!name.match(pattern);
|
|
3301
|
+
}
|
|
3302
|
+
return false;
|
|
3303
|
+
})?.options || {}
|
|
3304
|
+
};
|
|
3305
|
+
}
|
|
3306
|
+
#getUnknownReturn(props) {
|
|
3307
|
+
const options = this.#getOptions(props);
|
|
3308
|
+
if (options.unknownType === "any") {
|
|
3309
|
+
return schemaKeywords.any;
|
|
3310
|
+
}
|
|
3311
|
+
return schemaKeywords.unknown;
|
|
3312
|
+
}
|
|
3313
|
+
/**
|
|
3314
|
+
* Recursively creates a type literal with the given props.
|
|
3315
|
+
*/
|
|
3316
|
+
#parseProperties({ schema, name }) {
|
|
3317
|
+
const properties = schema?.properties || {};
|
|
3318
|
+
const additionalProperties = schema?.additionalProperties;
|
|
3319
|
+
const required = schema?.required;
|
|
3320
|
+
const propertiesSchemas = Object.keys(properties).map((propertyName) => {
|
|
3321
|
+
const validationFunctions = [];
|
|
3322
|
+
const propertySchema = properties[propertyName];
|
|
3323
|
+
const isRequired = Array.isArray(required) ? required?.includes(propertyName) : !!required;
|
|
3324
|
+
const nullable = propertySchema.nullable ?? propertySchema["x-nullable"] ?? false;
|
|
3325
|
+
validationFunctions.push(...this.parse({ schema: propertySchema, name: propertyName, parentName: name }));
|
|
3326
|
+
validationFunctions.push({
|
|
3327
|
+
keyword: schemaKeywords.name,
|
|
3328
|
+
args: propertyName
|
|
3329
|
+
});
|
|
3330
|
+
if (!isRequired && nullable) {
|
|
3331
|
+
validationFunctions.push({ keyword: schemaKeywords.nullish });
|
|
3332
|
+
} else if (!isRequired) {
|
|
3333
|
+
validationFunctions.push({ keyword: schemaKeywords.optional });
|
|
3334
|
+
}
|
|
3335
|
+
return {
|
|
3336
|
+
[propertyName]: validationFunctions
|
|
3337
|
+
};
|
|
3338
|
+
}).reduce((acc, curr) => ({ ...acc, ...curr }), {});
|
|
3339
|
+
let additionalPropertiesSchemas = [];
|
|
3340
|
+
if (additionalProperties) {
|
|
3341
|
+
additionalPropertiesSchemas = additionalProperties === true ? [{ keyword: this.#getUnknownReturn({ schema, name }) }] : this.parse({ schema: additionalProperties, parentName: name });
|
|
3342
|
+
}
|
|
3343
|
+
return [
|
|
3344
|
+
{
|
|
3345
|
+
keyword: schemaKeywords.object,
|
|
3346
|
+
args: {
|
|
3347
|
+
properties: propertiesSchemas,
|
|
3348
|
+
additionalProperties: additionalPropertiesSchemas
|
|
3349
|
+
}
|
|
3350
|
+
}
|
|
3351
|
+
];
|
|
3352
|
+
}
|
|
3353
|
+
/**
|
|
3354
|
+
* Create a type alias for the schema referenced by the given ReferenceObject
|
|
3355
|
+
*/
|
|
3356
|
+
#getRefAlias(obj) {
|
|
3357
|
+
const { $ref } = obj;
|
|
3358
|
+
let ref = this.refs[$ref];
|
|
3359
|
+
const originalName = getUniqueName($ref.replace(/.+\//, ""), this.#usedAliasNames);
|
|
3360
|
+
const propertyName = this.context.pluginManager.resolveName({
|
|
3361
|
+
name: originalName,
|
|
3362
|
+
pluginKey: this.context.plugin.key,
|
|
3363
|
+
type: "function"
|
|
3364
|
+
});
|
|
3365
|
+
if (ref) {
|
|
3366
|
+
return [
|
|
3367
|
+
{
|
|
3368
|
+
keyword: schemaKeywords.ref,
|
|
3369
|
+
args: { name: ref.propertyName, path: ref.path }
|
|
3370
|
+
}
|
|
3371
|
+
];
|
|
3372
|
+
}
|
|
3373
|
+
const fileName = this.context.pluginManager.resolveName({
|
|
3374
|
+
name: originalName,
|
|
3375
|
+
pluginKey: this.context.plugin.key,
|
|
3376
|
+
type: "file"
|
|
3377
|
+
});
|
|
3378
|
+
const file = this.context.pluginManager.getFile({
|
|
3379
|
+
name: fileName,
|
|
3380
|
+
pluginKey: this.context.plugin.key,
|
|
3381
|
+
extName: ".ts"
|
|
3382
|
+
});
|
|
3383
|
+
ref = this.refs[$ref] = {
|
|
3384
|
+
propertyName,
|
|
3385
|
+
originalName,
|
|
3386
|
+
path: file.path
|
|
3387
|
+
};
|
|
3388
|
+
return [
|
|
3389
|
+
{
|
|
3390
|
+
keyword: schemaKeywords.ref,
|
|
3391
|
+
args: { name: ref.propertyName, path: ref?.path }
|
|
3392
|
+
}
|
|
3393
|
+
];
|
|
3394
|
+
}
|
|
3395
|
+
#getParsedSchemaObject(schema) {
|
|
3396
|
+
const parsedSchema = getSchemaFactory(this.context.oas)(schema);
|
|
3397
|
+
return parsedSchema;
|
|
3398
|
+
}
|
|
3399
|
+
/**
|
|
3400
|
+
* This is the very core of the OpenAPI to TS conversion - it takes a
|
|
3401
|
+
* schema and returns the appropriate type.
|
|
3402
|
+
*/
|
|
3403
|
+
#parseSchemaObject({ schema: _schema, name, parentName }) {
|
|
3404
|
+
const options = this.#getOptions({ schema: _schema, name });
|
|
3405
|
+
const unknownReturn = this.#getUnknownReturn({ schema: _schema, name });
|
|
3406
|
+
const { schema, version } = this.#getParsedSchemaObject(_schema);
|
|
3407
|
+
if (!schema) {
|
|
3408
|
+
return [{ keyword: unknownReturn }];
|
|
3409
|
+
}
|
|
3410
|
+
const baseItems = [
|
|
3411
|
+
{
|
|
3412
|
+
keyword: schemaKeywords.schema,
|
|
3413
|
+
args: {
|
|
3414
|
+
type: schema.type,
|
|
3415
|
+
format: schema.format
|
|
3416
|
+
}
|
|
3417
|
+
}
|
|
3418
|
+
];
|
|
3419
|
+
const min = schema.minimum ?? schema.minLength ?? schema.minItems ?? void 0;
|
|
3420
|
+
const max = schema.maximum ?? schema.maxLength ?? schema.maxItems ?? void 0;
|
|
3421
|
+
const nullable = schema.nullable ?? schema["x-nullable"] ?? false;
|
|
3422
|
+
if (schema.default !== void 0 && !Array.isArray(schema.default)) {
|
|
3423
|
+
if (typeof schema.default === "string") {
|
|
3424
|
+
baseItems.push({
|
|
3425
|
+
keyword: schemaKeywords.default,
|
|
3426
|
+
args: transformers.stringify(schema.default)
|
|
3427
|
+
});
|
|
3428
|
+
} else if (typeof schema.default === "boolean") {
|
|
3429
|
+
baseItems.push({
|
|
3430
|
+
keyword: schemaKeywords.default,
|
|
3431
|
+
args: schema.default ?? false
|
|
3432
|
+
});
|
|
3433
|
+
} else {
|
|
3434
|
+
baseItems.push({
|
|
3435
|
+
keyword: schemaKeywords.default,
|
|
3436
|
+
args: schema.default
|
|
3437
|
+
});
|
|
3438
|
+
}
|
|
3439
|
+
}
|
|
3440
|
+
if (schema.description) {
|
|
3441
|
+
baseItems.push({
|
|
3442
|
+
keyword: schemaKeywords.describe,
|
|
3443
|
+
args: schema.description
|
|
3444
|
+
});
|
|
3445
|
+
}
|
|
3446
|
+
if (schema.pattern) {
|
|
3447
|
+
baseItems.unshift({
|
|
3448
|
+
keyword: schemaKeywords.matches,
|
|
3449
|
+
args: schema.pattern
|
|
3450
|
+
});
|
|
3451
|
+
}
|
|
3452
|
+
if (max !== void 0) {
|
|
3453
|
+
baseItems.unshift({ keyword: schemaKeywords.max, args: max });
|
|
3454
|
+
}
|
|
3455
|
+
if (min !== void 0) {
|
|
3456
|
+
baseItems.unshift({ keyword: schemaKeywords.min, args: min });
|
|
3457
|
+
}
|
|
3458
|
+
if (nullable) {
|
|
3459
|
+
baseItems.push({ keyword: schemaKeywords.nullable });
|
|
3460
|
+
}
|
|
3461
|
+
if (schema.type && Array.isArray(schema.type)) {
|
|
3462
|
+
const [_schema2, nullable2] = schema.type;
|
|
3463
|
+
if (nullable2 === "null") {
|
|
3464
|
+
baseItems.push({ keyword: schemaKeywords.nullable });
|
|
3465
|
+
}
|
|
3466
|
+
}
|
|
3467
|
+
if (schema.readOnly) {
|
|
3468
|
+
baseItems.push({ keyword: schemaKeywords.readOnly });
|
|
3469
|
+
}
|
|
3470
|
+
if (isReference(schema)) {
|
|
3471
|
+
return [
|
|
3472
|
+
...this.#getRefAlias(schema),
|
|
3473
|
+
nullable && { keyword: schemaKeywords.nullable },
|
|
3474
|
+
{
|
|
3475
|
+
keyword: schemaKeywords.schema,
|
|
3476
|
+
args: {
|
|
3477
|
+
type: schema.type,
|
|
3478
|
+
format: schema.format
|
|
3479
|
+
}
|
|
3480
|
+
}
|
|
3481
|
+
].filter(Boolean);
|
|
3482
|
+
}
|
|
3483
|
+
if (schema.oneOf) {
|
|
3484
|
+
const schemaWithoutOneOf = { ...schema, oneOf: void 0 };
|
|
3485
|
+
const union = {
|
|
3486
|
+
keyword: schemaKeywords.union,
|
|
3487
|
+
args: schema.oneOf.map((item) => {
|
|
3488
|
+
return item && this.parse({ schema: item, name, parentName })[0];
|
|
3489
|
+
}).filter(Boolean).filter((item) => {
|
|
3490
|
+
return item && item.keyword !== unknownReturn;
|
|
3491
|
+
})
|
|
3492
|
+
};
|
|
3493
|
+
if (schemaWithoutOneOf.properties) {
|
|
3494
|
+
return [...this.parse({ schema: schemaWithoutOneOf, name, parentName }), union, ...baseItems];
|
|
3495
|
+
}
|
|
3496
|
+
return [union, ...baseItems];
|
|
3497
|
+
}
|
|
3498
|
+
if (schema.anyOf) {
|
|
3499
|
+
const schemaWithoutAnyOf = { ...schema, anyOf: void 0 };
|
|
3500
|
+
const union = {
|
|
3501
|
+
keyword: schemaKeywords.union,
|
|
3502
|
+
args: schema.anyOf.map((item) => {
|
|
3503
|
+
return item && this.parse({ schema: item, name, parentName })[0];
|
|
3504
|
+
}).filter(Boolean).filter((item) => {
|
|
3505
|
+
return item && item.keyword !== unknownReturn;
|
|
3506
|
+
}).map((item) => {
|
|
3507
|
+
if (isKeyword(item, schemaKeywords.object)) {
|
|
3508
|
+
return {
|
|
3509
|
+
...item,
|
|
3510
|
+
args: {
|
|
3511
|
+
...item.args,
|
|
3512
|
+
strict: true
|
|
3513
|
+
}
|
|
3514
|
+
};
|
|
3515
|
+
}
|
|
3516
|
+
return item;
|
|
3517
|
+
})
|
|
3518
|
+
};
|
|
3519
|
+
if (schemaWithoutAnyOf.properties) {
|
|
3520
|
+
return [...this.parse({ schema: schemaWithoutAnyOf, name, parentName }), union, ...baseItems];
|
|
3521
|
+
}
|
|
3522
|
+
return [union, ...baseItems];
|
|
3523
|
+
}
|
|
3524
|
+
if (schema.allOf) {
|
|
3525
|
+
const schemaWithoutAllOf = { ...schema, allOf: void 0 };
|
|
3526
|
+
const and = {
|
|
3527
|
+
keyword: schemaKeywords.and,
|
|
3528
|
+
args: schema.allOf.map((item) => {
|
|
3529
|
+
return item && this.parse({ schema: item, name, parentName })[0];
|
|
3530
|
+
}).filter(Boolean).filter((item) => {
|
|
3531
|
+
return item && item.keyword !== unknownReturn;
|
|
3532
|
+
})
|
|
3533
|
+
};
|
|
3534
|
+
if (schemaWithoutAllOf.properties) {
|
|
3535
|
+
return [
|
|
3536
|
+
{
|
|
3537
|
+
...and,
|
|
3538
|
+
args: [...and.args || [], ...this.parse({ schema: schemaWithoutAllOf, name, parentName })]
|
|
3539
|
+
},
|
|
3540
|
+
...baseItems
|
|
3541
|
+
];
|
|
3542
|
+
}
|
|
3543
|
+
return [and, ...baseItems];
|
|
3544
|
+
}
|
|
3545
|
+
if (schema.enum) {
|
|
3546
|
+
const enumName = getUniqueName(pascalCase([parentName, name, options.enumSuffix].join(" ")), this.#getUsedEnumNames({ schema, name }));
|
|
3547
|
+
const typeName = this.context.pluginManager.resolveName({
|
|
3548
|
+
name: enumName,
|
|
3549
|
+
pluginKey: this.context.plugin.key,
|
|
3550
|
+
type: "type"
|
|
3551
|
+
});
|
|
3552
|
+
const nullableEnum = schema.enum.includes(null);
|
|
3553
|
+
if (nullableEnum) {
|
|
3554
|
+
baseItems.push({ keyword: schemaKeywords.nullable });
|
|
3555
|
+
}
|
|
3556
|
+
const filteredValues = schema.enum.filter((value) => value !== null);
|
|
3557
|
+
const extensionEnums = ["x-enumNames", "x-enum-varnames"].filter((extensionKey) => extensionKey in schema).map((extensionKey) => {
|
|
3558
|
+
return [
|
|
3559
|
+
{
|
|
3560
|
+
keyword: schemaKeywords.enum,
|
|
3561
|
+
args: {
|
|
3562
|
+
name,
|
|
3563
|
+
typeName,
|
|
3564
|
+
asConst: false,
|
|
3565
|
+
items: [...new Set(schema[extensionKey])].map((name2, index) => ({
|
|
3566
|
+
name: transformers.stringify(name2),
|
|
3567
|
+
value: schema.enum?.[index],
|
|
3568
|
+
format: isNumber(schema.enum?.[index]) ? "number" : "string"
|
|
3569
|
+
}))
|
|
3570
|
+
}
|
|
3571
|
+
},
|
|
3572
|
+
...baseItems.filter(
|
|
3573
|
+
(item) => item.keyword !== schemaKeywords.min && item.keyword !== schemaKeywords.max && item.keyword !== schemaKeywords.matches
|
|
3574
|
+
)
|
|
3575
|
+
];
|
|
3576
|
+
});
|
|
3577
|
+
if (schema.type === "number" || schema.type === "integer") {
|
|
3578
|
+
const enumNames = extensionEnums[0]?.find((item) => isKeyword(item, schemaKeywords.enum));
|
|
3579
|
+
return [
|
|
3580
|
+
{
|
|
3581
|
+
keyword: schemaKeywords.enum,
|
|
3582
|
+
args: {
|
|
3583
|
+
name: enumName,
|
|
3584
|
+
typeName,
|
|
3585
|
+
asConst: true,
|
|
3586
|
+
items: enumNames?.args?.items ? [...new Set(enumNames.args.items)].map(({ name: name2, value }) => ({
|
|
3587
|
+
name: name2,
|
|
3588
|
+
value,
|
|
3589
|
+
format: "number"
|
|
3590
|
+
})) : [...new Set(filteredValues)].map((value) => {
|
|
3591
|
+
return {
|
|
3592
|
+
name: value,
|
|
3593
|
+
value,
|
|
3594
|
+
format: "number"
|
|
3595
|
+
};
|
|
3596
|
+
})
|
|
3597
|
+
}
|
|
3598
|
+
},
|
|
3599
|
+
...baseItems.filter((item) => item.keyword !== schemaKeywords.min && item.keyword !== schemaKeywords.max && item.keyword !== schemaKeywords.matches)
|
|
3600
|
+
];
|
|
3601
|
+
}
|
|
3602
|
+
if (extensionEnums.length > 0 && extensionEnums[0]) {
|
|
3603
|
+
return extensionEnums[0];
|
|
3604
|
+
}
|
|
3605
|
+
return [
|
|
3606
|
+
{
|
|
3607
|
+
keyword: schemaKeywords.enum,
|
|
3608
|
+
args: {
|
|
3609
|
+
name: enumName,
|
|
3610
|
+
typeName,
|
|
3611
|
+
asConst: false,
|
|
3612
|
+
items: [...new Set(filteredValues)].map((value) => ({
|
|
3613
|
+
name: transformers.stringify(value),
|
|
3614
|
+
value,
|
|
3615
|
+
format: isNumber(value) ? "number" : "string"
|
|
3616
|
+
}))
|
|
3617
|
+
}
|
|
3618
|
+
},
|
|
3619
|
+
...baseItems.filter((item) => item.keyword !== schemaKeywords.min && item.keyword !== schemaKeywords.max && item.keyword !== schemaKeywords.matches)
|
|
3620
|
+
];
|
|
3621
|
+
}
|
|
3622
|
+
if ("prefixItems" in schema) {
|
|
3623
|
+
const prefixItems = schema.prefixItems;
|
|
3624
|
+
const min2 = schema.minimum ?? schema.minLength ?? schema.minItems ?? void 0;
|
|
3625
|
+
const max2 = schema.maximum ?? schema.maxLength ?? schema.maxItems ?? void 0;
|
|
3626
|
+
return [
|
|
3627
|
+
{
|
|
3628
|
+
keyword: schemaKeywords.tuple,
|
|
3629
|
+
args: {
|
|
3630
|
+
min: min2,
|
|
3631
|
+
max: max2,
|
|
3632
|
+
items: prefixItems.map((item) => {
|
|
3633
|
+
return this.parse({ schema: item, name, parentName })[0];
|
|
3634
|
+
}).filter(Boolean)
|
|
3635
|
+
}
|
|
3636
|
+
},
|
|
3637
|
+
...baseItems.filter((item) => item.keyword !== schemaKeywords.min && item.keyword !== schemaKeywords.max)
|
|
3638
|
+
];
|
|
3639
|
+
}
|
|
3640
|
+
if (version === "3.1" && "const" in schema) {
|
|
3641
|
+
if (schema["const"]) {
|
|
3642
|
+
return [
|
|
3643
|
+
{
|
|
3644
|
+
keyword: schemaKeywords.const,
|
|
3645
|
+
args: {
|
|
3646
|
+
name: schema["const"],
|
|
3647
|
+
format: typeof schema["const"] === "number" ? "number" : "string",
|
|
3648
|
+
value: schema["const"]
|
|
3649
|
+
}
|
|
3650
|
+
},
|
|
3651
|
+
...baseItems
|
|
3652
|
+
];
|
|
3653
|
+
}
|
|
3654
|
+
return [{ keyword: schemaKeywords.null }];
|
|
3655
|
+
}
|
|
3656
|
+
if (schema.format) {
|
|
3657
|
+
switch (schema.format) {
|
|
3658
|
+
case "binary":
|
|
3659
|
+
baseItems.push({ keyword: schemaKeywords.blob });
|
|
3660
|
+
return baseItems;
|
|
3661
|
+
case "date-time":
|
|
3662
|
+
if (options.dateType) {
|
|
3663
|
+
if (options.dateType === "date") {
|
|
3664
|
+
baseItems.unshift({ keyword: schemaKeywords.date, args: { type: "date" } });
|
|
3665
|
+
return baseItems;
|
|
3666
|
+
}
|
|
3667
|
+
if (options.dateType === "stringOffset") {
|
|
3668
|
+
baseItems.unshift({ keyword: schemaKeywords.datetime, args: { offset: true } });
|
|
3669
|
+
return baseItems;
|
|
3670
|
+
}
|
|
3671
|
+
if (options.dateType === "stringLocal") {
|
|
3672
|
+
baseItems.unshift({ keyword: schemaKeywords.datetime, args: { local: true } });
|
|
3673
|
+
return baseItems;
|
|
3674
|
+
}
|
|
3675
|
+
baseItems.unshift({ keyword: schemaKeywords.datetime, args: { offset: false } });
|
|
3676
|
+
return baseItems;
|
|
3677
|
+
}
|
|
3678
|
+
break;
|
|
3679
|
+
case "date":
|
|
3680
|
+
if (options.dateType) {
|
|
3681
|
+
if (options.dateType === "date") {
|
|
3682
|
+
baseItems.unshift({ keyword: schemaKeywords.date, args: { type: "date" } });
|
|
3683
|
+
return baseItems;
|
|
3684
|
+
}
|
|
3685
|
+
baseItems.unshift({ keyword: schemaKeywords.date, args: { type: "string" } });
|
|
3686
|
+
return baseItems;
|
|
3687
|
+
}
|
|
3688
|
+
break;
|
|
3689
|
+
case "time":
|
|
3690
|
+
if (options.dateType) {
|
|
3691
|
+
if (options.dateType === "date") {
|
|
3692
|
+
baseItems.unshift({ keyword: schemaKeywords.time, args: { type: "date" } });
|
|
3693
|
+
return baseItems;
|
|
3694
|
+
}
|
|
3695
|
+
baseItems.unshift({ keyword: schemaKeywords.time, args: { type: "string" } });
|
|
3696
|
+
return baseItems;
|
|
3697
|
+
}
|
|
3698
|
+
break;
|
|
3699
|
+
case "uuid":
|
|
3700
|
+
baseItems.unshift({ keyword: schemaKeywords.uuid });
|
|
3701
|
+
break;
|
|
3702
|
+
case "email":
|
|
3703
|
+
case "idn-email":
|
|
3704
|
+
baseItems.unshift({ keyword: schemaKeywords.email });
|
|
3705
|
+
break;
|
|
3706
|
+
case "uri":
|
|
3707
|
+
case "ipv4":
|
|
3708
|
+
case "ipv6":
|
|
3709
|
+
case "uri-reference":
|
|
3710
|
+
case "hostname":
|
|
3711
|
+
case "idn-hostname":
|
|
3712
|
+
baseItems.unshift({ keyword: schemaKeywords.url });
|
|
3713
|
+
break;
|
|
3714
|
+
default:
|
|
3715
|
+
break;
|
|
3716
|
+
}
|
|
3717
|
+
}
|
|
3718
|
+
if ("items" in schema || schema.type === "array") {
|
|
3719
|
+
const min2 = schema.minimum ?? schema.minLength ?? schema.minItems ?? void 0;
|
|
3720
|
+
const max2 = schema.maximum ?? schema.maxLength ?? schema.maxItems ?? void 0;
|
|
3721
|
+
const items = this.parse({ schema: "items" in schema ? schema.items : [], name, parentName });
|
|
3722
|
+
return [
|
|
3723
|
+
{
|
|
3724
|
+
keyword: schemaKeywords.array,
|
|
3725
|
+
args: {
|
|
3726
|
+
items,
|
|
3727
|
+
min: min2,
|
|
3728
|
+
max: max2
|
|
3729
|
+
}
|
|
3730
|
+
},
|
|
3731
|
+
...baseItems.filter((item) => item.keyword !== schemaKeywords.min && item.keyword !== schemaKeywords.max)
|
|
3732
|
+
];
|
|
3733
|
+
}
|
|
3734
|
+
if (schema.properties || schema.additionalProperties) {
|
|
3735
|
+
return [...this.#parseProperties({ schema, name }), ...baseItems];
|
|
3736
|
+
}
|
|
3737
|
+
if (schema.type) {
|
|
3738
|
+
if (Array.isArray(schema.type)) {
|
|
3739
|
+
const [type] = schema.type;
|
|
3740
|
+
return [
|
|
3741
|
+
...this.parse({
|
|
3742
|
+
schema: {
|
|
3743
|
+
...schema,
|
|
3744
|
+
type
|
|
3745
|
+
},
|
|
3746
|
+
name,
|
|
3747
|
+
parentName
|
|
3748
|
+
}),
|
|
3749
|
+
...baseItems
|
|
3750
|
+
].filter(Boolean);
|
|
3751
|
+
}
|
|
3752
|
+
if (!["boolean", "object", "number", "string", "integer"].includes(schema.type)) {
|
|
3753
|
+
this.context.pluginManager.logger.emit("warning", `Schema type '${schema.type}' is not valid for schema ${parentName}.${name}`);
|
|
3754
|
+
}
|
|
3755
|
+
return [{ keyword: schema.type }, ...baseItems];
|
|
3756
|
+
}
|
|
3757
|
+
return [{ keyword: unknownReturn }];
|
|
3758
|
+
}
|
|
3759
|
+
async build(...generators) {
|
|
3760
|
+
const { oas, contentType, include } = this.context;
|
|
3761
|
+
const schemas = getSchemas({ oas, contentType, includes: include });
|
|
3762
|
+
const promises = Object.entries(schemas).reduce((acc, [name, schema]) => {
|
|
3763
|
+
const options = this.#getOptions({ name });
|
|
3764
|
+
const promiseOperation = this.schema.call(this, name, schema, {
|
|
3765
|
+
...this.options,
|
|
3766
|
+
...options
|
|
3767
|
+
});
|
|
3768
|
+
if (promiseOperation) {
|
|
3769
|
+
acc.push(promiseOperation);
|
|
3770
|
+
}
|
|
3771
|
+
generators?.forEach((generator) => {
|
|
3772
|
+
const promise = generator.schema?.({
|
|
3773
|
+
instance: this,
|
|
3774
|
+
name,
|
|
3775
|
+
schema,
|
|
3776
|
+
options: {
|
|
3777
|
+
...this.options,
|
|
3778
|
+
...options
|
|
3779
|
+
}
|
|
3780
|
+
});
|
|
3781
|
+
if (promise) {
|
|
3782
|
+
acc.push(promise);
|
|
3783
|
+
}
|
|
3784
|
+
});
|
|
3785
|
+
return acc;
|
|
3786
|
+
}, []);
|
|
3787
|
+
const files = await Promise.all(promises);
|
|
3788
|
+
return files.flat().filter(Boolean);
|
|
3789
|
+
}
|
|
3790
|
+
/**
|
|
3791
|
+
* Schema
|
|
3792
|
+
*/
|
|
3793
|
+
async schema(name, object, options) {
|
|
3794
|
+
return [];
|
|
3795
|
+
}
|
|
3796
|
+
};
|
|
3797
|
+
|
|
3106
3798
|
// src/components/Operation.tsx
|
|
3107
3799
|
init_esm_shims();
|
|
3108
3800
|
var import_jsx_runtime = __toESM(require_jsx_runtime(), 1);
|
|
@@ -3119,7 +3811,7 @@ import { useContext } from "@kubb/react";
|
|
|
3119
3811
|
|
|
3120
3812
|
// src/components/Schema.tsx
|
|
3121
3813
|
init_esm_shims();
|
|
3122
|
-
import { File,
|
|
3814
|
+
import { File, createContext as createContext2, useApp, useFile } from "@kubb/react";
|
|
3123
3815
|
var import_jsx_runtime2 = __toESM(require_jsx_runtime(), 1);
|
|
3124
3816
|
var SchemaContext = createContext2({
|
|
3125
3817
|
name: "unknown",
|
|
@@ -3132,7 +3824,11 @@ Schema.File = function({ output, isTypeOnly, children }) {
|
|
|
3132
3824
|
const { plugin, pluginManager, mode } = useApp();
|
|
3133
3825
|
const { name } = useSchema();
|
|
3134
3826
|
if (mode === "single") {
|
|
3135
|
-
const baseName2 =
|
|
3827
|
+
const baseName2 = `${pluginManager.resolveName({
|
|
3828
|
+
name,
|
|
3829
|
+
pluginKey: plugin.key,
|
|
3830
|
+
type: "file"
|
|
3831
|
+
})}.ts`;
|
|
3136
3832
|
const resolvedPath2 = pluginManager.resolvePath({
|
|
3137
3833
|
baseName: "",
|
|
3138
3834
|
pluginKey: plugin.key
|
|
@@ -3140,7 +3836,7 @@ Schema.File = function({ output, isTypeOnly, children }) {
|
|
|
3140
3836
|
if (!resolvedPath2) {
|
|
3141
3837
|
return null;
|
|
3142
3838
|
}
|
|
3143
|
-
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
3839
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
3144
3840
|
File,
|
|
3145
3841
|
{
|
|
3146
3842
|
baseName: baseName2,
|
|
@@ -3150,7 +3846,7 @@ Schema.File = function({ output, isTypeOnly, children }) {
|
|
|
3150
3846
|
},
|
|
3151
3847
|
children
|
|
3152
3848
|
}
|
|
3153
|
-
)
|
|
3849
|
+
);
|
|
3154
3850
|
}
|
|
3155
3851
|
const baseName = `${pluginManager.resolveName({
|
|
3156
3852
|
name,
|
|
@@ -3164,7 +3860,7 @@ Schema.File = function({ output, isTypeOnly, children }) {
|
|
|
3164
3860
|
if (!resolvedPath) {
|
|
3165
3861
|
return null;
|
|
3166
3862
|
}
|
|
3167
|
-
return /* @__PURE__ */ (0, import_jsx_runtime2.
|
|
3863
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
|
|
3168
3864
|
File,
|
|
3169
3865
|
{
|
|
3170
3866
|
baseName,
|
|
@@ -3177,9 +3873,9 @@ Schema.File = function({ output, isTypeOnly, children }) {
|
|
|
3177
3873
|
children
|
|
3178
3874
|
]
|
|
3179
3875
|
}
|
|
3180
|
-
)
|
|
3876
|
+
);
|
|
3181
3877
|
};
|
|
3182
|
-
Schema.Imports = ({ isTypeOnly
|
|
3878
|
+
Schema.Imports = ({ isTypeOnly }) => {
|
|
3183
3879
|
const { tree } = useSchema();
|
|
3184
3880
|
const { path: root } = useFile();
|
|
3185
3881
|
const refs = SchemaGenerator.deepSearch(tree, schemaKeywords.ref);
|
|
@@ -3187,7 +3883,7 @@ Schema.Imports = ({ isTypeOnly, extName }) => {
|
|
|
3187
3883
|
if (!item.args.path) {
|
|
3188
3884
|
return void 0;
|
|
3189
3885
|
}
|
|
3190
|
-
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(File.Import, {
|
|
3886
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(File.Import, { root, name: [item.args.name], path: item.args.path, isTypeOnly }, i);
|
|
3191
3887
|
}).filter(Boolean) });
|
|
3192
3888
|
};
|
|
3193
3889
|
Schema.Context = SchemaContext;
|
|
@@ -3211,6 +3907,10 @@ Oas.Operation = Operation;
|
|
|
3211
3907
|
Oas.Schema = Schema;
|
|
3212
3908
|
|
|
3213
3909
|
export {
|
|
3910
|
+
schemaKeywords,
|
|
3911
|
+
isKeyword,
|
|
3912
|
+
SchemaGenerator,
|
|
3913
|
+
require_jsx_runtime,
|
|
3214
3914
|
Operation,
|
|
3215
3915
|
useSchema,
|
|
3216
3916
|
Schema,
|
|
@@ -3262,4 +3962,4 @@ react/cjs/react-jsx-runtime.development.js:
|
|
|
3262
3962
|
* LICENSE file in the root directory of this source tree.
|
|
3263
3963
|
*)
|
|
3264
3964
|
*/
|
|
3265
|
-
//# sourceMappingURL=chunk-
|
|
3965
|
+
//# sourceMappingURL=chunk-M347763D.js.map
|