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