@kubb/plugin-oas 3.0.0-alpha.1 → 3.0.0-alpha.11
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-LEACSHKT.js → chunk-2X5GZFQP.js} +712 -44
- package/dist/chunk-2X5GZFQP.js.map +1 -0
- package/dist/{chunk-DRLYORTT.cjs → chunk-47SNBYWH.cjs} +750 -69
- package/dist/chunk-47SNBYWH.cjs.map +1 -0
- package/dist/{chunk-UB552H4J.js → chunk-4VKHSKYX.js} +7 -24
- package/dist/{chunk-UB552H4J.js.map → chunk-4VKHSKYX.js.map} +1 -1
- package/dist/{chunk-Y4V7HHX7.js → chunk-4WUMV7QX.js} +9 -12
- package/dist/chunk-4WUMV7QX.js.map +1 -0
- package/dist/chunk-6AVEWDKE.cjs +8 -0
- package/dist/chunk-6AVEWDKE.cjs.map +1 -0
- package/dist/chunk-S6RFFHLW.cjs +38 -0
- package/dist/chunk-S6RFFHLW.cjs.map +1 -0
- package/dist/chunk-WN5S6RCU.js +6 -0
- package/dist/chunk-WN5S6RCU.js.map +1 -0
- package/dist/chunk-XQPCA75E.cjs +90 -0
- package/dist/chunk-XQPCA75E.cjs.map +1 -0
- package/dist/components.cjs +21 -17
- 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 +4 -17
- package/dist/components.js.map +1 -1
- package/dist/hooks.cjs +30 -35
- 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 +10 -23
- package/dist/hooks.js.map +1 -1
- package/dist/index.cjs +315 -262
- 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 +270 -239
- package/dist/index.js.map +1 -1
- package/dist/{types-Dte3MA6H.d.cts → types-CZTUCaE5.d.cts} +3 -1
- package/dist/{types-Dte3MA6H.d.ts → types-CZTUCaE5.d.ts} +3 -1
- package/dist/utils.cjs +39 -73
- 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 +10 -67
- package/dist/utils.js.map +1 -1
- package/package.json +11 -10
- 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 -0
- package/src/utils/getParams.ts +1 -1
- package/src/utils/index.ts +2 -1
- package/dist/OperationGenerator-CeM_9pxW.d.cts +0 -60
- package/dist/OperationGenerator-DhUhvRJE.d.ts +0 -60
- package/dist/chunk-CJXRFYEF.cjs +0 -698
- package/dist/chunk-CJXRFYEF.cjs.map +0 -1
- package/dist/chunk-DRLYORTT.cjs.map +0 -1
- package/dist/chunk-K6KUETAI.js +0 -698
- package/dist/chunk-K6KUETAI.js.map +0 -1
- package/dist/chunk-LEACSHKT.js.map +0 -1
- package/dist/chunk-P42X362U.cjs +0 -101
- package/dist/chunk-P42X362U.cjs.map +0 -1
- package/dist/chunk-QLJIL3U5.cjs +0 -35
- package/dist/chunk-QLJIL3U5.cjs.map +0 -1
- package/dist/chunk-Y4V7HHX7.js.map +0 -1
- package/src/utils/getGroupedByTagFiles.ts +0 -82
|
@@ -1,18 +1,21 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
2
|
|
|
3
|
+
var chunkXQPCA75E_cjs = require('./chunk-XQPCA75E.cjs');
|
|
4
|
+
var core = require('@kubb/core');
|
|
5
|
+
var transformers = require('@kubb/core/transformers');
|
|
6
|
+
var utils = require('@kubb/core/utils');
|
|
7
|
+
var oas = require('@kubb/oas');
|
|
8
|
+
var remeda = require('remeda');
|
|
9
|
+
var react = require('@kubb/react');
|
|
3
10
|
|
|
4
|
-
|
|
11
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
5
12
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
var _chunkP42X362Ucjs = require('./chunk-P42X362U.cjs');
|
|
13
|
+
var transformers__default = /*#__PURE__*/_interopDefault(transformers);
|
|
10
14
|
|
|
11
15
|
// ../../node_modules/.pnpm/react@18.3.1/node_modules/react/cjs/react.production.min.js
|
|
12
|
-
var require_react_production_min =
|
|
16
|
+
var require_react_production_min = chunkXQPCA75E_cjs.__commonJS({
|
|
13
17
|
"../../node_modules/.pnpm/react@18.3.1/node_modules/react/cjs/react.production.min.js"(exports) {
|
|
14
|
-
|
|
15
|
-
_chunkP42X362Ucjs.init_cjs_shims.call(void 0, );
|
|
18
|
+
chunkXQPCA75E_cjs.init_cjs_shims();
|
|
16
19
|
var l = Symbol.for("react.element");
|
|
17
20
|
var n = Symbol.for("react.portal");
|
|
18
21
|
var p = Symbol.for("react.fragment");
|
|
@@ -283,13 +286,11 @@ var require_react_production_min = _chunkP42X362Ucjs.__commonJS.call(void 0, {
|
|
|
283
286
|
});
|
|
284
287
|
|
|
285
288
|
// ../../node_modules/.pnpm/react@18.3.1/node_modules/react/cjs/react.development.js
|
|
286
|
-
var require_react_development =
|
|
289
|
+
var require_react_development = chunkXQPCA75E_cjs.__commonJS({
|
|
287
290
|
"../../node_modules/.pnpm/react@18.3.1/node_modules/react/cjs/react.development.js"(exports, module) {
|
|
288
|
-
|
|
289
|
-
_chunkP42X362Ucjs.init_cjs_shims.call(void 0, );
|
|
291
|
+
chunkXQPCA75E_cjs.init_cjs_shims();
|
|
290
292
|
if (process.env.NODE_ENV !== "production") {
|
|
291
293
|
(function() {
|
|
292
|
-
"use strict";
|
|
293
294
|
if (typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== "undefined" && typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart === "function") {
|
|
294
295
|
__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(new Error());
|
|
295
296
|
}
|
|
@@ -2158,10 +2159,9 @@ var require_react_development = _chunkP42X362Ucjs.__commonJS.call(void 0, {
|
|
|
2158
2159
|
});
|
|
2159
2160
|
|
|
2160
2161
|
// ../../node_modules/.pnpm/react@18.3.1/node_modules/react/index.js
|
|
2161
|
-
var require_react =
|
|
2162
|
+
var require_react = chunkXQPCA75E_cjs.__commonJS({
|
|
2162
2163
|
"../../node_modules/.pnpm/react@18.3.1/node_modules/react/index.js"(exports, module) {
|
|
2163
|
-
|
|
2164
|
-
_chunkP42X362Ucjs.init_cjs_shims.call(void 0, );
|
|
2164
|
+
chunkXQPCA75E_cjs.init_cjs_shims();
|
|
2165
2165
|
if (process.env.NODE_ENV === "production") {
|
|
2166
2166
|
module.exports = require_react_production_min();
|
|
2167
2167
|
} else {
|
|
@@ -2171,10 +2171,9 @@ var require_react = _chunkP42X362Ucjs.__commonJS.call(void 0, {
|
|
|
2171
2171
|
});
|
|
2172
2172
|
|
|
2173
2173
|
// ../../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 =
|
|
2174
|
+
var require_react_jsx_runtime_production_min = chunkXQPCA75E_cjs.__commonJS({
|
|
2175
2175
|
"../../node_modules/.pnpm/react@18.3.1/node_modules/react/cjs/react-jsx-runtime.production.min.js"(exports) {
|
|
2176
|
-
|
|
2177
|
-
_chunkP42X362Ucjs.init_cjs_shims.call(void 0, );
|
|
2176
|
+
chunkXQPCA75E_cjs.init_cjs_shims();
|
|
2178
2177
|
var f = require_react();
|
|
2179
2178
|
var k = Symbol.for("react.element");
|
|
2180
2179
|
var l = Symbol.for("react.fragment");
|
|
@@ -2197,13 +2196,11 @@ var require_react_jsx_runtime_production_min = _chunkP42X362Ucjs.__commonJS.call
|
|
|
2197
2196
|
});
|
|
2198
2197
|
|
|
2199
2198
|
// ../../node_modules/.pnpm/react@18.3.1/node_modules/react/cjs/react-jsx-runtime.development.js
|
|
2200
|
-
var require_react_jsx_runtime_development =
|
|
2199
|
+
var require_react_jsx_runtime_development = chunkXQPCA75E_cjs.__commonJS({
|
|
2201
2200
|
"../../node_modules/.pnpm/react@18.3.1/node_modules/react/cjs/react-jsx-runtime.development.js"(exports) {
|
|
2202
|
-
|
|
2203
|
-
_chunkP42X362Ucjs.init_cjs_shims.call(void 0, );
|
|
2201
|
+
chunkXQPCA75E_cjs.init_cjs_shims();
|
|
2204
2202
|
if (process.env.NODE_ENV !== "production") {
|
|
2205
2203
|
(function() {
|
|
2206
|
-
"use strict";
|
|
2207
2204
|
var React = require_react();
|
|
2208
2205
|
var REACT_ELEMENT_TYPE = Symbol.for("react.element");
|
|
2209
2206
|
var REACT_PORTAL_TYPE = Symbol.for("react.portal");
|
|
@@ -2876,11 +2873,6 @@ var require_react_jsx_runtime_development = _chunkP42X362Ucjs.__commonJS.call(vo
|
|
|
2876
2873
|
}
|
|
2877
2874
|
function getSourceInfoErrorAddendum(source) {
|
|
2878
2875
|
{
|
|
2879
|
-
if (source !== void 0) {
|
|
2880
|
-
var fileName = source.fileName.replace(/^.*[\\\/]/, "");
|
|
2881
|
-
var lineNumber = source.lineNumber;
|
|
2882
|
-
return "\n\nCheck your code at " + fileName + ":" + lineNumber + ".";
|
|
2883
|
-
}
|
|
2884
2876
|
return "";
|
|
2885
2877
|
}
|
|
2886
2878
|
}
|
|
@@ -3006,7 +2998,7 @@ var require_react_jsx_runtime_development = _chunkP42X362Ucjs.__commonJS.call(vo
|
|
|
3006
2998
|
if (type === void 0 || typeof type === "object" && type !== null && Object.keys(type).length === 0) {
|
|
3007
2999
|
info += " You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.";
|
|
3008
3000
|
}
|
|
3009
|
-
var sourceInfo = getSourceInfoErrorAddendum(
|
|
3001
|
+
var sourceInfo = getSourceInfoErrorAddendum();
|
|
3010
3002
|
if (sourceInfo) {
|
|
3011
3003
|
info += sourceInfo;
|
|
3012
3004
|
} else {
|
|
@@ -3091,10 +3083,9 @@ var require_react_jsx_runtime_development = _chunkP42X362Ucjs.__commonJS.call(vo
|
|
|
3091
3083
|
});
|
|
3092
3084
|
|
|
3093
3085
|
// ../../node_modules/.pnpm/react@18.3.1/node_modules/react/jsx-runtime.js
|
|
3094
|
-
var require_jsx_runtime =
|
|
3086
|
+
var require_jsx_runtime = chunkXQPCA75E_cjs.__commonJS({
|
|
3095
3087
|
"../../node_modules/.pnpm/react@18.3.1/node_modules/react/jsx-runtime.js"(exports, module) {
|
|
3096
|
-
|
|
3097
|
-
_chunkP42X362Ucjs.init_cjs_shims.call(void 0, );
|
|
3088
|
+
chunkXQPCA75E_cjs.init_cjs_shims();
|
|
3098
3089
|
if (process.env.NODE_ENV === "production") {
|
|
3099
3090
|
module.exports = require_react_jsx_runtime_production_min();
|
|
3100
3091
|
} else {
|
|
@@ -3103,25 +3094,709 @@ var require_jsx_runtime = _chunkP42X362Ucjs.__commonJS.call(void 0, {
|
|
|
3103
3094
|
}
|
|
3104
3095
|
});
|
|
3105
3096
|
|
|
3097
|
+
// src/SchemaMapper.ts
|
|
3098
|
+
chunkXQPCA75E_cjs.init_cjs_shims();
|
|
3099
|
+
var schemaKeywords = {
|
|
3100
|
+
any: "any",
|
|
3101
|
+
strict: "strict",
|
|
3102
|
+
unknown: "unknown",
|
|
3103
|
+
number: "number",
|
|
3104
|
+
integer: "integer",
|
|
3105
|
+
string: "string",
|
|
3106
|
+
boolean: "boolean",
|
|
3107
|
+
undefined: "undefined",
|
|
3108
|
+
nullable: "nullable",
|
|
3109
|
+
null: "null",
|
|
3110
|
+
nullish: "nullish",
|
|
3111
|
+
array: "array",
|
|
3112
|
+
tuple: "tuple",
|
|
3113
|
+
enum: "enum",
|
|
3114
|
+
union: "union",
|
|
3115
|
+
datetime: "datetime",
|
|
3116
|
+
date: "date",
|
|
3117
|
+
email: "email",
|
|
3118
|
+
uuid: "uuid",
|
|
3119
|
+
url: "url",
|
|
3120
|
+
/* intersection */
|
|
3121
|
+
default: "default",
|
|
3122
|
+
const: "const",
|
|
3123
|
+
and: "and",
|
|
3124
|
+
describe: "describe",
|
|
3125
|
+
min: "min",
|
|
3126
|
+
max: "max",
|
|
3127
|
+
optional: "optional",
|
|
3128
|
+
readOnly: "readOnly",
|
|
3129
|
+
// custom ones
|
|
3130
|
+
object: "object",
|
|
3131
|
+
ref: "ref",
|
|
3132
|
+
matches: "matches",
|
|
3133
|
+
firstName: "firstName",
|
|
3134
|
+
lastName: "lastName",
|
|
3135
|
+
password: "password",
|
|
3136
|
+
phone: "phone",
|
|
3137
|
+
blob: "blob",
|
|
3138
|
+
deprecated: "deprecated",
|
|
3139
|
+
example: "example",
|
|
3140
|
+
schema: "schema",
|
|
3141
|
+
catchall: "catchall",
|
|
3142
|
+
time: "time",
|
|
3143
|
+
name: "name"
|
|
3144
|
+
};
|
|
3145
|
+
function isKeyword(meta, keyword) {
|
|
3146
|
+
return meta.keyword === keyword;
|
|
3147
|
+
}
|
|
3148
|
+
|
|
3149
|
+
// src/SchemaGenerator.ts
|
|
3150
|
+
chunkXQPCA75E_cjs.init_cjs_shims();
|
|
3151
|
+
var SchemaGenerator = class _SchemaGenerator extends core.BaseGenerator {
|
|
3152
|
+
// Collect the types of all referenced schemas, so we can export them later
|
|
3153
|
+
refs = {};
|
|
3154
|
+
// Keep track of already used type aliases
|
|
3155
|
+
#usedAliasNames = {};
|
|
3156
|
+
/**
|
|
3157
|
+
* Creates a type node from a given schema.
|
|
3158
|
+
* Delegates to getBaseTypeFromSchema internally and
|
|
3159
|
+
* optionally adds a union with null.
|
|
3160
|
+
*/
|
|
3161
|
+
parse(props) {
|
|
3162
|
+
const options = this.#getOptions(props);
|
|
3163
|
+
const defaultSchemas = this.#parseSchemaObject(props);
|
|
3164
|
+
const schemas = options.transformers?.schema?.(props, defaultSchemas) || defaultSchemas || [];
|
|
3165
|
+
return remeda.uniqueWith(schemas, remeda.isDeepEqual);
|
|
3166
|
+
}
|
|
3167
|
+
deepSearch(tree, keyword) {
|
|
3168
|
+
return _SchemaGenerator.deepSearch(tree, keyword);
|
|
3169
|
+
}
|
|
3170
|
+
find(tree, keyword) {
|
|
3171
|
+
return _SchemaGenerator.find(tree, keyword);
|
|
3172
|
+
}
|
|
3173
|
+
static deepSearch(tree, keyword) {
|
|
3174
|
+
const foundItems = [];
|
|
3175
|
+
tree?.forEach((schema) => {
|
|
3176
|
+
if (schema.keyword === keyword) {
|
|
3177
|
+
foundItems.push(schema);
|
|
3178
|
+
}
|
|
3179
|
+
if (schema.keyword === schemaKeywords.object) {
|
|
3180
|
+
const subItem = schema;
|
|
3181
|
+
Object.values(subItem.args?.properties || {}).forEach((entrySchema) => {
|
|
3182
|
+
foundItems.push(..._SchemaGenerator.deepSearch(entrySchema, keyword));
|
|
3183
|
+
});
|
|
3184
|
+
Object.values(subItem.args?.additionalProperties || {}).forEach((entrySchema) => {
|
|
3185
|
+
foundItems.push(..._SchemaGenerator.deepSearch([entrySchema], keyword));
|
|
3186
|
+
});
|
|
3187
|
+
}
|
|
3188
|
+
if (schema.keyword === schemaKeywords.array) {
|
|
3189
|
+
const subItem = schema;
|
|
3190
|
+
subItem.args.items.forEach((entrySchema) => {
|
|
3191
|
+
foundItems.push(..._SchemaGenerator.deepSearch([entrySchema], keyword));
|
|
3192
|
+
});
|
|
3193
|
+
}
|
|
3194
|
+
if (schema.keyword === schemaKeywords.and) {
|
|
3195
|
+
const subItem = schema;
|
|
3196
|
+
subItem.args.forEach((entrySchema) => {
|
|
3197
|
+
foundItems.push(..._SchemaGenerator.deepSearch([entrySchema], keyword));
|
|
3198
|
+
});
|
|
3199
|
+
}
|
|
3200
|
+
if (schema.keyword === schemaKeywords.tuple) {
|
|
3201
|
+
const subItem = schema;
|
|
3202
|
+
subItem.args.items.forEach((entrySchema) => {
|
|
3203
|
+
foundItems.push(..._SchemaGenerator.deepSearch([entrySchema], keyword));
|
|
3204
|
+
});
|
|
3205
|
+
}
|
|
3206
|
+
if (schema.keyword === schemaKeywords.union) {
|
|
3207
|
+
const subItem = schema;
|
|
3208
|
+
subItem.args.forEach((entrySchema) => {
|
|
3209
|
+
foundItems.push(..._SchemaGenerator.deepSearch([entrySchema], keyword));
|
|
3210
|
+
});
|
|
3211
|
+
}
|
|
3212
|
+
});
|
|
3213
|
+
return foundItems;
|
|
3214
|
+
}
|
|
3215
|
+
static findInObject(tree, keyword) {
|
|
3216
|
+
let foundItem = void 0;
|
|
3217
|
+
tree?.forEach((schema) => {
|
|
3218
|
+
if (!foundItem && schema.keyword === keyword) {
|
|
3219
|
+
foundItem = schema;
|
|
3220
|
+
}
|
|
3221
|
+
if (schema.keyword === schemaKeywords.object) {
|
|
3222
|
+
const subItem = schema;
|
|
3223
|
+
Object.values(subItem.args?.properties || {}).forEach((entrySchema) => {
|
|
3224
|
+
if (!foundItem) {
|
|
3225
|
+
foundItem = _SchemaGenerator.find(entrySchema, keyword);
|
|
3226
|
+
}
|
|
3227
|
+
});
|
|
3228
|
+
Object.values(subItem.args?.additionalProperties || {}).forEach((entrySchema) => {
|
|
3229
|
+
if (!foundItem) {
|
|
3230
|
+
foundItem = _SchemaGenerator.find([entrySchema], keyword);
|
|
3231
|
+
}
|
|
3232
|
+
});
|
|
3233
|
+
}
|
|
3234
|
+
});
|
|
3235
|
+
return foundItem;
|
|
3236
|
+
}
|
|
3237
|
+
static find(tree, keyword) {
|
|
3238
|
+
let foundItem = void 0;
|
|
3239
|
+
tree?.forEach((schema) => {
|
|
3240
|
+
if (!foundItem && schema.keyword === keyword) {
|
|
3241
|
+
foundItem = schema;
|
|
3242
|
+
}
|
|
3243
|
+
if (schema.keyword === schemaKeywords.array) {
|
|
3244
|
+
const subItem = schema;
|
|
3245
|
+
subItem.args.items.forEach((entrySchema) => {
|
|
3246
|
+
if (!foundItem) {
|
|
3247
|
+
foundItem = _SchemaGenerator.find([entrySchema], keyword);
|
|
3248
|
+
}
|
|
3249
|
+
});
|
|
3250
|
+
}
|
|
3251
|
+
if (schema.keyword === schemaKeywords.and) {
|
|
3252
|
+
const subItem = schema;
|
|
3253
|
+
subItem.args.forEach((entrySchema) => {
|
|
3254
|
+
if (!foundItem) {
|
|
3255
|
+
foundItem = _SchemaGenerator.find([entrySchema], keyword);
|
|
3256
|
+
}
|
|
3257
|
+
});
|
|
3258
|
+
}
|
|
3259
|
+
if (schema.keyword === schemaKeywords.tuple) {
|
|
3260
|
+
const subItem = schema;
|
|
3261
|
+
subItem.args.items.forEach((entrySchema) => {
|
|
3262
|
+
if (!foundItem) {
|
|
3263
|
+
foundItem = _SchemaGenerator.find([entrySchema], keyword);
|
|
3264
|
+
}
|
|
3265
|
+
});
|
|
3266
|
+
}
|
|
3267
|
+
if (schema.keyword === schemaKeywords.union) {
|
|
3268
|
+
const subItem = schema;
|
|
3269
|
+
subItem.args.forEach((entrySchema) => {
|
|
3270
|
+
if (!foundItem) {
|
|
3271
|
+
foundItem = _SchemaGenerator.find([entrySchema], keyword);
|
|
3272
|
+
}
|
|
3273
|
+
});
|
|
3274
|
+
}
|
|
3275
|
+
});
|
|
3276
|
+
return foundItem;
|
|
3277
|
+
}
|
|
3278
|
+
#getUsedEnumNames(props) {
|
|
3279
|
+
const options = this.#getOptions(props);
|
|
3280
|
+
return options.usedEnumNames || {};
|
|
3281
|
+
}
|
|
3282
|
+
#getOptions({ name }) {
|
|
3283
|
+
const { override = [] } = this.context;
|
|
3284
|
+
return {
|
|
3285
|
+
...this.options,
|
|
3286
|
+
...override.find(({ pattern, type }) => {
|
|
3287
|
+
if (name && type === "schemaName") {
|
|
3288
|
+
return !!name.match(pattern);
|
|
3289
|
+
}
|
|
3290
|
+
return false;
|
|
3291
|
+
})?.options || {}
|
|
3292
|
+
};
|
|
3293
|
+
}
|
|
3294
|
+
#getUnknownReturn(props) {
|
|
3295
|
+
const options = this.#getOptions(props);
|
|
3296
|
+
if (options.unknownType === "any") {
|
|
3297
|
+
return schemaKeywords.any;
|
|
3298
|
+
}
|
|
3299
|
+
return schemaKeywords.unknown;
|
|
3300
|
+
}
|
|
3301
|
+
/**
|
|
3302
|
+
* Recursively creates a type literal with the given props.
|
|
3303
|
+
*/
|
|
3304
|
+
#parseProperties({ schema, name }) {
|
|
3305
|
+
const properties = schema?.properties || {};
|
|
3306
|
+
const additionalProperties = schema?.additionalProperties;
|
|
3307
|
+
const required = schema?.required;
|
|
3308
|
+
const propertiesSchemas = Object.keys(properties).map((propertyName) => {
|
|
3309
|
+
const validationFunctions = [];
|
|
3310
|
+
const propertySchema = properties[propertyName];
|
|
3311
|
+
const isRequired = Array.isArray(required) ? required?.includes(propertyName) : !!required;
|
|
3312
|
+
const nullable = propertySchema.nullable ?? propertySchema["x-nullable"] ?? false;
|
|
3313
|
+
validationFunctions.push(...this.parse({ schema: propertySchema, name: propertyName, parentName: name }));
|
|
3314
|
+
validationFunctions.push({
|
|
3315
|
+
keyword: schemaKeywords.name,
|
|
3316
|
+
args: propertyName
|
|
3317
|
+
});
|
|
3318
|
+
if (!isRequired && nullable) {
|
|
3319
|
+
validationFunctions.push({ keyword: schemaKeywords.nullish });
|
|
3320
|
+
} else if (!isRequired) {
|
|
3321
|
+
validationFunctions.push({ keyword: schemaKeywords.optional });
|
|
3322
|
+
}
|
|
3323
|
+
return {
|
|
3324
|
+
[propertyName]: validationFunctions
|
|
3325
|
+
};
|
|
3326
|
+
}).reduce((acc, curr) => ({ ...acc, ...curr }), {});
|
|
3327
|
+
let additionalPropertiesSchemas = [];
|
|
3328
|
+
if (additionalProperties) {
|
|
3329
|
+
additionalPropertiesSchemas = additionalProperties === true ? [{ keyword: this.#getUnknownReturn({ schema, name }) }] : this.parse({ schema: additionalProperties, parentName: name });
|
|
3330
|
+
}
|
|
3331
|
+
return [
|
|
3332
|
+
{
|
|
3333
|
+
keyword: schemaKeywords.object,
|
|
3334
|
+
args: {
|
|
3335
|
+
properties: propertiesSchemas,
|
|
3336
|
+
additionalProperties: additionalPropertiesSchemas
|
|
3337
|
+
}
|
|
3338
|
+
}
|
|
3339
|
+
];
|
|
3340
|
+
}
|
|
3341
|
+
/**
|
|
3342
|
+
* Create a type alias for the schema referenced by the given ReferenceObject
|
|
3343
|
+
*/
|
|
3344
|
+
#getRefAlias(obj) {
|
|
3345
|
+
const { $ref } = obj;
|
|
3346
|
+
let ref = this.refs[$ref];
|
|
3347
|
+
const originalName = utils.getUniqueName($ref.replace(/.+\//, ""), this.#usedAliasNames);
|
|
3348
|
+
const propertyName = this.context.pluginManager.resolveName({
|
|
3349
|
+
name: originalName,
|
|
3350
|
+
pluginKey: this.context.plugin.key,
|
|
3351
|
+
type: "function"
|
|
3352
|
+
});
|
|
3353
|
+
if (ref) {
|
|
3354
|
+
return [
|
|
3355
|
+
{
|
|
3356
|
+
keyword: schemaKeywords.ref,
|
|
3357
|
+
args: { name: ref.propertyName, path: ref.path }
|
|
3358
|
+
}
|
|
3359
|
+
];
|
|
3360
|
+
}
|
|
3361
|
+
const fileName = this.context.pluginManager.resolveName({
|
|
3362
|
+
name: originalName,
|
|
3363
|
+
pluginKey: this.context.plugin.key,
|
|
3364
|
+
type: "file"
|
|
3365
|
+
});
|
|
3366
|
+
const file = this.context.pluginManager.getFile({
|
|
3367
|
+
name: fileName,
|
|
3368
|
+
pluginKey: this.context.plugin.key,
|
|
3369
|
+
extName: ".ts"
|
|
3370
|
+
});
|
|
3371
|
+
ref = this.refs[$ref] = {
|
|
3372
|
+
propertyName,
|
|
3373
|
+
originalName,
|
|
3374
|
+
path: file.path
|
|
3375
|
+
};
|
|
3376
|
+
return [
|
|
3377
|
+
{
|
|
3378
|
+
keyword: schemaKeywords.ref,
|
|
3379
|
+
args: { name: ref.propertyName, path: ref?.path }
|
|
3380
|
+
}
|
|
3381
|
+
];
|
|
3382
|
+
}
|
|
3383
|
+
#getParsedSchemaObject(schema) {
|
|
3384
|
+
const parsedSchema = chunkXQPCA75E_cjs.getSchemaFactory(this.context.oas)(schema);
|
|
3385
|
+
return parsedSchema;
|
|
3386
|
+
}
|
|
3387
|
+
/**
|
|
3388
|
+
* This is the very core of the OpenAPI to TS conversion - it takes a
|
|
3389
|
+
* schema and returns the appropriate type.
|
|
3390
|
+
*/
|
|
3391
|
+
#parseSchemaObject({ schema: _schema, name, parentName }) {
|
|
3392
|
+
const options = this.#getOptions({ schema: _schema, name });
|
|
3393
|
+
const unknownReturn = this.#getUnknownReturn({ schema: _schema, name });
|
|
3394
|
+
const { schema, version } = this.#getParsedSchemaObject(_schema);
|
|
3395
|
+
if (!schema) {
|
|
3396
|
+
return [{ keyword: unknownReturn }];
|
|
3397
|
+
}
|
|
3398
|
+
const baseItems = [
|
|
3399
|
+
{
|
|
3400
|
+
keyword: schemaKeywords.schema,
|
|
3401
|
+
args: {
|
|
3402
|
+
type: schema.type,
|
|
3403
|
+
format: schema.format
|
|
3404
|
+
}
|
|
3405
|
+
}
|
|
3406
|
+
];
|
|
3407
|
+
const min = schema.minimum ?? schema.minLength ?? schema.minItems ?? void 0;
|
|
3408
|
+
const max = schema.maximum ?? schema.maxLength ?? schema.maxItems ?? void 0;
|
|
3409
|
+
const nullable = schema.nullable ?? schema["x-nullable"] ?? false;
|
|
3410
|
+
if (schema.default !== void 0 && !Array.isArray(schema.default)) {
|
|
3411
|
+
if (typeof schema.default === "string") {
|
|
3412
|
+
baseItems.push({
|
|
3413
|
+
keyword: schemaKeywords.default,
|
|
3414
|
+
args: transformers__default.default.stringify(schema.default)
|
|
3415
|
+
});
|
|
3416
|
+
} else if (typeof schema.default === "boolean") {
|
|
3417
|
+
baseItems.push({
|
|
3418
|
+
keyword: schemaKeywords.default,
|
|
3419
|
+
args: schema.default ?? false
|
|
3420
|
+
});
|
|
3421
|
+
} else {
|
|
3422
|
+
baseItems.push({
|
|
3423
|
+
keyword: schemaKeywords.default,
|
|
3424
|
+
args: schema.default
|
|
3425
|
+
});
|
|
3426
|
+
}
|
|
3427
|
+
}
|
|
3428
|
+
if (schema.description) {
|
|
3429
|
+
baseItems.push({
|
|
3430
|
+
keyword: schemaKeywords.describe,
|
|
3431
|
+
args: schema.description
|
|
3432
|
+
});
|
|
3433
|
+
}
|
|
3434
|
+
if (schema.pattern) {
|
|
3435
|
+
baseItems.unshift({
|
|
3436
|
+
keyword: schemaKeywords.matches,
|
|
3437
|
+
args: schema.pattern
|
|
3438
|
+
});
|
|
3439
|
+
}
|
|
3440
|
+
if (max !== void 0) {
|
|
3441
|
+
baseItems.unshift({ keyword: schemaKeywords.max, args: max });
|
|
3442
|
+
}
|
|
3443
|
+
if (min !== void 0) {
|
|
3444
|
+
baseItems.unshift({ keyword: schemaKeywords.min, args: min });
|
|
3445
|
+
}
|
|
3446
|
+
if (nullable) {
|
|
3447
|
+
baseItems.push({ keyword: schemaKeywords.nullable });
|
|
3448
|
+
}
|
|
3449
|
+
if (schema.type && Array.isArray(schema.type)) {
|
|
3450
|
+
const [_schema2, nullable2] = schema.type;
|
|
3451
|
+
if (nullable2 === "null") {
|
|
3452
|
+
baseItems.push({ keyword: schemaKeywords.nullable });
|
|
3453
|
+
}
|
|
3454
|
+
}
|
|
3455
|
+
if (schema.readOnly) {
|
|
3456
|
+
baseItems.push({ keyword: schemaKeywords.readOnly });
|
|
3457
|
+
}
|
|
3458
|
+
if (oas.isReference(schema)) {
|
|
3459
|
+
return [
|
|
3460
|
+
...this.#getRefAlias(schema),
|
|
3461
|
+
nullable && { keyword: schemaKeywords.nullable },
|
|
3462
|
+
{
|
|
3463
|
+
keyword: schemaKeywords.schema,
|
|
3464
|
+
args: {
|
|
3465
|
+
type: schema.type,
|
|
3466
|
+
format: schema.format
|
|
3467
|
+
}
|
|
3468
|
+
}
|
|
3469
|
+
].filter(Boolean);
|
|
3470
|
+
}
|
|
3471
|
+
if (schema.oneOf) {
|
|
3472
|
+
const schemaWithoutOneOf = { ...schema, oneOf: void 0 };
|
|
3473
|
+
const union = {
|
|
3474
|
+
keyword: schemaKeywords.union,
|
|
3475
|
+
args: schema.oneOf.map((item) => {
|
|
3476
|
+
return item && this.parse({ schema: item, name, parentName })[0];
|
|
3477
|
+
}).filter(Boolean).filter((item) => {
|
|
3478
|
+
return item && item.keyword !== unknownReturn;
|
|
3479
|
+
})
|
|
3480
|
+
};
|
|
3481
|
+
if (schemaWithoutOneOf.properties) {
|
|
3482
|
+
return [...this.parse({ schema: schemaWithoutOneOf, name, parentName }), union, ...baseItems];
|
|
3483
|
+
}
|
|
3484
|
+
return [union, ...baseItems];
|
|
3485
|
+
}
|
|
3486
|
+
if (schema.anyOf) {
|
|
3487
|
+
const schemaWithoutAnyOf = { ...schema, anyOf: void 0 };
|
|
3488
|
+
const union = {
|
|
3489
|
+
keyword: schemaKeywords.union,
|
|
3490
|
+
args: schema.anyOf.map((item) => {
|
|
3491
|
+
return item && this.parse({ schema: item, name, parentName })[0];
|
|
3492
|
+
}).filter(Boolean).filter((item) => {
|
|
3493
|
+
return item && item.keyword !== unknownReturn;
|
|
3494
|
+
}).map((item) => {
|
|
3495
|
+
if (isKeyword(item, schemaKeywords.object)) {
|
|
3496
|
+
return {
|
|
3497
|
+
...item,
|
|
3498
|
+
args: {
|
|
3499
|
+
...item.args,
|
|
3500
|
+
strict: true
|
|
3501
|
+
}
|
|
3502
|
+
};
|
|
3503
|
+
}
|
|
3504
|
+
return item;
|
|
3505
|
+
})
|
|
3506
|
+
};
|
|
3507
|
+
if (schemaWithoutAnyOf.properties) {
|
|
3508
|
+
return [...this.parse({ schema: schemaWithoutAnyOf, name, parentName }), union, ...baseItems];
|
|
3509
|
+
}
|
|
3510
|
+
return [union, ...baseItems];
|
|
3511
|
+
}
|
|
3512
|
+
if (schema.allOf) {
|
|
3513
|
+
const schemaWithoutAllOf = { ...schema, allOf: void 0 };
|
|
3514
|
+
const and = {
|
|
3515
|
+
keyword: schemaKeywords.and,
|
|
3516
|
+
args: schema.allOf.map((item) => {
|
|
3517
|
+
return item && this.parse({ schema: item, name, parentName })[0];
|
|
3518
|
+
}).filter(Boolean).filter((item) => {
|
|
3519
|
+
return item && item.keyword !== unknownReturn;
|
|
3520
|
+
})
|
|
3521
|
+
};
|
|
3522
|
+
if (schemaWithoutAllOf.properties) {
|
|
3523
|
+
return [
|
|
3524
|
+
{
|
|
3525
|
+
...and,
|
|
3526
|
+
args: [...and.args || [], ...this.parse({ schema: schemaWithoutAllOf, name, parentName })]
|
|
3527
|
+
},
|
|
3528
|
+
...baseItems
|
|
3529
|
+
];
|
|
3530
|
+
}
|
|
3531
|
+
return [and, ...baseItems];
|
|
3532
|
+
}
|
|
3533
|
+
if (schema.enum) {
|
|
3534
|
+
const enumName = utils.getUniqueName(transformers.pascalCase([parentName, name, options.enumSuffix].join(" ")), this.#getUsedEnumNames({ schema, name }));
|
|
3535
|
+
const typeName = this.context.pluginManager.resolveName({
|
|
3536
|
+
name: enumName,
|
|
3537
|
+
pluginKey: this.context.plugin.key,
|
|
3538
|
+
type: "type"
|
|
3539
|
+
});
|
|
3540
|
+
const nullableEnum = schema.enum.includes(null);
|
|
3541
|
+
if (nullableEnum) {
|
|
3542
|
+
baseItems.push({ keyword: schemaKeywords.nullable });
|
|
3543
|
+
}
|
|
3544
|
+
const filteredValues = schema.enum.filter((value) => value !== null);
|
|
3545
|
+
const extensionEnums = ["x-enumNames", "x-enum-varnames"].filter((extensionKey) => extensionKey in schema).map((extensionKey) => {
|
|
3546
|
+
return [
|
|
3547
|
+
{
|
|
3548
|
+
keyword: schemaKeywords.enum,
|
|
3549
|
+
args: {
|
|
3550
|
+
name,
|
|
3551
|
+
typeName,
|
|
3552
|
+
asConst: false,
|
|
3553
|
+
items: [...new Set(schema[extensionKey])].map((name2, index) => ({
|
|
3554
|
+
name: transformers__default.default.stringify(name2),
|
|
3555
|
+
value: schema.enum?.[index],
|
|
3556
|
+
format: remeda.isNumber(schema.enum?.[index]) ? "number" : "string"
|
|
3557
|
+
}))
|
|
3558
|
+
}
|
|
3559
|
+
},
|
|
3560
|
+
...baseItems.filter(
|
|
3561
|
+
(item) => item.keyword !== schemaKeywords.min && item.keyword !== schemaKeywords.max && item.keyword !== schemaKeywords.matches
|
|
3562
|
+
)
|
|
3563
|
+
];
|
|
3564
|
+
});
|
|
3565
|
+
if (schema.type === "number" || schema.type === "integer") {
|
|
3566
|
+
const enumNames = extensionEnums[0]?.find((item) => isKeyword(item, schemaKeywords.enum));
|
|
3567
|
+
return [
|
|
3568
|
+
{
|
|
3569
|
+
keyword: schemaKeywords.enum,
|
|
3570
|
+
args: {
|
|
3571
|
+
name: enumName,
|
|
3572
|
+
typeName,
|
|
3573
|
+
asConst: true,
|
|
3574
|
+
items: enumNames?.args?.items ? [...new Set(enumNames.args.items)].map(({ name: name2, value }) => ({
|
|
3575
|
+
name: name2,
|
|
3576
|
+
value,
|
|
3577
|
+
format: "number"
|
|
3578
|
+
})) : [...new Set(filteredValues)].map((value) => {
|
|
3579
|
+
return {
|
|
3580
|
+
name: value,
|
|
3581
|
+
value,
|
|
3582
|
+
format: "number"
|
|
3583
|
+
};
|
|
3584
|
+
})
|
|
3585
|
+
}
|
|
3586
|
+
},
|
|
3587
|
+
...baseItems.filter((item) => item.keyword !== schemaKeywords.min && item.keyword !== schemaKeywords.max && item.keyword !== schemaKeywords.matches)
|
|
3588
|
+
];
|
|
3589
|
+
}
|
|
3590
|
+
if (extensionEnums.length > 0 && extensionEnums[0]) {
|
|
3591
|
+
return extensionEnums[0];
|
|
3592
|
+
}
|
|
3593
|
+
return [
|
|
3594
|
+
{
|
|
3595
|
+
keyword: schemaKeywords.enum,
|
|
3596
|
+
args: {
|
|
3597
|
+
name: enumName,
|
|
3598
|
+
typeName,
|
|
3599
|
+
asConst: false,
|
|
3600
|
+
items: [...new Set(filteredValues)].map((value) => ({
|
|
3601
|
+
name: transformers__default.default.stringify(value),
|
|
3602
|
+
value,
|
|
3603
|
+
format: remeda.isNumber(value) ? "number" : "string"
|
|
3604
|
+
}))
|
|
3605
|
+
}
|
|
3606
|
+
},
|
|
3607
|
+
...baseItems.filter((item) => item.keyword !== schemaKeywords.min && item.keyword !== schemaKeywords.max && item.keyword !== schemaKeywords.matches)
|
|
3608
|
+
];
|
|
3609
|
+
}
|
|
3610
|
+
if ("prefixItems" in schema) {
|
|
3611
|
+
const prefixItems = schema.prefixItems;
|
|
3612
|
+
const min2 = schema.minimum ?? schema.minLength ?? schema.minItems ?? void 0;
|
|
3613
|
+
const max2 = schema.maximum ?? schema.maxLength ?? schema.maxItems ?? void 0;
|
|
3614
|
+
return [
|
|
3615
|
+
{
|
|
3616
|
+
keyword: schemaKeywords.tuple,
|
|
3617
|
+
args: {
|
|
3618
|
+
min: min2,
|
|
3619
|
+
max: max2,
|
|
3620
|
+
items: prefixItems.map((item) => {
|
|
3621
|
+
return this.parse({ schema: item, name, parentName })[0];
|
|
3622
|
+
}).filter(Boolean)
|
|
3623
|
+
}
|
|
3624
|
+
},
|
|
3625
|
+
...baseItems.filter((item) => item.keyword !== schemaKeywords.min && item.keyword !== schemaKeywords.max)
|
|
3626
|
+
];
|
|
3627
|
+
}
|
|
3628
|
+
if (version === "3.1" && "const" in schema) {
|
|
3629
|
+
if (schema["const"]) {
|
|
3630
|
+
return [
|
|
3631
|
+
{
|
|
3632
|
+
keyword: schemaKeywords.const,
|
|
3633
|
+
args: {
|
|
3634
|
+
name: schema["const"],
|
|
3635
|
+
format: typeof schema["const"] === "number" ? "number" : "string",
|
|
3636
|
+
value: schema["const"]
|
|
3637
|
+
}
|
|
3638
|
+
},
|
|
3639
|
+
...baseItems
|
|
3640
|
+
];
|
|
3641
|
+
}
|
|
3642
|
+
return [{ keyword: schemaKeywords.null }];
|
|
3643
|
+
}
|
|
3644
|
+
if (schema.format) {
|
|
3645
|
+
switch (schema.format) {
|
|
3646
|
+
case "binary":
|
|
3647
|
+
baseItems.push({ keyword: schemaKeywords.blob });
|
|
3648
|
+
return baseItems;
|
|
3649
|
+
case "date-time":
|
|
3650
|
+
if (options.dateType) {
|
|
3651
|
+
if (options.dateType === "date") {
|
|
3652
|
+
baseItems.unshift({ keyword: schemaKeywords.date, args: { type: "date" } });
|
|
3653
|
+
return baseItems;
|
|
3654
|
+
}
|
|
3655
|
+
if (options.dateType === "stringOffset") {
|
|
3656
|
+
baseItems.unshift({ keyword: schemaKeywords.datetime, args: { offset: true } });
|
|
3657
|
+
return baseItems;
|
|
3658
|
+
}
|
|
3659
|
+
if (options.dateType === "stringLocal") {
|
|
3660
|
+
baseItems.unshift({ keyword: schemaKeywords.datetime, args: { local: true } });
|
|
3661
|
+
return baseItems;
|
|
3662
|
+
}
|
|
3663
|
+
baseItems.unshift({ keyword: schemaKeywords.datetime, args: { offset: false } });
|
|
3664
|
+
return baseItems;
|
|
3665
|
+
}
|
|
3666
|
+
break;
|
|
3667
|
+
case "date":
|
|
3668
|
+
if (options.dateType) {
|
|
3669
|
+
if (options.dateType === "date") {
|
|
3670
|
+
baseItems.unshift({ keyword: schemaKeywords.date, args: { type: "date" } });
|
|
3671
|
+
return baseItems;
|
|
3672
|
+
}
|
|
3673
|
+
baseItems.unshift({ keyword: schemaKeywords.date, args: { type: "string" } });
|
|
3674
|
+
return baseItems;
|
|
3675
|
+
}
|
|
3676
|
+
break;
|
|
3677
|
+
case "time":
|
|
3678
|
+
if (options.dateType) {
|
|
3679
|
+
if (options.dateType === "date") {
|
|
3680
|
+
baseItems.unshift({ keyword: schemaKeywords.time, args: { type: "date" } });
|
|
3681
|
+
return baseItems;
|
|
3682
|
+
}
|
|
3683
|
+
baseItems.unshift({ keyword: schemaKeywords.time, args: { type: "string" } });
|
|
3684
|
+
return baseItems;
|
|
3685
|
+
}
|
|
3686
|
+
break;
|
|
3687
|
+
case "uuid":
|
|
3688
|
+
baseItems.unshift({ keyword: schemaKeywords.uuid });
|
|
3689
|
+
break;
|
|
3690
|
+
case "email":
|
|
3691
|
+
case "idn-email":
|
|
3692
|
+
baseItems.unshift({ keyword: schemaKeywords.email });
|
|
3693
|
+
break;
|
|
3694
|
+
case "uri":
|
|
3695
|
+
case "ipv4":
|
|
3696
|
+
case "ipv6":
|
|
3697
|
+
case "uri-reference":
|
|
3698
|
+
case "hostname":
|
|
3699
|
+
case "idn-hostname":
|
|
3700
|
+
baseItems.unshift({ keyword: schemaKeywords.url });
|
|
3701
|
+
break;
|
|
3702
|
+
}
|
|
3703
|
+
}
|
|
3704
|
+
if ("items" in schema || schema.type === "array") {
|
|
3705
|
+
const min2 = schema.minimum ?? schema.minLength ?? schema.minItems ?? void 0;
|
|
3706
|
+
const max2 = schema.maximum ?? schema.maxLength ?? schema.maxItems ?? void 0;
|
|
3707
|
+
const items = this.parse({ schema: "items" in schema ? schema.items : [], name, parentName });
|
|
3708
|
+
return [
|
|
3709
|
+
{
|
|
3710
|
+
keyword: schemaKeywords.array,
|
|
3711
|
+
args: {
|
|
3712
|
+
items,
|
|
3713
|
+
min: min2,
|
|
3714
|
+
max: max2
|
|
3715
|
+
}
|
|
3716
|
+
},
|
|
3717
|
+
...baseItems.filter((item) => item.keyword !== schemaKeywords.min && item.keyword !== schemaKeywords.max)
|
|
3718
|
+
];
|
|
3719
|
+
}
|
|
3720
|
+
if (schema.properties || schema.additionalProperties) {
|
|
3721
|
+
return [...this.#parseProperties({ schema, name }), ...baseItems];
|
|
3722
|
+
}
|
|
3723
|
+
if (schema.type) {
|
|
3724
|
+
if (Array.isArray(schema.type)) {
|
|
3725
|
+
const [type] = schema.type;
|
|
3726
|
+
return [
|
|
3727
|
+
...this.parse({
|
|
3728
|
+
schema: {
|
|
3729
|
+
...schema,
|
|
3730
|
+
type
|
|
3731
|
+
},
|
|
3732
|
+
name,
|
|
3733
|
+
parentName
|
|
3734
|
+
}),
|
|
3735
|
+
...baseItems
|
|
3736
|
+
].filter(Boolean);
|
|
3737
|
+
}
|
|
3738
|
+
if (!["boolean", "object", "number", "string", "integer"].includes(schema.type)) {
|
|
3739
|
+
this.context.pluginManager.logger.emit("warning", `Schema type '${schema.type}' is not valid for schema ${parentName}.${name}`);
|
|
3740
|
+
}
|
|
3741
|
+
return [{ keyword: schema.type }, ...baseItems];
|
|
3742
|
+
}
|
|
3743
|
+
return [{ keyword: unknownReturn }];
|
|
3744
|
+
}
|
|
3745
|
+
async build(...generators) {
|
|
3746
|
+
const { oas, contentType, include } = this.context;
|
|
3747
|
+
const schemas = chunkXQPCA75E_cjs.getSchemas({ oas, contentType, includes: include });
|
|
3748
|
+
const promises = Object.entries(schemas).reduce((acc, [name, schema]) => {
|
|
3749
|
+
const options = this.#getOptions({ name });
|
|
3750
|
+
const promiseOperation = this.schema.call(this, name, schema, {
|
|
3751
|
+
...this.options,
|
|
3752
|
+
...options
|
|
3753
|
+
});
|
|
3754
|
+
if (promiseOperation) {
|
|
3755
|
+
acc.push(promiseOperation);
|
|
3756
|
+
}
|
|
3757
|
+
generators?.forEach((generator) => {
|
|
3758
|
+
const promise = generator.schema?.({
|
|
3759
|
+
instance: this,
|
|
3760
|
+
name,
|
|
3761
|
+
schema,
|
|
3762
|
+
options: {
|
|
3763
|
+
...this.options,
|
|
3764
|
+
...options
|
|
3765
|
+
}
|
|
3766
|
+
});
|
|
3767
|
+
if (promise) {
|
|
3768
|
+
acc.push(promise);
|
|
3769
|
+
}
|
|
3770
|
+
});
|
|
3771
|
+
return acc;
|
|
3772
|
+
}, []);
|
|
3773
|
+
const files = await Promise.all(promises);
|
|
3774
|
+
return files.flat().filter(Boolean);
|
|
3775
|
+
}
|
|
3776
|
+
/**
|
|
3777
|
+
* Schema
|
|
3778
|
+
*/
|
|
3779
|
+
async schema(name, object, options) {
|
|
3780
|
+
return [];
|
|
3781
|
+
}
|
|
3782
|
+
};
|
|
3783
|
+
|
|
3106
3784
|
// src/components/Operation.tsx
|
|
3107
|
-
|
|
3108
|
-
var import_jsx_runtime =
|
|
3109
|
-
var
|
|
3110
|
-
var OperationContext = _react.createContext.call(void 0, {});
|
|
3785
|
+
chunkXQPCA75E_cjs.init_cjs_shims();
|
|
3786
|
+
var import_jsx_runtime = chunkXQPCA75E_cjs.__toESM(require_jsx_runtime(), 1);
|
|
3787
|
+
var OperationContext = react.createContext({});
|
|
3111
3788
|
function Operation({ operation, children }) {
|
|
3112
3789
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(OperationContext.Provider, { value: { operation }, children });
|
|
3113
3790
|
}
|
|
3114
3791
|
Operation.Context = OperationContext;
|
|
3115
3792
|
|
|
3116
3793
|
// src/hooks/useSchema.ts
|
|
3117
|
-
|
|
3118
|
-
|
|
3794
|
+
chunkXQPCA75E_cjs.init_cjs_shims();
|
|
3119
3795
|
|
|
3120
3796
|
// src/components/Schema.tsx
|
|
3121
|
-
|
|
3122
|
-
|
|
3123
|
-
var
|
|
3124
|
-
var SchemaContext = _react.createContext.call(void 0, {
|
|
3797
|
+
chunkXQPCA75E_cjs.init_cjs_shims();
|
|
3798
|
+
var import_jsx_runtime2 = chunkXQPCA75E_cjs.__toESM(require_jsx_runtime(), 1);
|
|
3799
|
+
var SchemaContext = react.createContext({
|
|
3125
3800
|
name: "unknown",
|
|
3126
3801
|
tree: []
|
|
3127
3802
|
});
|
|
@@ -3129,10 +3804,14 @@ function Schema({ name, value, tree = [], children }) {
|
|
|
3129
3804
|
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(SchemaContext.Provider, { value: { name, schema: value, tree }, children });
|
|
3130
3805
|
}
|
|
3131
3806
|
Schema.File = function({ output, isTypeOnly, children }) {
|
|
3132
|
-
const { plugin, pluginManager, mode } =
|
|
3807
|
+
const { plugin, pluginManager, mode } = react.useApp();
|
|
3133
3808
|
const { name } = useSchema();
|
|
3134
3809
|
if (mode === "single") {
|
|
3135
|
-
const baseName2 =
|
|
3810
|
+
const baseName2 = `${pluginManager.resolveName({
|
|
3811
|
+
name,
|
|
3812
|
+
pluginKey: plugin.key,
|
|
3813
|
+
type: "file"
|
|
3814
|
+
})}.ts`;
|
|
3136
3815
|
const resolvedPath2 = pluginManager.resolvePath({
|
|
3137
3816
|
baseName: "",
|
|
3138
3817
|
pluginKey: plugin.key
|
|
@@ -3140,8 +3819,8 @@ Schema.File = function({ output, isTypeOnly, children }) {
|
|
|
3140
3819
|
if (!resolvedPath2) {
|
|
3141
3820
|
return null;
|
|
3142
3821
|
}
|
|
3143
|
-
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
3144
|
-
|
|
3822
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
3823
|
+
react.File,
|
|
3145
3824
|
{
|
|
3146
3825
|
baseName: baseName2,
|
|
3147
3826
|
path: resolvedPath2,
|
|
@@ -3150,7 +3829,7 @@ Schema.File = function({ output, isTypeOnly, children }) {
|
|
|
3150
3829
|
},
|
|
3151
3830
|
children
|
|
3152
3831
|
}
|
|
3153
|
-
)
|
|
3832
|
+
);
|
|
3154
3833
|
}
|
|
3155
3834
|
const baseName = `${pluginManager.resolveName({
|
|
3156
3835
|
name,
|
|
@@ -3164,8 +3843,8 @@ Schema.File = function({ output, isTypeOnly, children }) {
|
|
|
3164
3843
|
if (!resolvedPath) {
|
|
3165
3844
|
return null;
|
|
3166
3845
|
}
|
|
3167
|
-
return /* @__PURE__ */ (0, import_jsx_runtime2.
|
|
3168
|
-
|
|
3846
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
|
|
3847
|
+
react.File,
|
|
3169
3848
|
{
|
|
3170
3849
|
baseName,
|
|
3171
3850
|
path: resolvedPath,
|
|
@@ -3177,45 +3856,37 @@ Schema.File = function({ output, isTypeOnly, children }) {
|
|
|
3177
3856
|
children
|
|
3178
3857
|
]
|
|
3179
3858
|
}
|
|
3180
|
-
)
|
|
3859
|
+
);
|
|
3181
3860
|
};
|
|
3182
|
-
Schema.Imports = ({ isTypeOnly
|
|
3861
|
+
Schema.Imports = ({ isTypeOnly }) => {
|
|
3183
3862
|
const { tree } = useSchema();
|
|
3184
|
-
const { path: root } =
|
|
3185
|
-
const refs =
|
|
3186
|
-
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_jsx_runtime2.Fragment, { children:
|
|
3863
|
+
const { path: root } = react.useFile();
|
|
3864
|
+
const refs = SchemaGenerator.deepSearch(tree, schemaKeywords.ref);
|
|
3865
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_jsx_runtime2.Fragment, { children: refs?.map((item, i) => {
|
|
3187
3866
|
if (!item.args.path) {
|
|
3188
3867
|
return void 0;
|
|
3189
3868
|
}
|
|
3190
|
-
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
3191
|
-
})
|
|
3869
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(react.File.Import, { root, name: [item.args.name], path: item.args.path, isTypeOnly }, i);
|
|
3870
|
+
}).filter(Boolean) });
|
|
3192
3871
|
};
|
|
3193
3872
|
Schema.Context = SchemaContext;
|
|
3194
3873
|
|
|
3195
3874
|
// src/hooks/useSchema.ts
|
|
3196
3875
|
function useSchema() {
|
|
3197
|
-
const props =
|
|
3876
|
+
const props = react.useContext(Schema.Context);
|
|
3198
3877
|
return props;
|
|
3199
3878
|
}
|
|
3200
3879
|
|
|
3201
3880
|
// src/components/Oas.tsx
|
|
3202
|
-
|
|
3203
|
-
|
|
3204
|
-
var
|
|
3205
|
-
var OasContext = _react.createContext.call(void 0, {});
|
|
3881
|
+
chunkXQPCA75E_cjs.init_cjs_shims();
|
|
3882
|
+
var import_jsx_runtime3 = chunkXQPCA75E_cjs.__toESM(require_jsx_runtime(), 1);
|
|
3883
|
+
var OasContext = react.createContext({});
|
|
3206
3884
|
function Oas({ oas, children, operations, generator }) {
|
|
3207
3885
|
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(OasContext.Provider, { value: { oas, generator, operations }, children });
|
|
3208
3886
|
}
|
|
3209
3887
|
Oas.Context = OasContext;
|
|
3210
3888
|
Oas.Operation = Operation;
|
|
3211
3889
|
Oas.Schema = Schema;
|
|
3212
|
-
|
|
3213
|
-
|
|
3214
|
-
|
|
3215
|
-
|
|
3216
|
-
|
|
3217
|
-
|
|
3218
|
-
exports.Operation = Operation; exports.useSchema = useSchema; exports.Schema = Schema; exports.Oas = Oas;
|
|
3219
3890
|
/*! Bundled license information:
|
|
3220
3891
|
|
|
3221
3892
|
react/cjs/react.production.min.js:
|
|
@@ -3262,4 +3933,14 @@ react/cjs/react-jsx-runtime.development.js:
|
|
|
3262
3933
|
* LICENSE file in the root directory of this source tree.
|
|
3263
3934
|
*)
|
|
3264
3935
|
*/
|
|
3265
|
-
|
|
3936
|
+
|
|
3937
|
+
exports.Oas = Oas;
|
|
3938
|
+
exports.Operation = Operation;
|
|
3939
|
+
exports.Schema = Schema;
|
|
3940
|
+
exports.SchemaGenerator = SchemaGenerator;
|
|
3941
|
+
exports.isKeyword = isKeyword;
|
|
3942
|
+
exports.require_jsx_runtime = require_jsx_runtime;
|
|
3943
|
+
exports.schemaKeywords = schemaKeywords;
|
|
3944
|
+
exports.useSchema = useSchema;
|
|
3945
|
+
//# sourceMappingURL=chunk-47SNBYWH.cjs.map
|
|
3946
|
+
//# sourceMappingURL=chunk-47SNBYWH.cjs.map
|