@kubb/swagger-ts 2.18.4 → 2.18.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-H35DL3CM.cjs → chunk-DRW5SRC6.cjs} +278 -243
- package/dist/chunk-DRW5SRC6.cjs.map +1 -0
- package/dist/{chunk-NOXQZTV4.js → chunk-UJR52JIE.js} +288 -253
- package/dist/chunk-UJR52JIE.js.map +1 -0
- package/dist/components.cjs +4 -2
- package/dist/components.d.cts +20 -7
- package/dist/components.d.ts +20 -7
- package/dist/components.js +5 -3
- package/dist/index.cjs +3 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +4 -7
- package/dist/index.js.map +1 -1
- package/package.json +13 -12
- package/src/OperationGenerator.tsx +1 -19
- package/src/SchemaGenerator.tsx +10 -48
- package/src/components/OperationSchema.tsx +62 -20
- package/src/components/Schema.tsx +135 -0
- package/src/components/__snapshots__/Schema/pets.ts +0 -4
- package/src/components/__snapshots__/Schema/showPetById.ts +0 -4
- package/src/components/index.ts +1 -0
- package/src/{typeParser.ts → parser/index.ts} +8 -90
- package/src/plugin.ts +3 -3
- package/src/types.ts +2 -1
- package/dist/chunk-H35DL3CM.cjs.map +0 -1
- package/dist/chunk-NOXQZTV4.js.map +0 -1
@@ -1,5 +1,17 @@
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }// src/
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }// src/plugin.ts
|
2
|
+
var _path = require('path'); var _path2 = _interopRequireDefault(_path);
|
3
|
+
var _core = require('@kubb/core');
|
4
|
+
var _transformers = require('@kubb/core/transformers'); var _transformers2 = _interopRequireDefault(_transformers);
|
5
|
+
var _utils = require('@kubb/core/utils');
|
6
|
+
var _pluginoas = require('@kubb/plugin-oas');
|
7
|
+
|
8
|
+
// src/OperationGenerator.tsx
|
9
|
+
|
10
|
+
var _components = require('@kubb/plugin-oas/components');
|
2
11
|
var _react = require('@kubb/react');
|
12
|
+
|
13
|
+
// src/components/OasType.tsx
|
14
|
+
|
3
15
|
var _hooks = require('@kubb/plugin-oas/hooks');
|
4
16
|
var _jsxruntime = require('@kubb/react/jsx-runtime');
|
5
17
|
function Template({ name, typeName, api }) {
|
@@ -29,173 +41,28 @@ OasType.File = function({ name, typeName, templates = defaultTemplates }) {
|
|
29
41
|
OasType.templates = defaultTemplates;
|
30
42
|
|
31
43
|
// src/components/OperationSchema.tsx
|
32
|
-
|
44
|
+
|
33
45
|
var _parserts = require('@kubb/parser-ts');
|
34
|
-
var _factory = require('@kubb/parser-ts/factory'); var factory2 = _interopRequireWildcard(_factory); var factory = _interopRequireWildcard(_factory);
|
46
|
+
var _factory = require('@kubb/parser-ts/factory'); var factory3 = _interopRequireWildcard(_factory); var factory2 = _interopRequireWildcard(_factory); var factory = _interopRequireWildcard(_factory);
|
47
|
+
|
35
48
|
|
36
|
-
var _components = require('@kubb/plugin-oas/components');
|
37
49
|
|
38
50
|
|
39
51
|
// src/SchemaGenerator.tsx
|
40
52
|
|
41
|
-
var _pluginoas = require('@kubb/plugin-oas');
|
42
53
|
|
43
54
|
|
44
|
-
// src/plugin.ts
|
45
|
-
var _path = require('path'); var _path2 = _interopRequireDefault(_path);
|
46
|
-
var _core = require('@kubb/core');
|
47
55
|
|
48
|
-
|
56
|
+
// src/components/Schema.tsx
|
49
57
|
|
50
58
|
|
51
|
-
// src/OperationGenerator.tsx
|
52
59
|
|
53
60
|
|
54
61
|
|
55
62
|
|
56
|
-
var OperationGenerator = class extends _pluginoas.OperationGenerator {
|
57
|
-
async all(operations) {
|
58
|
-
const { oas, pluginManager, plugin, mode } = this.context;
|
59
|
-
const root = _react.createRoot.call(void 0, {
|
60
|
-
logger: pluginManager.logger
|
61
|
-
});
|
62
|
-
root.render(
|
63
|
-
/* @__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" }) }) })
|
64
|
-
);
|
65
|
-
return root.files;
|
66
|
-
}
|
67
|
-
async operation(operation, options) {
|
68
|
-
const { oas, pluginManager, plugin, mode } = this.context;
|
69
|
-
const root = _react.createRoot.call(void 0, {
|
70
|
-
logger: pluginManager.logger
|
71
|
-
});
|
72
|
-
root.render(
|
73
|
-
/* @__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, {}) }) }) })
|
74
|
-
);
|
75
|
-
return root.files;
|
76
|
-
}
|
77
|
-
async get() {
|
78
|
-
return null;
|
79
|
-
}
|
80
|
-
async post() {
|
81
|
-
return null;
|
82
|
-
}
|
83
|
-
async put() {
|
84
|
-
return null;
|
85
|
-
}
|
86
|
-
async patch() {
|
87
|
-
return null;
|
88
|
-
}
|
89
|
-
async delete() {
|
90
|
-
return null;
|
91
|
-
}
|
92
|
-
};
|
93
63
|
|
94
|
-
// src/plugin.ts
|
95
|
-
var pluginTsName = "plugin-ts";
|
96
|
-
var pluginTs = _core.createPlugin.call(void 0, (options) => {
|
97
|
-
const {
|
98
|
-
output = { path: "types" },
|
99
|
-
group,
|
100
|
-
exclude = [],
|
101
|
-
include,
|
102
|
-
override = [],
|
103
|
-
enumType = "asConst",
|
104
|
-
enumSuffix = "",
|
105
|
-
dateType = "string",
|
106
|
-
unknownType = "any",
|
107
|
-
optionalType = "questionToken",
|
108
|
-
transformers: transformers3 = {},
|
109
|
-
oasType = false
|
110
|
-
} = options;
|
111
|
-
const template = _optionalChain([group, 'optionalAccess', _ => _.output]) ? group.output : `${output.path}/{{tag}}Controller`;
|
112
|
-
return {
|
113
|
-
name: pluginTsName,
|
114
|
-
options: {
|
115
|
-
transformers: transformers3,
|
116
|
-
dateType,
|
117
|
-
optionalType,
|
118
|
-
oasType,
|
119
|
-
enumType,
|
120
|
-
enumSuffix,
|
121
|
-
// keep the used enumnames between SchemaGenerator and OperationGenerator per plugin(pluginKey)
|
122
|
-
usedEnumNames: {},
|
123
|
-
unknownType,
|
124
|
-
override
|
125
|
-
},
|
126
|
-
pre: [_pluginoas.pluginOasName],
|
127
|
-
resolvePath(baseName, pathMode, options2) {
|
128
|
-
const root = _path2.default.resolve(this.config.root, this.config.output.path);
|
129
|
-
const mode = _nullishCoalesce(pathMode, () => ( _core.FileManager.getMode(_path2.default.resolve(root, output.path))));
|
130
|
-
if (mode === "single") {
|
131
|
-
return _path2.default.resolve(root, output.path);
|
132
|
-
}
|
133
|
-
if (_optionalChain([options2, 'optionalAccess', _2 => _2.tag]) && _optionalChain([group, 'optionalAccess', _3 => _3.type]) === "tag") {
|
134
|
-
const tag = _transformers.camelCase.call(void 0, options2.tag);
|
135
|
-
return _path2.default.resolve(root, _utils.renderTemplate.call(void 0, template, { tag }), baseName);
|
136
|
-
}
|
137
|
-
return _path2.default.resolve(root, output.path, baseName);
|
138
|
-
},
|
139
|
-
resolveName(name, type) {
|
140
|
-
const resolvedName = _transformers.pascalCase.call(void 0, name, { isFile: type === "file" });
|
141
|
-
if (type) {
|
142
|
-
return _optionalChain([transformers3, 'optionalAccess', _4 => _4.name, 'optionalCall', _5 => _5(resolvedName, type)]) || resolvedName;
|
143
|
-
}
|
144
|
-
return resolvedName;
|
145
|
-
},
|
146
|
-
async writeFile(source, writePath) {
|
147
|
-
if (!writePath.endsWith(".ts") || !source) {
|
148
|
-
return;
|
149
|
-
}
|
150
|
-
return this.fileManager.write(source, writePath, { sanity: false });
|
151
|
-
},
|
152
|
-
async buildStart() {
|
153
|
-
const [swaggerPlugin] = _core.PluginManager.getDependedPlugins(this.plugins, [_pluginoas.pluginOasName]);
|
154
|
-
const oas = await swaggerPlugin.api.getOas();
|
155
|
-
const root = _path2.default.resolve(this.config.root, this.config.output.path);
|
156
|
-
const mode = _core.FileManager.getMode(_path2.default.resolve(root, output.path));
|
157
|
-
const schemaGenerator = new SchemaGenerator(this.plugin.options, {
|
158
|
-
oas,
|
159
|
-
pluginManager: this.pluginManager,
|
160
|
-
plugin: this.plugin,
|
161
|
-
contentType: swaggerPlugin.api.contentType,
|
162
|
-
include: void 0,
|
163
|
-
override,
|
164
|
-
mode,
|
165
|
-
output: output.path
|
166
|
-
});
|
167
|
-
const schemaFiles = await schemaGenerator.build();
|
168
|
-
await this.addFile(...schemaFiles);
|
169
|
-
const operationGenerator = new OperationGenerator(this.plugin.options, {
|
170
|
-
oas,
|
171
|
-
pluginManager: this.pluginManager,
|
172
|
-
plugin: this.plugin,
|
173
|
-
contentType: swaggerPlugin.api.contentType,
|
174
|
-
exclude,
|
175
|
-
include,
|
176
|
-
override,
|
177
|
-
mode
|
178
|
-
});
|
179
|
-
const operationFiles = await operationGenerator.build();
|
180
|
-
await this.addFile(...operationFiles);
|
181
|
-
},
|
182
|
-
async buildEnd() {
|
183
|
-
if (this.config.output.write === false) {
|
184
|
-
return;
|
185
|
-
}
|
186
|
-
const root = _path2.default.resolve(this.config.root, this.config.output.path);
|
187
|
-
await this.fileManager.addIndexes({
|
188
|
-
root,
|
189
|
-
output,
|
190
|
-
meta: { pluginKey: this.plugin.key },
|
191
|
-
logger: this.logger
|
192
|
-
});
|
193
|
-
}
|
194
|
-
};
|
195
|
-
});
|
196
|
-
|
197
|
-
// src/typeParser.ts
|
198
64
|
|
65
|
+
// src/parser/index.ts
|
199
66
|
|
200
67
|
|
201
68
|
|
@@ -292,19 +159,19 @@ var typeKeywordMapper = {
|
|
292
159
|
catchall: void 0,
|
293
160
|
name: void 0
|
294
161
|
};
|
295
|
-
function
|
162
|
+
function parse(parent, current, options) {
|
296
163
|
const value = typeKeywordMapper[current.keyword];
|
297
164
|
if (!value) {
|
298
165
|
return void 0;
|
299
166
|
}
|
300
167
|
if (_pluginoas.isKeyword.call(void 0, current, _pluginoas.schemaKeywords.union)) {
|
301
|
-
return typeKeywordMapper.union(current.args.map((schema) =>
|
168
|
+
return typeKeywordMapper.union(current.args.map((schema) => parse(current, schema, options)).filter(Boolean));
|
302
169
|
}
|
303
170
|
if (_pluginoas.isKeyword.call(void 0, current, _pluginoas.schemaKeywords.and)) {
|
304
|
-
return typeKeywordMapper.and(current.args.map((schema) =>
|
171
|
+
return typeKeywordMapper.and(current.args.map((schema) => parse(current, schema, options)).filter(Boolean));
|
305
172
|
}
|
306
173
|
if (_pluginoas.isKeyword.call(void 0, current, _pluginoas.schemaKeywords.array)) {
|
307
|
-
return typeKeywordMapper.array(current.args.items.map((schema) =>
|
174
|
+
return typeKeywordMapper.array(current.args.items.map((schema) => parse(current, schema, options)).filter(Boolean));
|
308
175
|
}
|
309
176
|
if (_pluginoas.isKeyword.call(void 0, current, _pluginoas.schemaKeywords.enum)) {
|
310
177
|
return typeKeywordMapper.enum(current.args.typeName);
|
@@ -316,13 +183,13 @@ function parseTypeMeta(parent, current, options) {
|
|
316
183
|
return value();
|
317
184
|
}
|
318
185
|
if (_pluginoas.isKeyword.call(void 0, current, _pluginoas.schemaKeywords.tuple)) {
|
319
|
-
return typeKeywordMapper.tuple(current.args.map((schema) =>
|
186
|
+
return typeKeywordMapper.tuple(current.args.map((schema) => parse(current, schema, options)).filter(Boolean));
|
320
187
|
}
|
321
188
|
if (_pluginoas.isKeyword.call(void 0, current, _pluginoas.schemaKeywords.const)) {
|
322
189
|
return typeKeywordMapper.const(current.args.name, current.args.format);
|
323
190
|
}
|
324
191
|
if (_pluginoas.isKeyword.call(void 0, current, _pluginoas.schemaKeywords.object)) {
|
325
|
-
const properties = Object.entries(_optionalChain([current, 'access',
|
192
|
+
const properties = Object.entries(_optionalChain([current, 'access', _ => _.args, 'optionalAccess', _2 => _2.properties]) || {}).filter((item) => {
|
326
193
|
const schemas = item[1];
|
327
194
|
return schemas && typeof schemas.map === "function";
|
328
195
|
}).map(([_name, schemas]) => {
|
@@ -340,7 +207,7 @@ function parseTypeMeta(parent, current, options) {
|
|
340
207
|
const defaultSchema = schemas.find((schema) => schema.keyword === _pluginoas.schemaKeywords.default);
|
341
208
|
const exampleSchema = schemas.find((schema) => schema.keyword === _pluginoas.schemaKeywords.example);
|
342
209
|
const schemaSchema = schemas.find((schema) => schema.keyword === _pluginoas.schemaKeywords.schema);
|
343
|
-
let type = schemas.map((schema) =>
|
210
|
+
let type = schemas.map((schema) => parse(current, schema, options)).filter(Boolean)[0];
|
344
211
|
if (isNullable) {
|
345
212
|
type = factory.createUnionDeclaration({
|
346
213
|
nodes: [type, factory.keywordTypeNodes.null]
|
@@ -369,12 +236,12 @@ function parseTypeMeta(parent, current, options) {
|
|
369
236
|
deprecatedSchema ? "@deprecated" : void 0,
|
370
237
|
defaultSchema ? `@default ${defaultSchema.args}` : void 0,
|
371
238
|
exampleSchema ? `@example ${exampleSchema.args}` : void 0,
|
372
|
-
_optionalChain([schemaSchema, 'optionalAccess',
|
239
|
+
_optionalChain([schemaSchema, 'optionalAccess', _3 => _3.args, 'optionalAccess', _4 => _4.type]) || _optionalChain([schemaSchema, 'optionalAccess', _5 => _5.args, 'optionalAccess', _6 => _6.format]) ? [`@type ${_optionalChain([schemaSchema, 'optionalAccess', _7 => _7.args, 'optionalAccess', _8 => _8.type]) || "unknown"}${!isOptional ? "" : " | undefined"}`, _optionalChain([schemaSchema, 'optionalAccess', _9 => _9.args, 'optionalAccess', _10 => _10.format])].filter(Boolean).join(", ") : void 0
|
373
240
|
].filter(Boolean)
|
374
241
|
});
|
375
242
|
});
|
376
|
-
const additionalProperties = _optionalChain([current, 'access',
|
377
|
-
current.args.additionalProperties.map((schema) =>
|
243
|
+
const additionalProperties = _optionalChain([current, 'access', _11 => _11.args, 'optionalAccess', _12 => _12.additionalProperties, 'optionalAccess', _13 => _13.length]) ? factory.createIndexSignature(
|
244
|
+
current.args.additionalProperties.map((schema) => parse(current, schema, options)).filter(Boolean).at(0)
|
378
245
|
) : void 0;
|
379
246
|
return typeKeywordMapper.object([...properties, additionalProperties].filter(Boolean));
|
380
247
|
}
|
@@ -392,159 +259,190 @@ function parseTypeMeta(parent, current, options) {
|
|
392
259
|
}
|
393
260
|
return void 0;
|
394
261
|
}
|
395
|
-
|
262
|
+
|
263
|
+
// src/components/Schema.tsx
|
264
|
+
|
265
|
+
function Schema(props) {
|
266
|
+
const { keysToOmit, description } = props;
|
267
|
+
const { tree, name } = _hooks.useSchema.call(void 0, );
|
268
|
+
const {
|
269
|
+
pluginManager,
|
270
|
+
plugin: {
|
271
|
+
options: { enumType, optionalType }
|
272
|
+
}
|
273
|
+
} = _react.useApp.call(void 0, );
|
274
|
+
const resolvedName = pluginManager.resolveName({
|
275
|
+
name,
|
276
|
+
pluginKey: [pluginTsName],
|
277
|
+
type: "function"
|
278
|
+
});
|
279
|
+
const typeName = pluginManager.resolveName({
|
280
|
+
name,
|
281
|
+
pluginKey: [pluginTsName],
|
282
|
+
type: "type"
|
283
|
+
});
|
396
284
|
const nodes = [];
|
397
285
|
const extraNodes = [];
|
398
|
-
if (!
|
286
|
+
if (!tree.length) {
|
399
287
|
return "";
|
400
288
|
}
|
401
|
-
const isNullish =
|
402
|
-
const isNullable =
|
403
|
-
const isOptional =
|
404
|
-
let type =
|
289
|
+
const isNullish = tree.some((item) => item.keyword === _pluginoas.schemaKeywords.nullish);
|
290
|
+
const isNullable = tree.some((item) => item.keyword === _pluginoas.schemaKeywords.nullable);
|
291
|
+
const isOptional = tree.some((item) => item.keyword === _pluginoas.schemaKeywords.optional);
|
292
|
+
let type = tree.map((schema) => parse(void 0, schema, { name: resolvedName, typeName, description, keysToOmit, optionalType, enumType })).filter(Boolean).at(0) || typeKeywordMapper.undefined();
|
405
293
|
if (isNullable) {
|
406
|
-
type =
|
407
|
-
nodes: [type,
|
294
|
+
type = factory2.createUnionDeclaration({
|
295
|
+
nodes: [type, factory2.keywordTypeNodes.null]
|
408
296
|
});
|
409
297
|
}
|
410
|
-
if (isNullish && ["undefined", "questionTokenAndUndefined"].includes(
|
411
|
-
type =
|
412
|
-
nodes: [type,
|
298
|
+
if (isNullish && ["undefined", "questionTokenAndUndefined"].includes(optionalType)) {
|
299
|
+
type = factory2.createUnionDeclaration({
|
300
|
+
nodes: [type, factory2.keywordTypeNodes.undefined]
|
413
301
|
});
|
414
302
|
}
|
415
|
-
if (isOptional && ["undefined", "questionTokenAndUndefined"].includes(
|
416
|
-
type =
|
417
|
-
nodes: [type,
|
303
|
+
if (isOptional && ["undefined", "questionTokenAndUndefined"].includes(optionalType)) {
|
304
|
+
type = factory2.createUnionDeclaration({
|
305
|
+
nodes: [type, factory2.keywordTypeNodes.undefined]
|
418
306
|
});
|
419
307
|
}
|
420
|
-
const node =
|
421
|
-
modifiers: [
|
422
|
-
name:
|
423
|
-
type: _optionalChain([
|
424
|
-
keys:
|
308
|
+
const node = factory2.createTypeAliasDeclaration({
|
309
|
+
modifiers: [factory2.modifiers.export],
|
310
|
+
name: resolvedName,
|
311
|
+
type: _optionalChain([keysToOmit, 'optionalAccess', _14 => _14.length]) ? factory2.createOmitDeclaration({
|
312
|
+
keys: keysToOmit,
|
425
313
|
type,
|
426
314
|
nonNullable: true
|
427
315
|
}) : type
|
428
316
|
});
|
429
|
-
const enumSchemas = _pluginoas.SchemaGenerator.deepSearch(
|
317
|
+
const enumSchemas = _pluginoas.SchemaGenerator.deepSearch(tree, _pluginoas.schemaKeywords.enum);
|
430
318
|
if (enumSchemas) {
|
431
319
|
enumSchemas.forEach((enumSchema) => {
|
432
320
|
extraNodes.push(
|
433
|
-
...
|
321
|
+
...factory2.createEnumDeclaration({
|
434
322
|
name: _transformers2.default.camelCase(enumSchema.args.name),
|
435
323
|
typeName: enumSchema.args.typeName,
|
436
|
-
enums: enumSchema.args.items.map((item) => item.value === void 0 ? void 0 : [_transformers2.default.trimQuotes(_optionalChain([item, 'access',
|
437
|
-
type:
|
324
|
+
enums: enumSchema.args.items.map((item) => item.value === void 0 ? void 0 : [_transformers2.default.trimQuotes(_optionalChain([item, 'access', _15 => _15.name, 'optionalAccess', _16 => _16.toString, 'call', _17 => _17()])), item.value]).filter(Boolean),
|
325
|
+
type: enumType
|
438
326
|
})
|
439
327
|
);
|
440
328
|
});
|
441
329
|
}
|
442
330
|
nodes.push(
|
443
|
-
|
331
|
+
factory2.appendJSDocToNode({
|
444
332
|
node,
|
445
|
-
comments: [
|
333
|
+
comments: [description ? `@description ${_transformers2.default.jsStringEscape(description)}` : void 0].filter(Boolean)
|
446
334
|
})
|
447
335
|
);
|
448
336
|
const filterdNodes = nodes.filter(
|
449
337
|
(node2) => !extraNodes.some(
|
450
|
-
(extraNode) => _optionalChain([extraNode, 'optionalAccess',
|
338
|
+
(extraNode) => _optionalChain([extraNode, 'optionalAccess', _18 => _18.name, 'optionalAccess', _19 => _19.escapedText]) === _optionalChain([node2, 'optionalAccess', _20 => _20.name, 'optionalAccess', _21 => _21.escapedText])
|
451
339
|
)
|
452
340
|
);
|
453
341
|
return _parserts.print.call(void 0, [...extraNodes, ...filterdNodes]);
|
454
342
|
}
|
343
|
+
Schema.File = function({}) {
|
344
|
+
const { pluginManager } = _react.useApp.call(void 0, );
|
345
|
+
const { schema } = _hooks.useSchema.call(void 0, );
|
346
|
+
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _components.Oas.Schema.File, { output: pluginManager.config.output.path, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.File.Source, { children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, Schema, { description: _optionalChain([schema, 'optionalAccess', _22 => _22.description]) }) }) });
|
347
|
+
};
|
455
348
|
|
456
349
|
// src/SchemaGenerator.tsx
|
457
350
|
|
458
|
-
var
|
459
|
-
async schema(name,
|
460
|
-
const { oas, pluginManager,
|
351
|
+
var SchemaGenerator2 = class extends _pluginoas.SchemaGenerator {
|
352
|
+
async schema(name, schema) {
|
353
|
+
const { oas, pluginManager, plugin, mode, output } = this.context;
|
461
354
|
const root = _react.createRoot.call(void 0, {
|
462
355
|
logger: pluginManager.logger
|
463
356
|
});
|
357
|
+
const tree = this.parse({ schema, name });
|
464
358
|
root.render(
|
465
|
-
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.App, { pluginManager, plugin, mode, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _components.Oas, { oas, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _components.Oas.Schema, {
|
359
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.App, { pluginManager, plugin, 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, {}) }) }) })
|
466
360
|
);
|
467
361
|
return root.files;
|
468
362
|
}
|
469
|
-
// TODO convert to a react component called `Schema.Parser` with props parser as part of the SchemaContext
|
470
|
-
getSource(name, schemas, { keysToOmit, description } = {}) {
|
471
|
-
const texts = [];
|
472
|
-
const resolvedName = this.context.pluginManager.resolveName({
|
473
|
-
name,
|
474
|
-
pluginKey: [pluginTsName],
|
475
|
-
type: "function"
|
476
|
-
});
|
477
|
-
const resolvedTypeName = this.context.pluginManager.resolveName({
|
478
|
-
name,
|
479
|
-
pluginKey: [pluginTsName],
|
480
|
-
type: "type"
|
481
|
-
});
|
482
|
-
const typeOutput = typeParser(schemas, {
|
483
|
-
name: resolvedName,
|
484
|
-
typeName: resolvedTypeName,
|
485
|
-
description,
|
486
|
-
enumType: this.options.enumType || "asConst",
|
487
|
-
optionalType: this.options.optionalType,
|
488
|
-
keysToOmit
|
489
|
-
});
|
490
|
-
texts.push(typeOutput);
|
491
|
-
return texts;
|
492
|
-
}
|
493
|
-
/**
|
494
|
-
* @deprecated only used for testing
|
495
|
-
*/
|
496
|
-
buildSource(name, schema, options = {}) {
|
497
|
-
const schemas = this.buildSchemas({ schema, name });
|
498
|
-
return this.getSource(name, schemas, options);
|
499
|
-
}
|
500
363
|
};
|
501
364
|
|
502
365
|
// src/components/OperationSchema.tsx
|
503
366
|
|
504
|
-
function printCombinedSchema(
|
367
|
+
function printCombinedSchema({
|
368
|
+
name,
|
369
|
+
operation,
|
370
|
+
schemas,
|
371
|
+
pluginManager
|
372
|
+
}) {
|
505
373
|
const properties = {};
|
506
374
|
if (schemas.response) {
|
507
|
-
|
375
|
+
const identifier = pluginManager.resolveName({
|
376
|
+
name: schemas.response.name,
|
377
|
+
pluginKey: [pluginTsName],
|
378
|
+
type: "function"
|
379
|
+
});
|
380
|
+
properties["response"] = factory3.createTypeReferenceNode(factory3.createIdentifier(identifier), void 0);
|
508
381
|
}
|
509
382
|
if (schemas.request) {
|
510
|
-
|
383
|
+
const identifier = pluginManager.resolveName({
|
384
|
+
name: schemas.request.name,
|
385
|
+
pluginKey: [pluginTsName],
|
386
|
+
type: "function"
|
387
|
+
});
|
388
|
+
properties["request"] = factory3.createTypeReferenceNode(factory3.createIdentifier(identifier), void 0);
|
511
389
|
}
|
512
390
|
if (schemas.pathParams) {
|
513
|
-
|
391
|
+
const identifier = pluginManager.resolveName({
|
392
|
+
name: schemas.pathParams.name,
|
393
|
+
pluginKey: [pluginTsName],
|
394
|
+
type: "function"
|
395
|
+
});
|
396
|
+
properties["pathParams"] = factory3.createTypeReferenceNode(factory3.createIdentifier(identifier), void 0);
|
514
397
|
}
|
515
398
|
if (schemas.queryParams) {
|
516
|
-
|
399
|
+
const identifier = pluginManager.resolveName({
|
400
|
+
name: schemas.queryParams.name,
|
401
|
+
pluginKey: [pluginTsName],
|
402
|
+
type: "function"
|
403
|
+
});
|
404
|
+
properties["queryParams"] = factory3.createTypeReferenceNode(factory3.createIdentifier(identifier), void 0);
|
517
405
|
}
|
518
406
|
if (schemas.headerParams) {
|
519
|
-
|
407
|
+
const identifier = pluginManager.resolveName({
|
408
|
+
name: schemas.headerParams.name,
|
409
|
+
pluginKey: [pluginTsName],
|
410
|
+
type: "function"
|
411
|
+
});
|
412
|
+
properties["headerParams"] = factory3.createTypeReferenceNode(factory3.createIdentifier(identifier), void 0);
|
520
413
|
}
|
521
414
|
if (schemas.errors) {
|
522
|
-
properties["errors"] =
|
415
|
+
properties["errors"] = factory3.createUnionDeclaration({
|
523
416
|
nodes: schemas.errors.map((error) => {
|
524
|
-
|
417
|
+
const identifier = pluginManager.resolveName({
|
418
|
+
name: error.name,
|
419
|
+
pluginKey: [pluginTsName],
|
420
|
+
type: "function"
|
421
|
+
});
|
422
|
+
return factory3.createTypeReferenceNode(factory3.createIdentifier(identifier), void 0);
|
525
423
|
})
|
526
424
|
});
|
527
425
|
}
|
528
|
-
const namespaceNode =
|
426
|
+
const namespaceNode = factory3.createTypeAliasDeclaration({
|
529
427
|
name: operation.method === "get" ? `${name}Query` : `${name}Mutation`,
|
530
|
-
type:
|
428
|
+
type: factory3.createTypeLiteralNode(
|
531
429
|
Object.keys(properties).map((key) => {
|
532
430
|
const type = properties[key];
|
533
431
|
if (!type) {
|
534
432
|
return void 0;
|
535
433
|
}
|
536
|
-
return
|
434
|
+
return factory3.createPropertySignature({
|
537
435
|
name: _transformers2.default.pascalCase(key),
|
538
436
|
type
|
539
437
|
});
|
540
438
|
}).filter(Boolean)
|
541
439
|
),
|
542
|
-
modifiers: [
|
440
|
+
modifiers: [factory3.modifiers.export]
|
543
441
|
});
|
544
442
|
return _parserts.print.call(void 0, namespaceNode);
|
545
443
|
}
|
546
|
-
function OperationSchema({}) {
|
547
|
-
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
444
|
+
function OperationSchema({ keysToOmit, description }) {
|
445
|
+
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, Schema, { keysToOmit, description });
|
548
446
|
}
|
549
447
|
OperationSchema.File = function({}) {
|
550
448
|
const { pluginManager, plugin, mode, fileManager } = _react.useApp.call(void 0, );
|
@@ -554,7 +452,7 @@ OperationSchema.File = function({}) {
|
|
554
452
|
const file = getFile(operation);
|
555
453
|
const schemas = getSchemas(operation);
|
556
454
|
const factoryName = getName(operation, { type: "type" });
|
557
|
-
const generator = new
|
455
|
+
const generator = new SchemaGenerator2(plugin.options, {
|
558
456
|
oas,
|
559
457
|
plugin,
|
560
458
|
pluginManager,
|
@@ -562,22 +460,159 @@ OperationSchema.File = function({}) {
|
|
562
460
|
override: plugin.options.override
|
563
461
|
});
|
564
462
|
const items = [schemas.pathParams, schemas.queryParams, schemas.headerParams, schemas.statusCodes, schemas.request, schemas.response].flat().filter(Boolean);
|
565
|
-
const mapItem = ({ name, schema
|
566
|
-
|
463
|
+
const mapItem = ({ name, schema, description, keysToOmit, ...options }, i) => {
|
464
|
+
const tree = generator.parse({ schema, name });
|
465
|
+
return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _components.Oas.Schema, { name, value: schema, tree, children: [
|
567
466
|
mode === "split" && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _components.Oas.Schema.Imports, { isTypeOnly: true }),
|
568
|
-
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.File.Source, { children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
467
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.File.Source, { children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, OperationSchema, { description, keysToOmit }) })
|
569
468
|
] }, i);
|
570
469
|
};
|
571
470
|
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.Parser, { language: "typescript", children: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _react.File, { baseName: file.baseName, path: file.path, meta: file.meta, children: [
|
572
471
|
items.map(mapItem),
|
573
|
-
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.File.Source, { children: printCombinedSchema(factoryName, operation, schemas) })
|
472
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.File.Source, { children: printCombinedSchema({ name: factoryName, operation, schemas, pluginManager }) })
|
574
473
|
] }) });
|
575
474
|
};
|
576
475
|
|
476
|
+
// src/OperationGenerator.tsx
|
477
|
+
|
478
|
+
var OperationGenerator = class extends _pluginoas.OperationGenerator {
|
479
|
+
async all(operations) {
|
480
|
+
const { oas, pluginManager, plugin, mode } = this.context;
|
481
|
+
const root = _react.createRoot.call(void 0, {
|
482
|
+
logger: pluginManager.logger
|
483
|
+
});
|
484
|
+
root.render(
|
485
|
+
/* @__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" }) }) })
|
486
|
+
);
|
487
|
+
return root.files;
|
488
|
+
}
|
489
|
+
async operation(operation, options) {
|
490
|
+
const { oas, pluginManager, plugin, mode } = this.context;
|
491
|
+
const root = _react.createRoot.call(void 0, {
|
492
|
+
logger: pluginManager.logger
|
493
|
+
});
|
494
|
+
root.render(
|
495
|
+
/* @__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, {}) }) }) })
|
496
|
+
);
|
497
|
+
return root.files;
|
498
|
+
}
|
499
|
+
};
|
500
|
+
|
501
|
+
// src/plugin.ts
|
502
|
+
var pluginTsName = "plugin-ts";
|
503
|
+
var pluginTs = _core.createPlugin.call(void 0, (options) => {
|
504
|
+
const {
|
505
|
+
output = { path: "types" },
|
506
|
+
group,
|
507
|
+
exclude = [],
|
508
|
+
include,
|
509
|
+
override = [],
|
510
|
+
enumType = "asConst",
|
511
|
+
enumSuffix = "",
|
512
|
+
dateType = "string",
|
513
|
+
unknownType = "any",
|
514
|
+
optionalType = "questionToken",
|
515
|
+
transformers: transformers4 = {},
|
516
|
+
oasType = false
|
517
|
+
} = options;
|
518
|
+
const template = _optionalChain([group, 'optionalAccess', _23 => _23.output]) ? group.output : `${output.path}/{{tag}}Controller`;
|
519
|
+
return {
|
520
|
+
name: pluginTsName,
|
521
|
+
options: {
|
522
|
+
transformers: transformers4,
|
523
|
+
dateType,
|
524
|
+
optionalType,
|
525
|
+
oasType,
|
526
|
+
enumType,
|
527
|
+
enumSuffix,
|
528
|
+
// keep the used enumnames between SchemaGenerator and OperationGenerator per plugin(pluginKey)
|
529
|
+
usedEnumNames: {},
|
530
|
+
unknownType,
|
531
|
+
override
|
532
|
+
},
|
533
|
+
pre: [_pluginoas.pluginOasName],
|
534
|
+
resolvePath(baseName, pathMode, options2) {
|
535
|
+
const root = _path2.default.resolve(this.config.root, this.config.output.path);
|
536
|
+
const mode = _nullishCoalesce(pathMode, () => ( _core.FileManager.getMode(_path2.default.resolve(root, output.path))));
|
537
|
+
if (mode === "single") {
|
538
|
+
return _path2.default.resolve(root, output.path);
|
539
|
+
}
|
540
|
+
if (_optionalChain([options2, 'optionalAccess', _24 => _24.tag]) && _optionalChain([group, 'optionalAccess', _25 => _25.type]) === "tag") {
|
541
|
+
const tag = _transformers.camelCase.call(void 0, options2.tag);
|
542
|
+
return _path2.default.resolve(root, _utils.renderTemplate.call(void 0, template, { tag }), baseName);
|
543
|
+
}
|
544
|
+
return _path2.default.resolve(root, output.path, baseName);
|
545
|
+
},
|
546
|
+
resolveName(name, type) {
|
547
|
+
const resolvedName = _transformers.pascalCase.call(void 0, name, { isFile: type === "file" });
|
548
|
+
if (type) {
|
549
|
+
return _optionalChain([transformers4, 'optionalAccess', _26 => _26.name, 'optionalCall', _27 => _27(resolvedName, type)]) || resolvedName;
|
550
|
+
}
|
551
|
+
return resolvedName;
|
552
|
+
},
|
553
|
+
async writeFile(path2, source) {
|
554
|
+
if (!path2.endsWith(".ts") || !source) {
|
555
|
+
return;
|
556
|
+
}
|
557
|
+
return this.fileManager.write(path2, source, { sanity: false });
|
558
|
+
},
|
559
|
+
async buildStart() {
|
560
|
+
const [swaggerPlugin] = _core.PluginManager.getDependedPlugins(this.plugins, [_pluginoas.pluginOasName]);
|
561
|
+
const oas = await swaggerPlugin.api.getOas();
|
562
|
+
const root = _path2.default.resolve(this.config.root, this.config.output.path);
|
563
|
+
const mode = _core.FileManager.getMode(_path2.default.resolve(root, output.path));
|
564
|
+
const schemaGenerator = new SchemaGenerator2(this.plugin.options, {
|
565
|
+
oas,
|
566
|
+
pluginManager: this.pluginManager,
|
567
|
+
plugin: this.plugin,
|
568
|
+
contentType: swaggerPlugin.api.contentType,
|
569
|
+
include: void 0,
|
570
|
+
override,
|
571
|
+
mode,
|
572
|
+
output: output.path
|
573
|
+
});
|
574
|
+
const schemaFiles = await schemaGenerator.build();
|
575
|
+
await this.addFile(...schemaFiles);
|
576
|
+
const operationGenerator = new OperationGenerator(this.plugin.options, {
|
577
|
+
oas,
|
578
|
+
pluginManager: this.pluginManager,
|
579
|
+
plugin: this.plugin,
|
580
|
+
contentType: swaggerPlugin.api.contentType,
|
581
|
+
exclude,
|
582
|
+
include,
|
583
|
+
override,
|
584
|
+
mode
|
585
|
+
});
|
586
|
+
const operationFiles = await operationGenerator.build();
|
587
|
+
await this.addFile(...operationFiles);
|
588
|
+
},
|
589
|
+
async buildEnd() {
|
590
|
+
if (this.config.output.write === false) {
|
591
|
+
return;
|
592
|
+
}
|
593
|
+
const root = _path2.default.resolve(this.config.root, this.config.output.path);
|
594
|
+
await this.fileManager.addIndexes({
|
595
|
+
root,
|
596
|
+
output,
|
597
|
+
meta: { pluginKey: this.plugin.key },
|
598
|
+
logger: this.logger
|
599
|
+
});
|
600
|
+
}
|
601
|
+
};
|
602
|
+
});
|
603
|
+
|
604
|
+
// src/index.ts
|
605
|
+
var definePluginDefault = pluginTs;
|
606
|
+
var definePlugin = pluginTs;
|
607
|
+
var src_default = definePluginDefault;
|
608
|
+
|
609
|
+
|
610
|
+
|
611
|
+
|
577
612
|
|
578
613
|
|
579
614
|
|
580
615
|
|
581
616
|
|
582
|
-
exports.OasType = OasType; exports.OperationSchema = OperationSchema; exports.pluginTsName = pluginTsName; exports.pluginTs = pluginTs;
|
583
|
-
//# sourceMappingURL=chunk-
|
617
|
+
exports.OasType = OasType; exports.Schema = Schema; exports.OperationSchema = OperationSchema; exports.pluginTsName = pluginTsName; exports.pluginTs = pluginTs; exports.definePlugin = definePlugin; exports.src_default = src_default;
|
618
|
+
//# sourceMappingURL=chunk-DRW5SRC6.cjs.map
|