@kubb/plugin-oas 3.0.0-alpha.1 → 3.0.0-alpha.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/OperationGenerator-By5WOmWB.d.ts +165 -0
- package/dist/OperationGenerator-Gd1X7wUz.d.cts +165 -0
- package/dist/{Schema-DefwBJMc.d.ts → Schema-B1vcPGiK.d.ts} +3 -5
- package/dist/{Schema-an5hOrjZ.d.cts → Schema-DoSFh7Qd.d.cts} +3 -5
- package/dist/{SchemaMapper-CsBQ6eEx.d.cts → SchemaMapper-sGcY1xL5.d.cts} +1 -2
- package/dist/{SchemaMapper-CsBQ6eEx.d.ts → SchemaMapper-sGcY1xL5.d.ts} +1 -2
- package/dist/{chunk-LEACSHKT.js → chunk-2X5GZFQP.js} +712 -44
- package/dist/chunk-2X5GZFQP.js.map +1 -0
- package/dist/{chunk-DRLYORTT.cjs → chunk-47SNBYWH.cjs} +750 -69
- package/dist/chunk-47SNBYWH.cjs.map +1 -0
- package/dist/{chunk-UB552H4J.js → chunk-4VKHSKYX.js} +7 -24
- package/dist/{chunk-UB552H4J.js.map → chunk-4VKHSKYX.js.map} +1 -1
- package/dist/{chunk-Y4V7HHX7.js → chunk-4WUMV7QX.js} +9 -12
- package/dist/chunk-4WUMV7QX.js.map +1 -0
- package/dist/chunk-6AVEWDKE.cjs +8 -0
- package/dist/chunk-6AVEWDKE.cjs.map +1 -0
- package/dist/chunk-S6RFFHLW.cjs +38 -0
- package/dist/chunk-S6RFFHLW.cjs.map +1 -0
- package/dist/chunk-WN5S6RCU.js +6 -0
- package/dist/chunk-WN5S6RCU.js.map +1 -0
- package/dist/chunk-XQPCA75E.cjs +90 -0
- package/dist/chunk-XQPCA75E.cjs.map +1 -0
- package/dist/components.cjs +21 -17
- package/dist/components.cjs.map +1 -1
- package/dist/components.d.cts +13 -7
- package/dist/components.d.ts +13 -7
- package/dist/components.js +4 -17
- package/dist/components.js.map +1 -1
- package/dist/hooks.cjs +30 -35
- package/dist/hooks.cjs.map +1 -1
- package/dist/hooks.d.cts +4 -4
- package/dist/hooks.d.ts +4 -4
- package/dist/hooks.js +10 -23
- package/dist/hooks.js.map +1 -1
- package/dist/index.cjs +315 -262
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +8 -77
- package/dist/index.d.ts +8 -77
- package/dist/index.js +270 -239
- package/dist/index.js.map +1 -1
- package/dist/{types-Dte3MA6H.d.cts → types-CZTUCaE5.d.cts} +3 -1
- package/dist/{types-Dte3MA6H.d.ts → types-CZTUCaE5.d.ts} +3 -1
- package/dist/utils.cjs +39 -73
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.d.cts +7 -33
- package/dist/utils.d.ts +7 -33
- package/dist/utils.js +10 -67
- package/dist/utils.js.map +1 -1
- package/package.json +11 -10
- package/src/OperationGenerator.ts +68 -32
- package/src/SchemaGenerator.ts +32 -15
- package/src/SchemaMapper.ts +1 -1
- package/src/components/Oas.tsx +9 -3
- package/src/components/Operation.tsx +1 -1
- package/src/components/Schema.tsx +29 -31
- package/src/generator.tsx +125 -0
- package/src/hooks/useOperationManager.ts +1 -0
- package/src/index.ts +3 -9
- package/src/plugin.ts +25 -38
- package/src/types.ts +2 -0
- package/src/utils/getParams.ts +1 -1
- package/src/utils/index.ts +2 -1
- package/dist/OperationGenerator-CeM_9pxW.d.cts +0 -60
- package/dist/OperationGenerator-DhUhvRJE.d.ts +0 -60
- package/dist/chunk-CJXRFYEF.cjs +0 -698
- package/dist/chunk-CJXRFYEF.cjs.map +0 -1
- package/dist/chunk-DRLYORTT.cjs.map +0 -1
- package/dist/chunk-K6KUETAI.js +0 -698
- package/dist/chunk-K6KUETAI.js.map +0 -1
- package/dist/chunk-LEACSHKT.js.map +0 -1
- package/dist/chunk-P42X362U.cjs +0 -101
- package/dist/chunk-P42X362U.cjs.map +0 -1
- package/dist/chunk-QLJIL3U5.cjs +0 -35
- package/dist/chunk-QLJIL3U5.cjs.map +0 -1
- package/dist/chunk-Y4V7HHX7.js.map +0 -1
- package/src/utils/getGroupedByTagFiles.ts +0 -82
package/dist/index.js
CHANGED
|
@@ -1,149 +1,94 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
} from
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
import {
|
|
10
|
-
__privateAdd,
|
|
11
|
-
__privateGet,
|
|
12
|
-
__privateMethod,
|
|
13
|
-
__privateSet,
|
|
14
|
-
getSchemas,
|
|
15
|
-
init_esm_shims
|
|
16
|
-
} from "./chunk-UB552H4J.js";
|
|
1
|
+
import { parseFromConfig } from './chunk-4WUMV7QX.js';
|
|
2
|
+
import './chunk-WN5S6RCU.js';
|
|
3
|
+
import { require_jsx_runtime, Oas } from './chunk-2X5GZFQP.js';
|
|
4
|
+
export { SchemaGenerator, isKeyword, schemaKeywords } from './chunk-2X5GZFQP.js';
|
|
5
|
+
import { init_esm_shims, getSchemas, __toESM } from './chunk-4VKHSKYX.js';
|
|
6
|
+
import { createPlugin, BaseGenerator } from '@kubb/core';
|
|
7
|
+
import transformers, { camelCase } from '@kubb/core/transformers';
|
|
8
|
+
import path from 'node:path';
|
|
9
|
+
import { createRoot, App } from '@kubb/react';
|
|
17
10
|
|
|
18
11
|
// src/index.ts
|
|
19
12
|
init_esm_shims();
|
|
20
13
|
|
|
21
|
-
// src/
|
|
14
|
+
// src/OperationGenerator.ts
|
|
22
15
|
init_esm_shims();
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
} = options;
|
|
37
|
-
const getOas = async ({ config, logger, formatOptions }) => {
|
|
38
|
-
try {
|
|
39
|
-
const oas = await parseFromConfig(config, formatOptions, oasClass);
|
|
40
|
-
if (validate) {
|
|
41
|
-
await oas.valdiate();
|
|
16
|
+
var OperationGenerator = class extends BaseGenerator {
|
|
17
|
+
#operationsByMethod = {};
|
|
18
|
+
get operationsByMethod() {
|
|
19
|
+
return this.#operationsByMethod;
|
|
20
|
+
}
|
|
21
|
+
set operationsByMethod(paths) {
|
|
22
|
+
this.#operationsByMethod = paths;
|
|
23
|
+
}
|
|
24
|
+
#getOptions(operation, method) {
|
|
25
|
+
const { override = [] } = this.context;
|
|
26
|
+
return override.find(({ pattern, type }) => {
|
|
27
|
+
if (type === "tag") {
|
|
28
|
+
return !!operation.getTags()[0]?.name.match(pattern);
|
|
42
29
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
const error = e;
|
|
46
|
-
logger.emit("warning", error?.message);
|
|
47
|
-
return parseFromConfig(config, {}, oasClass);
|
|
48
|
-
}
|
|
49
|
-
};
|
|
50
|
-
return {
|
|
51
|
-
name: pluginOasName,
|
|
52
|
-
options,
|
|
53
|
-
api() {
|
|
54
|
-
const { config, logger } = this;
|
|
55
|
-
return {
|
|
56
|
-
getOas(formatOptions) {
|
|
57
|
-
return getOas({ config, logger, formatOptions });
|
|
58
|
-
},
|
|
59
|
-
async getSchemas({ includes } = {}) {
|
|
60
|
-
const oas = await this.getOas();
|
|
61
|
-
return getSchemas({ oas, contentType, includes });
|
|
62
|
-
},
|
|
63
|
-
async getBaseURL() {
|
|
64
|
-
const oasInstance = await this.getOas();
|
|
65
|
-
const baseURL = oasInstance.api.servers?.at(serverIndex)?.url;
|
|
66
|
-
return baseURL;
|
|
67
|
-
},
|
|
68
|
-
contentType
|
|
69
|
-
};
|
|
70
|
-
},
|
|
71
|
-
resolvePath(baseName) {
|
|
72
|
-
if (output === false) {
|
|
73
|
-
return void 0;
|
|
30
|
+
if (type === "operationId") {
|
|
31
|
+
return !!operation.getOperationId().match(pattern);
|
|
74
32
|
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
},
|
|
78
|
-
resolveName(name, type) {
|
|
79
|
-
return camelCase(name, { isFile: type === "file" });
|
|
80
|
-
},
|
|
81
|
-
async writeFile(path2, source) {
|
|
82
|
-
if (!path2.endsWith(".json") || !source) {
|
|
83
|
-
return;
|
|
33
|
+
if (type === "path") {
|
|
34
|
+
return !!operation.path.match(pattern);
|
|
84
35
|
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
async buildStart() {
|
|
88
|
-
if (!output) {
|
|
89
|
-
return;
|
|
36
|
+
if (type === "method") {
|
|
37
|
+
return !!method.match(pattern);
|
|
90
38
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
logger: this.logger,
|
|
94
|
-
formatOptions: {
|
|
95
|
-
filterSet: filter,
|
|
96
|
-
sortSet: sort
|
|
97
|
-
}
|
|
98
|
-
});
|
|
99
|
-
await oas.dereference();
|
|
100
|
-
const schemas = getSchemas({ oas, contentType });
|
|
101
|
-
const mapSchema = async ([name, schema]) => {
|
|
102
|
-
const resolvedPath = this.resolvePath({
|
|
103
|
-
baseName: `${name}.json`,
|
|
104
|
-
pluginKey: this.plugin.key
|
|
105
|
-
});
|
|
106
|
-
const resvoledFileName = this.resolveName({
|
|
107
|
-
name: `${name}.json`,
|
|
108
|
-
pluginKey: [pluginOasName],
|
|
109
|
-
type: "file"
|
|
110
|
-
});
|
|
111
|
-
if (!resolvedPath) {
|
|
112
|
-
return;
|
|
113
|
-
}
|
|
114
|
-
await this.addFile({
|
|
115
|
-
path: resolvedPath,
|
|
116
|
-
baseName: resvoledFileName,
|
|
117
|
-
source: JSON.stringify(schema),
|
|
118
|
-
meta: {
|
|
119
|
-
pluginKey: this.plugin.key
|
|
120
|
-
}
|
|
121
|
-
});
|
|
122
|
-
};
|
|
123
|
-
const promises = Object.entries(schemas).map(mapSchema);
|
|
124
|
-
await Promise.all(promises);
|
|
125
|
-
}
|
|
126
|
-
};
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
// src/OperationGenerator.ts
|
|
130
|
-
init_esm_shims();
|
|
131
|
-
import { Generator } from "@kubb/core";
|
|
132
|
-
import transformers from "@kubb/core/transformers";
|
|
133
|
-
var _operationsByMethod, _OperationGenerator_instances, getOptions_fn, isExcluded_fn, isIncluded_fn, methods_get;
|
|
134
|
-
var OperationGenerator = class extends Generator {
|
|
135
|
-
constructor() {
|
|
136
|
-
super(...arguments);
|
|
137
|
-
__privateAdd(this, _OperationGenerator_instances);
|
|
138
|
-
__privateAdd(this, _operationsByMethod, {});
|
|
39
|
+
return false;
|
|
40
|
+
})?.options || {};
|
|
139
41
|
}
|
|
140
|
-
|
|
141
|
-
|
|
42
|
+
/**
|
|
43
|
+
*
|
|
44
|
+
* @deprecated
|
|
45
|
+
*/
|
|
46
|
+
#isExcluded(operation, method) {
|
|
47
|
+
const { exclude = [] } = this.context;
|
|
48
|
+
let matched = false;
|
|
49
|
+
exclude.forEach(({ pattern, type }) => {
|
|
50
|
+
if (type === "tag" && !matched) {
|
|
51
|
+
matched = !!operation.getTags()[0]?.name.match(pattern);
|
|
52
|
+
}
|
|
53
|
+
if (type === "operationId" && !matched) {
|
|
54
|
+
matched = !!operation.getOperationId().match(pattern);
|
|
55
|
+
}
|
|
56
|
+
if (type === "path" && !matched) {
|
|
57
|
+
matched = !!operation.path.match(pattern);
|
|
58
|
+
}
|
|
59
|
+
if (type === "method" && !matched) {
|
|
60
|
+
matched = !!method.match(pattern);
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
return matched;
|
|
142
64
|
}
|
|
143
|
-
|
|
144
|
-
|
|
65
|
+
/**
|
|
66
|
+
*
|
|
67
|
+
* @deprecated
|
|
68
|
+
*/
|
|
69
|
+
#isIncluded(operation, method) {
|
|
70
|
+
const { include = [] } = this.context;
|
|
71
|
+
let matched = false;
|
|
72
|
+
include.forEach(({ pattern, type }) => {
|
|
73
|
+
if (type === "tag" && !matched) {
|
|
74
|
+
matched = !!operation.getTags()[0]?.name.match(pattern);
|
|
75
|
+
}
|
|
76
|
+
if (type === "operationId" && !matched) {
|
|
77
|
+
matched = !!operation.getOperationId().match(pattern);
|
|
78
|
+
}
|
|
79
|
+
if (type === "path" && !matched) {
|
|
80
|
+
matched = !!operation.path.match(pattern);
|
|
81
|
+
}
|
|
82
|
+
if (type === "method" && !matched) {
|
|
83
|
+
matched = !!method.match(pattern);
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
return matched;
|
|
145
87
|
}
|
|
146
|
-
getSchemas(operation, {
|
|
88
|
+
getSchemas(operation, {
|
|
89
|
+
forStatusCode,
|
|
90
|
+
resolveName = (name) => name
|
|
91
|
+
} = {}) {
|
|
147
92
|
const pathParamsSchema = this.context.oas.getParametersSchema(operation, "path");
|
|
148
93
|
const queryParamsSchema = this.context.oas.getParametersSchema(operation, "query");
|
|
149
94
|
const headerParamsSchema = this.context.oas.getParametersSchema(operation, "header");
|
|
@@ -217,16 +162,17 @@ var OperationGenerator = class extends Generator {
|
|
|
217
162
|
statusCodes
|
|
218
163
|
};
|
|
219
164
|
}
|
|
220
|
-
|
|
165
|
+
#methods = ["get", "post", "patch", "put", "delete"];
|
|
166
|
+
async build(...generators) {
|
|
221
167
|
const { oas } = this.context;
|
|
222
168
|
const paths = oas.getPaths();
|
|
223
169
|
this.operationsByMethod = Object.entries(paths).reduce((acc, [path2, method]) => {
|
|
224
170
|
const methods = Object.keys(method);
|
|
225
171
|
methods.forEach((method2) => {
|
|
226
172
|
const operation = oas.operation(path2, method2);
|
|
227
|
-
if (operation &&
|
|
228
|
-
const isExcluded =
|
|
229
|
-
const isIncluded = this.context.include ?
|
|
173
|
+
if (operation && [this.#methods].some((methods2) => method2 === operation.method)) {
|
|
174
|
+
const isExcluded = this.#isExcluded(operation, method2);
|
|
175
|
+
const isIncluded = this.context.include ? this.#isIncluded(operation, method2) : true;
|
|
230
176
|
if (isIncluded && !isExcluded) {
|
|
231
177
|
if (!acc[path2]) {
|
|
232
178
|
acc[path2] = {};
|
|
@@ -247,26 +193,53 @@ var OperationGenerator = class extends Generator {
|
|
|
247
193
|
const methods = this.operationsByMethod[path2] ? Object.keys(this.operationsByMethod[path2]) : [];
|
|
248
194
|
methods.forEach((method) => {
|
|
249
195
|
const { operation } = this.operationsByMethod[path2]?.[method];
|
|
250
|
-
const options =
|
|
251
|
-
const
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
196
|
+
const options = this.#getOptions(operation, method);
|
|
197
|
+
const methodToCall = this[method];
|
|
198
|
+
if (typeof methodToCall === "function") {
|
|
199
|
+
const promiseMethod = methodToCall?.call(this, operation, {
|
|
200
|
+
...this.options,
|
|
201
|
+
...options
|
|
202
|
+
});
|
|
203
|
+
if (promiseMethod) {
|
|
204
|
+
acc.push(promiseMethod);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
255
207
|
const promiseOperation = this.operation.call(this, operation, {
|
|
256
208
|
...this.options,
|
|
257
209
|
...options
|
|
258
210
|
});
|
|
259
|
-
if (promiseMethod) {
|
|
260
|
-
acc.push(promiseMethod);
|
|
261
|
-
}
|
|
262
211
|
if (promiseOperation) {
|
|
263
212
|
acc.push(promiseOperation);
|
|
264
213
|
}
|
|
214
|
+
generators?.forEach((generator) => {
|
|
215
|
+
const promise = generator.operation?.({
|
|
216
|
+
instance: this,
|
|
217
|
+
operation,
|
|
218
|
+
options: {
|
|
219
|
+
...this.options,
|
|
220
|
+
...options
|
|
221
|
+
}
|
|
222
|
+
});
|
|
223
|
+
if (promise) {
|
|
224
|
+
acc.push(promise);
|
|
225
|
+
}
|
|
226
|
+
});
|
|
265
227
|
});
|
|
266
228
|
return acc;
|
|
267
229
|
}, []);
|
|
268
230
|
const operations = Object.values(this.operationsByMethod).map((item) => Object.values(item).map((item2) => item2.operation));
|
|
269
231
|
promises.push(this.all(operations.flat().filter(Boolean), this.operationsByMethod));
|
|
232
|
+
generators?.forEach((generator) => {
|
|
233
|
+
const promise = generator.operations?.({
|
|
234
|
+
instance: this,
|
|
235
|
+
operations: operations.flat().filter(Boolean),
|
|
236
|
+
operationsByMethod: this.operationsByMethod,
|
|
237
|
+
options: this.options
|
|
238
|
+
});
|
|
239
|
+
if (promise) {
|
|
240
|
+
promises.push(promise);
|
|
241
|
+
}
|
|
242
|
+
});
|
|
270
243
|
const files = await Promise.all(promises);
|
|
271
244
|
return files.flat().filter(Boolean);
|
|
272
245
|
}
|
|
@@ -274,134 +247,192 @@ var OperationGenerator = class extends Generator {
|
|
|
274
247
|
* Operation
|
|
275
248
|
*/
|
|
276
249
|
async operation(operation, options) {
|
|
277
|
-
return
|
|
250
|
+
return [];
|
|
278
251
|
}
|
|
279
252
|
/**
|
|
280
253
|
* GET
|
|
281
254
|
*/
|
|
282
255
|
async get(operation, options) {
|
|
283
|
-
return
|
|
256
|
+
return [];
|
|
284
257
|
}
|
|
285
258
|
/**
|
|
286
259
|
* POST
|
|
287
260
|
*/
|
|
288
261
|
async post(operation, options) {
|
|
289
|
-
return
|
|
262
|
+
return [];
|
|
290
263
|
}
|
|
291
264
|
/**
|
|
292
265
|
* PATCH
|
|
293
266
|
*/
|
|
294
267
|
async patch(operation, options) {
|
|
295
|
-
return
|
|
268
|
+
return [];
|
|
296
269
|
}
|
|
297
270
|
/**
|
|
298
271
|
* PUT
|
|
299
272
|
*/
|
|
300
273
|
async put(operation, options) {
|
|
301
|
-
return
|
|
274
|
+
return [];
|
|
302
275
|
}
|
|
303
276
|
/**
|
|
304
277
|
* DELETE
|
|
305
278
|
*/
|
|
306
279
|
async delete(operation, options) {
|
|
307
|
-
return
|
|
280
|
+
return [];
|
|
308
281
|
}
|
|
309
282
|
/**
|
|
310
283
|
* Combination of GET, POST, PATCH, PUT, DELETE
|
|
311
284
|
*/
|
|
312
285
|
async all(operations, paths) {
|
|
313
|
-
return
|
|
286
|
+
return [];
|
|
314
287
|
}
|
|
315
288
|
};
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
const { exclude = [] } = this.context;
|
|
342
|
-
let matched = false;
|
|
343
|
-
exclude.forEach(({ pattern, type }) => {
|
|
344
|
-
if (type === "tag" && !matched) {
|
|
345
|
-
matched = !!operation.getTags()[0]?.name.match(pattern);
|
|
346
|
-
}
|
|
347
|
-
if (type === "operationId" && !matched) {
|
|
348
|
-
matched = !!operation.getOperationId().match(pattern);
|
|
349
|
-
}
|
|
350
|
-
if (type === "path" && !matched) {
|
|
351
|
-
matched = !!operation.path.match(pattern);
|
|
352
|
-
}
|
|
353
|
-
if (type === "method" && !matched) {
|
|
354
|
-
matched = !!method.match(pattern);
|
|
355
|
-
}
|
|
356
|
-
});
|
|
357
|
-
return matched;
|
|
358
|
-
};
|
|
359
|
-
/**
|
|
360
|
-
*
|
|
361
|
-
* @deprecated
|
|
362
|
-
*/
|
|
363
|
-
isIncluded_fn = function(operation, method) {
|
|
364
|
-
const { include = [] } = this.context;
|
|
365
|
-
let matched = false;
|
|
366
|
-
include.forEach(({ pattern, type }) => {
|
|
367
|
-
if (type === "tag" && !matched) {
|
|
368
|
-
matched = !!operation.getTags()[0]?.name.match(pattern);
|
|
369
|
-
}
|
|
370
|
-
if (type === "operationId" && !matched) {
|
|
371
|
-
matched = !!operation.getOperationId().match(pattern);
|
|
372
|
-
}
|
|
373
|
-
if (type === "path" && !matched) {
|
|
374
|
-
matched = !!operation.path.match(pattern);
|
|
289
|
+
|
|
290
|
+
// src/plugin.ts
|
|
291
|
+
init_esm_shims();
|
|
292
|
+
var pluginOasName = "plugin-oas";
|
|
293
|
+
var pluginOas = createPlugin((options) => {
|
|
294
|
+
const {
|
|
295
|
+
output = { path: "schemas", export: false },
|
|
296
|
+
experimentalFilter: filter,
|
|
297
|
+
experimentalSort: sort,
|
|
298
|
+
validate = true,
|
|
299
|
+
serverIndex = 0,
|
|
300
|
+
contentType,
|
|
301
|
+
oasClass
|
|
302
|
+
} = options;
|
|
303
|
+
const getOas = async ({ config, logger, formatOptions }) => {
|
|
304
|
+
try {
|
|
305
|
+
const oas = await parseFromConfig(config, formatOptions, oasClass);
|
|
306
|
+
if (validate) {
|
|
307
|
+
await oas.valdiate();
|
|
308
|
+
}
|
|
309
|
+
return oas;
|
|
310
|
+
} catch (e) {
|
|
311
|
+
const error = e;
|
|
312
|
+
logger.emit("warning", error?.message);
|
|
313
|
+
return parseFromConfig(config, {}, oasClass);
|
|
375
314
|
}
|
|
376
|
-
|
|
377
|
-
|
|
315
|
+
};
|
|
316
|
+
return {
|
|
317
|
+
name: pluginOasName,
|
|
318
|
+
output: output === false ? {
|
|
319
|
+
path: "",
|
|
320
|
+
exportType: false
|
|
321
|
+
} : {
|
|
322
|
+
exportType: "barrelNamed",
|
|
323
|
+
...output
|
|
324
|
+
},
|
|
325
|
+
options,
|
|
326
|
+
context() {
|
|
327
|
+
const { config, logger } = this;
|
|
328
|
+
return {
|
|
329
|
+
getOas(formatOptions) {
|
|
330
|
+
return getOas({ config, logger, formatOptions });
|
|
331
|
+
},
|
|
332
|
+
async getSchemas({ includes } = {}) {
|
|
333
|
+
const oas = await this.getOas();
|
|
334
|
+
return getSchemas({ oas, contentType, includes });
|
|
335
|
+
},
|
|
336
|
+
async getBaseURL() {
|
|
337
|
+
const oasInstance = await this.getOas();
|
|
338
|
+
const baseURL = oasInstance.api.servers?.at(serverIndex)?.url;
|
|
339
|
+
return baseURL;
|
|
340
|
+
},
|
|
341
|
+
contentType
|
|
342
|
+
};
|
|
343
|
+
},
|
|
344
|
+
async buildStart() {
|
|
345
|
+
if (!output) {
|
|
346
|
+
return;
|
|
347
|
+
}
|
|
348
|
+
const oas = await getOas({
|
|
349
|
+
config: this.config,
|
|
350
|
+
logger: this.logger,
|
|
351
|
+
formatOptions: {
|
|
352
|
+
filterSet: filter,
|
|
353
|
+
sortSet: sort
|
|
354
|
+
}
|
|
355
|
+
});
|
|
356
|
+
await oas.dereference();
|
|
357
|
+
const root = path.resolve(this.config.root, this.config.output.path);
|
|
358
|
+
const schemas = getSchemas({ oas, contentType });
|
|
359
|
+
const mapSchema = async ([name, schema]) => {
|
|
360
|
+
const baseName = `${camelCase(name)}.json`;
|
|
361
|
+
const resolvedPath = path.resolve(root, output.path, baseName);
|
|
362
|
+
await this.addFile({
|
|
363
|
+
path: resolvedPath,
|
|
364
|
+
baseName,
|
|
365
|
+
meta: {
|
|
366
|
+
pluginKey: this.plugin.key
|
|
367
|
+
},
|
|
368
|
+
sources: [
|
|
369
|
+
{
|
|
370
|
+
name: camelCase(name),
|
|
371
|
+
isExportable: false,
|
|
372
|
+
isIndexable: false,
|
|
373
|
+
value: JSON.stringify(schema)
|
|
374
|
+
}
|
|
375
|
+
]
|
|
376
|
+
});
|
|
377
|
+
};
|
|
378
|
+
const promises = Object.entries(schemas).map(mapSchema);
|
|
379
|
+
await Promise.all(promises);
|
|
378
380
|
}
|
|
379
|
-
}
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
381
|
+
};
|
|
382
|
+
});
|
|
383
|
+
|
|
384
|
+
// src/generator.tsx
|
|
385
|
+
init_esm_shims();
|
|
386
|
+
var import_jsx_runtime = __toESM(require_jsx_runtime(), 1);
|
|
387
|
+
function createGenerator(parseOptions) {
|
|
388
|
+
return parseOptions;
|
|
389
|
+
}
|
|
390
|
+
function createReactGenerator(parseOptions) {
|
|
383
391
|
return {
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
+
...parseOptions,
|
|
393
|
+
async operations({ instance, options, operations, operationsByMethod }) {
|
|
394
|
+
if (!parseOptions.Operations) {
|
|
395
|
+
return [];
|
|
396
|
+
}
|
|
397
|
+
const { pluginManager, oas, plugin, mode } = instance.context;
|
|
398
|
+
const root = createRoot({
|
|
399
|
+
logger: pluginManager.logger
|
|
400
|
+
});
|
|
401
|
+
root.render(
|
|
402
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(App, { pluginManager, plugin, mode, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Oas, { oas, operations, generator: instance, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(parseOptions.Operations, { operations, instance, operationsByMethod, options }) }) })
|
|
403
|
+
);
|
|
404
|
+
return root.files;
|
|
405
|
+
},
|
|
406
|
+
async operation({ instance, operation, options }) {
|
|
407
|
+
if (!parseOptions.Operation) {
|
|
408
|
+
return [];
|
|
409
|
+
}
|
|
410
|
+
const { pluginManager, oas, plugin, mode } = instance.context;
|
|
411
|
+
const root = createRoot({
|
|
412
|
+
logger: pluginManager.logger
|
|
413
|
+
});
|
|
414
|
+
root.render(
|
|
415
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(App, { pluginManager, plugin: { ...plugin, options }, mode, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Oas, { oas, operations: [operation], generator: instance, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Oas.Operation, { operation, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(parseOptions.Operation, { operation, options, instance }) }) }) })
|
|
416
|
+
);
|
|
417
|
+
return root.files;
|
|
418
|
+
},
|
|
419
|
+
async schema({ instance, schema, name, options }) {
|
|
420
|
+
if (!parseOptions.Schema) {
|
|
421
|
+
return [];
|
|
422
|
+
}
|
|
423
|
+
const { pluginManager, oas, plugin, mode } = instance.context;
|
|
424
|
+
const root = createRoot({
|
|
425
|
+
logger: pluginManager.logger
|
|
426
|
+
});
|
|
427
|
+
const tree = instance.parse({ schema, name });
|
|
428
|
+
root.render(
|
|
429
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(App, { pluginManager, plugin: { ...plugin, options }, mode, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Oas, { oas, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Oas.Schema, { name, value: schema, tree, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(parseOptions.Schema, { schema, options, instance, name }) }) }) })
|
|
430
|
+
);
|
|
431
|
+
return root.files;
|
|
432
|
+
}
|
|
392
433
|
};
|
|
393
|
-
}
|
|
434
|
+
}
|
|
394
435
|
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
var src_default = definePluginDefault;
|
|
398
|
-
export {
|
|
399
|
-
OperationGenerator,
|
|
400
|
-
SchemaGenerator,
|
|
401
|
-
src_default as default,
|
|
402
|
-
isKeyword,
|
|
403
|
-
pluginOas,
|
|
404
|
-
pluginOasName,
|
|
405
|
-
schemaKeywords
|
|
406
|
-
};
|
|
436
|
+
export { OperationGenerator, createGenerator, createReactGenerator, pluginOas, pluginOasName };
|
|
437
|
+
//# sourceMappingURL=index.js.map
|
|
407
438
|
//# sourceMappingURL=index.js.map
|