@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,18 +1,16 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } 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; }
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } 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; } var _class;
|
|
2
2
|
|
|
3
3
|
|
|
4
|
-
var _chunkK4GEQ3C2cjs = require('./chunk-K4GEQ3C2.cjs');
|
|
5
4
|
|
|
6
5
|
|
|
7
6
|
|
|
8
|
-
|
|
9
|
-
var _chunkJ7IF3KA3cjs = require('./chunk-J7IF3KA3.cjs');
|
|
7
|
+
var _chunkNU4F7G47cjs = require('./chunk-NU4F7G47.cjs');
|
|
10
8
|
|
|
11
9
|
// ../../node_modules/.pnpm/react@18.3.1/node_modules/react/cjs/react.production.min.js
|
|
12
|
-
var require_react_production_min =
|
|
10
|
+
var require_react_production_min = _chunkNU4F7G47cjs.__commonJS.call(void 0, {
|
|
13
11
|
"../../node_modules/.pnpm/react@18.3.1/node_modules/react/cjs/react.production.min.js"(exports) {
|
|
14
12
|
"use strict";
|
|
15
|
-
|
|
13
|
+
_chunkNU4F7G47cjs.init_cjs_shims.call(void 0, );
|
|
16
14
|
var l = Symbol.for("react.element");
|
|
17
15
|
var n = Symbol.for("react.portal");
|
|
18
16
|
var p = Symbol.for("react.fragment");
|
|
@@ -283,10 +281,10 @@ var require_react_production_min = _chunkJ7IF3KA3cjs.__commonJS.call(void 0, {
|
|
|
283
281
|
});
|
|
284
282
|
|
|
285
283
|
// ../../node_modules/.pnpm/react@18.3.1/node_modules/react/cjs/react.development.js
|
|
286
|
-
var require_react_development =
|
|
284
|
+
var require_react_development = _chunkNU4F7G47cjs.__commonJS.call(void 0, {
|
|
287
285
|
"../../node_modules/.pnpm/react@18.3.1/node_modules/react/cjs/react.development.js"(exports, module) {
|
|
288
286
|
"use strict";
|
|
289
|
-
|
|
287
|
+
_chunkNU4F7G47cjs.init_cjs_shims.call(void 0, );
|
|
290
288
|
if (process.env.NODE_ENV !== "production") {
|
|
291
289
|
(function() {
|
|
292
290
|
"use strict";
|
|
@@ -2158,10 +2156,10 @@ var require_react_development = _chunkJ7IF3KA3cjs.__commonJS.call(void 0, {
|
|
|
2158
2156
|
});
|
|
2159
2157
|
|
|
2160
2158
|
// ../../node_modules/.pnpm/react@18.3.1/node_modules/react/index.js
|
|
2161
|
-
var require_react =
|
|
2159
|
+
var require_react = _chunkNU4F7G47cjs.__commonJS.call(void 0, {
|
|
2162
2160
|
"../../node_modules/.pnpm/react@18.3.1/node_modules/react/index.js"(exports, module) {
|
|
2163
2161
|
"use strict";
|
|
2164
|
-
|
|
2162
|
+
_chunkNU4F7G47cjs.init_cjs_shims.call(void 0, );
|
|
2165
2163
|
if (process.env.NODE_ENV === "production") {
|
|
2166
2164
|
module.exports = require_react_production_min();
|
|
2167
2165
|
} else {
|
|
@@ -2171,10 +2169,10 @@ var require_react = _chunkJ7IF3KA3cjs.__commonJS.call(void 0, {
|
|
|
2171
2169
|
});
|
|
2172
2170
|
|
|
2173
2171
|
// ../../node_modules/.pnpm/react@18.3.1/node_modules/react/cjs/react-jsx-runtime.production.min.js
|
|
2174
|
-
var require_react_jsx_runtime_production_min =
|
|
2172
|
+
var require_react_jsx_runtime_production_min = _chunkNU4F7G47cjs.__commonJS.call(void 0, {
|
|
2175
2173
|
"../../node_modules/.pnpm/react@18.3.1/node_modules/react/cjs/react-jsx-runtime.production.min.js"(exports) {
|
|
2176
2174
|
"use strict";
|
|
2177
|
-
|
|
2175
|
+
_chunkNU4F7G47cjs.init_cjs_shims.call(void 0, );
|
|
2178
2176
|
var f = require_react();
|
|
2179
2177
|
var k = Symbol.for("react.element");
|
|
2180
2178
|
var l = Symbol.for("react.fragment");
|
|
@@ -2197,10 +2195,10 @@ var require_react_jsx_runtime_production_min = _chunkJ7IF3KA3cjs.__commonJS.call
|
|
|
2197
2195
|
});
|
|
2198
2196
|
|
|
2199
2197
|
// ../../node_modules/.pnpm/react@18.3.1/node_modules/react/cjs/react-jsx-runtime.development.js
|
|
2200
|
-
var require_react_jsx_runtime_development =
|
|
2198
|
+
var require_react_jsx_runtime_development = _chunkNU4F7G47cjs.__commonJS.call(void 0, {
|
|
2201
2199
|
"../../node_modules/.pnpm/react@18.3.1/node_modules/react/cjs/react-jsx-runtime.development.js"(exports) {
|
|
2202
2200
|
"use strict";
|
|
2203
|
-
|
|
2201
|
+
_chunkNU4F7G47cjs.init_cjs_shims.call(void 0, );
|
|
2204
2202
|
if (process.env.NODE_ENV !== "production") {
|
|
2205
2203
|
(function() {
|
|
2206
2204
|
"use strict";
|
|
@@ -3091,10 +3089,10 @@ var require_react_jsx_runtime_development = _chunkJ7IF3KA3cjs.__commonJS.call(vo
|
|
|
3091
3089
|
});
|
|
3092
3090
|
|
|
3093
3091
|
// ../../node_modules/.pnpm/react@18.3.1/node_modules/react/jsx-runtime.js
|
|
3094
|
-
var require_jsx_runtime =
|
|
3092
|
+
var require_jsx_runtime = _chunkNU4F7G47cjs.__commonJS.call(void 0, {
|
|
3095
3093
|
"../../node_modules/.pnpm/react@18.3.1/node_modules/react/jsx-runtime.js"(exports, module) {
|
|
3096
3094
|
"use strict";
|
|
3097
|
-
|
|
3095
|
+
_chunkNU4F7G47cjs.init_cjs_shims.call(void 0, );
|
|
3098
3096
|
if (process.env.NODE_ENV === "production") {
|
|
3099
3097
|
module.exports = require_react_jsx_runtime_production_min();
|
|
3100
3098
|
} else {
|
|
@@ -3103,9 +3101,703 @@ var require_jsx_runtime = _chunkJ7IF3KA3cjs.__commonJS.call(void 0, {
|
|
|
3103
3101
|
}
|
|
3104
3102
|
});
|
|
3105
3103
|
|
|
3104
|
+
// src/SchemaMapper.ts
|
|
3105
|
+
_chunkNU4F7G47cjs.init_cjs_shims.call(void 0, );
|
|
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
|
+
_chunkNU4F7G47cjs.init_cjs_shims.call(void 0, );
|
|
3158
|
+
var _core = require('@kubb/core');
|
|
3159
|
+
var _transformers = require('@kubb/core/transformers'); var _transformers2 = _interopRequireDefault(_transformers);
|
|
3160
|
+
var _utils = require('@kubb/core/utils');
|
|
3161
|
+
var _oas = require('@kubb/oas');
|
|
3162
|
+
var _remeda = require('remeda');
|
|
3163
|
+
var SchemaGenerator = (_class = class _SchemaGenerator extends _core.BaseGenerator {constructor(...args2) { super(...args2); _class.prototype.__init.call(this); }
|
|
3164
|
+
// Collect the types of all referenced schemas, so we can export them later
|
|
3165
|
+
__init() {this.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 = _optionalChain([options, 'access', _ => _.transformers, 'optionalAccess', _2 => _2.schema, 'optionalCall', _3 => _3(props, defaultSchemas)]) || defaultSchemas || [];
|
|
3177
|
+
return _remeda.uniqueWith.call(void 0, schemas, _remeda.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
|
+
_optionalChain([tree, 'optionalAccess', _4 => _4.forEach, 'call', _5 => _5((schema) => {
|
|
3188
|
+
if (schema.keyword === keyword) {
|
|
3189
|
+
foundItems.push(schema);
|
|
3190
|
+
}
|
|
3191
|
+
if (schema.keyword === schemaKeywords.object) {
|
|
3192
|
+
const subItem = schema;
|
|
3193
|
+
Object.values(_optionalChain([subItem, 'access', _6 => _6.args, 'optionalAccess', _7 => _7.properties]) || {}).forEach((entrySchema) => {
|
|
3194
|
+
foundItems.push(..._SchemaGenerator.deepSearch(entrySchema, keyword));
|
|
3195
|
+
});
|
|
3196
|
+
Object.values(_optionalChain([subItem, 'access', _8 => _8.args, 'optionalAccess', _9 => _9.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
|
+
_optionalChain([tree, 'optionalAccess', _10 => _10.forEach, 'call', _11 => _11((schema) => {
|
|
3230
|
+
if (!foundItem && schema.keyword === keyword) {
|
|
3231
|
+
foundItem = schema;
|
|
3232
|
+
}
|
|
3233
|
+
if (schema.keyword === schemaKeywords.object) {
|
|
3234
|
+
const subItem = schema;
|
|
3235
|
+
Object.values(_optionalChain([subItem, 'access', _12 => _12.args, 'optionalAccess', _13 => _13.properties]) || {}).forEach((entrySchema) => {
|
|
3236
|
+
if (!foundItem) {
|
|
3237
|
+
foundItem = _SchemaGenerator.find(entrySchema, keyword);
|
|
3238
|
+
}
|
|
3239
|
+
});
|
|
3240
|
+
Object.values(_optionalChain([subItem, 'access', _14 => _14.args, 'optionalAccess', _15 => _15.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
|
+
_optionalChain([tree, 'optionalAccess', _16 => _16.forEach, 'call', _17 => _17((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
|
+
..._optionalChain([override, 'access', _18 => _18.find, 'call', _19 => _19(({ pattern, type }) => {
|
|
3299
|
+
if (name && type === "schemaName") {
|
|
3300
|
+
return !!name.match(pattern);
|
|
3301
|
+
}
|
|
3302
|
+
return false;
|
|
3303
|
+
}), 'optionalAccess', _20 => _20.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 = _optionalChain([schema, 'optionalAccess', _21 => _21.properties]) || {};
|
|
3318
|
+
const additionalProperties = _optionalChain([schema, 'optionalAccess', _22 => _22.additionalProperties]);
|
|
3319
|
+
const required = _optionalChain([schema, 'optionalAccess', _23 => _23.required]);
|
|
3320
|
+
const propertiesSchemas = Object.keys(properties).map((propertyName) => {
|
|
3321
|
+
const validationFunctions = [];
|
|
3322
|
+
const propertySchema = properties[propertyName];
|
|
3323
|
+
const isRequired = Array.isArray(required) ? _optionalChain([required, 'optionalAccess', _24 => _24.includes, 'call', _25 => _25(propertyName)]) : !!required;
|
|
3324
|
+
const nullable = _nullishCoalesce(_nullishCoalesce(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 = _utils.getUniqueName.call(void 0, $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: _optionalChain([ref, 'optionalAccess', _26 => _26.path]) }
|
|
3392
|
+
}
|
|
3393
|
+
];
|
|
3394
|
+
}
|
|
3395
|
+
#getParsedSchemaObject(schema) {
|
|
3396
|
+
const parsedSchema = _chunkNU4F7G47cjs.getSchemaFactory.call(void 0, 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 = _nullishCoalesce(_nullishCoalesce(_nullishCoalesce(schema.minimum, () => ( schema.minLength)), () => ( schema.minItems)), () => ( void 0));
|
|
3420
|
+
const max = _nullishCoalesce(_nullishCoalesce(_nullishCoalesce(schema.maximum, () => ( schema.maxLength)), () => ( schema.maxItems)), () => ( void 0));
|
|
3421
|
+
const nullable = _nullishCoalesce(_nullishCoalesce(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: _transformers2.default.stringify(schema.default)
|
|
3427
|
+
});
|
|
3428
|
+
} else if (typeof schema.default === "boolean") {
|
|
3429
|
+
baseItems.push({
|
|
3430
|
+
keyword: schemaKeywords.default,
|
|
3431
|
+
args: _nullishCoalesce(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 (_oas.isReference.call(void 0, 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 = _utils.getUniqueName.call(void 0, _transformers.pascalCase.call(void 0, [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: _transformers2.default.stringify(name2),
|
|
3567
|
+
value: _optionalChain([schema, 'access', _27 => _27.enum, 'optionalAccess', _28 => _28[index]]),
|
|
3568
|
+
format: _remeda.isNumber.call(void 0, _optionalChain([schema, 'access', _29 => _29.enum, 'optionalAccess', _30 => _30[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 = _optionalChain([extensionEnums, 'access', _31 => _31[0], 'optionalAccess', _32 => _32.find, 'call', _33 => _33((item) => isKeyword(item, schemaKeywords.enum))]);
|
|
3579
|
+
return [
|
|
3580
|
+
{
|
|
3581
|
+
keyword: schemaKeywords.enum,
|
|
3582
|
+
args: {
|
|
3583
|
+
name: enumName,
|
|
3584
|
+
typeName,
|
|
3585
|
+
asConst: true,
|
|
3586
|
+
items: _optionalChain([enumNames, 'optionalAccess', _34 => _34.args, 'optionalAccess', _35 => _35.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: _transformers2.default.stringify(value),
|
|
3614
|
+
value,
|
|
3615
|
+
format: _remeda.isNumber.call(void 0, 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 = _nullishCoalesce(_nullishCoalesce(_nullishCoalesce(schema.minimum, () => ( schema.minLength)), () => ( schema.minItems)), () => ( void 0));
|
|
3625
|
+
const max2 = _nullishCoalesce(_nullishCoalesce(_nullishCoalesce(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 = _nullishCoalesce(_nullishCoalesce(_nullishCoalesce(schema.minimum, () => ( schema.minLength)), () => ( schema.minItems)), () => ( void 0));
|
|
3720
|
+
const max2 = _nullishCoalesce(_nullishCoalesce(_nullishCoalesce(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 = _chunkNU4F7G47cjs.getSchemas.call(void 0, { 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
|
+
_optionalChain([generators, 'optionalAccess', _36 => _36.forEach, 'call', _37 => _37((generator) => {
|
|
3772
|
+
const promise = _optionalChain([generator, 'access', _38 => _38.schema, 'optionalCall', _39 => _39({
|
|
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
|
+
}, _class);
|
|
3797
|
+
|
|
3106
3798
|
// src/components/Operation.tsx
|
|
3107
|
-
|
|
3108
|
-
var import_jsx_runtime =
|
|
3799
|
+
_chunkNU4F7G47cjs.init_cjs_shims.call(void 0, );
|
|
3800
|
+
var import_jsx_runtime = _chunkNU4F7G47cjs.__toESM.call(void 0, require_jsx_runtime(), 1);
|
|
3109
3801
|
var _react = require('@kubb/react');
|
|
3110
3802
|
var OperationContext = _react.createContext.call(void 0, {});
|
|
3111
3803
|
function Operation({ operation, children }) {
|
|
@@ -3114,13 +3806,13 @@ function Operation({ operation, children }) {
|
|
|
3114
3806
|
Operation.Context = OperationContext;
|
|
3115
3807
|
|
|
3116
3808
|
// src/hooks/useSchema.ts
|
|
3117
|
-
|
|
3809
|
+
_chunkNU4F7G47cjs.init_cjs_shims.call(void 0, );
|
|
3118
3810
|
|
|
3119
3811
|
|
|
3120
3812
|
// src/components/Schema.tsx
|
|
3121
|
-
|
|
3813
|
+
_chunkNU4F7G47cjs.init_cjs_shims.call(void 0, );
|
|
3122
3814
|
|
|
3123
|
-
var import_jsx_runtime2 =
|
|
3815
|
+
var import_jsx_runtime2 = _chunkNU4F7G47cjs.__toESM.call(void 0, require_jsx_runtime(), 1);
|
|
3124
3816
|
var SchemaContext = _react.createContext.call(void 0, {
|
|
3125
3817
|
name: "unknown",
|
|
3126
3818
|
tree: []
|
|
@@ -3132,7 +3824,11 @@ Schema.File = function({ output, isTypeOnly, children }) {
|
|
|
3132
3824
|
const { plugin, pluginManager, mode } = _react.useApp.call(void 0, );
|
|
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
|
_react.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
|
_react.File,
|
|
3169
3865
|
{
|
|
3170
3866
|
baseName,
|
|
@@ -3177,18 +3873,18 @@ 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 } = _react.useFile.call(void 0, );
|
|
3185
|
-
const refs =
|
|
3186
|
-
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_jsx_runtime2.Fragment, { children: _optionalChain([refs, 'optionalAccess',
|
|
3881
|
+
const refs = SchemaGenerator.deepSearch(tree, schemaKeywords.ref);
|
|
3882
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_jsx_runtime2.Fragment, { children: _optionalChain([refs, 'optionalAccess', _40 => _40.map, 'call', _41 => _41((item, i) => {
|
|
3187
3883
|
if (!item.args.path) {
|
|
3188
3884
|
return void 0;
|
|
3189
3885
|
}
|
|
3190
|
-
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(_react.File.Import, {
|
|
3191
|
-
}), 'access',
|
|
3886
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(_react.File.Import, { root, name: [item.args.name], path: item.args.path, isTypeOnly }, i);
|
|
3887
|
+
}), 'access', _42 => _42.filter, 'call', _43 => _43(Boolean)]) });
|
|
3192
3888
|
};
|
|
3193
3889
|
Schema.Context = SchemaContext;
|
|
3194
3890
|
|
|
@@ -3199,9 +3895,9 @@ function useSchema() {
|
|
|
3199
3895
|
}
|
|
3200
3896
|
|
|
3201
3897
|
// src/components/Oas.tsx
|
|
3202
|
-
|
|
3898
|
+
_chunkNU4F7G47cjs.init_cjs_shims.call(void 0, );
|
|
3203
3899
|
|
|
3204
|
-
var import_jsx_runtime3 =
|
|
3900
|
+
var import_jsx_runtime3 = _chunkNU4F7G47cjs.__toESM.call(void 0, require_jsx_runtime(), 1);
|
|
3205
3901
|
var OasContext = _react.createContext.call(void 0, {});
|
|
3206
3902
|
function Oas({ oas, children, operations, generator }) {
|
|
3207
3903
|
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(OasContext.Provider, { value: { oas, generator, operations }, children });
|
|
@@ -3215,7 +3911,11 @@ Oas.Schema = Schema;
|
|
|
3215
3911
|
|
|
3216
3912
|
|
|
3217
3913
|
|
|
3218
|
-
|
|
3914
|
+
|
|
3915
|
+
|
|
3916
|
+
|
|
3917
|
+
|
|
3918
|
+
exports.schemaKeywords = schemaKeywords; exports.isKeyword = isKeyword; exports.SchemaGenerator = SchemaGenerator; exports.require_jsx_runtime = require_jsx_runtime; exports.Operation = Operation; exports.useSchema = useSchema; exports.Schema = Schema; exports.Oas = Oas;
|
|
3219
3919
|
/*! Bundled license information:
|
|
3220
3920
|
|
|
3221
3921
|
react/cjs/react.production.min.js:
|
|
@@ -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-IAUV3UKH.cjs.map
|