@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
|
@@ -1,14 +1,74 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
2
|
|
|
3
|
+
var react = require('@kubb/react');
|
|
4
|
+
var jsxRuntime = require('@kubb/react/jsx-runtime');
|
|
5
|
+
var transformers2 = require('@kubb/core/transformers');
|
|
6
|
+
var parserTs = require('@kubb/parser-ts');
|
|
7
|
+
var factory = require('@kubb/parser-ts/factory');
|
|
8
|
+
var pluginOas = require('@kubb/plugin-oas');
|
|
3
9
|
|
|
10
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
4
11
|
|
|
5
|
-
|
|
12
|
+
function _interopNamespace(e) {
|
|
13
|
+
if (e && e.__esModule) return e;
|
|
14
|
+
var n = Object.create(null);
|
|
15
|
+
if (e) {
|
|
16
|
+
Object.keys(e).forEach(function (k) {
|
|
17
|
+
if (k !== 'default') {
|
|
18
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
19
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
20
|
+
enumerable: true,
|
|
21
|
+
get: function () { return e[k]; }
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
n.default = e;
|
|
27
|
+
return Object.freeze(n);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
var transformers2__default = /*#__PURE__*/_interopDefault(transformers2);
|
|
31
|
+
var factory__namespace = /*#__PURE__*/_interopNamespace(factory);
|
|
32
|
+
|
|
33
|
+
var __create = Object.create;
|
|
34
|
+
var __defProp = Object.defineProperty;
|
|
35
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
36
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
37
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
38
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
39
|
+
var __esm = (fn, res) => function __init() {
|
|
40
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
41
|
+
};
|
|
42
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
43
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
44
|
+
};
|
|
45
|
+
var __copyProps = (to, from, except, desc) => {
|
|
46
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
47
|
+
for (let key of __getOwnPropNames(from))
|
|
48
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
49
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
50
|
+
}
|
|
51
|
+
return to;
|
|
52
|
+
};
|
|
53
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
54
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
55
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
56
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
57
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
58
|
+
__defProp(target, "default", { value: mod, enumerable: true }) ,
|
|
59
|
+
mod
|
|
60
|
+
));
|
|
61
|
+
|
|
62
|
+
// ../../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/cjs_shims.js
|
|
63
|
+
var init_cjs_shims = __esm({
|
|
64
|
+
"../../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/cjs_shims.js"() {
|
|
65
|
+
}
|
|
66
|
+
});
|
|
6
67
|
|
|
7
68
|
// ../../node_modules/.pnpm/react@18.3.1/node_modules/react/cjs/react.production.min.js
|
|
8
|
-
var require_react_production_min =
|
|
69
|
+
var require_react_production_min = __commonJS({
|
|
9
70
|
"../../node_modules/.pnpm/react@18.3.1/node_modules/react/cjs/react.production.min.js"(exports) {
|
|
10
|
-
|
|
11
|
-
_chunkSEH6NUCXcjs.init_cjs_shims.call(void 0, );
|
|
71
|
+
init_cjs_shims();
|
|
12
72
|
var l = Symbol.for("react.element");
|
|
13
73
|
var n = Symbol.for("react.portal");
|
|
14
74
|
var p = Symbol.for("react.fragment");
|
|
@@ -279,13 +339,11 @@ var require_react_production_min = _chunkSEH6NUCXcjs.__commonJS.call(void 0, {
|
|
|
279
339
|
});
|
|
280
340
|
|
|
281
341
|
// ../../node_modules/.pnpm/react@18.3.1/node_modules/react/cjs/react.development.js
|
|
282
|
-
var require_react_development =
|
|
342
|
+
var require_react_development = __commonJS({
|
|
283
343
|
"../../node_modules/.pnpm/react@18.3.1/node_modules/react/cjs/react.development.js"(exports, module) {
|
|
284
|
-
|
|
285
|
-
_chunkSEH6NUCXcjs.init_cjs_shims.call(void 0, );
|
|
344
|
+
init_cjs_shims();
|
|
286
345
|
if (process.env.NODE_ENV !== "production") {
|
|
287
346
|
(function() {
|
|
288
|
-
"use strict";
|
|
289
347
|
if (typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== "undefined" && typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart === "function") {
|
|
290
348
|
__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(new Error());
|
|
291
349
|
}
|
|
@@ -2154,10 +2212,9 @@ var require_react_development = _chunkSEH6NUCXcjs.__commonJS.call(void 0, {
|
|
|
2154
2212
|
});
|
|
2155
2213
|
|
|
2156
2214
|
// ../../node_modules/.pnpm/react@18.3.1/node_modules/react/index.js
|
|
2157
|
-
var require_react =
|
|
2215
|
+
var require_react = __commonJS({
|
|
2158
2216
|
"../../node_modules/.pnpm/react@18.3.1/node_modules/react/index.js"(exports, module) {
|
|
2159
|
-
|
|
2160
|
-
_chunkSEH6NUCXcjs.init_cjs_shims.call(void 0, );
|
|
2217
|
+
init_cjs_shims();
|
|
2161
2218
|
if (process.env.NODE_ENV === "production") {
|
|
2162
2219
|
module.exports = require_react_production_min();
|
|
2163
2220
|
} else {
|
|
@@ -2166,125 +2223,65 @@ var require_react = _chunkSEH6NUCXcjs.__commonJS.call(void 0, {
|
|
|
2166
2223
|
}
|
|
2167
2224
|
});
|
|
2168
2225
|
|
|
2169
|
-
// src/index.ts
|
|
2170
|
-
|
|
2171
|
-
|
|
2172
|
-
// src/plugin.ts
|
|
2173
|
-
_chunkSEH6NUCXcjs.init_cjs_shims.call(void 0, );
|
|
2174
|
-
var _path = require('path'); var _path2 = _interopRequireDefault(_path);
|
|
2175
|
-
var _core = require('@kubb/core');
|
|
2176
|
-
var _transformers = require('@kubb/core/transformers'); var _transformers2 = _interopRequireDefault(_transformers);
|
|
2177
|
-
var _utils = require('@kubb/core/utils');
|
|
2178
|
-
var _pluginoas = require('@kubb/plugin-oas');
|
|
2179
|
-
|
|
2180
|
-
// src/OperationGenerator.tsx
|
|
2181
|
-
_chunkSEH6NUCXcjs.init_cjs_shims.call(void 0, );
|
|
2182
|
-
|
|
2183
|
-
var _components = require('@kubb/plugin-oas/components');
|
|
2184
|
-
var _react = require('@kubb/react');
|
|
2226
|
+
// src/components/index.ts
|
|
2227
|
+
init_cjs_shims();
|
|
2185
2228
|
|
|
2186
2229
|
// src/components/OasType.tsx
|
|
2187
|
-
|
|
2188
|
-
|
|
2189
|
-
|
|
2190
|
-
|
|
2191
|
-
|
|
2192
|
-
|
|
2193
|
-
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.File.Source, { name, isExportable: true, isIndexable: true, children: `export const ${name} = ${JSON.stringify(api, void 0, 2)} as const` }),
|
|
2194
|
-
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "br", {}),
|
|
2195
|
-
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.File.Source, { name: typeName, isExportable: true, isIndexable: true, isTypeOnly: true, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.Type, { name: typeName, export: true, children: `Infer<typeof ${name}>` }) })
|
|
2230
|
+
init_cjs_shims();
|
|
2231
|
+
function OasType({ name, typeName, api }) {
|
|
2232
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
2233
|
+
/* @__PURE__ */ jsxRuntime.jsx(react.File.Source, { name, isExportable: true, isIndexable: true, children: `export const ${name} = ${JSON.stringify(api, void 0, 2)} as const` }),
|
|
2234
|
+
/* @__PURE__ */ jsxRuntime.jsx("br", {}),
|
|
2235
|
+
/* @__PURE__ */ jsxRuntime.jsx(react.File.Source, { name: typeName, isExportable: true, isIndexable: true, isTypeOnly: true, children: /* @__PURE__ */ jsxRuntime.jsx(react.Type, { name: typeName, export: true, children: `Infer<typeof ${name}>` }) })
|
|
2196
2236
|
] });
|
|
2197
2237
|
}
|
|
2198
|
-
var defaultTemplates = { default: Template };
|
|
2199
|
-
function OasType({ name, typeName, Template: Template2 = defaultTemplates.default }) {
|
|
2200
|
-
const oas = _hooks.useOas.call(void 0, );
|
|
2201
|
-
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, Template2, { name, typeName, api: oas.api });
|
|
2202
|
-
}
|
|
2203
|
-
OasType.File = function({ name, typeName, templates = defaultTemplates }) {
|
|
2204
|
-
const {
|
|
2205
|
-
pluginManager,
|
|
2206
|
-
plugin: { key: pluginKey }
|
|
2207
|
-
} = _react.useApp.call(void 0, );
|
|
2208
|
-
const file = pluginManager.getFile({ name, extName: ".ts", pluginKey });
|
|
2209
|
-
const Template2 = templates.default;
|
|
2210
|
-
return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _react.File, { baseName: file.baseName, path: file.path, meta: file.meta, children: [
|
|
2211
|
-
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.File.Import, { name: ["Infer"], path: "@kubb/oas", isTypeOnly: true }),
|
|
2212
|
-
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, OasType, { Template: Template2, name, typeName })
|
|
2213
|
-
] });
|
|
2214
|
-
};
|
|
2215
|
-
OasType.templates = defaultTemplates;
|
|
2216
|
-
|
|
2217
|
-
// src/components/OperationSchema.tsx
|
|
2218
|
-
_chunkSEH6NUCXcjs.init_cjs_shims.call(void 0, );
|
|
2219
|
-
|
|
2220
|
-
var _parserts = require('@kubb/parser-ts');
|
|
2221
|
-
var _factory = require('@kubb/parser-ts/factory'); var factory3 = _interopRequireWildcard(_factory); var factory2 = _interopRequireWildcard(_factory); var factory = _interopRequireWildcard(_factory);
|
|
2222
|
-
|
|
2223
|
-
|
|
2224
|
-
|
|
2225
|
-
|
|
2226
|
-
// src/SchemaGenerator.tsx
|
|
2227
|
-
_chunkSEH6NUCXcjs.init_cjs_shims.call(void 0, );
|
|
2228
|
-
|
|
2229
|
-
|
|
2230
|
-
|
|
2231
|
-
|
|
2232
|
-
// src/components/Schema.tsx
|
|
2233
|
-
_chunkSEH6NUCXcjs.init_cjs_shims.call(void 0, );
|
|
2234
|
-
var import_react3 = _chunkSEH6NUCXcjs.__toESM.call(void 0, require_react(), 1);
|
|
2235
|
-
|
|
2236
|
-
|
|
2237
|
-
|
|
2238
|
-
|
|
2239
|
-
|
|
2240
|
-
|
|
2241
2238
|
|
|
2239
|
+
// src/components/Type.tsx
|
|
2240
|
+
init_cjs_shims();
|
|
2241
|
+
var import_react3 = __toESM(require_react());
|
|
2242
2242
|
|
|
2243
2243
|
// src/parser/index.ts
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
|
|
2247
|
-
|
|
2244
|
+
init_cjs_shims();
|
|
2248
2245
|
var typeKeywordMapper = {
|
|
2249
|
-
any: () =>
|
|
2250
|
-
unknown: () =>
|
|
2251
|
-
number: () =>
|
|
2252
|
-
integer: () =>
|
|
2246
|
+
any: () => factory__namespace.keywordTypeNodes.any,
|
|
2247
|
+
unknown: () => factory__namespace.keywordTypeNodes.unknown,
|
|
2248
|
+
number: () => factory__namespace.keywordTypeNodes.number,
|
|
2249
|
+
integer: () => factory__namespace.keywordTypeNodes.number,
|
|
2253
2250
|
object: (nodes) => {
|
|
2254
2251
|
if (!nodes || !nodes.length) {
|
|
2255
|
-
return
|
|
2252
|
+
return factory__namespace.keywordTypeNodes.object;
|
|
2256
2253
|
}
|
|
2257
|
-
return
|
|
2254
|
+
return factory__namespace.createTypeLiteralNode(nodes);
|
|
2258
2255
|
},
|
|
2259
|
-
string: () =>
|
|
2260
|
-
boolean: () =>
|
|
2261
|
-
undefined: () =>
|
|
2256
|
+
string: () => factory__namespace.keywordTypeNodes.string,
|
|
2257
|
+
boolean: () => factory__namespace.keywordTypeNodes.boolean,
|
|
2258
|
+
undefined: () => factory__namespace.keywordTypeNodes.undefined,
|
|
2262
2259
|
nullable: void 0,
|
|
2263
|
-
null: () =>
|
|
2260
|
+
null: () => factory__namespace.keywordTypeNodes.null,
|
|
2264
2261
|
nullish: void 0,
|
|
2265
2262
|
array: (nodes) => {
|
|
2266
2263
|
if (!nodes) {
|
|
2267
2264
|
return void 0;
|
|
2268
2265
|
}
|
|
2269
|
-
return
|
|
2266
|
+
return factory__namespace.createArrayDeclaration({ nodes });
|
|
2270
2267
|
},
|
|
2271
2268
|
tuple: (nodes) => {
|
|
2272
2269
|
if (!nodes) {
|
|
2273
2270
|
return void 0;
|
|
2274
2271
|
}
|
|
2275
|
-
return
|
|
2272
|
+
return factory__namespace.createTupleTypeNode(nodes);
|
|
2276
2273
|
},
|
|
2277
2274
|
enum: (name) => {
|
|
2278
2275
|
if (!name) {
|
|
2279
2276
|
return void 0;
|
|
2280
2277
|
}
|
|
2281
|
-
return
|
|
2278
|
+
return factory__namespace.createTypeReferenceNode(name, void 0);
|
|
2282
2279
|
},
|
|
2283
2280
|
union: (nodes) => {
|
|
2284
2281
|
if (!nodes) {
|
|
2285
2282
|
return void 0;
|
|
2286
2283
|
}
|
|
2287
|
-
return
|
|
2284
|
+
return factory__namespace.createUnionDeclaration({
|
|
2288
2285
|
withParentheses: true,
|
|
2289
2286
|
nodes
|
|
2290
2287
|
});
|
|
@@ -2293,14 +2290,20 @@ var typeKeywordMapper = {
|
|
|
2293
2290
|
if (!name) {
|
|
2294
2291
|
return void 0;
|
|
2295
2292
|
}
|
|
2296
|
-
if (format === "
|
|
2297
|
-
|
|
2293
|
+
if (format === "boolean") {
|
|
2294
|
+
if (name === true) {
|
|
2295
|
+
return factory__namespace.createLiteralTypeNode(factory__namespace.createTrue());
|
|
2296
|
+
}
|
|
2297
|
+
return factory__namespace.createLiteralTypeNode(factory__namespace.createFalse());
|
|
2298
|
+
}
|
|
2299
|
+
if (format === "number" && typeof name === "number") {
|
|
2300
|
+
return factory__namespace.createLiteralTypeNode(factory__namespace.createNumericLiteral(name));
|
|
2298
2301
|
}
|
|
2299
|
-
return
|
|
2302
|
+
return factory__namespace.createLiteralTypeNode(factory__namespace.createStringLiteral(name.toString()));
|
|
2300
2303
|
},
|
|
2301
|
-
datetime: () =>
|
|
2302
|
-
date: (type = "string") => type === "string" ?
|
|
2303
|
-
time: (type = "string") => type === "string" ?
|
|
2304
|
+
datetime: () => factory__namespace.keywordTypeNodes.string,
|
|
2305
|
+
date: (type = "string") => type === "string" ? factory__namespace.keywordTypeNodes.string : factory__namespace.createTypeReferenceNode(factory__namespace.createIdentifier("Date")),
|
|
2306
|
+
time: (type = "string") => type === "string" ? factory__namespace.keywordTypeNodes.string : factory__namespace.createTypeReferenceNode(factory__namespace.createIdentifier("Date")),
|
|
2304
2307
|
uuid: void 0,
|
|
2305
2308
|
url: void 0,
|
|
2306
2309
|
strict: void 0,
|
|
@@ -2309,7 +2312,7 @@ var typeKeywordMapper = {
|
|
|
2309
2312
|
if (!nodes) {
|
|
2310
2313
|
return void 0;
|
|
2311
2314
|
}
|
|
2312
|
-
return
|
|
2315
|
+
return factory__namespace.createIntersectionDeclaration({
|
|
2313
2316
|
withParentheses: true,
|
|
2314
2317
|
nodes
|
|
2315
2318
|
});
|
|
@@ -2325,13 +2328,14 @@ var typeKeywordMapper = {
|
|
|
2325
2328
|
password: void 0,
|
|
2326
2329
|
phone: void 0,
|
|
2327
2330
|
readOnly: void 0,
|
|
2331
|
+
writeOnly: void 0,
|
|
2328
2332
|
ref: (propertyName) => {
|
|
2329
2333
|
if (!propertyName) {
|
|
2330
2334
|
return void 0;
|
|
2331
2335
|
}
|
|
2332
|
-
return
|
|
2336
|
+
return factory__namespace.createTypeReferenceNode(propertyName, void 0);
|
|
2333
2337
|
},
|
|
2334
|
-
blob: () =>
|
|
2338
|
+
blob: () => factory__namespace.createTypeReferenceNode("Blob", []),
|
|
2335
2339
|
deprecated: void 0,
|
|
2336
2340
|
example: void 0,
|
|
2337
2341
|
schema: void 0,
|
|
@@ -2343,94 +2347,94 @@ function parse(parent, current, options) {
|
|
|
2343
2347
|
if (!value) {
|
|
2344
2348
|
return void 0;
|
|
2345
2349
|
}
|
|
2346
|
-
if (
|
|
2350
|
+
if (pluginOas.isKeyword(current, pluginOas.schemaKeywords.union)) {
|
|
2347
2351
|
return typeKeywordMapper.union(current.args.map((schema) => parse(current, schema, options)).filter(Boolean));
|
|
2348
2352
|
}
|
|
2349
|
-
if (
|
|
2353
|
+
if (pluginOas.isKeyword(current, pluginOas.schemaKeywords.and)) {
|
|
2350
2354
|
return typeKeywordMapper.and(current.args.map((schema) => parse(current, schema, options)).filter(Boolean));
|
|
2351
2355
|
}
|
|
2352
|
-
if (
|
|
2356
|
+
if (pluginOas.isKeyword(current, pluginOas.schemaKeywords.array)) {
|
|
2353
2357
|
return typeKeywordMapper.array(current.args.items.map((schema) => parse(current, schema, options)).filter(Boolean));
|
|
2354
2358
|
}
|
|
2355
|
-
if (
|
|
2359
|
+
if (pluginOas.isKeyword(current, pluginOas.schemaKeywords.enum)) {
|
|
2356
2360
|
return typeKeywordMapper.enum(current.args.typeName);
|
|
2357
2361
|
}
|
|
2358
|
-
if (
|
|
2362
|
+
if (pluginOas.isKeyword(current, pluginOas.schemaKeywords.ref)) {
|
|
2359
2363
|
return typeKeywordMapper.ref(current.args.name);
|
|
2360
2364
|
}
|
|
2361
|
-
if (
|
|
2365
|
+
if (pluginOas.isKeyword(current, pluginOas.schemaKeywords.blob)) {
|
|
2362
2366
|
return value();
|
|
2363
2367
|
}
|
|
2364
|
-
if (
|
|
2368
|
+
if (pluginOas.isKeyword(current, pluginOas.schemaKeywords.tuple)) {
|
|
2365
2369
|
return typeKeywordMapper.tuple(current.args.items.map((schema) => parse(current, schema, options)).filter(Boolean));
|
|
2366
2370
|
}
|
|
2367
|
-
if (
|
|
2371
|
+
if (pluginOas.isKeyword(current, pluginOas.schemaKeywords.const)) {
|
|
2368
2372
|
return typeKeywordMapper.const(current.args.name, current.args.format);
|
|
2369
2373
|
}
|
|
2370
|
-
if (
|
|
2371
|
-
const properties = Object.entries(
|
|
2374
|
+
if (pluginOas.isKeyword(current, pluginOas.schemaKeywords.object)) {
|
|
2375
|
+
const properties = Object.entries(current.args?.properties || {}).filter((item) => {
|
|
2372
2376
|
const schemas = item[1];
|
|
2373
2377
|
return schemas && typeof schemas.map === "function";
|
|
2374
2378
|
}).map(([name, schemas]) => {
|
|
2375
|
-
const nameSchema = schemas.find((schema) => schema.keyword ===
|
|
2376
|
-
const mappedName =
|
|
2377
|
-
if (
|
|
2378
|
-
return
|
|
2379
|
+
const nameSchema = schemas.find((schema) => schema.keyword === pluginOas.schemaKeywords.name);
|
|
2380
|
+
const mappedName = nameSchema?.args || name;
|
|
2381
|
+
if (options.mapper?.[mappedName]) {
|
|
2382
|
+
return options.mapper?.[mappedName];
|
|
2379
2383
|
}
|
|
2380
|
-
const isNullish = schemas.some((schema) => schema.keyword ===
|
|
2381
|
-
const isNullable = schemas.some((schema) => schema.keyword ===
|
|
2382
|
-
const isOptional = schemas.some((schema) => schema.keyword ===
|
|
2383
|
-
const isReadonly = schemas.some((schema) => schema.keyword ===
|
|
2384
|
-
const describeSchema = schemas.find((schema) => schema.keyword ===
|
|
2385
|
-
const deprecatedSchema = schemas.find((schema) => schema.keyword ===
|
|
2386
|
-
const defaultSchema = schemas.find((schema) => schema.keyword ===
|
|
2387
|
-
const exampleSchema = schemas.find((schema) => schema.keyword ===
|
|
2388
|
-
const schemaSchema = schemas.find((schema) => schema.keyword ===
|
|
2384
|
+
const isNullish = schemas.some((schema) => schema.keyword === pluginOas.schemaKeywords.nullish);
|
|
2385
|
+
const isNullable = schemas.some((schema) => schema.keyword === pluginOas.schemaKeywords.nullable);
|
|
2386
|
+
const isOptional = schemas.some((schema) => schema.keyword === pluginOas.schemaKeywords.optional);
|
|
2387
|
+
const isReadonly = schemas.some((schema) => schema.keyword === pluginOas.schemaKeywords.readOnly);
|
|
2388
|
+
const describeSchema = schemas.find((schema) => schema.keyword === pluginOas.schemaKeywords.describe);
|
|
2389
|
+
const deprecatedSchema = schemas.find((schema) => schema.keyword === pluginOas.schemaKeywords.deprecated);
|
|
2390
|
+
const defaultSchema = schemas.find((schema) => schema.keyword === pluginOas.schemaKeywords.default);
|
|
2391
|
+
const exampleSchema = schemas.find((schema) => schema.keyword === pluginOas.schemaKeywords.example);
|
|
2392
|
+
const schemaSchema = schemas.find((schema) => schema.keyword === pluginOas.schemaKeywords.schema);
|
|
2389
2393
|
let type = schemas.map((schema) => parse(current, schema, options)).filter(Boolean)[0];
|
|
2390
2394
|
if (isNullable) {
|
|
2391
|
-
type =
|
|
2392
|
-
nodes: [type,
|
|
2395
|
+
type = factory__namespace.createUnionDeclaration({
|
|
2396
|
+
nodes: [type, factory__namespace.keywordTypeNodes.null]
|
|
2393
2397
|
});
|
|
2394
2398
|
}
|
|
2395
2399
|
if (isNullish && ["undefined", "questionTokenAndUndefined"].includes(options.optionalType)) {
|
|
2396
|
-
type =
|
|
2397
|
-
nodes: [type,
|
|
2400
|
+
type = factory__namespace.createUnionDeclaration({
|
|
2401
|
+
nodes: [type, factory__namespace.keywordTypeNodes.undefined]
|
|
2398
2402
|
});
|
|
2399
2403
|
}
|
|
2400
2404
|
if (isOptional && ["undefined", "questionTokenAndUndefined"].includes(options.optionalType)) {
|
|
2401
|
-
type =
|
|
2402
|
-
nodes: [type,
|
|
2405
|
+
type = factory__namespace.createUnionDeclaration({
|
|
2406
|
+
nodes: [type, factory__namespace.keywordTypeNodes.undefined]
|
|
2403
2407
|
});
|
|
2404
2408
|
}
|
|
2405
|
-
const propertySignature =
|
|
2409
|
+
const propertySignature = factory__namespace.createPropertySignature({
|
|
2406
2410
|
questionToken: isOptional || isNullish ? ["questionToken", "questionTokenAndUndefined"].includes(options.optionalType) : false,
|
|
2407
2411
|
name: mappedName,
|
|
2408
2412
|
type,
|
|
2409
2413
|
readOnly: isReadonly
|
|
2410
2414
|
});
|
|
2411
|
-
return
|
|
2415
|
+
return factory__namespace.appendJSDocToNode({
|
|
2412
2416
|
node: propertySignature,
|
|
2413
2417
|
comments: [
|
|
2414
|
-
describeSchema ? `@description ${
|
|
2418
|
+
describeSchema ? `@description ${transformers2__default.default.jsStringEscape(describeSchema.args)}` : void 0,
|
|
2415
2419
|
deprecatedSchema ? "@deprecated" : void 0,
|
|
2416
2420
|
defaultSchema ? `@default ${defaultSchema.args}` : void 0,
|
|
2417
2421
|
exampleSchema ? `@example ${exampleSchema.args}` : void 0,
|
|
2418
|
-
|
|
2422
|
+
schemaSchema?.args?.type || schemaSchema?.args?.format ? [`@type ${schemaSchema?.args?.type || "unknown"}${!isOptional ? "" : " | undefined"}`, schemaSchema?.args?.format].filter(Boolean).join(", ") : void 0
|
|
2419
2423
|
].filter(Boolean)
|
|
2420
2424
|
});
|
|
2421
2425
|
});
|
|
2422
|
-
const additionalProperties =
|
|
2426
|
+
const additionalProperties = current.args?.additionalProperties?.length ? factory__namespace.createIndexSignature(
|
|
2423
2427
|
current.args.additionalProperties.map((schema) => parse(current, schema, options)).filter(Boolean).at(0)
|
|
2424
2428
|
) : void 0;
|
|
2425
2429
|
return typeKeywordMapper.object([...properties, additionalProperties].filter(Boolean));
|
|
2426
2430
|
}
|
|
2427
|
-
if (
|
|
2431
|
+
if (pluginOas.isKeyword(current, pluginOas.schemaKeywords.datetime)) {
|
|
2428
2432
|
return typeKeywordMapper.datetime();
|
|
2429
2433
|
}
|
|
2430
|
-
if (
|
|
2434
|
+
if (pluginOas.isKeyword(current, pluginOas.schemaKeywords.date)) {
|
|
2431
2435
|
return typeKeywordMapper.date(current.args.type);
|
|
2432
2436
|
}
|
|
2433
|
-
if (
|
|
2437
|
+
if (pluginOas.isKeyword(current, pluginOas.schemaKeywords.time)) {
|
|
2434
2438
|
return typeKeywordMapper.time(current.args.type);
|
|
2435
2439
|
}
|
|
2436
2440
|
if (current.keyword in typeKeywordMapper) {
|
|
@@ -2438,42 +2442,18 @@ function parse(parent, current, options) {
|
|
|
2438
2442
|
}
|
|
2439
2443
|
return void 0;
|
|
2440
2444
|
}
|
|
2441
|
-
|
|
2442
|
-
// src/components/Schema.tsx
|
|
2443
|
-
|
|
2444
|
-
function Schema(props) {
|
|
2445
|
-
const { keysToOmit, description } = props;
|
|
2446
|
-
const { tree, name } = _hooks.useSchema.call(void 0, );
|
|
2447
|
-
const {
|
|
2448
|
-
pluginManager,
|
|
2449
|
-
plugin: {
|
|
2450
|
-
options: { mapper, enumType, optionalType }
|
|
2451
|
-
}
|
|
2452
|
-
} = _react.useApp.call(void 0, );
|
|
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
|
-
});
|
|
2445
|
+
function Type2({ name, typedName, tree, keysToOmit, optionalType, enumType, mapper, description }) {
|
|
2466
2446
|
const typeNodes = [];
|
|
2467
2447
|
if (!tree.length) {
|
|
2468
2448
|
return "";
|
|
2469
2449
|
}
|
|
2470
|
-
const isNullish = tree.some((item) => item.keyword ===
|
|
2471
|
-
const isNullable = tree.some((item) => item.keyword ===
|
|
2472
|
-
const isOptional = tree.some((item) => item.keyword ===
|
|
2450
|
+
const isNullish = tree.some((item) => item.keyword === pluginOas.schemaKeywords.nullish);
|
|
2451
|
+
const isNullable = tree.some((item) => item.keyword === pluginOas.schemaKeywords.nullable);
|
|
2452
|
+
const isOptional = tree.some((item) => item.keyword === pluginOas.schemaKeywords.optional);
|
|
2473
2453
|
let type = tree.map(
|
|
2474
2454
|
(schema) => parse(void 0, schema, {
|
|
2475
|
-
name
|
|
2476
|
-
typeName,
|
|
2455
|
+
name,
|
|
2456
|
+
typeName: typedName,
|
|
2477
2457
|
description,
|
|
2478
2458
|
keysToOmit,
|
|
2479
2459
|
optionalType,
|
|
@@ -2482,330 +2462,60 @@ function Schema(props) {
|
|
|
2482
2462
|
})
|
|
2483
2463
|
).filter(Boolean).at(0) || typeKeywordMapper.undefined();
|
|
2484
2464
|
if (isNullable) {
|
|
2485
|
-
type =
|
|
2486
|
-
nodes: [type,
|
|
2465
|
+
type = factory__namespace.createUnionDeclaration({
|
|
2466
|
+
nodes: [type, factory__namespace.keywordTypeNodes.null]
|
|
2487
2467
|
});
|
|
2488
2468
|
}
|
|
2489
2469
|
if (isNullish && ["undefined", "questionTokenAndUndefined"].includes(optionalType)) {
|
|
2490
|
-
type =
|
|
2491
|
-
nodes: [type,
|
|
2470
|
+
type = factory__namespace.createUnionDeclaration({
|
|
2471
|
+
nodes: [type, factory__namespace.keywordTypeNodes.undefined]
|
|
2492
2472
|
});
|
|
2493
2473
|
}
|
|
2494
2474
|
if (isOptional && ["undefined", "questionTokenAndUndefined"].includes(optionalType)) {
|
|
2495
|
-
type =
|
|
2496
|
-
nodes: [type,
|
|
2475
|
+
type = factory__namespace.createUnionDeclaration({
|
|
2476
|
+
nodes: [type, factory__namespace.keywordTypeNodes.undefined]
|
|
2497
2477
|
});
|
|
2498
2478
|
}
|
|
2499
|
-
const node =
|
|
2500
|
-
modifiers: [
|
|
2501
|
-
name
|
|
2502
|
-
type:
|
|
2479
|
+
const node = factory__namespace.createTypeAliasDeclaration({
|
|
2480
|
+
modifiers: [factory__namespace.modifiers.export],
|
|
2481
|
+
name,
|
|
2482
|
+
type: keysToOmit?.length ? factory__namespace.createOmitDeclaration({
|
|
2503
2483
|
keys: keysToOmit,
|
|
2504
2484
|
type,
|
|
2505
2485
|
nonNullable: true
|
|
2506
2486
|
}) : type
|
|
2507
2487
|
});
|
|
2508
|
-
const enumSchemas =
|
|
2509
|
-
const enums = enumSchemas.map((enumSchema) => {
|
|
2510
|
-
const name2 = enumType === "asPascalConst" ?
|
|
2511
|
-
const
|
|
2512
|
-
const [nameNode, typeNode] =
|
|
2488
|
+
const enumSchemas = pluginOas.SchemaGenerator.deepSearch(tree, pluginOas.schemaKeywords.enum);
|
|
2489
|
+
const enums = [...new Set(enumSchemas)].map((enumSchema) => {
|
|
2490
|
+
const name2 = enumType === "asPascalConst" ? transformers2__default.default.pascalCase(enumSchema.args.name) : transformers2__default.default.camelCase(enumSchema.args.name);
|
|
2491
|
+
const typeName = enumSchema.args.typeName;
|
|
2492
|
+
const [nameNode, typeNode] = factory__namespace.createEnumDeclaration({
|
|
2513
2493
|
name: name2,
|
|
2514
|
-
typeName
|
|
2515
|
-
enums: enumSchema.args.items.map((item) => item.value === void 0 ? void 0 : [
|
|
2494
|
+
typeName,
|
|
2495
|
+
enums: enumSchema.args.items.map((item) => item.value === void 0 ? void 0 : [transformers2__default.default.trimQuotes(item.name?.toString()), item.value]).filter(Boolean),
|
|
2516
2496
|
type: enumType
|
|
2517
2497
|
});
|
|
2518
2498
|
return {
|
|
2519
2499
|
nameNode,
|
|
2520
2500
|
typeNode,
|
|
2521
2501
|
name: name2,
|
|
2522
|
-
typeName
|
|
2502
|
+
typeName
|
|
2523
2503
|
};
|
|
2524
2504
|
});
|
|
2525
2505
|
typeNodes.push(
|
|
2526
|
-
|
|
2506
|
+
factory__namespace.appendJSDocToNode({
|
|
2527
2507
|
node,
|
|
2528
|
-
comments: [description ? `@description ${
|
|
2508
|
+
comments: [description ? `@description ${transformers2__default.default.jsStringEscape(description)}` : void 0].filter(Boolean)
|
|
2529
2509
|
})
|
|
2530
2510
|
);
|
|
2531
|
-
return /* @__PURE__ */
|
|
2532
|
-
enums.map(({ name: name2, nameNode, typeName
|
|
2533
|
-
nameNode && /* @__PURE__ */
|
|
2534
|
-
/* @__PURE__ */
|
|
2511
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(import_react3.Fragment, { children: [
|
|
2512
|
+
enums.map(({ name: name2, nameNode, typeName, typeNode }, index) => /* @__PURE__ */ jsxRuntime.jsxs(import_react3.Fragment, { children: [
|
|
2513
|
+
nameNode && /* @__PURE__ */ jsxRuntime.jsx(react.File.Source, { name: name2, isExportable: true, isIndexable: true, children: parserTs.print([nameNode]) }),
|
|
2514
|
+
/* @__PURE__ */ jsxRuntime.jsx(react.File.Source, { name: typeName, isIndexable: true, isExportable: ["enum", "asConst", "constEnum", "literal", void 0].includes(enumType), isTypeOnly: true, children: parserTs.print([typeNode]) })
|
|
2535
2515
|
] }, [name2, nameNode].join("-"))),
|
|
2536
|
-
enums.every((item) => item.typeName !==
|
|
2516
|
+
enums.every((item) => item.typeName !== name) && /* @__PURE__ */ jsxRuntime.jsx(react.File.Source, { name: typedName, isTypeOnly: true, isExportable: true, isIndexable: true, children: parserTs.print(typeNodes) })
|
|
2537
2517
|
] });
|
|
2538
2518
|
}
|
|
2539
|
-
Schema.File = function({}) {
|
|
2540
|
-
const { pluginManager } = _react.useApp.call(void 0, );
|
|
2541
|
-
const { schema } = _hooks.useSchema.call(void 0, );
|
|
2542
|
-
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _components.Oas.Schema.File, { isTypeOnly: true, output: pluginManager.config.output.path, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, Schema, { description: _optionalChain([schema, 'optionalAccess', _23 => _23.description]) }) });
|
|
2543
|
-
};
|
|
2544
|
-
|
|
2545
|
-
// src/SchemaGenerator.tsx
|
|
2546
|
-
|
|
2547
|
-
var SchemaGenerator2 = class extends _pluginoas.SchemaGenerator {
|
|
2548
|
-
async schema(name, schema, options) {
|
|
2549
|
-
const { oas, pluginManager, plugin, mode, output } = this.context;
|
|
2550
|
-
const root = _react.createRoot.call(void 0, {
|
|
2551
|
-
logger: pluginManager.logger
|
|
2552
|
-
});
|
|
2553
|
-
const tree = this.parse({ schema, name });
|
|
2554
|
-
root.render(
|
|
2555
|
-
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.App, { pluginManager, plugin: { ...plugin, options }, mode, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _components.Oas, { oas, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _components.Oas.Schema, { name, value: schema, tree, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, Schema.File, {}) }) }) })
|
|
2556
|
-
);
|
|
2557
|
-
return root.files;
|
|
2558
|
-
}
|
|
2559
|
-
};
|
|
2560
|
-
|
|
2561
|
-
// src/components/OperationSchema.tsx
|
|
2562
|
-
|
|
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: _transformers2.default.pascalCase(key),
|
|
2632
|
-
type
|
|
2633
|
-
});
|
|
2634
|
-
}).filter(Boolean)
|
|
2635
|
-
),
|
|
2636
|
-
modifiers: [factory3.modifiers.export]
|
|
2637
|
-
});
|
|
2638
|
-
return _parserts.print.call(void 0, namespaceNode);
|
|
2639
|
-
}
|
|
2640
|
-
function OperationSchema({ keysToOmit, description }) {
|
|
2641
|
-
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, Schema, { keysToOmit, description });
|
|
2642
|
-
}
|
|
2643
|
-
OperationSchema.File = function({}) {
|
|
2644
|
-
const { pluginManager, plugin, mode } = _react.useApp.call(void 0, );
|
|
2645
|
-
const oas = _hooks.useOas.call(void 0, );
|
|
2646
|
-
const { getSchemas, getFile, getName } = _hooks.useOperationManager.call(void 0, );
|
|
2647
|
-
const operation = _hooks.useOperation.call(void 0, );
|
|
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__ */ _jsxruntime.jsxs.call(void 0, _components.Oas.Schema, { name, value: schema, tree, children: [
|
|
2662
|
-
mode === "split" && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _components.Oas.Schema.Imports, { isTypeOnly: true }),
|
|
2663
|
-
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, OperationSchema, { description, keysToOmit })
|
|
2664
|
-
] }, i);
|
|
2665
|
-
};
|
|
2666
|
-
const combinedSchemaName = operation.method === "get" ? `${factoryName}Query` : `${factoryName}Mutation`;
|
|
2667
|
-
return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _react.File, { baseName: file.baseName, path: file.path, meta: file.meta, children: [
|
|
2668
|
-
items.map(mapItem),
|
|
2669
|
-
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.File.Source, { name: combinedSchemaName, isExportable: true, isIndexable: true, isTypeOnly: true, children: printCombinedSchema({ name: combinedSchemaName, operation, schemas, pluginManager }) })
|
|
2670
|
-
] });
|
|
2671
|
-
};
|
|
2672
|
-
|
|
2673
|
-
// src/OperationGenerator.tsx
|
|
2674
|
-
|
|
2675
|
-
var OperationGenerator = class extends _pluginoas.OperationGenerator {
|
|
2676
|
-
async all(operations) {
|
|
2677
|
-
const { oas, pluginManager, plugin, mode } = this.context;
|
|
2678
|
-
const root = _react.createRoot.call(void 0, {
|
|
2679
|
-
logger: pluginManager.logger
|
|
2680
|
-
});
|
|
2681
|
-
root.render(
|
|
2682
|
-
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.App, { pluginManager, plugin, mode, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _components.Oas, { oas, operations, generator: this, children: plugin.options.oasType && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, 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 = _react.createRoot.call(void 0, {
|
|
2689
|
-
logger: pluginManager.logger
|
|
2690
|
-
});
|
|
2691
|
-
root.render(
|
|
2692
|
-
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.App, { pluginManager, plugin: { ...plugin, options }, mode, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _components.Oas, { oas, operations: [operation], generator: this, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _components.Oas.Operation, { operation, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, OperationSchema.File, {}) }) }) })
|
|
2693
|
-
);
|
|
2694
|
-
return root.files;
|
|
2695
|
-
}
|
|
2696
|
-
};
|
|
2697
|
-
|
|
2698
|
-
// src/plugin.ts
|
|
2699
|
-
var pluginTsName = "plugin-ts";
|
|
2700
|
-
var pluginTs = _core.createPlugin.call(void 0, (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 = _optionalChain([group, 'optionalAccess', _24 => _24.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: [_pluginoas.pluginOasName],
|
|
2738
|
-
resolvePath(baseName, pathMode, options2) {
|
|
2739
|
-
const root = _path2.default.resolve(this.config.root, this.config.output.path);
|
|
2740
|
-
const mode = _nullishCoalesce(pathMode, () => ( _core.FileManager.getMode(_path2.default.resolve(root, output.path))));
|
|
2741
|
-
if (mode === "single") {
|
|
2742
|
-
return _path2.default.resolve(root, output.path);
|
|
2743
|
-
}
|
|
2744
|
-
if (_optionalChain([options2, 'optionalAccess', _25 => _25.tag]) && _optionalChain([group, 'optionalAccess', _26 => _26.type]) === "tag") {
|
|
2745
|
-
const tag = _transformers.camelCase.call(void 0, options2.tag);
|
|
2746
|
-
return _path2.default.resolve(root, _utils.renderTemplate.call(void 0, template, { tag }), baseName);
|
|
2747
|
-
}
|
|
2748
|
-
return _path2.default.resolve(root, output.path, baseName);
|
|
2749
|
-
},
|
|
2750
|
-
resolveName(name, type) {
|
|
2751
|
-
const resolvedName = _transformers.pascalCase.call(void 0, name, { isFile: type === "file" });
|
|
2752
|
-
if (type) {
|
|
2753
|
-
return _optionalChain([transformers4, 'optionalAccess', _27 => _27.name, 'optionalCall', _28 => _28(resolvedName, type)]) || resolvedName;
|
|
2754
|
-
}
|
|
2755
|
-
return resolvedName;
|
|
2756
|
-
},
|
|
2757
|
-
async buildStart() {
|
|
2758
|
-
const [swaggerPlugin] = _core.PluginManager.getDependedPlugins(this.plugins, [_pluginoas.pluginOasName]);
|
|
2759
|
-
const oas = await swaggerPlugin.context.getOas();
|
|
2760
|
-
const root = _path2.default.resolve(this.config.root, this.config.output.path);
|
|
2761
|
-
const mode = _core.FileManager.getMode(_path2.default.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
|
-
|
|
2803
|
-
|
|
2804
|
-
|
|
2805
|
-
|
|
2806
|
-
|
|
2807
|
-
|
|
2808
|
-
exports.OasType = OasType; exports.Schema = Schema; exports.OperationSchema = OperationSchema; exports.pluginTsName = pluginTsName; exports.pluginTs = pluginTs;
|
|
2809
2519
|
/*! Bundled license information:
|
|
2810
2520
|
|
|
2811
2521
|
react/cjs/react.production.min.js:
|
|
@@ -2830,4 +2540,9 @@ react/cjs/react.development.js:
|
|
|
2830
2540
|
* LICENSE file in the root directory of this source tree.
|
|
2831
2541
|
*)
|
|
2832
2542
|
*/
|
|
2833
|
-
|
|
2543
|
+
|
|
2544
|
+
exports.OasType = OasType;
|
|
2545
|
+
exports.Type = Type2;
|
|
2546
|
+
exports.init_cjs_shims = init_cjs_shims;
|
|
2547
|
+
//# sourceMappingURL=chunk-XMTK3ZZE.cjs.map
|
|
2548
|
+
//# sourceMappingURL=chunk-XMTK3ZZE.cjs.map
|