@kubb/plugin-ts 3.0.0-alpha.9 → 3.0.0-beta.2
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/README.md +14 -5
- package/dist/{chunk-UVAKTXUA.js → chunk-AG2BUY33.js} +86 -398
- package/dist/chunk-AG2BUY33.js.map +1 -0
- package/dist/chunk-L7QZ6DBL.cjs +332 -0
- package/dist/chunk-L7QZ6DBL.cjs.map +1 -0
- package/dist/chunk-QZ2DBYXR.js +303 -0
- package/dist/chunk-QZ2DBYXR.js.map +1 -0
- package/dist/{chunk-PV5Q7I5O.cjs → chunk-XMTK3ZZE.cjs} +185 -470
- package/dist/chunk-XMTK3ZZE.cjs.map +1 -0
- package/dist/components.cjs +11 -12
- package/dist/components.cjs.map +1 -1
- package/dist/components.d.cts +14 -44
- package/dist/components.d.ts +14 -44
- package/dist/components.js +2 -16
- package/dist/components.js.map +1 -1
- package/dist/generators.cjs +17 -0
- package/dist/generators.cjs.map +1 -0
- package/dist/generators.d.cts +10 -0
- package/dist/generators.d.ts +10 -0
- package/dist/generators.js +4 -0
- package/dist/generators.js.map +1 -0
- package/dist/index.cjs +12 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -123
- package/dist/index.d.ts +4 -123
- package/dist/index.js +3 -9
- package/dist/index.js.map +1 -1
- package/dist/types-DoCOabdx.d.cts +98 -0
- package/dist/types-DoCOabdx.d.ts +98 -0
- package/package.json +21 -15
- package/src/components/OasType.tsx +3 -50
- package/src/components/{Schema.tsx → Type.tsx} +19 -54
- package/src/components/index.ts +1 -2
- package/src/generators/__snapshots__/bodyUploadFileApiAssetsPost.ts +6 -0
- package/src/generators/__snapshots__/catTypeAsConst.ts +11 -0
- package/src/generators/__snapshots__/createPet.ts +41 -0
- package/src/generators/__snapshots__/createPetWithUnknownTypeUnknown.ts +41 -0
- package/src/generators/__snapshots__/deletePet.ts +5 -0
- package/src/generators/__snapshots__/dogTypeAsConst.ts +11 -0
- package/src/generators/__snapshots__/enumAllOf.ts +10 -0
- package/src/generators/__snapshots__/enumArray.ts +19 -0
- package/src/generators/__snapshots__/enumInObject.ts +13 -0
- package/src/generators/__snapshots__/enumItems.ts +8 -0
- package/src/generators/__snapshots__/enumNames.ts +6 -0
- package/src/generators/__snapshots__/enumNamesConst.ts +6 -0
- package/src/generators/__snapshots__/enumNamesLiteral.ts +3 -0
- package/src/generators/__snapshots__/enumNamesPascalConst.ts +8 -0
- package/src/generators/__snapshots__/enumNamesType.ts +8 -0
- package/src/generators/__snapshots__/enumNullableMember.ts +8 -0
- package/src/generators/__snapshots__/enumNullableType.ts +8 -0
- package/src/generators/__snapshots__/enumString.ts +10 -0
- package/src/generators/__snapshots__/enumVarNamesType.ts +8 -0
- package/src/generators/__snapshots__/getPets.ts +27 -0
- package/src/generators/__snapshots__/mixedValueTypeConst.ts +9 -0
- package/src/generators/__snapshots__/nullConstNull.ts +7 -0
- package/src/generators/__snapshots__/numberValueConst.ts +9 -0
- package/src/generators/__snapshots__/petMapper.ts +15 -0
- package/src/generators/__snapshots__/petQuestionToken.ts +19 -0
- package/src/generators/__snapshots__/petQuestionTokenAndUndefined.ts +19 -0
- package/src/generators/__snapshots__/petUndefined.ts +19 -0
- package/src/generators/__snapshots__/pets.ts +14 -0
- package/src/generators/__snapshots__/petsStoreAdvancedDiscriminator.ts +31 -0
- package/src/generators/__snapshots__/petsStoreDiscriminator.ts +13 -0
- package/src/generators/__snapshots__/petsStoreRef.ts +1 -0
- package/src/generators/__snapshots__/plainDateDate.ts +1 -0
- package/src/generators/__snapshots__/plainDateString.ts +1 -0
- package/src/generators/__snapshots__/plainEmail.ts +1 -0
- package/src/generators/__snapshots__/plainFile.ts +1 -0
- package/src/generators/__snapshots__/plainTimeDate.ts +1 -0
- package/src/generators/__snapshots__/plainUuid.ts +1 -0
- package/src/generators/__snapshots__/readOnly.ts +20 -0
- package/src/{components/__snapshots__/Schema → generators/__snapshots__}/showPetById.ts +9 -9
- package/src/generators/__snapshots__/stringValueConst.ts +9 -0
- package/src/generators/index.ts +2 -0
- package/src/generators/oasGenerator.tsx +29 -0
- package/src/generators/typeGenerator.tsx +200 -0
- package/src/parser/index.ts +12 -3
- package/src/plugin.ts +26 -33
- package/src/types.ts +16 -52
- package/dist/chunk-PV5Q7I5O.cjs.map +0 -1
- package/dist/chunk-SEH6NUCX.cjs +0 -42
- package/dist/chunk-SEH6NUCX.cjs.map +0 -1
- package/dist/chunk-TTGZBH7H.js +0 -42
- package/dist/chunk-TTGZBH7H.js.map +0 -1
- package/dist/chunk-UVAKTXUA.js.map +0 -1
- package/dist/oas.cjs +0 -7
- package/dist/oas.cjs.map +0 -1
- package/dist/oas.d.cts +0 -1
- package/dist/oas.d.ts +0 -1
- package/dist/oas.js +0 -7
- package/dist/oas.js.map +0 -1
- package/src/OperationGenerator.tsx +0 -49
- package/src/SchemaGenerator.tsx +0 -31
- package/src/components/OperationSchema.tsx +0 -161
- package/src/components/__snapshots__/Schema/pets.ts +0 -27
- package/src/oas/index.ts +0 -1
package/README.md
CHANGED
|
@@ -14,12 +14,8 @@
|
|
|
14
14
|
[![Coverage][coverage-src]][coverage-href]
|
|
15
15
|
[![License][license-src]][license-href]
|
|
16
16
|
|
|
17
|
-
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
|
|
18
|
-
<!-- ALL-CONTRIBUTORS-BADGE:END -->
|
|
19
|
-
</p>
|
|
20
|
-
|
|
21
17
|
<h4>
|
|
22
|
-
<a href="https://codesandbox.io/s/github/kubb-labs/kubb/tree/
|
|
18
|
+
<a href="https://codesandbox.io/s/github/kubb-labs/kubb/tree/main//examples/typescript" target="_blank">View Demo</a>
|
|
23
19
|
<span> · </span>
|
|
24
20
|
<a href="https://kubb.dev/" target="_blank">Documentation</a>
|
|
25
21
|
<span> · </span>
|
|
@@ -29,6 +25,19 @@
|
|
|
29
25
|
</h4>
|
|
30
26
|
</div>
|
|
31
27
|
|
|
28
|
+
## Supporting Kubb
|
|
29
|
+
|
|
30
|
+
Kubb uses an MIT-licensed open source project with its ongoing development made possible entirely by the support of Sponsors. If you would like to become a sponsor, please consider:
|
|
31
|
+
|
|
32
|
+
- [Become a Sponsor on GitHub](https://github.com/sponsors/stijnvanhulle)
|
|
33
|
+
|
|
34
|
+
<p align="center">
|
|
35
|
+
<a href="https://github.com/sponsors/stijnvanhulle">
|
|
36
|
+
<img src="https://raw.githubusercontent.com/stijnvanhulle/sponsors/main/sponsors.svg" alt="My sponsors" />
|
|
37
|
+
</a>
|
|
38
|
+
</p>
|
|
39
|
+
|
|
40
|
+
|
|
32
41
|
<!-- Badges -->
|
|
33
42
|
|
|
34
43
|
[npm-version-src]: https://img.shields.io/npm/v/@kubb/plugin-ts?flat&colorA=18181B&colorB=f58517
|
|
@@ -1,13 +1,48 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { File, Type } from '@kubb/react';
|
|
2
|
+
import { jsxs, Fragment, jsx } from '@kubb/react/jsx-runtime';
|
|
3
|
+
import transformers2 from '@kubb/core/transformers';
|
|
4
|
+
import { print } from '@kubb/parser-ts';
|
|
5
|
+
import * as factory from '@kubb/parser-ts/factory';
|
|
6
|
+
import { schemaKeywords, SchemaGenerator, isKeyword } from '@kubb/plugin-oas';
|
|
7
|
+
|
|
8
|
+
var __create = Object.create;
|
|
9
|
+
var __defProp = Object.defineProperty;
|
|
10
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
11
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
12
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
13
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
14
|
+
var __esm = (fn, res) => function __init() {
|
|
15
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
16
|
+
};
|
|
17
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
18
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
19
|
+
};
|
|
20
|
+
var __copyProps = (to, from, except, desc) => {
|
|
21
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
22
|
+
for (let key of __getOwnPropNames(from))
|
|
23
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
24
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
25
|
+
}
|
|
26
|
+
return to;
|
|
27
|
+
};
|
|
28
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
29
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
30
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
31
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
32
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
33
|
+
__defProp(target, "default", { value: mod, enumerable: true }) ,
|
|
34
|
+
mod
|
|
35
|
+
));
|
|
36
|
+
|
|
37
|
+
// ../../node_modules/.pnpm/tsup@8.3.0_@microsoft+api-extractor@7.47.9_@types+node@20.16.10__@swc+core@1.7.22_jiti@2.1.2__uanfwh7zphuhqcdzaksoxhdkee/node_modules/tsup/assets/esm_shims.js
|
|
38
|
+
var init_esm_shims = __esm({
|
|
39
|
+
"../../node_modules/.pnpm/tsup@8.3.0_@microsoft+api-extractor@7.47.9_@types+node@20.16.10__@swc+core@1.7.22_jiti@2.1.2__uanfwh7zphuhqcdzaksoxhdkee/node_modules/tsup/assets/esm_shims.js"() {
|
|
40
|
+
}
|
|
41
|
+
});
|
|
6
42
|
|
|
7
43
|
// ../../node_modules/.pnpm/react@18.3.1/node_modules/react/cjs/react.production.min.js
|
|
8
44
|
var require_react_production_min = __commonJS({
|
|
9
45
|
"../../node_modules/.pnpm/react@18.3.1/node_modules/react/cjs/react.production.min.js"(exports) {
|
|
10
|
-
"use strict";
|
|
11
46
|
init_esm_shims();
|
|
12
47
|
var l = Symbol.for("react.element");
|
|
13
48
|
var n = Symbol.for("react.portal");
|
|
@@ -281,11 +316,9 @@ var require_react_production_min = __commonJS({
|
|
|
281
316
|
// ../../node_modules/.pnpm/react@18.3.1/node_modules/react/cjs/react.development.js
|
|
282
317
|
var require_react_development = __commonJS({
|
|
283
318
|
"../../node_modules/.pnpm/react@18.3.1/node_modules/react/cjs/react.development.js"(exports, module) {
|
|
284
|
-
"use strict";
|
|
285
319
|
init_esm_shims();
|
|
286
320
|
if (process.env.NODE_ENV !== "production") {
|
|
287
321
|
(function() {
|
|
288
|
-
"use strict";
|
|
289
322
|
if (typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== "undefined" && typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart === "function") {
|
|
290
323
|
__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(new Error());
|
|
291
324
|
}
|
|
@@ -2156,7 +2189,6 @@ var require_react_development = __commonJS({
|
|
|
2156
2189
|
// ../../node_modules/.pnpm/react@18.3.1/node_modules/react/index.js
|
|
2157
2190
|
var require_react = __commonJS({
|
|
2158
2191
|
"../../node_modules/.pnpm/react@18.3.1/node_modules/react/index.js"(exports, module) {
|
|
2159
|
-
"use strict";
|
|
2160
2192
|
init_esm_shims();
|
|
2161
2193
|
if (process.env.NODE_ENV === "production") {
|
|
2162
2194
|
module.exports = require_react_production_min();
|
|
@@ -2166,85 +2198,25 @@ var require_react = __commonJS({
|
|
|
2166
2198
|
}
|
|
2167
2199
|
});
|
|
2168
2200
|
|
|
2169
|
-
// src/index.ts
|
|
2201
|
+
// src/components/index.ts
|
|
2170
2202
|
init_esm_shims();
|
|
2171
2203
|
|
|
2172
|
-
// src/plugin.ts
|
|
2173
|
-
init_esm_shims();
|
|
2174
|
-
import path from "node:path";
|
|
2175
|
-
import { FileManager, PluginManager, createPlugin } from "@kubb/core";
|
|
2176
|
-
import { camelCase, pascalCase } from "@kubb/core/transformers";
|
|
2177
|
-
import { renderTemplate } from "@kubb/core/utils";
|
|
2178
|
-
import { pluginOasName } from "@kubb/plugin-oas";
|
|
2179
|
-
|
|
2180
|
-
// src/OperationGenerator.tsx
|
|
2181
|
-
init_esm_shims();
|
|
2182
|
-
import { OperationGenerator as Generator2 } from "@kubb/plugin-oas";
|
|
2183
|
-
import { Oas as Oas4 } from "@kubb/plugin-oas/components";
|
|
2184
|
-
import { App as App2, createRoot as createRoot2 } from "@kubb/react";
|
|
2185
|
-
|
|
2186
2204
|
// src/components/OasType.tsx
|
|
2187
2205
|
init_esm_shims();
|
|
2188
|
-
|
|
2189
|
-
import { File, Type, useApp } from "@kubb/react";
|
|
2190
|
-
import { Fragment, jsx, jsxs } from "@kubb/react/jsx-runtime";
|
|
2191
|
-
function Template({ name, typeName, api }) {
|
|
2206
|
+
function OasType({ name, typeName, api }) {
|
|
2192
2207
|
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
2193
2208
|
/* @__PURE__ */ jsx(File.Source, { name, isExportable: true, isIndexable: true, children: `export const ${name} = ${JSON.stringify(api, void 0, 2)} as const` }),
|
|
2194
2209
|
/* @__PURE__ */ jsx("br", {}),
|
|
2195
2210
|
/* @__PURE__ */ jsx(File.Source, { name: typeName, isExportable: true, isIndexable: true, isTypeOnly: true, children: /* @__PURE__ */ jsx(Type, { name: typeName, export: true, children: `Infer<typeof ${name}>` }) })
|
|
2196
2211
|
] });
|
|
2197
2212
|
}
|
|
2198
|
-
var defaultTemplates = { default: Template };
|
|
2199
|
-
function OasType({ name, typeName, Template: Template2 = defaultTemplates.default }) {
|
|
2200
|
-
const oas = useOas();
|
|
2201
|
-
return /* @__PURE__ */ jsx(Template2, { name, typeName, api: oas.api });
|
|
2202
|
-
}
|
|
2203
|
-
OasType.File = function({ name, typeName, templates = defaultTemplates }) {
|
|
2204
|
-
const {
|
|
2205
|
-
pluginManager,
|
|
2206
|
-
plugin: { key: pluginKey }
|
|
2207
|
-
} = useApp();
|
|
2208
|
-
const file = pluginManager.getFile({ name, extName: ".ts", pluginKey });
|
|
2209
|
-
const Template2 = templates.default;
|
|
2210
|
-
return /* @__PURE__ */ jsxs(File, { baseName: file.baseName, path: file.path, meta: file.meta, children: [
|
|
2211
|
-
/* @__PURE__ */ jsx(File.Import, { name: ["Infer"], path: "@kubb/oas", isTypeOnly: true }),
|
|
2212
|
-
/* @__PURE__ */ jsx(OasType, { Template: Template2, name, typeName })
|
|
2213
|
-
] });
|
|
2214
|
-
};
|
|
2215
|
-
OasType.templates = defaultTemplates;
|
|
2216
|
-
|
|
2217
|
-
// src/components/OperationSchema.tsx
|
|
2218
|
-
init_esm_shims();
|
|
2219
|
-
import transformers3 from "@kubb/core/transformers";
|
|
2220
|
-
import { print as print2 } from "@kubb/parser-ts";
|
|
2221
|
-
import * as factory3 from "@kubb/parser-ts/factory";
|
|
2222
|
-
import { Oas as Oas3 } from "@kubb/plugin-oas/components";
|
|
2223
|
-
import { useOas as useOas2, useOperation, useOperationManager } from "@kubb/plugin-oas/hooks";
|
|
2224
|
-
import { File as File3, useApp as useApp3 } from "@kubb/react";
|
|
2225
|
-
|
|
2226
|
-
// src/SchemaGenerator.tsx
|
|
2227
|
-
init_esm_shims();
|
|
2228
|
-
import { SchemaGenerator as Generator } from "@kubb/plugin-oas";
|
|
2229
|
-
import { Oas as Oas2 } from "@kubb/plugin-oas/components";
|
|
2230
|
-
import { App, createRoot } from "@kubb/react";
|
|
2231
2213
|
|
|
2232
|
-
// src/components/
|
|
2214
|
+
// src/components/Type.tsx
|
|
2233
2215
|
init_esm_shims();
|
|
2234
|
-
var import_react3 = __toESM(require_react()
|
|
2235
|
-
import { Oas } from "@kubb/plugin-oas/components";
|
|
2236
|
-
import { File as File2, useApp as useApp2 } from "@kubb/react";
|
|
2237
|
-
import transformers2 from "@kubb/core/transformers";
|
|
2238
|
-
import { print } from "@kubb/parser-ts";
|
|
2239
|
-
import * as factory2 from "@kubb/parser-ts/factory";
|
|
2240
|
-
import { SchemaGenerator, schemaKeywords as schemaKeywords2 } from "@kubb/plugin-oas";
|
|
2241
|
-
import { useSchema } from "@kubb/plugin-oas/hooks";
|
|
2216
|
+
var import_react3 = __toESM(require_react());
|
|
2242
2217
|
|
|
2243
2218
|
// src/parser/index.ts
|
|
2244
2219
|
init_esm_shims();
|
|
2245
|
-
import transformers from "@kubb/core/transformers";
|
|
2246
|
-
import * as factory from "@kubb/parser-ts/factory";
|
|
2247
|
-
import { isKeyword, schemaKeywords } from "@kubb/plugin-oas";
|
|
2248
2220
|
var typeKeywordMapper = {
|
|
2249
2221
|
any: () => factory.keywordTypeNodes.any,
|
|
2250
2222
|
unknown: () => factory.keywordTypeNodes.unknown,
|
|
@@ -2293,7 +2265,13 @@ var typeKeywordMapper = {
|
|
|
2293
2265
|
if (!name) {
|
|
2294
2266
|
return void 0;
|
|
2295
2267
|
}
|
|
2296
|
-
if (format === "
|
|
2268
|
+
if (format === "boolean") {
|
|
2269
|
+
if (name === true) {
|
|
2270
|
+
return factory.createLiteralTypeNode(factory.createTrue());
|
|
2271
|
+
}
|
|
2272
|
+
return factory.createLiteralTypeNode(factory.createFalse());
|
|
2273
|
+
}
|
|
2274
|
+
if (format === "number" && typeof name === "number") {
|
|
2297
2275
|
return factory.createLiteralTypeNode(factory.createNumericLiteral(name));
|
|
2298
2276
|
}
|
|
2299
2277
|
return factory.createLiteralTypeNode(factory.createStringLiteral(name.toString()));
|
|
@@ -2325,6 +2303,7 @@ var typeKeywordMapper = {
|
|
|
2325
2303
|
password: void 0,
|
|
2326
2304
|
phone: void 0,
|
|
2327
2305
|
readOnly: void 0,
|
|
2306
|
+
writeOnly: void 0,
|
|
2328
2307
|
ref: (propertyName) => {
|
|
2329
2308
|
if (!propertyName) {
|
|
2330
2309
|
return void 0;
|
|
@@ -2411,7 +2390,7 @@ function parse(parent, current, options) {
|
|
|
2411
2390
|
return factory.appendJSDocToNode({
|
|
2412
2391
|
node: propertySignature,
|
|
2413
2392
|
comments: [
|
|
2414
|
-
describeSchema ? `@description ${
|
|
2393
|
+
describeSchema ? `@description ${transformers2.jsStringEscape(describeSchema.args)}` : void 0,
|
|
2415
2394
|
deprecatedSchema ? "@deprecated" : void 0,
|
|
2416
2395
|
defaultSchema ? `@default ${defaultSchema.args}` : void 0,
|
|
2417
2396
|
exampleSchema ? `@example ${exampleSchema.args}` : void 0,
|
|
@@ -2438,42 +2417,18 @@ function parse(parent, current, options) {
|
|
|
2438
2417
|
}
|
|
2439
2418
|
return void 0;
|
|
2440
2419
|
}
|
|
2441
|
-
|
|
2442
|
-
// src/components/Schema.tsx
|
|
2443
|
-
import { jsx as jsx2, jsxs as jsxs2 } from "@kubb/react/jsx-runtime";
|
|
2444
|
-
function Schema(props) {
|
|
2445
|
-
const { keysToOmit, description } = props;
|
|
2446
|
-
const { tree, name } = useSchema();
|
|
2447
|
-
const {
|
|
2448
|
-
pluginManager,
|
|
2449
|
-
plugin: {
|
|
2450
|
-
options: { mapper, enumType, optionalType }
|
|
2451
|
-
}
|
|
2452
|
-
} = useApp2();
|
|
2453
|
-
if (enumType === "asPascalConst") {
|
|
2454
|
-
pluginManager.logger.emit("warning", `enumType '${enumType}' is deprecated`);
|
|
2455
|
-
}
|
|
2456
|
-
const resolvedName = pluginManager.resolveName({
|
|
2457
|
-
name,
|
|
2458
|
-
pluginKey: [pluginTsName],
|
|
2459
|
-
type: "function"
|
|
2460
|
-
});
|
|
2461
|
-
const typeName = pluginManager.resolveName({
|
|
2462
|
-
name,
|
|
2463
|
-
pluginKey: [pluginTsName],
|
|
2464
|
-
type: "type"
|
|
2465
|
-
});
|
|
2420
|
+
function Type2({ name, typedName, tree, keysToOmit, optionalType, enumType, mapper, description }) {
|
|
2466
2421
|
const typeNodes = [];
|
|
2467
2422
|
if (!tree.length) {
|
|
2468
2423
|
return "";
|
|
2469
2424
|
}
|
|
2470
|
-
const isNullish = tree.some((item) => item.keyword ===
|
|
2471
|
-
const isNullable = tree.some((item) => item.keyword ===
|
|
2472
|
-
const isOptional = tree.some((item) => item.keyword ===
|
|
2425
|
+
const isNullish = tree.some((item) => item.keyword === schemaKeywords.nullish);
|
|
2426
|
+
const isNullable = tree.some((item) => item.keyword === schemaKeywords.nullable);
|
|
2427
|
+
const isOptional = tree.some((item) => item.keyword === schemaKeywords.optional);
|
|
2473
2428
|
let type = tree.map(
|
|
2474
2429
|
(schema) => parse(void 0, schema, {
|
|
2475
|
-
name
|
|
2476
|
-
typeName,
|
|
2430
|
+
name,
|
|
2431
|
+
typeName: typedName,
|
|
2477
2432
|
description,
|
|
2478
2433
|
keysToOmit,
|
|
2479
2434
|
optionalType,
|
|
@@ -2482,36 +2437,36 @@ function Schema(props) {
|
|
|
2482
2437
|
})
|
|
2483
2438
|
).filter(Boolean).at(0) || typeKeywordMapper.undefined();
|
|
2484
2439
|
if (isNullable) {
|
|
2485
|
-
type =
|
|
2486
|
-
nodes: [type,
|
|
2440
|
+
type = factory.createUnionDeclaration({
|
|
2441
|
+
nodes: [type, factory.keywordTypeNodes.null]
|
|
2487
2442
|
});
|
|
2488
2443
|
}
|
|
2489
2444
|
if (isNullish && ["undefined", "questionTokenAndUndefined"].includes(optionalType)) {
|
|
2490
|
-
type =
|
|
2491
|
-
nodes: [type,
|
|
2445
|
+
type = factory.createUnionDeclaration({
|
|
2446
|
+
nodes: [type, factory.keywordTypeNodes.undefined]
|
|
2492
2447
|
});
|
|
2493
2448
|
}
|
|
2494
2449
|
if (isOptional && ["undefined", "questionTokenAndUndefined"].includes(optionalType)) {
|
|
2495
|
-
type =
|
|
2496
|
-
nodes: [type,
|
|
2450
|
+
type = factory.createUnionDeclaration({
|
|
2451
|
+
nodes: [type, factory.keywordTypeNodes.undefined]
|
|
2497
2452
|
});
|
|
2498
2453
|
}
|
|
2499
|
-
const node =
|
|
2500
|
-
modifiers: [
|
|
2501
|
-
name
|
|
2502
|
-
type: keysToOmit?.length ?
|
|
2454
|
+
const node = factory.createTypeAliasDeclaration({
|
|
2455
|
+
modifiers: [factory.modifiers.export],
|
|
2456
|
+
name,
|
|
2457
|
+
type: keysToOmit?.length ? factory.createOmitDeclaration({
|
|
2503
2458
|
keys: keysToOmit,
|
|
2504
2459
|
type,
|
|
2505
2460
|
nonNullable: true
|
|
2506
2461
|
}) : type
|
|
2507
2462
|
});
|
|
2508
|
-
const enumSchemas = SchemaGenerator.deepSearch(tree,
|
|
2509
|
-
const enums = enumSchemas.map((enumSchema) => {
|
|
2463
|
+
const enumSchemas = SchemaGenerator.deepSearch(tree, schemaKeywords.enum);
|
|
2464
|
+
const enums = [...new Set(enumSchemas)].map((enumSchema) => {
|
|
2510
2465
|
const name2 = enumType === "asPascalConst" ? transformers2.pascalCase(enumSchema.args.name) : transformers2.camelCase(enumSchema.args.name);
|
|
2511
|
-
const
|
|
2512
|
-
const [nameNode, typeNode] =
|
|
2466
|
+
const typeName = enumSchema.args.typeName;
|
|
2467
|
+
const [nameNode, typeNode] = factory.createEnumDeclaration({
|
|
2513
2468
|
name: name2,
|
|
2514
|
-
typeName
|
|
2469
|
+
typeName,
|
|
2515
2470
|
enums: enumSchema.args.items.map((item) => item.value === void 0 ? void 0 : [transformers2.trimQuotes(item.name?.toString()), item.value]).filter(Boolean),
|
|
2516
2471
|
type: enumType
|
|
2517
2472
|
});
|
|
@@ -2519,293 +2474,23 @@ function Schema(props) {
|
|
|
2519
2474
|
nameNode,
|
|
2520
2475
|
typeNode,
|
|
2521
2476
|
name: name2,
|
|
2522
|
-
typeName
|
|
2477
|
+
typeName
|
|
2523
2478
|
};
|
|
2524
2479
|
});
|
|
2525
2480
|
typeNodes.push(
|
|
2526
|
-
|
|
2481
|
+
factory.appendJSDocToNode({
|
|
2527
2482
|
node,
|
|
2528
2483
|
comments: [description ? `@description ${transformers2.jsStringEscape(description)}` : void 0].filter(Boolean)
|
|
2529
2484
|
})
|
|
2530
2485
|
);
|
|
2531
|
-
return /* @__PURE__ */
|
|
2532
|
-
enums.map(({ name: name2, nameNode, typeName
|
|
2533
|
-
nameNode && /* @__PURE__ */
|
|
2534
|
-
/* @__PURE__ */
|
|
2486
|
+
return /* @__PURE__ */ jsxs(import_react3.Fragment, { children: [
|
|
2487
|
+
enums.map(({ name: name2, nameNode, typeName, typeNode }, index) => /* @__PURE__ */ jsxs(import_react3.Fragment, { children: [
|
|
2488
|
+
nameNode && /* @__PURE__ */ jsx(File.Source, { name: name2, isExportable: true, isIndexable: true, children: print([nameNode]) }),
|
|
2489
|
+
/* @__PURE__ */ jsx(File.Source, { name: typeName, isIndexable: true, isExportable: ["enum", "asConst", "constEnum", "literal", void 0].includes(enumType), isTypeOnly: true, children: print([typeNode]) })
|
|
2535
2490
|
] }, [name2, nameNode].join("-"))),
|
|
2536
|
-
enums.every((item) => item.typeName !==
|
|
2491
|
+
enums.every((item) => item.typeName !== name) && /* @__PURE__ */ jsx(File.Source, { name: typedName, isTypeOnly: true, isExportable: true, isIndexable: true, children: print(typeNodes) })
|
|
2537
2492
|
] });
|
|
2538
2493
|
}
|
|
2539
|
-
Schema.File = function({}) {
|
|
2540
|
-
const { pluginManager } = useApp2();
|
|
2541
|
-
const { schema } = useSchema();
|
|
2542
|
-
return /* @__PURE__ */ jsx2(Oas.Schema.File, { isTypeOnly: true, output: pluginManager.config.output.path, children: /* @__PURE__ */ jsx2(Schema, { description: schema?.description }) });
|
|
2543
|
-
};
|
|
2544
|
-
|
|
2545
|
-
// src/SchemaGenerator.tsx
|
|
2546
|
-
import { jsx as jsx3 } from "@kubb/react/jsx-runtime";
|
|
2547
|
-
var SchemaGenerator2 = class extends Generator {
|
|
2548
|
-
async schema(name, schema, options) {
|
|
2549
|
-
const { oas, pluginManager, plugin, mode, output } = this.context;
|
|
2550
|
-
const root = createRoot({
|
|
2551
|
-
logger: pluginManager.logger
|
|
2552
|
-
});
|
|
2553
|
-
const tree = this.parse({ schema, name });
|
|
2554
|
-
root.render(
|
|
2555
|
-
/* @__PURE__ */ jsx3(App, { pluginManager, plugin: { ...plugin, options }, mode, children: /* @__PURE__ */ jsx3(Oas2, { oas, children: /* @__PURE__ */ jsx3(Oas2.Schema, { name, value: schema, tree, children: /* @__PURE__ */ jsx3(Schema.File, {}) }) }) })
|
|
2556
|
-
);
|
|
2557
|
-
return root.files;
|
|
2558
|
-
}
|
|
2559
|
-
};
|
|
2560
|
-
|
|
2561
|
-
// src/components/OperationSchema.tsx
|
|
2562
|
-
import { jsx as jsx4, jsxs as jsxs3 } from "@kubb/react/jsx-runtime";
|
|
2563
|
-
function printCombinedSchema({
|
|
2564
|
-
name,
|
|
2565
|
-
operation,
|
|
2566
|
-
schemas,
|
|
2567
|
-
pluginManager
|
|
2568
|
-
}) {
|
|
2569
|
-
const properties = {};
|
|
2570
|
-
if (schemas.response) {
|
|
2571
|
-
const identifier = pluginManager.resolveName({
|
|
2572
|
-
name: schemas.response.name,
|
|
2573
|
-
pluginKey: [pluginTsName],
|
|
2574
|
-
type: "function"
|
|
2575
|
-
});
|
|
2576
|
-
properties["response"] = factory3.createTypeReferenceNode(factory3.createIdentifier(identifier), void 0);
|
|
2577
|
-
}
|
|
2578
|
-
if (schemas.request) {
|
|
2579
|
-
const identifier = pluginManager.resolveName({
|
|
2580
|
-
name: schemas.request.name,
|
|
2581
|
-
pluginKey: [pluginTsName],
|
|
2582
|
-
type: "function"
|
|
2583
|
-
});
|
|
2584
|
-
properties["request"] = factory3.createTypeReferenceNode(factory3.createIdentifier(identifier), void 0);
|
|
2585
|
-
}
|
|
2586
|
-
if (schemas.pathParams) {
|
|
2587
|
-
const identifier = pluginManager.resolveName({
|
|
2588
|
-
name: schemas.pathParams.name,
|
|
2589
|
-
pluginKey: [pluginTsName],
|
|
2590
|
-
type: "function"
|
|
2591
|
-
});
|
|
2592
|
-
properties["pathParams"] = factory3.createTypeReferenceNode(factory3.createIdentifier(identifier), void 0);
|
|
2593
|
-
}
|
|
2594
|
-
if (schemas.queryParams) {
|
|
2595
|
-
const identifier = pluginManager.resolveName({
|
|
2596
|
-
name: schemas.queryParams.name,
|
|
2597
|
-
pluginKey: [pluginTsName],
|
|
2598
|
-
type: "function"
|
|
2599
|
-
});
|
|
2600
|
-
properties["queryParams"] = factory3.createTypeReferenceNode(factory3.createIdentifier(identifier), void 0);
|
|
2601
|
-
}
|
|
2602
|
-
if (schemas.headerParams) {
|
|
2603
|
-
const identifier = pluginManager.resolveName({
|
|
2604
|
-
name: schemas.headerParams.name,
|
|
2605
|
-
pluginKey: [pluginTsName],
|
|
2606
|
-
type: "function"
|
|
2607
|
-
});
|
|
2608
|
-
properties["headerParams"] = factory3.createTypeReferenceNode(factory3.createIdentifier(identifier), void 0);
|
|
2609
|
-
}
|
|
2610
|
-
if (schemas.errors) {
|
|
2611
|
-
properties["errors"] = factory3.createUnionDeclaration({
|
|
2612
|
-
nodes: schemas.errors.map((error) => {
|
|
2613
|
-
const identifier = pluginManager.resolveName({
|
|
2614
|
-
name: error.name,
|
|
2615
|
-
pluginKey: [pluginTsName],
|
|
2616
|
-
type: "function"
|
|
2617
|
-
});
|
|
2618
|
-
return factory3.createTypeReferenceNode(factory3.createIdentifier(identifier), void 0);
|
|
2619
|
-
})
|
|
2620
|
-
});
|
|
2621
|
-
}
|
|
2622
|
-
const namespaceNode = factory3.createTypeAliasDeclaration({
|
|
2623
|
-
name,
|
|
2624
|
-
type: factory3.createTypeLiteralNode(
|
|
2625
|
-
Object.keys(properties).map((key) => {
|
|
2626
|
-
const type = properties[key];
|
|
2627
|
-
if (!type) {
|
|
2628
|
-
return void 0;
|
|
2629
|
-
}
|
|
2630
|
-
return factory3.createPropertySignature({
|
|
2631
|
-
name: transformers3.pascalCase(key),
|
|
2632
|
-
type
|
|
2633
|
-
});
|
|
2634
|
-
}).filter(Boolean)
|
|
2635
|
-
),
|
|
2636
|
-
modifiers: [factory3.modifiers.export]
|
|
2637
|
-
});
|
|
2638
|
-
return print2(namespaceNode);
|
|
2639
|
-
}
|
|
2640
|
-
function OperationSchema({ keysToOmit, description }) {
|
|
2641
|
-
return /* @__PURE__ */ jsx4(Schema, { keysToOmit, description });
|
|
2642
|
-
}
|
|
2643
|
-
OperationSchema.File = function({}) {
|
|
2644
|
-
const { pluginManager, plugin, mode } = useApp3();
|
|
2645
|
-
const oas = useOas2();
|
|
2646
|
-
const { getSchemas, getFile, getName } = useOperationManager();
|
|
2647
|
-
const operation = useOperation();
|
|
2648
|
-
const file = getFile(operation);
|
|
2649
|
-
const schemas = getSchemas(operation);
|
|
2650
|
-
const factoryName = getName(operation, { type: "type" });
|
|
2651
|
-
const generator = new SchemaGenerator2(plugin.options, {
|
|
2652
|
-
oas,
|
|
2653
|
-
plugin,
|
|
2654
|
-
pluginManager,
|
|
2655
|
-
mode,
|
|
2656
|
-
override: plugin.options.override
|
|
2657
|
-
});
|
|
2658
|
-
const items = [schemas.pathParams, schemas.queryParams, schemas.headerParams, schemas.statusCodes, schemas.request, schemas.response].flat().filter(Boolean);
|
|
2659
|
-
const mapItem = ({ name, schema, description, keysToOmit, ...options }, i) => {
|
|
2660
|
-
const tree = generator.parse({ schema, name });
|
|
2661
|
-
return /* @__PURE__ */ jsxs3(Oas3.Schema, { name, value: schema, tree, children: [
|
|
2662
|
-
mode === "split" && /* @__PURE__ */ jsx4(Oas3.Schema.Imports, { isTypeOnly: true }),
|
|
2663
|
-
/* @__PURE__ */ jsx4(OperationSchema, { description, keysToOmit })
|
|
2664
|
-
] }, i);
|
|
2665
|
-
};
|
|
2666
|
-
const combinedSchemaName = operation.method === "get" ? `${factoryName}Query` : `${factoryName}Mutation`;
|
|
2667
|
-
return /* @__PURE__ */ jsxs3(File3, { baseName: file.baseName, path: file.path, meta: file.meta, children: [
|
|
2668
|
-
items.map(mapItem),
|
|
2669
|
-
/* @__PURE__ */ jsx4(File3.Source, { name: combinedSchemaName, isExportable: true, isIndexable: true, isTypeOnly: true, children: printCombinedSchema({ name: combinedSchemaName, operation, schemas, pluginManager }) })
|
|
2670
|
-
] });
|
|
2671
|
-
};
|
|
2672
|
-
|
|
2673
|
-
// src/OperationGenerator.tsx
|
|
2674
|
-
import { jsx as jsx5 } from "@kubb/react/jsx-runtime";
|
|
2675
|
-
var OperationGenerator = class extends Generator2 {
|
|
2676
|
-
async all(operations) {
|
|
2677
|
-
const { oas, pluginManager, plugin, mode } = this.context;
|
|
2678
|
-
const root = createRoot2({
|
|
2679
|
-
logger: pluginManager.logger
|
|
2680
|
-
});
|
|
2681
|
-
root.render(
|
|
2682
|
-
/* @__PURE__ */ jsx5(App2, { pluginManager, plugin, mode, children: /* @__PURE__ */ jsx5(Oas4, { oas, operations, generator: this, children: plugin.options.oasType && /* @__PURE__ */ jsx5(OasType.File, { name: "oas", typeName: "Oas" }) }) })
|
|
2683
|
-
);
|
|
2684
|
-
return root.files;
|
|
2685
|
-
}
|
|
2686
|
-
async operation(operation, options) {
|
|
2687
|
-
const { oas, pluginManager, plugin, mode } = this.context;
|
|
2688
|
-
const root = createRoot2({
|
|
2689
|
-
logger: pluginManager.logger
|
|
2690
|
-
});
|
|
2691
|
-
root.render(
|
|
2692
|
-
/* @__PURE__ */ jsx5(App2, { pluginManager, plugin: { ...plugin, options }, mode, children: /* @__PURE__ */ jsx5(Oas4, { oas, operations: [operation], generator: this, children: /* @__PURE__ */ jsx5(Oas4.Operation, { operation, children: /* @__PURE__ */ jsx5(OperationSchema.File, {}) }) }) })
|
|
2693
|
-
);
|
|
2694
|
-
return root.files;
|
|
2695
|
-
}
|
|
2696
|
-
};
|
|
2697
|
-
|
|
2698
|
-
// src/plugin.ts
|
|
2699
|
-
var pluginTsName = "plugin-ts";
|
|
2700
|
-
var pluginTs = createPlugin((options) => {
|
|
2701
|
-
const {
|
|
2702
|
-
output = { path: "types" },
|
|
2703
|
-
group,
|
|
2704
|
-
exclude = [],
|
|
2705
|
-
include,
|
|
2706
|
-
override = [],
|
|
2707
|
-
enumType = "asConst",
|
|
2708
|
-
enumSuffix = "",
|
|
2709
|
-
dateType = "string",
|
|
2710
|
-
unknownType = "any",
|
|
2711
|
-
optionalType = "questionToken",
|
|
2712
|
-
transformers: transformers4 = {},
|
|
2713
|
-
oasType = false,
|
|
2714
|
-
mapper = {}
|
|
2715
|
-
} = options;
|
|
2716
|
-
const template = group?.output ? group.output : `${output.path}/{{tag}}Controller`;
|
|
2717
|
-
return {
|
|
2718
|
-
name: pluginTsName,
|
|
2719
|
-
output: {
|
|
2720
|
-
exportType: "barrelNamed",
|
|
2721
|
-
...output
|
|
2722
|
-
},
|
|
2723
|
-
options: {
|
|
2724
|
-
extName: output.extName,
|
|
2725
|
-
transformers: transformers4,
|
|
2726
|
-
dateType,
|
|
2727
|
-
optionalType,
|
|
2728
|
-
oasType,
|
|
2729
|
-
enumType,
|
|
2730
|
-
enumSuffix,
|
|
2731
|
-
// keep the used enumnames between SchemaGenerator and OperationGenerator per plugin(pluginKey)
|
|
2732
|
-
usedEnumNames: {},
|
|
2733
|
-
unknownType,
|
|
2734
|
-
override,
|
|
2735
|
-
mapper
|
|
2736
|
-
},
|
|
2737
|
-
pre: [pluginOasName],
|
|
2738
|
-
resolvePath(baseName, pathMode, options2) {
|
|
2739
|
-
const root = path.resolve(this.config.root, this.config.output.path);
|
|
2740
|
-
const mode = pathMode ?? FileManager.getMode(path.resolve(root, output.path));
|
|
2741
|
-
if (mode === "single") {
|
|
2742
|
-
return path.resolve(root, output.path);
|
|
2743
|
-
}
|
|
2744
|
-
if (options2?.tag && group?.type === "tag") {
|
|
2745
|
-
const tag = camelCase(options2.tag);
|
|
2746
|
-
return path.resolve(root, renderTemplate(template, { tag }), baseName);
|
|
2747
|
-
}
|
|
2748
|
-
return path.resolve(root, output.path, baseName);
|
|
2749
|
-
},
|
|
2750
|
-
resolveName(name, type) {
|
|
2751
|
-
const resolvedName = pascalCase(name, { isFile: type === "file" });
|
|
2752
|
-
if (type) {
|
|
2753
|
-
return transformers4?.name?.(resolvedName, type) || resolvedName;
|
|
2754
|
-
}
|
|
2755
|
-
return resolvedName;
|
|
2756
|
-
},
|
|
2757
|
-
async buildStart() {
|
|
2758
|
-
const [swaggerPlugin] = PluginManager.getDependedPlugins(this.plugins, [pluginOasName]);
|
|
2759
|
-
const oas = await swaggerPlugin.context.getOas();
|
|
2760
|
-
const root = path.resolve(this.config.root, this.config.output.path);
|
|
2761
|
-
const mode = FileManager.getMode(path.resolve(root, output.path));
|
|
2762
|
-
const schemaGenerator = new SchemaGenerator2(this.plugin.options, {
|
|
2763
|
-
oas,
|
|
2764
|
-
pluginManager: this.pluginManager,
|
|
2765
|
-
plugin: this.plugin,
|
|
2766
|
-
contentType: swaggerPlugin.context.contentType,
|
|
2767
|
-
include: void 0,
|
|
2768
|
-
override,
|
|
2769
|
-
mode,
|
|
2770
|
-
output: output.path
|
|
2771
|
-
});
|
|
2772
|
-
const schemaFiles = await schemaGenerator.build();
|
|
2773
|
-
await this.addFile(...schemaFiles);
|
|
2774
|
-
const operationGenerator = new OperationGenerator(this.plugin.options, {
|
|
2775
|
-
oas,
|
|
2776
|
-
pluginManager: this.pluginManager,
|
|
2777
|
-
plugin: this.plugin,
|
|
2778
|
-
contentType: swaggerPlugin.context.contentType,
|
|
2779
|
-
exclude,
|
|
2780
|
-
include,
|
|
2781
|
-
override,
|
|
2782
|
-
mode
|
|
2783
|
-
});
|
|
2784
|
-
const operationFiles = await operationGenerator.build();
|
|
2785
|
-
await this.addFile(...operationFiles);
|
|
2786
|
-
if (this.config.output.exportType) {
|
|
2787
|
-
const barrelFiles = await this.fileManager.getBarrelFiles({
|
|
2788
|
-
root,
|
|
2789
|
-
output,
|
|
2790
|
-
files: this.fileManager.files,
|
|
2791
|
-
meta: {
|
|
2792
|
-
pluginKey: this.plugin.key
|
|
2793
|
-
},
|
|
2794
|
-
logger: this.logger
|
|
2795
|
-
});
|
|
2796
|
-
await this.addFile(...barrelFiles);
|
|
2797
|
-
}
|
|
2798
|
-
}
|
|
2799
|
-
};
|
|
2800
|
-
});
|
|
2801
|
-
|
|
2802
|
-
export {
|
|
2803
|
-
OasType,
|
|
2804
|
-
Schema,
|
|
2805
|
-
OperationSchema,
|
|
2806
|
-
pluginTsName,
|
|
2807
|
-
pluginTs
|
|
2808
|
-
};
|
|
2809
2494
|
/*! Bundled license information:
|
|
2810
2495
|
|
|
2811
2496
|
react/cjs/react.production.min.js:
|
|
@@ -2830,4 +2515,7 @@ react/cjs/react.development.js:
|
|
|
2830
2515
|
* LICENSE file in the root directory of this source tree.
|
|
2831
2516
|
*)
|
|
2832
2517
|
*/
|
|
2833
|
-
|
|
2518
|
+
|
|
2519
|
+
export { OasType, Type2 as Type, init_esm_shims };
|
|
2520
|
+
//# sourceMappingURL=chunk-AG2BUY33.js.map
|
|
2521
|
+
//# sourceMappingURL=chunk-AG2BUY33.js.map
|