@kubb/plugin-oas 3.0.0-alpha.2 → 3.0.0-alpha.21
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 +13 -4
- package/dist/OperationGenerator-CHXolL0o.d.cts +553 -0
- package/dist/OperationGenerator-CHXolL0o.d.ts +553 -0
- package/dist/Schema-Ch0dHkM5.d.ts +22 -0
- package/dist/Schema-ClNodlyP.d.cts +22 -0
- package/dist/chunk-6UWOTOZJ.cjs +92 -0
- package/dist/chunk-6UWOTOZJ.cjs.map +1 -0
- package/dist/chunk-AZKUU24F.js +700 -0
- package/dist/chunk-AZKUU24F.js.map +1 -0
- package/dist/chunk-DFQJ57GH.js +45 -0
- package/dist/chunk-DFQJ57GH.js.map +1 -0
- package/dist/chunk-GF26SDHQ.js +28 -0
- package/dist/chunk-GF26SDHQ.js.map +1 -0
- package/dist/chunk-HP5WAFBU.cjs +48 -0
- package/dist/chunk-HP5WAFBU.cjs.map +1 -0
- package/dist/chunk-JNGUNN72.cjs +708 -0
- package/dist/chunk-JNGUNN72.cjs.map +1 -0
- package/dist/chunk-PADR76WZ.cjs +4 -0
- package/dist/chunk-PADR76WZ.cjs.map +1 -0
- package/dist/chunk-R47XMJ32.js +3 -0
- package/dist/chunk-R47XMJ32.js.map +1 -0
- package/dist/{chunk-Y4V7HHX7.js → chunk-THGCWF2O.js} +8 -13
- package/dist/{chunk-Y4V7HHX7.js.map → chunk-THGCWF2O.js.map} +1 -1
- package/dist/chunk-TRA5BTWI.js +88 -0
- package/dist/chunk-TRA5BTWI.js.map +1 -0
- package/dist/chunk-UO57DZPV.cjs +36 -0
- package/dist/chunk-UO57DZPV.cjs.map +1 -0
- package/dist/chunk-ZWHQ54JM.cjs +32 -0
- package/dist/chunk-ZWHQ54JM.cjs.map +1 -0
- package/dist/components.cjs +20 -17
- package/dist/components.cjs.map +1 -1
- package/dist/components.d.cts +12 -8
- package/dist/components.d.ts +12 -8
- package/dist/components.js +3 -17
- package/dist/components.js.map +1 -1
- package/dist/generators.cjs +14 -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 +5 -0
- package/dist/generators.js.map +1 -0
- package/dist/hooks.cjs +101 -57
- package/dist/hooks.cjs.map +1 -1
- package/dist/hooks.d.cts +40 -8
- package/dist/hooks.d.ts +40 -8
- package/dist/hooks.js +90 -53
- package/dist/hooks.js.map +1 -1
- package/dist/index.cjs +283 -261
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +6 -77
- package/dist/index.d.ts +6 -77
- package/dist/index.js +235 -240
- package/dist/index.js.map +1 -1
- package/dist/utils.cjs +32 -87
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.d.cts +7 -41
- package/dist/utils.d.ts +7 -41
- package/dist/utils.js +8 -86
- package/dist/utils.js.map +1 -1
- package/package.json +20 -14
- package/src/OperationGenerator.ts +75 -43
- package/src/SchemaGenerator.ts +44 -18
- 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 +2 -102
- package/src/generator.tsx +133 -0
- package/src/generators/index.ts +1 -0
- package/src/generators/jsonGenerator.ts +32 -0
- package/src/hooks/index.ts +2 -0
- package/src/hooks/useOperationManager.ts +76 -28
- package/src/hooks/useSchemaManager.ts +77 -0
- package/src/index.ts +3 -9
- package/src/plugin.ts +64 -47
- package/src/types.ts +23 -12
- package/src/utils/getParams.ts +2 -2
- package/src/utils/index.ts +2 -2
- package/dist/OperationGenerator-CeM_9pxW.d.cts +0 -60
- package/dist/OperationGenerator-DhUhvRJE.d.ts +0 -60
- package/dist/Schema-DefwBJMc.d.ts +0 -35
- package/dist/Schema-an5hOrjZ.d.cts +0 -35
- package/dist/SchemaMapper-CsBQ6eEx.d.cts +0 -248
- package/dist/SchemaMapper-CsBQ6eEx.d.ts +0 -248
- package/dist/chunk-CJXRFYEF.cjs +0 -698
- package/dist/chunk-CJXRFYEF.cjs.map +0 -1
- package/dist/chunk-DRLYORTT.cjs +0 -3265
- 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 +0 -3265
- 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-UB552H4J.js +0 -101
- package/dist/chunk-UB552H4J.js.map +0 -1
- package/dist/types-Dte3MA6H.d.cts +0 -143
- package/dist/types-Dte3MA6H.d.ts +0 -143
- package/src/utils/getGroupedByTagFiles.ts +0 -82
- package/src/utils/refSorter.ts +0 -13
package/dist/index.js
CHANGED
|
@@ -1,148 +1,95 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
} from
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
import {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
__privateMethod,
|
|
13
|
-
__privateSet,
|
|
14
|
-
getSchemas,
|
|
15
|
-
init_esm_shims
|
|
16
|
-
} from "./chunk-UB552H4J.js";
|
|
1
|
+
import { parseFromConfig } from './chunk-THGCWF2O.js';
|
|
2
|
+
import { jsonGenerator } from './chunk-TRA5BTWI.js';
|
|
3
|
+
export { createGenerator, createReactGenerator } from './chunk-TRA5BTWI.js';
|
|
4
|
+
import './chunk-R47XMJ32.js';
|
|
5
|
+
import { SchemaGenerator } from './chunk-AZKUU24F.js';
|
|
6
|
+
export { SchemaGenerator, isKeyword, schemaKeywords } from './chunk-AZKUU24F.js';
|
|
7
|
+
import { getSchemas } from './chunk-DFQJ57GH.js';
|
|
8
|
+
import './chunk-GF26SDHQ.js';
|
|
9
|
+
import { createPlugin, FileManager, BaseGenerator } from '@kubb/core';
|
|
10
|
+
import transformers from '@kubb/core/transformers';
|
|
11
|
+
import path from 'node:path';
|
|
17
12
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
experimentalSort: sort,
|
|
32
|
-
validate = true,
|
|
33
|
-
serverIndex = 0,
|
|
34
|
-
contentType,
|
|
35
|
-
oasClass
|
|
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();
|
|
13
|
+
var OperationGenerator = class extends BaseGenerator {
|
|
14
|
+
#operationsByMethod = {};
|
|
15
|
+
get operationsByMethod() {
|
|
16
|
+
return this.#operationsByMethod;
|
|
17
|
+
}
|
|
18
|
+
set operationsByMethod(paths) {
|
|
19
|
+
this.#operationsByMethod = paths;
|
|
20
|
+
}
|
|
21
|
+
#getOptions(operation, method) {
|
|
22
|
+
const { override = [] } = this.context;
|
|
23
|
+
return override.find(({ pattern, type }) => {
|
|
24
|
+
if (type === "tag") {
|
|
25
|
+
return !!operation.getTags()[0]?.name.match(pattern);
|
|
42
26
|
}
|
|
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
|
-
context() {
|
|
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;
|
|
27
|
+
if (type === "operationId") {
|
|
28
|
+
return !!operation.getOperationId().match(pattern);
|
|
74
29
|
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
},
|
|
78
|
-
resolveName(name, type) {
|
|
79
|
-
return camelCase(name, { isFile: type === "file" });
|
|
80
|
-
},
|
|
81
|
-
async buildStart() {
|
|
82
|
-
if (!output) {
|
|
83
|
-
return;
|
|
30
|
+
if (type === "path") {
|
|
31
|
+
return !!operation.path.match(pattern);
|
|
84
32
|
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
sortSet: sort
|
|
91
|
-
}
|
|
92
|
-
});
|
|
93
|
-
await oas.dereference();
|
|
94
|
-
const schemas = getSchemas({ oas, contentType });
|
|
95
|
-
const mapSchema = async ([name, schema]) => {
|
|
96
|
-
const resolvedPath = this.resolvePath({
|
|
97
|
-
baseName: `${name}.json`,
|
|
98
|
-
pluginKey: this.plugin.key
|
|
99
|
-
});
|
|
100
|
-
const resvoledFileName = this.resolveName({
|
|
101
|
-
name: `${name}.json`,
|
|
102
|
-
pluginKey: [pluginOasName],
|
|
103
|
-
type: "file"
|
|
104
|
-
});
|
|
105
|
-
if (!resolvedPath) {
|
|
106
|
-
return;
|
|
107
|
-
}
|
|
108
|
-
await this.addFile({
|
|
109
|
-
path: resolvedPath,
|
|
110
|
-
baseName: resvoledFileName,
|
|
111
|
-
source: JSON.stringify(schema),
|
|
112
|
-
meta: {
|
|
113
|
-
pluginKey: this.plugin.key
|
|
114
|
-
}
|
|
115
|
-
});
|
|
116
|
-
};
|
|
117
|
-
const promises = Object.entries(schemas).map(mapSchema);
|
|
118
|
-
await Promise.all(promises);
|
|
119
|
-
}
|
|
120
|
-
};
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
// src/OperationGenerator.ts
|
|
124
|
-
init_esm_shims();
|
|
125
|
-
import { Generator } from "@kubb/core";
|
|
126
|
-
import transformers from "@kubb/core/transformers";
|
|
127
|
-
var _operationsByMethod, _OperationGenerator_instances, getOptions_fn, isExcluded_fn, isIncluded_fn, methods_get;
|
|
128
|
-
var OperationGenerator = class extends Generator {
|
|
129
|
-
constructor() {
|
|
130
|
-
super(...arguments);
|
|
131
|
-
__privateAdd(this, _OperationGenerator_instances);
|
|
132
|
-
__privateAdd(this, _operationsByMethod, {});
|
|
33
|
+
if (type === "method") {
|
|
34
|
+
return !!method.match(pattern);
|
|
35
|
+
}
|
|
36
|
+
return false;
|
|
37
|
+
})?.options || {};
|
|
133
38
|
}
|
|
134
|
-
|
|
135
|
-
|
|
39
|
+
/**
|
|
40
|
+
*
|
|
41
|
+
* @deprecated
|
|
42
|
+
*/
|
|
43
|
+
#isExcluded(operation, method) {
|
|
44
|
+
const { exclude = [] } = this.context;
|
|
45
|
+
let matched = false;
|
|
46
|
+
exclude.forEach(({ pattern, type }) => {
|
|
47
|
+
if (type === "tag" && !matched) {
|
|
48
|
+
matched = !!operation.getTags()[0]?.name.match(pattern);
|
|
49
|
+
}
|
|
50
|
+
if (type === "operationId" && !matched) {
|
|
51
|
+
matched = !!operation.getOperationId().match(pattern);
|
|
52
|
+
}
|
|
53
|
+
if (type === "path" && !matched) {
|
|
54
|
+
matched = !!operation.path.match(pattern);
|
|
55
|
+
}
|
|
56
|
+
if (type === "method" && !matched) {
|
|
57
|
+
matched = !!method.match(pattern);
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
return matched;
|
|
136
61
|
}
|
|
137
|
-
|
|
138
|
-
|
|
62
|
+
/**
|
|
63
|
+
*
|
|
64
|
+
* @deprecated
|
|
65
|
+
*/
|
|
66
|
+
#isIncluded(operation, method) {
|
|
67
|
+
const { include = [] } = this.context;
|
|
68
|
+
let matched = false;
|
|
69
|
+
include.forEach(({ pattern, type }) => {
|
|
70
|
+
if (type === "tag" && !matched) {
|
|
71
|
+
matched = !!operation.getTags()[0]?.name.match(pattern);
|
|
72
|
+
}
|
|
73
|
+
if (type === "operationId" && !matched) {
|
|
74
|
+
matched = !!operation.getOperationId().match(pattern);
|
|
75
|
+
}
|
|
76
|
+
if (type === "path" && !matched) {
|
|
77
|
+
matched = !!operation.path.match(pattern);
|
|
78
|
+
}
|
|
79
|
+
if (type === "method" && !matched) {
|
|
80
|
+
matched = !!method.match(pattern);
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
return matched;
|
|
139
84
|
}
|
|
140
|
-
getSchemas(operation, {
|
|
85
|
+
getSchemas(operation, {
|
|
86
|
+
resolveName = (name) => name
|
|
87
|
+
} = {}) {
|
|
141
88
|
const pathParamsSchema = this.context.oas.getParametersSchema(operation, "path");
|
|
142
89
|
const queryParamsSchema = this.context.oas.getParametersSchema(operation, "query");
|
|
143
90
|
const headerParamsSchema = this.context.oas.getParametersSchema(operation, "header");
|
|
144
91
|
const requestSchema = this.context.oas.getRequestSchema(operation);
|
|
145
|
-
const responseStatusCode =
|
|
92
|
+
const responseStatusCode = operation.schema.responses && Object.keys(operation.schema.responses).find((key) => key.startsWith("2")) || 200;
|
|
146
93
|
const responseSchema = this.context.oas.getResponseSchema(operation, responseStatusCode);
|
|
147
94
|
const statusCodes = operation.getResponseStatusCodes().map((statusCode) => {
|
|
148
95
|
let name = statusCode;
|
|
@@ -211,16 +158,17 @@ var OperationGenerator = class extends Generator {
|
|
|
211
158
|
statusCodes
|
|
212
159
|
};
|
|
213
160
|
}
|
|
214
|
-
|
|
161
|
+
#methods = ["get", "post", "patch", "put", "delete"];
|
|
162
|
+
async build(...generators) {
|
|
215
163
|
const { oas } = this.context;
|
|
216
164
|
const paths = oas.getPaths();
|
|
217
165
|
this.operationsByMethod = Object.entries(paths).reduce((acc, [path2, method]) => {
|
|
218
166
|
const methods = Object.keys(method);
|
|
219
167
|
methods.forEach((method2) => {
|
|
220
168
|
const operation = oas.operation(path2, method2);
|
|
221
|
-
if (operation &&
|
|
222
|
-
const isExcluded =
|
|
223
|
-
const isIncluded = this.context.include ?
|
|
169
|
+
if (operation && [this.#methods].some((methods2) => method2 === operation.method)) {
|
|
170
|
+
const isExcluded = this.#isExcluded(operation, method2);
|
|
171
|
+
const isIncluded = this.context.include ? this.#isIncluded(operation, method2) : true;
|
|
224
172
|
if (isIncluded && !isExcluded) {
|
|
225
173
|
if (!acc[path2]) {
|
|
226
174
|
acc[path2] = {};
|
|
@@ -241,26 +189,53 @@ var OperationGenerator = class extends Generator {
|
|
|
241
189
|
const methods = this.operationsByMethod[path2] ? Object.keys(this.operationsByMethod[path2]) : [];
|
|
242
190
|
methods.forEach((method) => {
|
|
243
191
|
const { operation } = this.operationsByMethod[path2]?.[method];
|
|
244
|
-
const options =
|
|
245
|
-
const
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
192
|
+
const options = this.#getOptions(operation, method);
|
|
193
|
+
const methodToCall = this[method];
|
|
194
|
+
if (typeof methodToCall === "function") {
|
|
195
|
+
const promiseMethod = methodToCall?.call(this, operation, {
|
|
196
|
+
...this.options,
|
|
197
|
+
...options
|
|
198
|
+
});
|
|
199
|
+
if (promiseMethod) {
|
|
200
|
+
acc.push(promiseMethod);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
249
203
|
const promiseOperation = this.operation.call(this, operation, {
|
|
250
204
|
...this.options,
|
|
251
205
|
...options
|
|
252
206
|
});
|
|
253
|
-
if (promiseMethod) {
|
|
254
|
-
acc.push(promiseMethod);
|
|
255
|
-
}
|
|
256
207
|
if (promiseOperation) {
|
|
257
208
|
acc.push(promiseOperation);
|
|
258
209
|
}
|
|
210
|
+
generators?.forEach((generator) => {
|
|
211
|
+
const promise = generator.operation?.({
|
|
212
|
+
instance: this,
|
|
213
|
+
operation,
|
|
214
|
+
options: {
|
|
215
|
+
...this.options,
|
|
216
|
+
...options
|
|
217
|
+
}
|
|
218
|
+
});
|
|
219
|
+
if (promise) {
|
|
220
|
+
acc.push(promise);
|
|
221
|
+
}
|
|
222
|
+
});
|
|
259
223
|
});
|
|
260
224
|
return acc;
|
|
261
225
|
}, []);
|
|
262
226
|
const operations = Object.values(this.operationsByMethod).map((item) => Object.values(item).map((item2) => item2.operation));
|
|
263
227
|
promises.push(this.all(operations.flat().filter(Boolean), this.operationsByMethod));
|
|
228
|
+
generators?.forEach((generator) => {
|
|
229
|
+
const promise = generator.operations?.({
|
|
230
|
+
instance: this,
|
|
231
|
+
operations: operations.flat().filter(Boolean),
|
|
232
|
+
operationsByMethod: this.operationsByMethod,
|
|
233
|
+
options: this.options
|
|
234
|
+
});
|
|
235
|
+
if (promise) {
|
|
236
|
+
promises.push(promise);
|
|
237
|
+
}
|
|
238
|
+
});
|
|
264
239
|
const files = await Promise.all(promises);
|
|
265
240
|
return files.flat().filter(Boolean);
|
|
266
241
|
}
|
|
@@ -268,134 +243,154 @@ var OperationGenerator = class extends Generator {
|
|
|
268
243
|
* Operation
|
|
269
244
|
*/
|
|
270
245
|
async operation(operation, options) {
|
|
271
|
-
return
|
|
246
|
+
return [];
|
|
272
247
|
}
|
|
273
248
|
/**
|
|
274
249
|
* GET
|
|
275
250
|
*/
|
|
276
251
|
async get(operation, options) {
|
|
277
|
-
return
|
|
252
|
+
return [];
|
|
278
253
|
}
|
|
279
254
|
/**
|
|
280
255
|
* POST
|
|
281
256
|
*/
|
|
282
257
|
async post(operation, options) {
|
|
283
|
-
return
|
|
258
|
+
return [];
|
|
284
259
|
}
|
|
285
260
|
/**
|
|
286
261
|
* PATCH
|
|
287
262
|
*/
|
|
288
263
|
async patch(operation, options) {
|
|
289
|
-
return
|
|
264
|
+
return [];
|
|
290
265
|
}
|
|
291
266
|
/**
|
|
292
267
|
* PUT
|
|
293
268
|
*/
|
|
294
269
|
async put(operation, options) {
|
|
295
|
-
return
|
|
270
|
+
return [];
|
|
296
271
|
}
|
|
297
272
|
/**
|
|
298
273
|
* DELETE
|
|
299
274
|
*/
|
|
300
275
|
async delete(operation, options) {
|
|
301
|
-
return
|
|
276
|
+
return [];
|
|
302
277
|
}
|
|
303
278
|
/**
|
|
304
279
|
* Combination of GET, POST, PATCH, PUT, DELETE
|
|
305
280
|
*/
|
|
306
281
|
async all(operations, paths) {
|
|
307
|
-
return
|
|
282
|
+
return [];
|
|
308
283
|
}
|
|
309
284
|
};
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
exclude.forEach(({ pattern, type }) => {
|
|
338
|
-
if (type === "tag" && !matched) {
|
|
339
|
-
matched = !!operation.getTags()[0]?.name.match(pattern);
|
|
340
|
-
}
|
|
341
|
-
if (type === "operationId" && !matched) {
|
|
342
|
-
matched = !!operation.getOperationId().match(pattern);
|
|
343
|
-
}
|
|
344
|
-
if (type === "path" && !matched) {
|
|
345
|
-
matched = !!operation.path.match(pattern);
|
|
346
|
-
}
|
|
347
|
-
if (type === "method" && !matched) {
|
|
348
|
-
matched = !!method.match(pattern);
|
|
349
|
-
}
|
|
350
|
-
});
|
|
351
|
-
return matched;
|
|
352
|
-
};
|
|
353
|
-
/**
|
|
354
|
-
*
|
|
355
|
-
* @deprecated
|
|
356
|
-
*/
|
|
357
|
-
isIncluded_fn = function(operation, method) {
|
|
358
|
-
const { include = [] } = this.context;
|
|
359
|
-
let matched = false;
|
|
360
|
-
include.forEach(({ pattern, type }) => {
|
|
361
|
-
if (type === "tag" && !matched) {
|
|
362
|
-
matched = !!operation.getTags()[0]?.name.match(pattern);
|
|
363
|
-
}
|
|
364
|
-
if (type === "operationId" && !matched) {
|
|
365
|
-
matched = !!operation.getOperationId().match(pattern);
|
|
366
|
-
}
|
|
367
|
-
if (type === "path" && !matched) {
|
|
368
|
-
matched = !!operation.path.match(pattern);
|
|
369
|
-
}
|
|
370
|
-
if (type === "method" && !matched) {
|
|
371
|
-
matched = !!method.match(pattern);
|
|
285
|
+
var pluginOasName = "plugin-oas";
|
|
286
|
+
var pluginOas = createPlugin((options) => {
|
|
287
|
+
const {
|
|
288
|
+
output = {
|
|
289
|
+
path: "schemas",
|
|
290
|
+
export: false,
|
|
291
|
+
exportType: "barrelNamed"
|
|
292
|
+
},
|
|
293
|
+
experimentalFilter: filter,
|
|
294
|
+
experimentalSort: sort,
|
|
295
|
+
validate = true,
|
|
296
|
+
generators = [jsonGenerator],
|
|
297
|
+
serverIndex = 0,
|
|
298
|
+
contentType,
|
|
299
|
+
oasClass
|
|
300
|
+
} = options;
|
|
301
|
+
const getOas = async ({ config, logger, formatOptions }) => {
|
|
302
|
+
try {
|
|
303
|
+
const oas = await parseFromConfig(config, formatOptions, oasClass);
|
|
304
|
+
if (validate) {
|
|
305
|
+
await oas.valdiate();
|
|
306
|
+
}
|
|
307
|
+
return oas;
|
|
308
|
+
} catch (e) {
|
|
309
|
+
const error = e;
|
|
310
|
+
logger.emit("warning", error?.message);
|
|
311
|
+
return parseFromConfig(config, {}, oasClass);
|
|
372
312
|
}
|
|
373
|
-
}
|
|
374
|
-
return matched;
|
|
375
|
-
};
|
|
376
|
-
methods_get = function() {
|
|
313
|
+
};
|
|
377
314
|
return {
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
315
|
+
name: pluginOasName,
|
|
316
|
+
options: {
|
|
317
|
+
output,
|
|
318
|
+
...options
|
|
319
|
+
},
|
|
320
|
+
context() {
|
|
321
|
+
const { config, logger } = this;
|
|
322
|
+
return {
|
|
323
|
+
getOas(formatOptions) {
|
|
324
|
+
return getOas({ config, logger, formatOptions });
|
|
325
|
+
},
|
|
326
|
+
async getSchemas({ includes } = {}) {
|
|
327
|
+
const oas = await this.getOas();
|
|
328
|
+
return getSchemas({ oas, contentType, includes });
|
|
329
|
+
},
|
|
330
|
+
async getBaseURL() {
|
|
331
|
+
const oasInstance = await this.getOas();
|
|
332
|
+
return oasInstance.api.servers?.at(serverIndex)?.url;
|
|
333
|
+
},
|
|
334
|
+
contentType
|
|
335
|
+
};
|
|
336
|
+
},
|
|
337
|
+
resolvePath(baseName, pathMode, options2) {
|
|
338
|
+
const root = path.resolve(this.config.root, this.config.output.path);
|
|
339
|
+
const mode = pathMode ?? FileManager.getMode(path.resolve(root, output.path));
|
|
340
|
+
if (mode === "single") {
|
|
341
|
+
return path.resolve(root, output.path);
|
|
342
|
+
}
|
|
343
|
+
return path.resolve(root, output.path, baseName);
|
|
344
|
+
},
|
|
345
|
+
async buildStart() {
|
|
346
|
+
if (!output) {
|
|
347
|
+
return;
|
|
348
|
+
}
|
|
349
|
+
const oas = await getOas({
|
|
350
|
+
config: this.config,
|
|
351
|
+
logger: this.logger,
|
|
352
|
+
formatOptions: {
|
|
353
|
+
filterSet: filter,
|
|
354
|
+
sortSet: sort
|
|
355
|
+
}
|
|
356
|
+
});
|
|
357
|
+
await oas.dereference();
|
|
358
|
+
const schemaGenerator = new SchemaGenerator(
|
|
359
|
+
{
|
|
360
|
+
unknownType: "unknown",
|
|
361
|
+
dateType: "date",
|
|
362
|
+
transformers: {},
|
|
363
|
+
...this.plugin.options
|
|
364
|
+
},
|
|
365
|
+
{
|
|
366
|
+
oas,
|
|
367
|
+
pluginManager: this.pluginManager,
|
|
368
|
+
plugin: this.plugin,
|
|
369
|
+
contentType,
|
|
370
|
+
include: void 0,
|
|
371
|
+
override: void 0,
|
|
372
|
+
mode: "split",
|
|
373
|
+
output: output.path
|
|
374
|
+
}
|
|
375
|
+
);
|
|
376
|
+
const schemaFiles = await schemaGenerator.build(...generators);
|
|
377
|
+
await this.addFile(...schemaFiles);
|
|
378
|
+
const operationGenerator = new OperationGenerator(this.plugin.options, {
|
|
379
|
+
oas,
|
|
380
|
+
pluginManager: this.pluginManager,
|
|
381
|
+
plugin: this.plugin,
|
|
382
|
+
contentType,
|
|
383
|
+
exclude: void 0,
|
|
384
|
+
include: void 0,
|
|
385
|
+
override: void 0,
|
|
386
|
+
mode: "split"
|
|
387
|
+
});
|
|
388
|
+
const operationFiles = await operationGenerator.build(...generators);
|
|
389
|
+
await this.addFile(...operationFiles);
|
|
390
|
+
}
|
|
386
391
|
};
|
|
387
|
-
};
|
|
392
|
+
});
|
|
388
393
|
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
var src_default = definePluginDefault;
|
|
392
|
-
export {
|
|
393
|
-
OperationGenerator,
|
|
394
|
-
SchemaGenerator,
|
|
395
|
-
src_default as default,
|
|
396
|
-
isKeyword,
|
|
397
|
-
pluginOas,
|
|
398
|
-
pluginOasName,
|
|
399
|
-
schemaKeywords
|
|
400
|
-
};
|
|
394
|
+
export { OperationGenerator, pluginOas, pluginOasName };
|
|
395
|
+
//# sourceMappingURL=index.js.map
|
|
401
396
|
//# sourceMappingURL=index.js.map
|