@kubb/agent 5.0.0-alpha.35 → 5.0.0-alpha.36
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/.output/nitro.json +1 -1
- package/.output/server/chunks/nitro/nitro.mjs +1293 -20554
- package/.output/server/chunks/nitro/nitro.mjs.map +1 -1
- package/.output/server/chunks/routes/api/health.get.mjs +16 -14
- package/.output/server/chunks/routes/api/health.get.mjs.map +1 -1
- package/.output/server/index.mjs +16 -14
- package/.output/server/index.mjs.map +1 -1
- package/.output/server/node_modules/.nitro/ws@8.18.0/lib/constants.js +18 -0
- package/.output/server/node_modules/.nitro/ws@8.18.0/lib/permessage-deflate.js +514 -0
- package/.output/server/node_modules/.nitro/ws@8.18.0/lib/sender.js +602 -0
- package/.output/server/node_modules/.nitro/ws@8.18.0/lib/stream.js +159 -0
- package/.output/server/node_modules/.nitro/ws@8.18.0/lib/websocket-server.js +540 -0
- package/.output/server/node_modules/.nitro/ws@8.18.0/lib/websocket.js +1388 -0
- package/.output/server/node_modules/.nitro/ws@8.18.0/package.json +69 -0
- package/.output/server/node_modules/.nitro/ws@8.18.0/wrapper.mjs +8 -0
- package/.output/server/node_modules/.nitro/ws@8.20.0/lib/buffer-util.js +131 -0
- package/.output/server/node_modules/.nitro/ws@8.20.0/lib/event-target.js +292 -0
- package/.output/server/node_modules/.nitro/ws@8.20.0/lib/extension.js +203 -0
- package/.output/server/node_modules/.nitro/ws@8.20.0/lib/limiter.js +55 -0
- package/.output/server/node_modules/.nitro/ws@8.20.0/lib/receiver.js +706 -0
- package/.output/server/node_modules/.nitro/ws@8.20.0/lib/subprotocol.js +62 -0
- package/.output/server/node_modules/.nitro/ws@8.20.0/lib/validation.js +152 -0
- package/.output/server/node_modules/@clack/core/dist/index.mjs +11 -0
- package/.output/server/node_modules/@clack/core/package.json +60 -0
- package/.output/server/node_modules/@clack/prompts/dist/index.mjs +137 -0
- package/.output/server/node_modules/@clack/prompts/package.json +65 -0
- package/.output/server/node_modules/@kubb/ast/dist/chunk--u3MIqq1.js +8 -0
- package/.output/server/node_modules/@kubb/ast/dist/index.js +423 -0
- package/.output/server/node_modules/@kubb/ast/package.json +70 -0
- package/.output/server/node_modules/@kubb/core/dist/chunk--u3MIqq1.js +8 -0
- package/.output/server/node_modules/@kubb/core/dist/hooks.js +23 -0
- package/.output/server/node_modules/@kubb/core/dist/index.js +2311 -0
- package/.output/server/node_modules/@kubb/core/package.json +109 -0
- package/.output/server/node_modules/@kubb/fabric-core/dist/chunk-O_arW02_.js +17 -0
- package/.output/server/node_modules/@kubb/fabric-core/dist/defaultParser-iCpMSYCp.js +15 -0
- package/.output/server/node_modules/@kubb/fabric-core/dist/getRelativePath-NAm_Y-vp.js +55 -0
- package/.output/server/node_modules/@kubb/fabric-core/dist/index.js +653 -0
- package/.output/server/node_modules/@kubb/fabric-core/dist/onProcessExit-Cput7j2c.js +742 -0
- package/.output/server/node_modules/@kubb/fabric-core/dist/parsers/typescript.js +101 -0
- package/.output/server/node_modules/@kubb/fabric-core/dist/parsers.js +17 -0
- package/.output/server/node_modules/@kubb/fabric-core/dist/plugins.js +375 -0
- package/.output/server/node_modules/@kubb/fabric-core/package.json +111 -0
- package/.output/server/node_modules/@kubb/oas/dist/chunk--u3MIqq1.js +8 -0
- package/.output/server/node_modules/@kubb/oas/dist/index.js +918 -0
- package/.output/server/node_modules/@kubb/oas/package.json +94 -0
- package/.output/server/node_modules/@kubb/plugin-client/dist/StaticClassClient-bCe7RG_w.js +636 -0
- package/.output/server/node_modules/@kubb/plugin-client/dist/chunk--u3MIqq1.js +8 -0
- package/.output/server/node_modules/@kubb/plugin-client/dist/components.js +2 -0
- package/.output/server/node_modules/@kubb/plugin-client/dist/generators-BffddRNu.js +723 -0
- package/.output/server/node_modules/@kubb/plugin-client/dist/index.js +124 -0
- package/.output/server/node_modules/@kubb/plugin-client/dist/templates/clients/axios.source.js +6 -0
- package/.output/server/node_modules/@kubb/plugin-client/dist/templates/clients/fetch.source.js +6 -0
- package/.output/server/node_modules/@kubb/plugin-client/dist/templates/config.source.js +6 -0
- package/.output/server/node_modules/@kubb/plugin-client/package.json +153 -0
- package/.output/server/node_modules/@kubb/plugin-cypress/dist/chunk--u3MIqq1.js +8 -0
- package/.output/server/node_modules/@kubb/plugin-cypress/dist/components-BK_6GU4v.js +257 -0
- package/.output/server/node_modules/@kubb/plugin-cypress/dist/generators-D5YFtyyC.js +71 -0
- package/.output/server/node_modules/@kubb/plugin-cypress/dist/index.js +79 -0
- package/.output/server/node_modules/@kubb/plugin-cypress/package.json +108 -0
- package/.output/server/node_modules/@kubb/plugin-faker/dist/chunk--u3MIqq1.js +8 -0
- package/.output/server/node_modules/@kubb/plugin-faker/dist/components-BkBIov4R.js +419 -0
- package/.output/server/node_modules/@kubb/plugin-faker/dist/fakerGenerator-BztogaeO.js +200 -0
- package/.output/server/node_modules/@kubb/plugin-faker/dist/index.js +141 -0
- package/.output/server/node_modules/@kubb/plugin-faker/package.json +103 -0
- package/.output/server/node_modules/@kubb/plugin-mcp/dist/Server-H3SwqhwF.js +178 -0
- package/.output/server/node_modules/@kubb/plugin-mcp/dist/chunk--u3MIqq1.js +8 -0
- package/.output/server/node_modules/@kubb/plugin-mcp/dist/generators-BqkMrcs9.js +274 -0
- package/.output/server/node_modules/@kubb/plugin-mcp/dist/index.js +122 -0
- package/.output/server/node_modules/@kubb/plugin-mcp/package.json +107 -0
- package/.output/server/node_modules/@kubb/plugin-msw/dist/chunk--u3MIqq1.js +8 -0
- package/.output/server/node_modules/@kubb/plugin-msw/dist/components-DgtTZkWX.js +277 -0
- package/.output/server/node_modules/@kubb/plugin-msw/dist/generators-C34kqa1L.js +161 -0
- package/.output/server/node_modules/@kubb/plugin-msw/dist/index.js +84 -0
- package/.output/server/node_modules/@kubb/plugin-msw/package.json +109 -0
- package/.output/server/node_modules/@kubb/plugin-oas/dist/SchemaMapper-CqMkO2T1.js +58 -0
- package/.output/server/node_modules/@kubb/plugin-oas/dist/chunk--u3MIqq1.js +8 -0
- package/.output/server/node_modules/@kubb/plugin-oas/dist/generators-D7C3CXsN.js +79 -0
- package/.output/server/node_modules/@kubb/plugin-oas/dist/generators.js +2 -0
- package/.output/server/node_modules/@kubb/plugin-oas/dist/getFooter-Pw3tLCiV.js +112 -0
- package/.output/server/node_modules/@kubb/plugin-oas/dist/hooks.js +200 -0
- package/.output/server/node_modules/@kubb/plugin-oas/dist/index.js +408 -0
- package/.output/server/node_modules/@kubb/plugin-oas/dist/requestBody-pRavthCw.js +1336 -0
- package/.output/server/node_modules/@kubb/plugin-oas/dist/utils.js +268 -0
- package/.output/server/node_modules/@kubb/plugin-oas/package.json +122 -0
- package/.output/server/node_modules/@kubb/plugin-react-query/dist/chunk--u3MIqq1.js +8 -0
- package/.output/server/node_modules/@kubb/plugin-react-query/dist/components-CpyHYGOw.js +1520 -0
- package/.output/server/node_modules/@kubb/plugin-react-query/dist/generators-CpiBv5eE.js +1427 -0
- package/.output/server/node_modules/@kubb/plugin-react-query/dist/index.js +166 -0
- package/.output/server/node_modules/@kubb/plugin-react-query/package.json +112 -0
- package/.output/server/node_modules/@kubb/plugin-redoc/dist/chunk--u3MIqq1.js +8 -0
- package/.output/server/node_modules/@kubb/plugin-redoc/dist/index.js +65 -0
- package/.output/server/node_modules/@kubb/plugin-redoc/package.json +85 -0
- package/.output/server/node_modules/@kubb/plugin-redoc/static/redoc.hbs +22 -0
- package/.output/server/node_modules/@kubb/plugin-solid-query/dist/chunk--u3MIqq1.js +8 -0
- package/.output/server/node_modules/@kubb/plugin-solid-query/dist/components-BhStIi1M.js +665 -0
- package/.output/server/node_modules/@kubb/plugin-solid-query/dist/generators-CQClzsST.js +415 -0
- package/.output/server/node_modules/@kubb/plugin-solid-query/dist/index.js +145 -0
- package/.output/server/node_modules/@kubb/plugin-solid-query/package.json +113 -0
- package/.output/server/node_modules/@kubb/plugin-svelte-query/dist/chunk--u3MIqq1.js +8 -0
- package/.output/server/node_modules/@kubb/plugin-svelte-query/dist/components-DntKBsnB.js +666 -0
- package/.output/server/node_modules/@kubb/plugin-svelte-query/dist/generators-BtTsGGrM.js +414 -0
- package/.output/server/node_modules/@kubb/plugin-svelte-query/dist/index.js +145 -0
- package/.output/server/node_modules/@kubb/plugin-svelte-query/package.json +113 -0
- package/.output/server/node_modules/@kubb/plugin-swr/dist/chunk--u3MIqq1.js +8 -0
- package/.output/server/node_modules/@kubb/plugin-swr/dist/components-DRDGvgXG.js +702 -0
- package/.output/server/node_modules/@kubb/plugin-swr/dist/generators-ClWZJ-YG.js +399 -0
- package/.output/server/node_modules/@kubb/plugin-swr/dist/index.js +144 -0
- package/.output/server/node_modules/@kubb/plugin-swr/package.json +115 -0
- package/.output/server/node_modules/@kubb/plugin-ts/dist/chunk--u3MIqq1.js +8 -0
- package/.output/server/node_modules/@kubb/plugin-ts/dist/components-C7fu-sK1.js +723 -0
- package/.output/server/node_modules/@kubb/plugin-ts/dist/index.js +2 -0
- package/.output/server/node_modules/@kubb/plugin-ts/dist/plugin-CYC-FGXe.js +479 -0
- package/.output/server/node_modules/@kubb/plugin-ts/package.json +105 -0
- package/.output/server/node_modules/@kubb/plugin-vue-query/dist/chunk--u3MIqq1.js +8 -0
- package/.output/server/node_modules/@kubb/plugin-vue-query/dist/components-_AMBl0g-.js +1029 -0
- package/.output/server/node_modules/@kubb/plugin-vue-query/dist/generators-Zb1s5Wmb.js +661 -0
- package/.output/server/node_modules/@kubb/plugin-vue-query/dist/index.js +157 -0
- package/.output/server/node_modules/@kubb/plugin-vue-query/package.json +114 -0
- package/.output/server/node_modules/@kubb/plugin-zod/dist/chunk--u3MIqq1.js +8 -0
- package/.output/server/node_modules/@kubb/plugin-zod/dist/components-eECfXVou.js +842 -0
- package/.output/server/node_modules/@kubb/plugin-zod/dist/generators-D1R6NNf2.js +290 -0
- package/.output/server/node_modules/@kubb/plugin-zod/dist/index.js +175 -0
- package/.output/server/node_modules/@kubb/plugin-zod/dist/templates/ToZod.source.js +6 -0
- package/.output/server/node_modules/@kubb/plugin-zod/package.json +112 -0
- package/.output/server/node_modules/@kubb/react-fabric/dist/chunk-BGCRLu6H.js +38 -0
- package/.output/server/node_modules/@kubb/react-fabric/dist/index.js +525 -0
- package/.output/server/node_modules/@kubb/react-fabric/dist/jsx-runtime-Bl0DfUmV.js +1448 -0
- package/.output/server/node_modules/@kubb/react-fabric/dist/jsx-runtime.js +12 -0
- package/.output/server/node_modules/@kubb/react-fabric/dist/parsers.js +2 -0
- package/.output/server/node_modules/@kubb/react-fabric/dist/plugins.js +4 -0
- package/.output/server/node_modules/@kubb/react-fabric/dist/reactPlugin-QQPrjNuQ.js +17813 -0
- package/.output/server/node_modules/@kubb/react-fabric/package.json +143 -0
- package/.output/server/node_modules/buffer-from/index.js +72 -0
- package/.output/server/node_modules/buffer-from/package.json +19 -0
- package/.output/server/node_modules/empathic/access.js +39 -0
- package/.output/server/node_modules/empathic/access.mjs +34 -0
- package/.output/server/node_modules/empathic/find.js +81 -0
- package/.output/server/node_modules/empathic/find.mjs +76 -0
- package/.output/server/node_modules/empathic/package.json +49 -0
- package/.output/server/node_modules/empathic/package.mjs +52 -0
- package/.output/server/node_modules/empathic/resolve.js +31 -0
- package/.output/server/node_modules/empathic/resolve.mjs +27 -0
- package/.output/server/node_modules/empathic/walk.js +22 -0
- package/.output/server/node_modules/empathic/walk.mjs +20 -0
- package/.output/server/node_modules/fast-string-truncated-width/dist/index.js +171 -0
- package/.output/server/node_modules/fast-string-truncated-width/dist/utils.js +15 -0
- package/.output/server/node_modules/fast-string-truncated-width/package.json +35 -0
- package/.output/server/node_modules/fast-string-width/dist/index.js +14 -0
- package/.output/server/node_modules/fast-string-width/package.json +34 -0
- package/.output/server/node_modules/fast-wrap-ansi/lib/main.js +216 -0
- package/.output/server/node_modules/fast-wrap-ansi/package.json +51 -0
- package/.output/server/node_modules/p-limit/index.js +127 -0
- package/.output/server/node_modules/p-limit/package.json +58 -0
- package/.output/server/node_modules/react-devtools-core/dist/backend.js +18302 -0
- package/.output/server/node_modules/react-devtools-core/package.json +38 -0
- package/.output/server/node_modules/sisteransi/package.json +34 -0
- package/.output/server/node_modules/sisteransi/src/index.js +58 -0
- package/.output/server/node_modules/source-map-support/package.json +31 -0
- package/.output/server/node_modules/source-map-support/source-map-support.js +625 -0
- package/.output/server/node_modules/typescript/lib/typescript.js +200276 -0
- package/.output/server/node_modules/typescript/package.json +120 -0
- package/.output/server/node_modules/yocto-queue/index.js +90 -0
- package/.output/server/node_modules/yocto-queue/package.json +48 -0
- package/.output/server/package.json +34 -2
- package/package.json +20 -20
- /package/.output/server/node_modules/{ws → .nitro/ws@8.18.0}/lib/buffer-util.js +0 -0
- /package/.output/server/node_modules/{ws → .nitro/ws@8.18.0}/lib/event-target.js +0 -0
- /package/.output/server/node_modules/{ws → .nitro/ws@8.18.0}/lib/extension.js +0 -0
- /package/.output/server/node_modules/{ws → .nitro/ws@8.18.0}/lib/limiter.js +0 -0
- /package/.output/server/node_modules/{ws → .nitro/ws@8.18.0}/lib/receiver.js +0 -0
- /package/.output/server/node_modules/{ws → .nitro/ws@8.18.0}/lib/subprotocol.js +0 -0
- /package/.output/server/node_modules/{ws → .nitro/ws@8.18.0}/lib/validation.js +0 -0
- /package/.output/server/node_modules/{ws → .nitro/ws@8.20.0}/lib/constants.js +0 -0
- /package/.output/server/node_modules/{ws → .nitro/ws@8.20.0}/lib/permessage-deflate.js +0 -0
- /package/.output/server/node_modules/{ws → .nitro/ws@8.20.0}/lib/sender.js +0 -0
- /package/.output/server/node_modules/{ws → .nitro/ws@8.20.0}/lib/stream.js +0 -0
- /package/.output/server/node_modules/{ws → .nitro/ws@8.20.0}/lib/websocket-server.js +0 -0
- /package/.output/server/node_modules/{ws → .nitro/ws@8.20.0}/lib/websocket.js +0 -0
- /package/.output/server/node_modules/{ws → .nitro/ws@8.20.0}/package.json +0 -0
- /package/.output/server/node_modules/{ws → .nitro/ws@8.20.0}/wrapper.mjs +0 -0
|
@@ -0,0 +1,1336 @@
|
|
|
1
|
+
import "./chunk--u3MIqq1.js";
|
|
2
|
+
import { i as pascalCase } from "./getFooter-Pw3tLCiV.js";
|
|
3
|
+
import { n as schemaKeywords, t as isKeyword } from "./SchemaMapper-CqMkO2T1.js";
|
|
4
|
+
import { KUBB_INLINE_REF_PREFIX, isDiscriminator, isNullable, isOpenApiV3_1Document, isReference } from "@kubb/oas";
|
|
5
|
+
import { isDeepEqual, isNumber, uniqueWith } from "remeda";
|
|
6
|
+
import { Fabric, createReactFabric } from "@kubb/react-fabric";
|
|
7
|
+
import { jsx } from "@kubb/react-fabric/jsx-runtime";
|
|
8
|
+
//#region ../../internals/utils/src/names.ts
|
|
9
|
+
/**
|
|
10
|
+
* Returns a unique name by appending an incrementing numeric suffix when the name has already been used.
|
|
11
|
+
* Mutates `data` in-place as a usage counter so subsequent calls remain consistent.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* const seen: Record<string, number> = {}
|
|
15
|
+
* getUniqueName('Foo', seen) // 'Foo'
|
|
16
|
+
* getUniqueName('Foo', seen) // 'Foo2'
|
|
17
|
+
* getUniqueName('Foo', seen) // 'Foo3'
|
|
18
|
+
*/
|
|
19
|
+
function getUniqueName(originalName, data) {
|
|
20
|
+
let used = data[originalName] || 0;
|
|
21
|
+
if (used) {
|
|
22
|
+
data[originalName] = ++used;
|
|
23
|
+
originalName += used;
|
|
24
|
+
}
|
|
25
|
+
data[originalName] = 1;
|
|
26
|
+
return originalName;
|
|
27
|
+
}
|
|
28
|
+
//#endregion
|
|
29
|
+
//#region ../../internals/utils/src/string.ts
|
|
30
|
+
/**
|
|
31
|
+
* Strips a single matching pair of `"..."`, `'...'`, or `` `...` `` from both ends of `text`.
|
|
32
|
+
* Returns the string unchanged when no balanced quote pair is found.
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* trimQuotes('"hello"') // 'hello'
|
|
36
|
+
* trimQuotes('hello') // 'hello'
|
|
37
|
+
*/
|
|
38
|
+
function trimQuotes(text) {
|
|
39
|
+
if (text.length >= 2) {
|
|
40
|
+
const first = text[0];
|
|
41
|
+
const last = text[text.length - 1];
|
|
42
|
+
if (first === "\"" && last === "\"" || first === "'" && last === "'" || first === "`" && last === "`") return text.slice(1, -1);
|
|
43
|
+
}
|
|
44
|
+
return text;
|
|
45
|
+
}
|
|
46
|
+
//#endregion
|
|
47
|
+
//#region ../../internals/utils/src/object.ts
|
|
48
|
+
/**
|
|
49
|
+
* Serializes a primitive value to a JSON string literal, stripping any surrounding quote characters first.
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* stringify('hello') // '"hello"'
|
|
53
|
+
* stringify('"hello"') // '"hello"'
|
|
54
|
+
*/
|
|
55
|
+
function stringify(value) {
|
|
56
|
+
if (value === void 0 || value === null) return "\"\"";
|
|
57
|
+
return JSON.stringify(trimQuotes(value.toString()));
|
|
58
|
+
}
|
|
59
|
+
//#endregion
|
|
60
|
+
//#region ../../node_modules/.pnpm/yocto-queue@1.2.2/node_modules/yocto-queue/index.js
|
|
61
|
+
var Node = class {
|
|
62
|
+
value;
|
|
63
|
+
next;
|
|
64
|
+
constructor(value) {
|
|
65
|
+
this.value = value;
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
var Queue = class {
|
|
69
|
+
#head;
|
|
70
|
+
#tail;
|
|
71
|
+
#size;
|
|
72
|
+
constructor() {
|
|
73
|
+
this.clear();
|
|
74
|
+
}
|
|
75
|
+
enqueue(value) {
|
|
76
|
+
const node = new Node(value);
|
|
77
|
+
if (this.#head) {
|
|
78
|
+
this.#tail.next = node;
|
|
79
|
+
this.#tail = node;
|
|
80
|
+
} else {
|
|
81
|
+
this.#head = node;
|
|
82
|
+
this.#tail = node;
|
|
83
|
+
}
|
|
84
|
+
this.#size++;
|
|
85
|
+
}
|
|
86
|
+
dequeue() {
|
|
87
|
+
const current = this.#head;
|
|
88
|
+
if (!current) return;
|
|
89
|
+
this.#head = this.#head.next;
|
|
90
|
+
this.#size--;
|
|
91
|
+
if (!this.#head) this.#tail = void 0;
|
|
92
|
+
return current.value;
|
|
93
|
+
}
|
|
94
|
+
peek() {
|
|
95
|
+
if (!this.#head) return;
|
|
96
|
+
return this.#head.value;
|
|
97
|
+
}
|
|
98
|
+
clear() {
|
|
99
|
+
this.#head = void 0;
|
|
100
|
+
this.#tail = void 0;
|
|
101
|
+
this.#size = 0;
|
|
102
|
+
}
|
|
103
|
+
get size() {
|
|
104
|
+
return this.#size;
|
|
105
|
+
}
|
|
106
|
+
*[Symbol.iterator]() {
|
|
107
|
+
let current = this.#head;
|
|
108
|
+
while (current) {
|
|
109
|
+
yield current.value;
|
|
110
|
+
current = current.next;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
*drain() {
|
|
114
|
+
while (this.#head) yield this.dequeue();
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
//#endregion
|
|
118
|
+
//#region ../../node_modules/.pnpm/p-limit@7.3.0/node_modules/p-limit/index.js
|
|
119
|
+
function pLimit(concurrency) {
|
|
120
|
+
let rejectOnClear = false;
|
|
121
|
+
if (typeof concurrency === "object") ({concurrency, rejectOnClear = false} = concurrency);
|
|
122
|
+
validateConcurrency(concurrency);
|
|
123
|
+
if (typeof rejectOnClear !== "boolean") throw new TypeError("Expected `rejectOnClear` to be a boolean");
|
|
124
|
+
const queue = new Queue();
|
|
125
|
+
let activeCount = 0;
|
|
126
|
+
const resumeNext = () => {
|
|
127
|
+
if (activeCount < concurrency && queue.size > 0) {
|
|
128
|
+
activeCount++;
|
|
129
|
+
queue.dequeue().run();
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
const next = () => {
|
|
133
|
+
activeCount--;
|
|
134
|
+
resumeNext();
|
|
135
|
+
};
|
|
136
|
+
const run = async (function_, resolve, arguments_) => {
|
|
137
|
+
const result = (async () => function_(...arguments_))();
|
|
138
|
+
resolve(result);
|
|
139
|
+
try {
|
|
140
|
+
await result;
|
|
141
|
+
} catch {}
|
|
142
|
+
next();
|
|
143
|
+
};
|
|
144
|
+
const enqueue = (function_, resolve, reject, arguments_) => {
|
|
145
|
+
const queueItem = { reject };
|
|
146
|
+
new Promise((internalResolve) => {
|
|
147
|
+
queueItem.run = internalResolve;
|
|
148
|
+
queue.enqueue(queueItem);
|
|
149
|
+
}).then(run.bind(void 0, function_, resolve, arguments_));
|
|
150
|
+
if (activeCount < concurrency) resumeNext();
|
|
151
|
+
};
|
|
152
|
+
const generator = (function_, ...arguments_) => new Promise((resolve, reject) => {
|
|
153
|
+
enqueue(function_, resolve, reject, arguments_);
|
|
154
|
+
});
|
|
155
|
+
Object.defineProperties(generator, {
|
|
156
|
+
activeCount: { get: () => activeCount },
|
|
157
|
+
pendingCount: { get: () => queue.size },
|
|
158
|
+
clearQueue: { value() {
|
|
159
|
+
if (!rejectOnClear) {
|
|
160
|
+
queue.clear();
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
const abortError = AbortSignal.abort().reason;
|
|
164
|
+
while (queue.size > 0) queue.dequeue().reject(abortError);
|
|
165
|
+
} },
|
|
166
|
+
concurrency: {
|
|
167
|
+
get: () => concurrency,
|
|
168
|
+
set(newConcurrency) {
|
|
169
|
+
validateConcurrency(newConcurrency);
|
|
170
|
+
concurrency = newConcurrency;
|
|
171
|
+
queueMicrotask(() => {
|
|
172
|
+
while (activeCount < concurrency && queue.size > 0) resumeNext();
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
},
|
|
176
|
+
map: { async value(iterable, function_) {
|
|
177
|
+
const promises = Array.from(iterable, (value, index) => this(function_, value, index));
|
|
178
|
+
return Promise.all(promises);
|
|
179
|
+
} }
|
|
180
|
+
});
|
|
181
|
+
return generator;
|
|
182
|
+
}
|
|
183
|
+
function validateConcurrency(concurrency) {
|
|
184
|
+
if (!((Number.isInteger(concurrency) || concurrency === Number.POSITIVE_INFINITY) && concurrency > 0)) throw new TypeError("Expected `concurrency` to be a number from 1 and up");
|
|
185
|
+
}
|
|
186
|
+
//#endregion
|
|
187
|
+
//#region src/utils/getSchemaFactory.ts
|
|
188
|
+
/**
|
|
189
|
+
* Creates a factory function that generates a versioned OpenAPI schema result.
|
|
190
|
+
*
|
|
191
|
+
* The returned function accepts an optional schema object and produces a {@link SchemaResult} containing the dereferenced schema and the OpenAPI version ('3.0' or '3.1').
|
|
192
|
+
*
|
|
193
|
+
* @returns A function that takes an optional schema and returns a versioned schema result.
|
|
194
|
+
*/
|
|
195
|
+
function getSchemaFactory(oas) {
|
|
196
|
+
return (schema) => {
|
|
197
|
+
const version = isOpenApiV3_1Document(oas.api) ? "3.1" : "3.0";
|
|
198
|
+
return {
|
|
199
|
+
schemaObject: oas.dereferenceWithRef(schema),
|
|
200
|
+
version
|
|
201
|
+
};
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
//#endregion
|
|
205
|
+
//#region src/utils.tsx
|
|
206
|
+
function isBuildOperationsV1Options(options) {
|
|
207
|
+
return (options.version ?? "1") === "1";
|
|
208
|
+
}
|
|
209
|
+
async function buildOperations(operationsOrNodes, options) {
|
|
210
|
+
const { config, fabric, plugin } = options;
|
|
211
|
+
if (!options.Component) return;
|
|
212
|
+
const fabricChild = createReactFabric();
|
|
213
|
+
if (isBuildOperationsV1Options(options)) {
|
|
214
|
+
const { generator, Component } = options;
|
|
215
|
+
const { pluginManager, oas, mode } = generator.context;
|
|
216
|
+
await fabricChild.render(/* @__PURE__ */ jsx(Fabric, {
|
|
217
|
+
meta: {
|
|
218
|
+
pluginManager,
|
|
219
|
+
plugin,
|
|
220
|
+
mode,
|
|
221
|
+
oas
|
|
222
|
+
},
|
|
223
|
+
children: /* @__PURE__ */ jsx(Component, {
|
|
224
|
+
config,
|
|
225
|
+
operations: operationsOrNodes,
|
|
226
|
+
generator,
|
|
227
|
+
plugin
|
|
228
|
+
})
|
|
229
|
+
}));
|
|
230
|
+
} else {
|
|
231
|
+
const { Component } = options;
|
|
232
|
+
await fabricChild.render(/* @__PURE__ */ jsx(Fabric, {
|
|
233
|
+
meta: { plugin },
|
|
234
|
+
children: /* @__PURE__ */ jsx(Component, {
|
|
235
|
+
config,
|
|
236
|
+
nodes: operationsOrNodes,
|
|
237
|
+
plugin
|
|
238
|
+
})
|
|
239
|
+
}));
|
|
240
|
+
}
|
|
241
|
+
await fabric.context.fileManager.upsert(...fabricChild.files);
|
|
242
|
+
fabricChild.unmount();
|
|
243
|
+
}
|
|
244
|
+
function isBuildOperationV1Options(options) {
|
|
245
|
+
return (options.version ?? "1") === "1";
|
|
246
|
+
}
|
|
247
|
+
async function buildOperation(operationOrNode, options) {
|
|
248
|
+
const { config, fabric, plugin } = options;
|
|
249
|
+
if (!options.Component) return;
|
|
250
|
+
const fabricChild = createReactFabric();
|
|
251
|
+
if (isBuildOperationV1Options(options)) {
|
|
252
|
+
const { generator, Component } = options;
|
|
253
|
+
const { pluginManager, oas, mode } = generator.context;
|
|
254
|
+
await fabricChild.render(/* @__PURE__ */ jsx(Fabric, {
|
|
255
|
+
meta: {
|
|
256
|
+
pluginManager,
|
|
257
|
+
plugin,
|
|
258
|
+
mode,
|
|
259
|
+
oas
|
|
260
|
+
},
|
|
261
|
+
children: /* @__PURE__ */ jsx(Component, {
|
|
262
|
+
config,
|
|
263
|
+
operation: operationOrNode,
|
|
264
|
+
plugin,
|
|
265
|
+
generator
|
|
266
|
+
})
|
|
267
|
+
}));
|
|
268
|
+
} else {
|
|
269
|
+
const { Component } = options;
|
|
270
|
+
await fabricChild.render(/* @__PURE__ */ jsx(Fabric, {
|
|
271
|
+
meta: { plugin },
|
|
272
|
+
children: /* @__PURE__ */ jsx(Component, {
|
|
273
|
+
config,
|
|
274
|
+
node: operationOrNode,
|
|
275
|
+
plugin
|
|
276
|
+
})
|
|
277
|
+
}));
|
|
278
|
+
}
|
|
279
|
+
await fabric.context.fileManager.upsert(...fabricChild.files);
|
|
280
|
+
fabricChild.unmount();
|
|
281
|
+
}
|
|
282
|
+
function isBuildSchemaV1Options(options) {
|
|
283
|
+
return (options.version ?? "1") === "1";
|
|
284
|
+
}
|
|
285
|
+
async function buildSchema(schema, options) {
|
|
286
|
+
const { config, fabric, plugin } = options;
|
|
287
|
+
if (!options.Component) return;
|
|
288
|
+
const fabricChild = createReactFabric();
|
|
289
|
+
if (isBuildSchemaV1Options(options)) {
|
|
290
|
+
const { generator, Component } = options;
|
|
291
|
+
const { pluginManager, oas, mode } = generator.context;
|
|
292
|
+
await fabricChild.render(/* @__PURE__ */ jsx(Fabric, {
|
|
293
|
+
meta: {
|
|
294
|
+
pluginManager,
|
|
295
|
+
plugin,
|
|
296
|
+
mode,
|
|
297
|
+
oas
|
|
298
|
+
},
|
|
299
|
+
children: /* @__PURE__ */ jsx(Component, {
|
|
300
|
+
config,
|
|
301
|
+
schema,
|
|
302
|
+
plugin,
|
|
303
|
+
generator
|
|
304
|
+
})
|
|
305
|
+
}));
|
|
306
|
+
} else {
|
|
307
|
+
const { Component } = options;
|
|
308
|
+
await fabricChild.render(/* @__PURE__ */ jsx(Fabric, {
|
|
309
|
+
meta: { plugin },
|
|
310
|
+
children: /* @__PURE__ */ jsx(Component, {
|
|
311
|
+
config,
|
|
312
|
+
node: schema,
|
|
313
|
+
plugin
|
|
314
|
+
})
|
|
315
|
+
}));
|
|
316
|
+
}
|
|
317
|
+
await fabric.context.fileManager.upsert(...fabricChild.files);
|
|
318
|
+
fabricChild.unmount();
|
|
319
|
+
}
|
|
320
|
+
//#endregion
|
|
321
|
+
//#region src/SchemaGenerator.ts
|
|
322
|
+
/** Max concurrent generator tasks (across generators). */
|
|
323
|
+
const GENERATOR_CONCURRENCY = 3;
|
|
324
|
+
/** Max concurrent schema parsing tasks (per generator). */
|
|
325
|
+
const SCHEMA_CONCURRENCY = 30;
|
|
326
|
+
var SchemaGenerator = class SchemaGenerator {
|
|
327
|
+
#options;
|
|
328
|
+
#context;
|
|
329
|
+
constructor(options, context) {
|
|
330
|
+
this.#options = options;
|
|
331
|
+
this.#context = context;
|
|
332
|
+
}
|
|
333
|
+
get options() {
|
|
334
|
+
return this.#options;
|
|
335
|
+
}
|
|
336
|
+
set options(options) {
|
|
337
|
+
this.#options = {
|
|
338
|
+
...this.#options,
|
|
339
|
+
...options
|
|
340
|
+
};
|
|
341
|
+
}
|
|
342
|
+
get context() {
|
|
343
|
+
return this.#context;
|
|
344
|
+
}
|
|
345
|
+
refs = {};
|
|
346
|
+
#schemaNameMapping = /* @__PURE__ */ new Map();
|
|
347
|
+
#nameMappingInitialized = false;
|
|
348
|
+
#parseCache = /* @__PURE__ */ new Map();
|
|
349
|
+
/**
|
|
350
|
+
* Ensure the name mapping is initialized (lazy initialization)
|
|
351
|
+
*/
|
|
352
|
+
#ensureNameMapping() {
|
|
353
|
+
if (this.#nameMappingInitialized) return;
|
|
354
|
+
const { oas, contentType, include } = this.context;
|
|
355
|
+
const { nameMapping } = oas.getSchemas({
|
|
356
|
+
contentType,
|
|
357
|
+
includes: include
|
|
358
|
+
});
|
|
359
|
+
this.#schemaNameMapping = nameMapping;
|
|
360
|
+
this.#nameMappingInitialized = true;
|
|
361
|
+
}
|
|
362
|
+
/**
|
|
363
|
+
* Creates a type node from a given schema.
|
|
364
|
+
* Delegates to getBaseTypeFromSchema internally and
|
|
365
|
+
* optionally adds a union with null.
|
|
366
|
+
*/
|
|
367
|
+
parse(props) {
|
|
368
|
+
const options = this.#getOptions(props.name);
|
|
369
|
+
let shouldCache = props.schema && typeof props.schema === "object" && !options.transformers?.schema;
|
|
370
|
+
let cacheKey = "";
|
|
371
|
+
if (shouldCache) try {
|
|
372
|
+
cacheKey = JSON.stringify({
|
|
373
|
+
schema: props.schema,
|
|
374
|
+
name: props.name,
|
|
375
|
+
parentName: props.parentName,
|
|
376
|
+
rootName: props.rootName
|
|
377
|
+
});
|
|
378
|
+
const cached = this.#parseCache.get(cacheKey);
|
|
379
|
+
if (cached) return cached;
|
|
380
|
+
} catch {
|
|
381
|
+
shouldCache = false;
|
|
382
|
+
}
|
|
383
|
+
const defaultSchemas = this.#parseSchemaObject(props);
|
|
384
|
+
const result = uniqueWith(options.transformers?.schema?.(props, defaultSchemas) || defaultSchemas || [], isDeepEqual);
|
|
385
|
+
if (shouldCache && cacheKey) this.#parseCache.set(cacheKey, result);
|
|
386
|
+
return result;
|
|
387
|
+
}
|
|
388
|
+
static deepSearch(tree, keyword) {
|
|
389
|
+
const foundItems = [];
|
|
390
|
+
tree?.forEach((schema) => {
|
|
391
|
+
if (schema.keyword === keyword) foundItems.push(schema);
|
|
392
|
+
if (isKeyword(schema, schemaKeywords.object)) {
|
|
393
|
+
Object.values(schema.args?.properties || {}).forEach((entrySchema) => {
|
|
394
|
+
foundItems.push(...SchemaGenerator.deepSearch(entrySchema, keyword));
|
|
395
|
+
});
|
|
396
|
+
Object.values(schema.args?.additionalProperties || {}).forEach((entrySchema) => {
|
|
397
|
+
foundItems.push(...SchemaGenerator.deepSearch([entrySchema], keyword));
|
|
398
|
+
});
|
|
399
|
+
if (schema.args?.patternProperties) Object.values(schema.args.patternProperties).forEach((entrySchemas) => {
|
|
400
|
+
entrySchemas.forEach((entrySchema) => {
|
|
401
|
+
foundItems.push(...SchemaGenerator.deepSearch([entrySchema], keyword));
|
|
402
|
+
});
|
|
403
|
+
});
|
|
404
|
+
}
|
|
405
|
+
if (isKeyword(schema, schemaKeywords.array)) schema.args.items.forEach((entrySchema) => {
|
|
406
|
+
foundItems.push(...SchemaGenerator.deepSearch([entrySchema], keyword));
|
|
407
|
+
});
|
|
408
|
+
if (isKeyword(schema, schemaKeywords.and)) schema.args.forEach((entrySchema) => {
|
|
409
|
+
foundItems.push(...SchemaGenerator.deepSearch([entrySchema], keyword));
|
|
410
|
+
});
|
|
411
|
+
if (isKeyword(schema, schemaKeywords.tuple)) schema.args.items.forEach((entrySchema) => {
|
|
412
|
+
foundItems.push(...SchemaGenerator.deepSearch([entrySchema], keyword));
|
|
413
|
+
});
|
|
414
|
+
if (isKeyword(schema, schemaKeywords.union)) schema.args.forEach((entrySchema) => {
|
|
415
|
+
foundItems.push(...SchemaGenerator.deepSearch([entrySchema], keyword));
|
|
416
|
+
});
|
|
417
|
+
});
|
|
418
|
+
return foundItems;
|
|
419
|
+
}
|
|
420
|
+
static find(tree, keyword) {
|
|
421
|
+
let foundItem;
|
|
422
|
+
tree?.forEach((schema) => {
|
|
423
|
+
if (!foundItem && schema.keyword === keyword) foundItem = schema;
|
|
424
|
+
if (isKeyword(schema, schemaKeywords.array)) schema.args.items.forEach((entrySchema) => {
|
|
425
|
+
if (!foundItem) foundItem = SchemaGenerator.find([entrySchema], keyword);
|
|
426
|
+
});
|
|
427
|
+
if (isKeyword(schema, schemaKeywords.and)) schema.args.forEach((entrySchema) => {
|
|
428
|
+
if (!foundItem) foundItem = SchemaGenerator.find([entrySchema], keyword);
|
|
429
|
+
});
|
|
430
|
+
if (isKeyword(schema, schemaKeywords.tuple)) schema.args.items.forEach((entrySchema) => {
|
|
431
|
+
if (!foundItem) foundItem = SchemaGenerator.find([entrySchema], keyword);
|
|
432
|
+
});
|
|
433
|
+
if (isKeyword(schema, schemaKeywords.union)) schema.args.forEach((entrySchema) => {
|
|
434
|
+
if (!foundItem) foundItem = SchemaGenerator.find([entrySchema], keyword);
|
|
435
|
+
});
|
|
436
|
+
});
|
|
437
|
+
return foundItem;
|
|
438
|
+
}
|
|
439
|
+
static combineObjects(tree) {
|
|
440
|
+
if (!tree) return [];
|
|
441
|
+
return tree.map((schema) => {
|
|
442
|
+
if (!isKeyword(schema, schemaKeywords.and)) return schema;
|
|
443
|
+
let mergedProperties = null;
|
|
444
|
+
let mergedAdditionalProps = [];
|
|
445
|
+
const newArgs = [];
|
|
446
|
+
for (const subSchema of schema.args) if (isKeyword(subSchema, schemaKeywords.object)) {
|
|
447
|
+
const { properties = {}, additionalProperties = [] } = subSchema.args ?? {};
|
|
448
|
+
if (!mergedProperties) mergedProperties = {};
|
|
449
|
+
for (const [key, value] of Object.entries(properties)) mergedProperties[key] = value;
|
|
450
|
+
if (additionalProperties.length > 0) mergedAdditionalProps = additionalProperties;
|
|
451
|
+
} else newArgs.push(subSchema);
|
|
452
|
+
if (mergedProperties) newArgs.push({
|
|
453
|
+
keyword: schemaKeywords.object,
|
|
454
|
+
args: {
|
|
455
|
+
properties: mergedProperties,
|
|
456
|
+
additionalProperties: mergedAdditionalProps
|
|
457
|
+
}
|
|
458
|
+
});
|
|
459
|
+
return {
|
|
460
|
+
keyword: schemaKeywords.and,
|
|
461
|
+
args: newArgs
|
|
462
|
+
};
|
|
463
|
+
});
|
|
464
|
+
}
|
|
465
|
+
#getOptions(name) {
|
|
466
|
+
const { override = [] } = this.context;
|
|
467
|
+
return {
|
|
468
|
+
...this.options,
|
|
469
|
+
...override.find(({ pattern, type }) => {
|
|
470
|
+
if (name && type === "schemaName") return !!name.match(pattern);
|
|
471
|
+
return false;
|
|
472
|
+
})?.options || {}
|
|
473
|
+
};
|
|
474
|
+
}
|
|
475
|
+
#getUnknownType(name) {
|
|
476
|
+
const options = this.#getOptions(name);
|
|
477
|
+
if (options.unknownType === "any") return schemaKeywords.any;
|
|
478
|
+
if (options.unknownType === "void") return schemaKeywords.void;
|
|
479
|
+
return schemaKeywords.unknown;
|
|
480
|
+
}
|
|
481
|
+
#getEmptyType(name) {
|
|
482
|
+
const options = this.#getOptions(name);
|
|
483
|
+
if (options.emptySchemaType === "any") return schemaKeywords.any;
|
|
484
|
+
if (options.emptySchemaType === "void") return schemaKeywords.void;
|
|
485
|
+
return schemaKeywords.unknown;
|
|
486
|
+
}
|
|
487
|
+
/**
|
|
488
|
+
* Recursively creates a type literal with the given props.
|
|
489
|
+
*/
|
|
490
|
+
#parseProperties(name, schemaObject, rootName) {
|
|
491
|
+
const properties = schemaObject?.properties || {};
|
|
492
|
+
const additionalProperties = schemaObject?.additionalProperties;
|
|
493
|
+
const required = schemaObject?.required;
|
|
494
|
+
const patternProperties = schemaObject && "patternProperties" in schemaObject ? schemaObject.patternProperties : void 0;
|
|
495
|
+
const propertiesSchemas = Object.keys(properties).map((propertyName) => {
|
|
496
|
+
const validationFunctions = [];
|
|
497
|
+
const propertySchema = properties[propertyName];
|
|
498
|
+
const isRequired = Array.isArray(required) ? required?.includes(propertyName) : !!required;
|
|
499
|
+
const nullable = isNullable(propertySchema);
|
|
500
|
+
validationFunctions.push(...this.parse({
|
|
501
|
+
schema: propertySchema,
|
|
502
|
+
name: propertyName,
|
|
503
|
+
parentName: name,
|
|
504
|
+
rootName: rootName || name
|
|
505
|
+
}));
|
|
506
|
+
validationFunctions.push({
|
|
507
|
+
keyword: schemaKeywords.name,
|
|
508
|
+
args: propertyName
|
|
509
|
+
});
|
|
510
|
+
if (!isRequired && nullable) validationFunctions.push({ keyword: schemaKeywords.nullish });
|
|
511
|
+
else if (!isRequired) validationFunctions.push({ keyword: schemaKeywords.optional });
|
|
512
|
+
return { [propertyName]: validationFunctions };
|
|
513
|
+
}).reduce((acc, curr) => ({
|
|
514
|
+
...acc,
|
|
515
|
+
...curr
|
|
516
|
+
}), {});
|
|
517
|
+
let additionalPropertiesSchemas = [];
|
|
518
|
+
if (additionalProperties) additionalPropertiesSchemas = additionalProperties === true || !Object.keys(additionalProperties).length ? [{ keyword: this.#getUnknownType(name) }] : this.parse({
|
|
519
|
+
schema: additionalProperties,
|
|
520
|
+
name: null,
|
|
521
|
+
parentName: name,
|
|
522
|
+
rootName: rootName || name
|
|
523
|
+
});
|
|
524
|
+
let patternPropertiesSchemas = {};
|
|
525
|
+
if (patternProperties && typeof patternProperties === "object") patternPropertiesSchemas = Object.entries(patternProperties).reduce((acc, [pattern, patternSchema]) => {
|
|
526
|
+
const schemas = patternSchema === true || !Object.keys(patternSchema).length ? [{ keyword: this.#getUnknownType(name) }] : this.parse({
|
|
527
|
+
schema: patternSchema,
|
|
528
|
+
name: null,
|
|
529
|
+
parentName: name,
|
|
530
|
+
rootName: rootName || name
|
|
531
|
+
});
|
|
532
|
+
return {
|
|
533
|
+
...acc,
|
|
534
|
+
[pattern]: schemas
|
|
535
|
+
};
|
|
536
|
+
}, {});
|
|
537
|
+
const args = {
|
|
538
|
+
properties: propertiesSchemas,
|
|
539
|
+
additionalProperties: additionalPropertiesSchemas
|
|
540
|
+
};
|
|
541
|
+
if (Object.keys(patternPropertiesSchemas).length > 0) args["patternProperties"] = patternPropertiesSchemas;
|
|
542
|
+
return [{
|
|
543
|
+
keyword: schemaKeywords.object,
|
|
544
|
+
args
|
|
545
|
+
}];
|
|
546
|
+
}
|
|
547
|
+
/**
|
|
548
|
+
* Create a type alias for the schema referenced by the given ReferenceObject
|
|
549
|
+
*/
|
|
550
|
+
#getRefAlias(schemaObject, name) {
|
|
551
|
+
const { $ref } = schemaObject;
|
|
552
|
+
const ref = this.refs[$ref];
|
|
553
|
+
if (ref) {
|
|
554
|
+
const dereferencedSchema = this.context.oas.dereferenceWithRef(schemaObject);
|
|
555
|
+
if (dereferencedSchema && isDiscriminator(dereferencedSchema)) {
|
|
556
|
+
const [key] = Object.entries(dereferencedSchema.discriminator.mapping || {}).find(([_key, value]) => value.replace(/.+\//, "") === name) || [];
|
|
557
|
+
if (key) return [{
|
|
558
|
+
keyword: schemaKeywords.and,
|
|
559
|
+
args: [{
|
|
560
|
+
keyword: schemaKeywords.ref,
|
|
561
|
+
args: {
|
|
562
|
+
name: ref.propertyName,
|
|
563
|
+
$ref,
|
|
564
|
+
path: ref.path,
|
|
565
|
+
isImportable: !!this.context.oas.get($ref)
|
|
566
|
+
}
|
|
567
|
+
}, {
|
|
568
|
+
keyword: schemaKeywords.object,
|
|
569
|
+
args: { properties: { [dereferencedSchema.discriminator.propertyName]: [{
|
|
570
|
+
keyword: schemaKeywords.const,
|
|
571
|
+
args: {
|
|
572
|
+
name: key,
|
|
573
|
+
format: "string",
|
|
574
|
+
value: key
|
|
575
|
+
}
|
|
576
|
+
}] } }
|
|
577
|
+
}]
|
|
578
|
+
}];
|
|
579
|
+
}
|
|
580
|
+
return [{
|
|
581
|
+
keyword: schemaKeywords.ref,
|
|
582
|
+
args: {
|
|
583
|
+
name: ref.propertyName,
|
|
584
|
+
$ref,
|
|
585
|
+
path: ref.path,
|
|
586
|
+
isImportable: !!this.context.oas.get($ref)
|
|
587
|
+
}
|
|
588
|
+
}];
|
|
589
|
+
}
|
|
590
|
+
if ($ref.startsWith("#") && !$ref.startsWith("#/components/")) try {
|
|
591
|
+
const inlineSchema = this.context.oas.get($ref);
|
|
592
|
+
if (inlineSchema && !isReference(inlineSchema)) return this.parse({
|
|
593
|
+
schema: inlineSchema,
|
|
594
|
+
name,
|
|
595
|
+
parentName: null,
|
|
596
|
+
rootName: null
|
|
597
|
+
});
|
|
598
|
+
} catch {}
|
|
599
|
+
this.#ensureNameMapping();
|
|
600
|
+
const originalName = $ref.replace(/.+\//, "");
|
|
601
|
+
const resolvedName = this.#schemaNameMapping.get($ref) || originalName;
|
|
602
|
+
const propertyName = this.context.pluginManager.resolveName({
|
|
603
|
+
name: resolvedName,
|
|
604
|
+
pluginKey: this.context.plugin.key,
|
|
605
|
+
type: "function"
|
|
606
|
+
});
|
|
607
|
+
const fileName = this.context.pluginManager.resolveName({
|
|
608
|
+
name: resolvedName,
|
|
609
|
+
pluginKey: this.context.plugin.key,
|
|
610
|
+
type: "file"
|
|
611
|
+
});
|
|
612
|
+
const file = this.context.pluginManager.getFile({
|
|
613
|
+
name: fileName,
|
|
614
|
+
pluginKey: this.context.plugin.key,
|
|
615
|
+
extname: ".ts"
|
|
616
|
+
});
|
|
617
|
+
this.refs[$ref] = {
|
|
618
|
+
propertyName,
|
|
619
|
+
originalName: resolvedName,
|
|
620
|
+
path: file.path
|
|
621
|
+
};
|
|
622
|
+
return this.#getRefAlias(schemaObject, name);
|
|
623
|
+
}
|
|
624
|
+
#getParsedSchemaObject(schema) {
|
|
625
|
+
return getSchemaFactory(this.context.oas)(schema);
|
|
626
|
+
}
|
|
627
|
+
#addDiscriminatorToSchema({ schema, schemaObject, discriminator }) {
|
|
628
|
+
if (!isKeyword(schema, schemaKeywords.union)) return schema;
|
|
629
|
+
if (discriminator.propertyName.startsWith("x-")) return schema;
|
|
630
|
+
const objectPropertySchema = SchemaGenerator.find(this.parse({
|
|
631
|
+
schema: schemaObject,
|
|
632
|
+
name: null,
|
|
633
|
+
parentName: null,
|
|
634
|
+
rootName: null
|
|
635
|
+
}), schemaKeywords.object);
|
|
636
|
+
return {
|
|
637
|
+
...schema,
|
|
638
|
+
args: Object.entries(discriminator.mapping || {}).map(([key, value]) => {
|
|
639
|
+
let arg;
|
|
640
|
+
if (value.startsWith(KUBB_INLINE_REF_PREFIX)) {
|
|
641
|
+
const index = Number.parseInt(value.replace(KUBB_INLINE_REF_PREFIX, ""), 10);
|
|
642
|
+
if (!Number.isNaN(index) && index >= 0 && index < schema.args.length) arg = schema.args[index];
|
|
643
|
+
} else arg = schema.args.find((item) => isKeyword(item, schemaKeywords.ref) && item.args.$ref === value);
|
|
644
|
+
if (!arg) return;
|
|
645
|
+
return {
|
|
646
|
+
keyword: schemaKeywords.and,
|
|
647
|
+
args: [arg, {
|
|
648
|
+
keyword: schemaKeywords.object,
|
|
649
|
+
args: { properties: {
|
|
650
|
+
...objectPropertySchema?.args?.properties || {},
|
|
651
|
+
[discriminator.propertyName]: [{
|
|
652
|
+
keyword: schemaKeywords.const,
|
|
653
|
+
args: {
|
|
654
|
+
name: key,
|
|
655
|
+
format: "string",
|
|
656
|
+
value: key
|
|
657
|
+
}
|
|
658
|
+
}, ...objectPropertySchema?.args?.properties[discriminator.propertyName] || []].filter((item) => !isKeyword(item, schemaKeywords.enum))
|
|
659
|
+
} }
|
|
660
|
+
}]
|
|
661
|
+
};
|
|
662
|
+
}).filter(Boolean)
|
|
663
|
+
};
|
|
664
|
+
}
|
|
665
|
+
/**
|
|
666
|
+
* Checks if an allOf item reference would create a circular reference.
|
|
667
|
+
* This happens when a child schema extends a discriminator parent via allOf,
|
|
668
|
+
* and the parent has a oneOf/anyOf that references or maps to the child.
|
|
669
|
+
*
|
|
670
|
+
* Without oneOf/anyOf, the discriminator is just for documentation/validation
|
|
671
|
+
* purposes and doesn't create a TypeScript union type that would be circular.
|
|
672
|
+
*/
|
|
673
|
+
#wouldCreateCircularReference(item, childSchemaName) {
|
|
674
|
+
if (!isReference(item) || !childSchemaName) return false;
|
|
675
|
+
const dereferencedSchema = this.context.oas.dereferenceWithRef(item);
|
|
676
|
+
if (dereferencedSchema && isDiscriminator(dereferencedSchema)) {
|
|
677
|
+
const parentOneOf = dereferencedSchema.oneOf || dereferencedSchema.anyOf;
|
|
678
|
+
if (!parentOneOf) return false;
|
|
679
|
+
const childRef = `#/components/schemas/${childSchemaName}`;
|
|
680
|
+
if (parentOneOf.some((oneOfItem) => {
|
|
681
|
+
return isReference(oneOfItem) && oneOfItem.$ref === childRef;
|
|
682
|
+
})) return true;
|
|
683
|
+
const mapping = dereferencedSchema.discriminator.mapping || {};
|
|
684
|
+
if (Object.values(mapping).some((value) => value === childRef)) return true;
|
|
685
|
+
}
|
|
686
|
+
return false;
|
|
687
|
+
}
|
|
688
|
+
/**
|
|
689
|
+
* This is the very core of the OpenAPI to TS conversion - it takes a
|
|
690
|
+
* schema and returns the appropriate type.
|
|
691
|
+
*/
|
|
692
|
+
#parseSchemaObject({ schema: _schemaObject, name, parentName, rootName }) {
|
|
693
|
+
const normalizedSchema = this.context.oas.flattenSchema(_schemaObject);
|
|
694
|
+
const { schemaObject, version } = this.#getParsedSchemaObject(normalizedSchema);
|
|
695
|
+
const options = this.#getOptions(name);
|
|
696
|
+
const emptyType = this.#getEmptyType(name);
|
|
697
|
+
if (!schemaObject) return [{ keyword: emptyType }];
|
|
698
|
+
const baseItems = [{
|
|
699
|
+
keyword: schemaKeywords.schema,
|
|
700
|
+
args: {
|
|
701
|
+
type: schemaObject.type,
|
|
702
|
+
format: schemaObject.format
|
|
703
|
+
}
|
|
704
|
+
}];
|
|
705
|
+
const min = schemaObject.minimum ?? schemaObject.minLength ?? schemaObject.minItems ?? void 0;
|
|
706
|
+
const max = schemaObject.maximum ?? schemaObject.maxLength ?? schemaObject.maxItems ?? void 0;
|
|
707
|
+
const exclusiveMinimum = schemaObject.exclusiveMinimum;
|
|
708
|
+
const exclusiveMaximum = schemaObject.exclusiveMaximum;
|
|
709
|
+
const nullable = isNullable(schemaObject);
|
|
710
|
+
const defaultNullAndNullable = schemaObject.default === null && nullable;
|
|
711
|
+
if (schemaObject.default !== void 0 && !defaultNullAndNullable && !Array.isArray(schemaObject.default)) if (typeof schemaObject.default === "string") baseItems.push({
|
|
712
|
+
keyword: schemaKeywords.default,
|
|
713
|
+
args: stringify(schemaObject.default)
|
|
714
|
+
});
|
|
715
|
+
else if (typeof schemaObject.default === "boolean") baseItems.push({
|
|
716
|
+
keyword: schemaKeywords.default,
|
|
717
|
+
args: schemaObject.default ?? false
|
|
718
|
+
});
|
|
719
|
+
else baseItems.push({
|
|
720
|
+
keyword: schemaKeywords.default,
|
|
721
|
+
args: schemaObject.default
|
|
722
|
+
});
|
|
723
|
+
if (schemaObject.deprecated) baseItems.push({ keyword: schemaKeywords.deprecated });
|
|
724
|
+
if (schemaObject.description) baseItems.push({
|
|
725
|
+
keyword: schemaKeywords.describe,
|
|
726
|
+
args: schemaObject.description
|
|
727
|
+
});
|
|
728
|
+
if (max !== void 0) if (exclusiveMaximum) baseItems.unshift({
|
|
729
|
+
keyword: schemaKeywords.exclusiveMaximum,
|
|
730
|
+
args: max
|
|
731
|
+
});
|
|
732
|
+
else baseItems.unshift({
|
|
733
|
+
keyword: schemaKeywords.max,
|
|
734
|
+
args: max
|
|
735
|
+
});
|
|
736
|
+
if (min !== void 0) if (exclusiveMinimum) baseItems.unshift({
|
|
737
|
+
keyword: schemaKeywords.exclusiveMinimum,
|
|
738
|
+
args: min
|
|
739
|
+
});
|
|
740
|
+
else baseItems.unshift({
|
|
741
|
+
keyword: schemaKeywords.min,
|
|
742
|
+
args: min
|
|
743
|
+
});
|
|
744
|
+
if (typeof exclusiveMaximum === "number") baseItems.unshift({
|
|
745
|
+
keyword: schemaKeywords.exclusiveMaximum,
|
|
746
|
+
args: exclusiveMaximum
|
|
747
|
+
});
|
|
748
|
+
if (typeof exclusiveMinimum === "number") baseItems.unshift({
|
|
749
|
+
keyword: schemaKeywords.exclusiveMinimum,
|
|
750
|
+
args: exclusiveMinimum
|
|
751
|
+
});
|
|
752
|
+
if (nullable) baseItems.push({ keyword: schemaKeywords.nullable });
|
|
753
|
+
if (schemaObject.type && Array.isArray(schemaObject.type)) {
|
|
754
|
+
const items = schemaObject.type.filter((value) => value !== "null");
|
|
755
|
+
if (items.length > 1) return [...[{
|
|
756
|
+
keyword: schemaKeywords.union,
|
|
757
|
+
args: items.map((item) => this.parse({
|
|
758
|
+
schema: {
|
|
759
|
+
...schemaObject,
|
|
760
|
+
type: item
|
|
761
|
+
},
|
|
762
|
+
name,
|
|
763
|
+
parentName,
|
|
764
|
+
rootName
|
|
765
|
+
})[0]).filter((x) => Boolean(x)).map((item) => isKeyword(item, schemaKeywords.object) ? {
|
|
766
|
+
...item,
|
|
767
|
+
args: {
|
|
768
|
+
...item.args,
|
|
769
|
+
strict: true
|
|
770
|
+
}
|
|
771
|
+
} : item)
|
|
772
|
+
}], ...baseItems].filter(Boolean);
|
|
773
|
+
}
|
|
774
|
+
if (schemaObject.readOnly) baseItems.push({ keyword: schemaKeywords.readOnly });
|
|
775
|
+
if (schemaObject.writeOnly) baseItems.push({ keyword: schemaKeywords.writeOnly });
|
|
776
|
+
if (isReference(schemaObject)) return [
|
|
777
|
+
...this.#getRefAlias(schemaObject, name),
|
|
778
|
+
...baseItems.filter((item) => item.keyword === schemaKeywords.default),
|
|
779
|
+
schemaObject.description && {
|
|
780
|
+
keyword: schemaKeywords.describe,
|
|
781
|
+
args: schemaObject.description
|
|
782
|
+
},
|
|
783
|
+
schemaObject.pattern && schemaObject.type === "string" && {
|
|
784
|
+
keyword: schemaKeywords.matches,
|
|
785
|
+
args: schemaObject.pattern
|
|
786
|
+
},
|
|
787
|
+
nullable && { keyword: schemaKeywords.nullable },
|
|
788
|
+
schemaObject.readOnly && { keyword: schemaKeywords.readOnly },
|
|
789
|
+
schemaObject.writeOnly && { keyword: schemaKeywords.writeOnly },
|
|
790
|
+
{
|
|
791
|
+
keyword: schemaKeywords.schema,
|
|
792
|
+
args: {
|
|
793
|
+
type: schemaObject.type,
|
|
794
|
+
format: schemaObject.format
|
|
795
|
+
}
|
|
796
|
+
}
|
|
797
|
+
].filter((x) => Boolean(x));
|
|
798
|
+
if (schemaObject.oneOf || schemaObject.anyOf) {
|
|
799
|
+
const schemaWithoutOneOf = {
|
|
800
|
+
...schemaObject,
|
|
801
|
+
oneOf: void 0,
|
|
802
|
+
anyOf: void 0
|
|
803
|
+
};
|
|
804
|
+
const discriminator = this.context.oas.getDiscriminator(schemaObject);
|
|
805
|
+
const union = {
|
|
806
|
+
keyword: schemaKeywords.union,
|
|
807
|
+
args: (schemaObject.oneOf || schemaObject.anyOf).map((item) => {
|
|
808
|
+
return item && this.parse({
|
|
809
|
+
schema: item,
|
|
810
|
+
name,
|
|
811
|
+
parentName,
|
|
812
|
+
rootName
|
|
813
|
+
})[0];
|
|
814
|
+
}).filter((x) => Boolean(x))
|
|
815
|
+
};
|
|
816
|
+
if (discriminator) {
|
|
817
|
+
if (this.context && this.context.oas.options.discriminator !== "inherit") return [this.#addDiscriminatorToSchema({
|
|
818
|
+
schemaObject: schemaWithoutOneOf,
|
|
819
|
+
schema: union,
|
|
820
|
+
discriminator
|
|
821
|
+
}), ...baseItems];
|
|
822
|
+
}
|
|
823
|
+
if (schemaWithoutOneOf.properties) {
|
|
824
|
+
const propertySchemas = this.parse({
|
|
825
|
+
schema: schemaWithoutOneOf,
|
|
826
|
+
name,
|
|
827
|
+
parentName,
|
|
828
|
+
rootName
|
|
829
|
+
});
|
|
830
|
+
union.args = [...union.args.map((arg) => {
|
|
831
|
+
return {
|
|
832
|
+
keyword: schemaKeywords.and,
|
|
833
|
+
args: [arg, ...propertySchemas]
|
|
834
|
+
};
|
|
835
|
+
})];
|
|
836
|
+
return [union, ...baseItems];
|
|
837
|
+
}
|
|
838
|
+
return [union, ...baseItems];
|
|
839
|
+
}
|
|
840
|
+
if (schemaObject.allOf) {
|
|
841
|
+
const schemaWithoutAllOf = {
|
|
842
|
+
...schemaObject,
|
|
843
|
+
allOf: void 0
|
|
844
|
+
};
|
|
845
|
+
const and = {
|
|
846
|
+
keyword: schemaKeywords.and,
|
|
847
|
+
args: schemaObject.allOf.flatMap((item) => {
|
|
848
|
+
if (this.#wouldCreateCircularReference(item, name)) return [];
|
|
849
|
+
return item ? this.parse({
|
|
850
|
+
schema: item,
|
|
851
|
+
name,
|
|
852
|
+
parentName,
|
|
853
|
+
rootName
|
|
854
|
+
}) : [];
|
|
855
|
+
}).filter(Boolean)
|
|
856
|
+
};
|
|
857
|
+
if (schemaWithoutAllOf.required?.length) {
|
|
858
|
+
const allOfItems = schemaObject.allOf;
|
|
859
|
+
const resolvedSchemas = [];
|
|
860
|
+
for (const item of allOfItems) {
|
|
861
|
+
const resolved = isReference(item) ? this.context.oas.get(item.$ref) : item;
|
|
862
|
+
if (resolved) resolvedSchemas.push(resolved);
|
|
863
|
+
}
|
|
864
|
+
const existingKeys = schemaWithoutAllOf.properties ? new Set(Object.keys(schemaWithoutAllOf.properties)) : null;
|
|
865
|
+
const parsedItems = [];
|
|
866
|
+
for (const key of schemaWithoutAllOf.required) {
|
|
867
|
+
if (existingKeys?.has(key)) continue;
|
|
868
|
+
for (const schema of resolvedSchemas) if (schema.properties?.[key]) {
|
|
869
|
+
parsedItems.push({
|
|
870
|
+
properties: { [key]: schema.properties[key] },
|
|
871
|
+
required: [key]
|
|
872
|
+
});
|
|
873
|
+
break;
|
|
874
|
+
}
|
|
875
|
+
}
|
|
876
|
+
for (const item of parsedItems) {
|
|
877
|
+
const parsed = this.parse({
|
|
878
|
+
schema: item,
|
|
879
|
+
name,
|
|
880
|
+
parentName,
|
|
881
|
+
rootName
|
|
882
|
+
});
|
|
883
|
+
if (Array.isArray(parsed)) and.args = and.args ? and.args.concat(parsed) : parsed;
|
|
884
|
+
}
|
|
885
|
+
}
|
|
886
|
+
if (schemaWithoutAllOf.properties) and.args = [...and.args || [], ...this.parse({
|
|
887
|
+
schema: schemaWithoutAllOf,
|
|
888
|
+
name,
|
|
889
|
+
parentName,
|
|
890
|
+
rootName
|
|
891
|
+
})];
|
|
892
|
+
return SchemaGenerator.combineObjects([and, ...baseItems]);
|
|
893
|
+
}
|
|
894
|
+
if (schemaObject.enum) {
|
|
895
|
+
if (schemaObject.type === "array") {
|
|
896
|
+
const normalizedItems = {
|
|
897
|
+
...typeof schemaObject.items === "object" && !Array.isArray(schemaObject.items) ? schemaObject.items : {},
|
|
898
|
+
enum: schemaObject.enum
|
|
899
|
+
};
|
|
900
|
+
const { enum: _, ...schemaWithoutEnum } = schemaObject;
|
|
901
|
+
const normalizedSchema = {
|
|
902
|
+
...schemaWithoutEnum,
|
|
903
|
+
items: normalizedItems
|
|
904
|
+
};
|
|
905
|
+
return this.parse({
|
|
906
|
+
schema: normalizedSchema,
|
|
907
|
+
name,
|
|
908
|
+
parentName,
|
|
909
|
+
rootName
|
|
910
|
+
});
|
|
911
|
+
}
|
|
912
|
+
const useCollisionDetection = this.context.oas.options.collisionDetection ?? false;
|
|
913
|
+
const enumNameParts = useCollisionDetection && rootName && rootName !== parentName ? [
|
|
914
|
+
rootName,
|
|
915
|
+
parentName,
|
|
916
|
+
name,
|
|
917
|
+
options.enumSuffix
|
|
918
|
+
] : [
|
|
919
|
+
parentName,
|
|
920
|
+
name,
|
|
921
|
+
options.enumSuffix
|
|
922
|
+
];
|
|
923
|
+
const enumName = useCollisionDetection ? pascalCase(enumNameParts.join(" ")) : getUniqueName(pascalCase(enumNameParts.join(" ")), this.options.usedEnumNames || {});
|
|
924
|
+
const typeName = this.context.pluginManager.resolveName({
|
|
925
|
+
name: enumName,
|
|
926
|
+
pluginKey: this.context.plugin.key,
|
|
927
|
+
type: "type"
|
|
928
|
+
});
|
|
929
|
+
if (schemaObject.enum.includes(null)) baseItems.push({ keyword: schemaKeywords.nullable });
|
|
930
|
+
const filteredValues = schemaObject.enum.filter((value) => value !== null);
|
|
931
|
+
const extensionEnums = ["x-enumNames", "x-enum-varnames"].filter((extensionKey) => extensionKey in schemaObject).map((extensionKey) => {
|
|
932
|
+
return [{
|
|
933
|
+
keyword: schemaKeywords.enum,
|
|
934
|
+
args: {
|
|
935
|
+
name,
|
|
936
|
+
typeName,
|
|
937
|
+
asConst: false,
|
|
938
|
+
items: [...new Set(schemaObject[extensionKey])].map((name, index) => ({
|
|
939
|
+
name: stringify(name),
|
|
940
|
+
value: schemaObject.enum?.[index],
|
|
941
|
+
format: isNumber(schemaObject.enum?.[index]) ? "number" : "string"
|
|
942
|
+
}))
|
|
943
|
+
}
|
|
944
|
+
}, ...baseItems.filter((item) => item.keyword !== schemaKeywords.min && item.keyword !== schemaKeywords.max && item.keyword !== schemaKeywords.matches)];
|
|
945
|
+
});
|
|
946
|
+
if (schemaObject.type === "number" || schemaObject.type === "integer") {
|
|
947
|
+
const enumNames = extensionEnums[0]?.find((item) => isKeyword(item, schemaKeywords.enum));
|
|
948
|
+
return [{
|
|
949
|
+
keyword: schemaKeywords.enum,
|
|
950
|
+
args: {
|
|
951
|
+
name: enumName,
|
|
952
|
+
typeName,
|
|
953
|
+
asConst: true,
|
|
954
|
+
items: enumNames?.args?.items ? [...new Set(enumNames.args.items)].map(({ name, value }) => ({
|
|
955
|
+
name,
|
|
956
|
+
value,
|
|
957
|
+
format: "number"
|
|
958
|
+
})) : [...new Set(filteredValues)].map((value) => {
|
|
959
|
+
return {
|
|
960
|
+
name: value,
|
|
961
|
+
value,
|
|
962
|
+
format: "number"
|
|
963
|
+
};
|
|
964
|
+
})
|
|
965
|
+
}
|
|
966
|
+
}, ...baseItems.filter((item) => item.keyword !== schemaKeywords.min && item.keyword !== schemaKeywords.max && item.keyword !== schemaKeywords.matches)];
|
|
967
|
+
}
|
|
968
|
+
if (schemaObject.type === "boolean") {
|
|
969
|
+
const enumNames = extensionEnums[0]?.find((item) => isKeyword(item, schemaKeywords.enum));
|
|
970
|
+
return [{
|
|
971
|
+
keyword: schemaKeywords.enum,
|
|
972
|
+
args: {
|
|
973
|
+
name: enumName,
|
|
974
|
+
typeName,
|
|
975
|
+
asConst: true,
|
|
976
|
+
items: enumNames?.args?.items ? [...new Set(enumNames.args.items)].map(({ name, value }) => ({
|
|
977
|
+
name,
|
|
978
|
+
value,
|
|
979
|
+
format: "boolean"
|
|
980
|
+
})) : [...new Set(filteredValues)].map((value) => {
|
|
981
|
+
return {
|
|
982
|
+
name: value,
|
|
983
|
+
value,
|
|
984
|
+
format: "boolean"
|
|
985
|
+
};
|
|
986
|
+
})
|
|
987
|
+
}
|
|
988
|
+
}, ...baseItems.filter((item) => item.keyword !== schemaKeywords.matches)];
|
|
989
|
+
}
|
|
990
|
+
if (extensionEnums.length > 0 && extensionEnums[0]) return extensionEnums[0];
|
|
991
|
+
return [{
|
|
992
|
+
keyword: schemaKeywords.enum,
|
|
993
|
+
args: {
|
|
994
|
+
name: enumName,
|
|
995
|
+
typeName,
|
|
996
|
+
asConst: false,
|
|
997
|
+
items: [...new Set(filteredValues)].map((value) => ({
|
|
998
|
+
name: stringify(value),
|
|
999
|
+
value,
|
|
1000
|
+
format: isNumber(value) ? "number" : "string"
|
|
1001
|
+
}))
|
|
1002
|
+
}
|
|
1003
|
+
}, ...baseItems.filter((item) => item.keyword !== schemaKeywords.min && item.keyword !== schemaKeywords.max && item.keyword !== schemaKeywords.matches)];
|
|
1004
|
+
}
|
|
1005
|
+
if ("prefixItems" in schemaObject) {
|
|
1006
|
+
const prefixItems = schemaObject.prefixItems;
|
|
1007
|
+
const items = "items" in schemaObject ? schemaObject.items : [];
|
|
1008
|
+
const min = schemaObject.minimum ?? schemaObject.minLength ?? schemaObject.minItems ?? void 0;
|
|
1009
|
+
const max = schemaObject.maximum ?? schemaObject.maxLength ?? schemaObject.maxItems ?? void 0;
|
|
1010
|
+
return [{
|
|
1011
|
+
keyword: schemaKeywords.tuple,
|
|
1012
|
+
args: {
|
|
1013
|
+
min,
|
|
1014
|
+
max,
|
|
1015
|
+
items: prefixItems.map((item) => {
|
|
1016
|
+
return this.parse({
|
|
1017
|
+
schema: item,
|
|
1018
|
+
name,
|
|
1019
|
+
parentName,
|
|
1020
|
+
rootName
|
|
1021
|
+
})[0];
|
|
1022
|
+
}).filter((x) => Boolean(x)),
|
|
1023
|
+
rest: this.parse({
|
|
1024
|
+
schema: items,
|
|
1025
|
+
name,
|
|
1026
|
+
parentName,
|
|
1027
|
+
rootName
|
|
1028
|
+
})[0]
|
|
1029
|
+
}
|
|
1030
|
+
}, ...baseItems.filter((item) => item.keyword !== schemaKeywords.min && item.keyword !== schemaKeywords.max)];
|
|
1031
|
+
}
|
|
1032
|
+
if (version === "3.1" && "const" in schemaObject) {
|
|
1033
|
+
if (schemaObject["const"] === null) return [{ keyword: schemaKeywords.null }];
|
|
1034
|
+
if (schemaObject["const"] === void 0) return [{ keyword: schemaKeywords.undefined }];
|
|
1035
|
+
let format = typeof schemaObject["const"];
|
|
1036
|
+
if (format !== "number" && format !== "boolean") format = "string";
|
|
1037
|
+
return [{
|
|
1038
|
+
keyword: schemaKeywords.const,
|
|
1039
|
+
args: {
|
|
1040
|
+
name: schemaObject["const"],
|
|
1041
|
+
format,
|
|
1042
|
+
value: schemaObject["const"]
|
|
1043
|
+
}
|
|
1044
|
+
}, ...baseItems];
|
|
1045
|
+
}
|
|
1046
|
+
/**
|
|
1047
|
+
* > Structural validation alone may be insufficient to allow an application to correctly utilize certain values. The "format"
|
|
1048
|
+
* > annotation keyword is defined to allow schema authors to convey semantic information for a fixed subset of values which are
|
|
1049
|
+
* > accurately described by authoritative resources, be they RFCs or other external specifications.
|
|
1050
|
+
*
|
|
1051
|
+
* In other words: format is more specific than type alone, hence it should override the type value, if possible.
|
|
1052
|
+
*
|
|
1053
|
+
* see also https://json-schema.org/draft/2020-12/draft-bhutton-json-schema-validation-00#rfc.section.7
|
|
1054
|
+
*/
|
|
1055
|
+
if (schemaObject.type === "string" && schemaObject.contentMediaType === "application/octet-stream") {
|
|
1056
|
+
baseItems.unshift({ keyword: schemaKeywords.blob });
|
|
1057
|
+
return baseItems;
|
|
1058
|
+
}
|
|
1059
|
+
if (schemaObject.format) {
|
|
1060
|
+
if (schemaObject.type === "integer" && schemaObject.format === "int64") {
|
|
1061
|
+
baseItems.unshift({ keyword: options.integerType === "bigint" ? schemaKeywords.bigint : schemaKeywords.integer });
|
|
1062
|
+
return baseItems;
|
|
1063
|
+
}
|
|
1064
|
+
if (schemaObject.type === "integer" && schemaObject.format === "int32") {
|
|
1065
|
+
baseItems.unshift({ keyword: schemaKeywords.integer });
|
|
1066
|
+
return baseItems;
|
|
1067
|
+
}
|
|
1068
|
+
if (schemaObject.type === "number" && (schemaObject.format === "float" || schemaObject.format === "double")) {
|
|
1069
|
+
baseItems.unshift({ keyword: schemaKeywords.number });
|
|
1070
|
+
return baseItems;
|
|
1071
|
+
}
|
|
1072
|
+
switch (schemaObject.format) {
|
|
1073
|
+
case "binary":
|
|
1074
|
+
baseItems.unshift({ keyword: schemaKeywords.blob });
|
|
1075
|
+
return baseItems;
|
|
1076
|
+
case "date-time":
|
|
1077
|
+
if (options.dateType) {
|
|
1078
|
+
if (options.dateType === "date") {
|
|
1079
|
+
baseItems.unshift({
|
|
1080
|
+
keyword: schemaKeywords.date,
|
|
1081
|
+
args: { type: "date" }
|
|
1082
|
+
});
|
|
1083
|
+
return baseItems;
|
|
1084
|
+
}
|
|
1085
|
+
if (options.dateType === "stringOffset") {
|
|
1086
|
+
baseItems.unshift({
|
|
1087
|
+
keyword: schemaKeywords.datetime,
|
|
1088
|
+
args: { offset: true }
|
|
1089
|
+
});
|
|
1090
|
+
return baseItems;
|
|
1091
|
+
}
|
|
1092
|
+
if (options.dateType === "stringLocal") {
|
|
1093
|
+
baseItems.unshift({
|
|
1094
|
+
keyword: schemaKeywords.datetime,
|
|
1095
|
+
args: { local: true }
|
|
1096
|
+
});
|
|
1097
|
+
return baseItems;
|
|
1098
|
+
}
|
|
1099
|
+
baseItems.unshift({
|
|
1100
|
+
keyword: schemaKeywords.datetime,
|
|
1101
|
+
args: { offset: false }
|
|
1102
|
+
});
|
|
1103
|
+
return baseItems;
|
|
1104
|
+
}
|
|
1105
|
+
break;
|
|
1106
|
+
case "date":
|
|
1107
|
+
if (options.dateType) {
|
|
1108
|
+
if (options.dateType === "date") {
|
|
1109
|
+
baseItems.unshift({
|
|
1110
|
+
keyword: schemaKeywords.date,
|
|
1111
|
+
args: { type: "date" }
|
|
1112
|
+
});
|
|
1113
|
+
return baseItems;
|
|
1114
|
+
}
|
|
1115
|
+
baseItems.unshift({
|
|
1116
|
+
keyword: schemaKeywords.date,
|
|
1117
|
+
args: { type: "string" }
|
|
1118
|
+
});
|
|
1119
|
+
return baseItems;
|
|
1120
|
+
}
|
|
1121
|
+
break;
|
|
1122
|
+
case "time":
|
|
1123
|
+
if (options.dateType) {
|
|
1124
|
+
if (options.dateType === "date") {
|
|
1125
|
+
baseItems.unshift({
|
|
1126
|
+
keyword: schemaKeywords.time,
|
|
1127
|
+
args: { type: "date" }
|
|
1128
|
+
});
|
|
1129
|
+
return baseItems;
|
|
1130
|
+
}
|
|
1131
|
+
baseItems.unshift({
|
|
1132
|
+
keyword: schemaKeywords.time,
|
|
1133
|
+
args: { type: "string" }
|
|
1134
|
+
});
|
|
1135
|
+
return baseItems;
|
|
1136
|
+
}
|
|
1137
|
+
break;
|
|
1138
|
+
case "uuid":
|
|
1139
|
+
baseItems.unshift({ keyword: schemaKeywords.uuid });
|
|
1140
|
+
return baseItems;
|
|
1141
|
+
case "email":
|
|
1142
|
+
case "idn-email":
|
|
1143
|
+
baseItems.unshift({ keyword: schemaKeywords.email });
|
|
1144
|
+
return baseItems;
|
|
1145
|
+
case "uri":
|
|
1146
|
+
case "ipv4":
|
|
1147
|
+
case "ipv6":
|
|
1148
|
+
case "uri-reference":
|
|
1149
|
+
case "hostname":
|
|
1150
|
+
case "idn-hostname":
|
|
1151
|
+
baseItems.unshift({ keyword: schemaKeywords.url });
|
|
1152
|
+
return baseItems;
|
|
1153
|
+
default: break;
|
|
1154
|
+
}
|
|
1155
|
+
}
|
|
1156
|
+
if (schemaObject.pattern && schemaObject.type === "string") {
|
|
1157
|
+
baseItems.unshift({
|
|
1158
|
+
keyword: schemaKeywords.matches,
|
|
1159
|
+
args: schemaObject.pattern
|
|
1160
|
+
});
|
|
1161
|
+
return baseItems;
|
|
1162
|
+
}
|
|
1163
|
+
if ("items" in schemaObject || schemaObject.type === "array") {
|
|
1164
|
+
const min = schemaObject.minimum ?? schemaObject.minLength ?? schemaObject.minItems ?? void 0;
|
|
1165
|
+
const max = schemaObject.maximum ?? schemaObject.maxLength ?? schemaObject.maxItems ?? void 0;
|
|
1166
|
+
const items = this.parse({
|
|
1167
|
+
schema: "items" in schemaObject ? schemaObject.items : [],
|
|
1168
|
+
name,
|
|
1169
|
+
parentName,
|
|
1170
|
+
rootName
|
|
1171
|
+
});
|
|
1172
|
+
const unique = !!schemaObject.uniqueItems;
|
|
1173
|
+
return [{
|
|
1174
|
+
keyword: schemaKeywords.array,
|
|
1175
|
+
args: {
|
|
1176
|
+
items,
|
|
1177
|
+
min,
|
|
1178
|
+
max,
|
|
1179
|
+
unique
|
|
1180
|
+
}
|
|
1181
|
+
}, ...baseItems.filter((item) => item.keyword !== schemaKeywords.min && item.keyword !== schemaKeywords.max)];
|
|
1182
|
+
}
|
|
1183
|
+
if (schemaObject.properties || schemaObject.additionalProperties || "patternProperties" in schemaObject) {
|
|
1184
|
+
if (isDiscriminator(schemaObject)) {
|
|
1185
|
+
const schemaObjectOverridden = Object.keys(schemaObject.properties || {}).reduce((acc, propertyName) => {
|
|
1186
|
+
if (acc.properties?.[propertyName] && propertyName === schemaObject.discriminator.propertyName) {
|
|
1187
|
+
const existingProperty = acc.properties[propertyName];
|
|
1188
|
+
return {
|
|
1189
|
+
...acc,
|
|
1190
|
+
properties: {
|
|
1191
|
+
...acc.properties,
|
|
1192
|
+
[propertyName]: {
|
|
1193
|
+
...existingProperty,
|
|
1194
|
+
enum: schemaObject.discriminator.mapping ? Object.keys(schemaObject.discriminator.mapping) : void 0
|
|
1195
|
+
}
|
|
1196
|
+
}
|
|
1197
|
+
};
|
|
1198
|
+
}
|
|
1199
|
+
return acc;
|
|
1200
|
+
}, schemaObject);
|
|
1201
|
+
return [...this.#parseProperties(name, schemaObjectOverridden, rootName), ...baseItems];
|
|
1202
|
+
}
|
|
1203
|
+
return [...this.#parseProperties(name, schemaObject, rootName), ...baseItems];
|
|
1204
|
+
}
|
|
1205
|
+
if (schemaObject.type) {
|
|
1206
|
+
const type = Array.isArray(schemaObject.type) ? schemaObject.type.filter((item) => item !== "null")[0] : schemaObject.type;
|
|
1207
|
+
if (![
|
|
1208
|
+
"boolean",
|
|
1209
|
+
"object",
|
|
1210
|
+
"number",
|
|
1211
|
+
"string",
|
|
1212
|
+
"integer",
|
|
1213
|
+
"null"
|
|
1214
|
+
].includes(type)) this.context.events?.emit("warn", `Schema type '${schemaObject.type}' is not valid for schema ${parentName}.${name}`);
|
|
1215
|
+
return [{ keyword: type }, ...baseItems];
|
|
1216
|
+
}
|
|
1217
|
+
let inferredType;
|
|
1218
|
+
if (schemaObject.minLength !== void 0 || schemaObject.maxLength !== void 0 || schemaObject.pattern !== void 0) inferredType = "string";
|
|
1219
|
+
else if (schemaObject.minimum !== void 0 || schemaObject.maximum !== void 0) inferredType = "number";
|
|
1220
|
+
if (inferredType) return [{ keyword: inferredType }, ...baseItems];
|
|
1221
|
+
return [{ keyword: emptyType }, ...baseItems];
|
|
1222
|
+
}
|
|
1223
|
+
async build(...generators) {
|
|
1224
|
+
const { oas, contentType, include } = this.context;
|
|
1225
|
+
if (!this.#nameMappingInitialized) {
|
|
1226
|
+
const { schemas, nameMapping } = oas.getSchemas({
|
|
1227
|
+
contentType,
|
|
1228
|
+
includes: include
|
|
1229
|
+
});
|
|
1230
|
+
this.#schemaNameMapping = nameMapping;
|
|
1231
|
+
this.#nameMappingInitialized = true;
|
|
1232
|
+
const schemaEntries = Object.entries(schemas);
|
|
1233
|
+
this.context.events?.emit("debug", {
|
|
1234
|
+
date: /* @__PURE__ */ new Date(),
|
|
1235
|
+
logs: [
|
|
1236
|
+
`Building ${schemaEntries.length} schemas`,
|
|
1237
|
+
` • Content Type: ${contentType || "application/json"}`,
|
|
1238
|
+
` • Generators: ${generators.length}`
|
|
1239
|
+
]
|
|
1240
|
+
});
|
|
1241
|
+
return this.#doBuild(schemas, generators);
|
|
1242
|
+
}
|
|
1243
|
+
const { schemas } = oas.getSchemas({
|
|
1244
|
+
contentType,
|
|
1245
|
+
includes: include
|
|
1246
|
+
});
|
|
1247
|
+
return this.#doBuild(schemas, generators);
|
|
1248
|
+
}
|
|
1249
|
+
async #doBuild(schemas, generators) {
|
|
1250
|
+
const schemaEntries = Object.entries(schemas);
|
|
1251
|
+
const generatorLimit = pLimit(GENERATOR_CONCURRENCY);
|
|
1252
|
+
const schemaLimit = pLimit(SCHEMA_CONCURRENCY);
|
|
1253
|
+
const writeTasks = generators.map((generator) => generatorLimit(async () => {
|
|
1254
|
+
if (generator.version === "2") return [];
|
|
1255
|
+
const v1Generator = generator;
|
|
1256
|
+
const schemaTasks = schemaEntries.map(([name, schemaObject]) => schemaLimit(async () => {
|
|
1257
|
+
const options = this.#getOptions(name);
|
|
1258
|
+
const tree = this.parse({
|
|
1259
|
+
schema: schemaObject,
|
|
1260
|
+
name,
|
|
1261
|
+
parentName: null,
|
|
1262
|
+
rootName: name
|
|
1263
|
+
});
|
|
1264
|
+
if (v1Generator.type === "react") {
|
|
1265
|
+
await buildSchema({
|
|
1266
|
+
name,
|
|
1267
|
+
value: schemaObject,
|
|
1268
|
+
tree
|
|
1269
|
+
}, {
|
|
1270
|
+
config: this.context.pluginManager.config,
|
|
1271
|
+
fabric: this.context.fabric,
|
|
1272
|
+
Component: v1Generator.Schema,
|
|
1273
|
+
generator: this,
|
|
1274
|
+
plugin: {
|
|
1275
|
+
...this.context.plugin,
|
|
1276
|
+
options: {
|
|
1277
|
+
...this.options,
|
|
1278
|
+
...options
|
|
1279
|
+
}
|
|
1280
|
+
}
|
|
1281
|
+
});
|
|
1282
|
+
return [];
|
|
1283
|
+
}
|
|
1284
|
+
return await v1Generator.schema?.({
|
|
1285
|
+
config: this.context.pluginManager.config,
|
|
1286
|
+
generator: this,
|
|
1287
|
+
schema: {
|
|
1288
|
+
name,
|
|
1289
|
+
value: schemaObject,
|
|
1290
|
+
tree
|
|
1291
|
+
},
|
|
1292
|
+
plugin: {
|
|
1293
|
+
...this.context.plugin,
|
|
1294
|
+
options: {
|
|
1295
|
+
...this.options,
|
|
1296
|
+
...options
|
|
1297
|
+
}
|
|
1298
|
+
}
|
|
1299
|
+
}) ?? [];
|
|
1300
|
+
}));
|
|
1301
|
+
return (await Promise.all(schemaTasks)).flat();
|
|
1302
|
+
}));
|
|
1303
|
+
return (await Promise.all(writeTasks)).flat();
|
|
1304
|
+
}
|
|
1305
|
+
};
|
|
1306
|
+
//#endregion
|
|
1307
|
+
//#region src/utils/requestBody.ts
|
|
1308
|
+
/**
|
|
1309
|
+
* Sentinel value injected into `schema.required` to signal that the request body is required.
|
|
1310
|
+
* Downstream generators check for this marker to emit the correct required constraint.
|
|
1311
|
+
*/
|
|
1312
|
+
const KUBB_REQUIRED_REQUEST_BODY_MARKER = "__kubb_required_request_body__";
|
|
1313
|
+
function getRequestBody(operationSchema) {
|
|
1314
|
+
const requestBody = operationSchema?.operation?.schema?.requestBody;
|
|
1315
|
+
if (!requestBody || "$ref" in requestBody) return;
|
|
1316
|
+
return requestBody;
|
|
1317
|
+
}
|
|
1318
|
+
function isRequestBodyRequired(operationSchema) {
|
|
1319
|
+
const requestBody = getRequestBody(operationSchema);
|
|
1320
|
+
return !!requestBody && requestBody.required === true;
|
|
1321
|
+
}
|
|
1322
|
+
function withRequiredRequestBodySchema(operationSchema) {
|
|
1323
|
+
if (!operationSchema || !isRequestBodyRequired(operationSchema)) return operationSchema;
|
|
1324
|
+
if (Array.isArray(operationSchema.schema.required) && operationSchema.schema.required.length > 0) return operationSchema;
|
|
1325
|
+
return {
|
|
1326
|
+
...operationSchema,
|
|
1327
|
+
schema: {
|
|
1328
|
+
...operationSchema.schema,
|
|
1329
|
+
required: [KUBB_REQUIRED_REQUEST_BODY_MARKER]
|
|
1330
|
+
}
|
|
1331
|
+
};
|
|
1332
|
+
}
|
|
1333
|
+
//#endregion
|
|
1334
|
+
export { buildOperations as a, pLimit as c, buildOperation as i, withRequiredRequestBodySchema as n, buildSchema as o, SchemaGenerator as r, getSchemaFactory as s, isRequestBodyRequired as t };
|
|
1335
|
+
|
|
1336
|
+
//# sourceMappingURL=requestBody-pRavthCw.js.map
|