@kubb/plugin-oas 0.0.0-canary-20240806053140 → 0.0.0-canary-20241106205013
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/OperationGenerator-Bw6sj3Eb.d.cts +560 -0
- package/dist/OperationGenerator-Bw6sj3Eb.d.ts +560 -0
- package/dist/Schema-4FwWfdim.d.cts +22 -0
- package/dist/Schema-BlGtSgNB.d.ts +22 -0
- package/dist/chunk-2TGWPVZN.cjs +92 -0
- package/dist/chunk-2TGWPVZN.cjs.map +1 -0
- package/dist/chunk-A3ROGKLW.cjs +752 -0
- package/dist/chunk-A3ROGKLW.cjs.map +1 -0
- package/dist/chunk-ABOQ73FL.cjs +36 -0
- package/dist/chunk-ABOQ73FL.cjs.map +1 -0
- package/dist/chunk-BG77DP54.js +30 -0
- package/dist/chunk-BG77DP54.js.map +1 -0
- package/dist/chunk-GF26SDHQ.js +28 -0
- package/dist/chunk-GF26SDHQ.js.map +1 -0
- package/dist/chunk-JA75IPYU.js +744 -0
- package/dist/chunk-JA75IPYU.js.map +1 -0
- package/dist/chunk-PADR76WZ.cjs +4 -0
- package/dist/chunk-PADR76WZ.cjs.map +1 -0
- package/dist/chunk-QAFBZLJA.cjs +48 -0
- package/dist/chunk-QAFBZLJA.cjs.map +1 -0
- package/dist/chunk-R47XMJ32.js +3 -0
- package/dist/chunk-R47XMJ32.js.map +1 -0
- package/dist/chunk-TNWNNVQW.js +88 -0
- package/dist/chunk-TNWNNVQW.js.map +1 -0
- package/dist/chunk-XNCEFOE6.js +45 -0
- package/dist/chunk-XNCEFOE6.js.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 -9
- package/dist/components.d.ts +12 -9
- 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 +9 -0
- package/dist/generators.d.ts +9 -0
- package/dist/generators.js +5 -0
- package/dist/generators.js.map +1 -0
- package/dist/hooks.cjs +90 -58
- package/dist/hooks.cjs.map +1 -1
- package/dist/hooks.d.cts +37 -10
- package/dist/hooks.d.ts +37 -10
- package/dist/hooks.js +79 -54
- package/dist/hooks.js.map +1 -1
- package/dist/index.cjs +277 -270
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +6 -78
- package/dist/index.d.ts +6 -78
- package/dist/index.js +235 -255
- 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 +8 -43
- package/dist/utils.d.ts +8 -43
- package/dist/utils.js +8 -86
- package/dist/utils.js.map +1 -1
- package/package.json +21 -15
- package/src/OperationGenerator.ts +91 -64
- package/src/SchemaGenerator.ts +102 -22
- package/src/SchemaMapper.ts +24 -5
- 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 +129 -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 +56 -30
- package/src/hooks/useSchemaManager.ts +77 -0
- package/src/index.ts +5 -13
- package/src/plugin.ts +73 -69
- package/src/types.ts +29 -27
- package/src/utils/getParams.ts +2 -2
- package/src/utils/getSchemaFactory.ts +1 -1
- package/src/utils/index.ts +2 -2
- package/src/utils/parseFromConfig.ts +7 -7
- package/dist/OperationGenerator-BV6QRtkW.d.cts +0 -60
- package/dist/OperationGenerator-DO5tNGuT.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-6QFVU3BI.js +0 -3265
- package/dist/chunk-6QFVU3BI.js.map +0 -1
- package/dist/chunk-7BYOJGO3.js +0 -35
- package/dist/chunk-7BYOJGO3.js.map +0 -1
- package/dist/chunk-DHPXS6V7.cjs +0 -35
- package/dist/chunk-DHPXS6V7.cjs.map +0 -1
- package/dist/chunk-E4NYDEAU.js +0 -101
- package/dist/chunk-E4NYDEAU.js.map +0 -1
- package/dist/chunk-KGR7UP2W.js +0 -695
- package/dist/chunk-KGR7UP2W.js.map +0 -1
- package/dist/chunk-M62LERKB.cjs +0 -695
- package/dist/chunk-M62LERKB.cjs.map +0 -1
- package/dist/chunk-NLQIW5KR.cjs +0 -3265
- package/dist/chunk-NLQIW5KR.cjs.map +0 -1
- package/dist/chunk-PHNRHM3I.cjs +0 -101
- package/dist/chunk-PHNRHM3I.cjs.map +0 -1
- package/dist/types-Db0qp8u-.d.cts +0 -148
- package/dist/types-Db0qp8u-.d.ts +0 -148
- package/src/utils/getGroupedByTagFiles.ts +0 -82
- package/src/utils/refSorter.ts +0 -13
package/dist/index.js
CHANGED
|
@@ -1,155 +1,86 @@
|
|
|
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-E4NYDEAU.js";
|
|
1
|
+
import { parseFromConfig } from './chunk-BG77DP54.js';
|
|
2
|
+
import { jsonGenerator } from './chunk-TNWNNVQW.js';
|
|
3
|
+
export { createGenerator, createReactGenerator } from './chunk-TNWNNVQW.js';
|
|
4
|
+
import './chunk-R47XMJ32.js';
|
|
5
|
+
import { SchemaGenerator } from './chunk-JA75IPYU.js';
|
|
6
|
+
export { SchemaGenerator, isKeyword, schemaKeywords } from './chunk-JA75IPYU.js';
|
|
7
|
+
import { getSchemas } from './chunk-XNCEFOE6.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
|
-
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;
|
|
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 writeFile(path2, source) {
|
|
82
|
-
if (!path2.endsWith(".json") || !source) {
|
|
83
|
-
return;
|
|
30
|
+
if (type === "path") {
|
|
31
|
+
return !!operation.path.match(pattern);
|
|
84
32
|
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
async buildStart() {
|
|
88
|
-
if (!output) {
|
|
89
|
-
return;
|
|
33
|
+
if (type === "method") {
|
|
34
|
+
return !!method.match(pattern);
|
|
90
35
|
}
|
|
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, {});
|
|
36
|
+
return false;
|
|
37
|
+
})?.options || {};
|
|
139
38
|
}
|
|
140
|
-
|
|
141
|
-
|
|
39
|
+
#isExcluded(operation, method) {
|
|
40
|
+
const { exclude = [] } = this.context;
|
|
41
|
+
let matched = false;
|
|
42
|
+
exclude.forEach(({ pattern, type }) => {
|
|
43
|
+
if (type === "tag" && !matched) {
|
|
44
|
+
matched = !!operation.getTags()[0]?.name.match(pattern);
|
|
45
|
+
}
|
|
46
|
+
if (type === "operationId" && !matched) {
|
|
47
|
+
matched = !!operation.getOperationId().match(pattern);
|
|
48
|
+
}
|
|
49
|
+
if (type === "path" && !matched) {
|
|
50
|
+
matched = !!operation.path.match(pattern);
|
|
51
|
+
}
|
|
52
|
+
if (type === "method" && !matched) {
|
|
53
|
+
matched = !!method.match(pattern);
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
return matched;
|
|
142
57
|
}
|
|
143
|
-
|
|
144
|
-
|
|
58
|
+
#isIncluded(operation, method) {
|
|
59
|
+
const { include = [] } = this.context;
|
|
60
|
+
let matched = false;
|
|
61
|
+
include.forEach(({ pattern, type }) => {
|
|
62
|
+
if (type === "tag" && !matched) {
|
|
63
|
+
matched = !!operation.getTags()[0]?.name.match(pattern);
|
|
64
|
+
}
|
|
65
|
+
if (type === "operationId" && !matched) {
|
|
66
|
+
matched = !!operation.getOperationId().match(pattern);
|
|
67
|
+
}
|
|
68
|
+
if (type === "path" && !matched) {
|
|
69
|
+
matched = !!operation.path.match(pattern);
|
|
70
|
+
}
|
|
71
|
+
if (type === "method" && !matched) {
|
|
72
|
+
matched = !!method.match(pattern);
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
return matched;
|
|
145
76
|
}
|
|
146
|
-
getSchemas(operation, {
|
|
77
|
+
getSchemas(operation, {
|
|
78
|
+
resolveName = (name) => name
|
|
79
|
+
} = {}) {
|
|
147
80
|
const pathParamsSchema = this.context.oas.getParametersSchema(operation, "path");
|
|
148
81
|
const queryParamsSchema = this.context.oas.getParametersSchema(operation, "query");
|
|
149
82
|
const headerParamsSchema = this.context.oas.getParametersSchema(operation, "header");
|
|
150
83
|
const requestSchema = this.context.oas.getRequestSchema(operation);
|
|
151
|
-
const responseStatusCode = forStatusCode || operation.schema.responses && Object.keys(operation.schema.responses).find((key) => key.startsWith("2")) || 200;
|
|
152
|
-
const responseSchema = this.context.oas.getResponseSchema(operation, responseStatusCode);
|
|
153
84
|
const statusCodes = operation.getResponseStatusCodes().map((statusCode) => {
|
|
154
85
|
let name = statusCode;
|
|
155
86
|
if (name === "default") {
|
|
@@ -163,9 +94,14 @@ var OperationGenerator = class extends Generator {
|
|
|
163
94
|
operation,
|
|
164
95
|
operationName: transformers.pascalCase(`${operation.getOperationId()}`),
|
|
165
96
|
statusCode: name === "error" ? void 0 : Number(statusCode),
|
|
166
|
-
keys: schema?.properties ? Object.keys(schema.properties) : void 0
|
|
97
|
+
keys: schema?.properties ? Object.keys(schema.properties) : void 0,
|
|
98
|
+
keysToOmit: schema?.properties ? Object.keys(schema.properties).filter((key) => {
|
|
99
|
+
const item = schema.properties?.[key];
|
|
100
|
+
return item?.writeOnly;
|
|
101
|
+
}) : void 0
|
|
167
102
|
};
|
|
168
103
|
});
|
|
104
|
+
const hasResponses = statusCodes.some((item) => item.statusCode?.toString().startsWith("2"));
|
|
169
105
|
return {
|
|
170
106
|
pathParams: pathParamsSchema ? {
|
|
171
107
|
name: resolveName(transformers.pascalCase(`${operation.getOperationId()} PathParams`)),
|
|
@@ -202,31 +138,33 @@ var OperationGenerator = class extends Generator {
|
|
|
202
138
|
} : void 0,
|
|
203
139
|
response: {
|
|
204
140
|
name: resolveName(transformers.pascalCase(`${operation.getOperationId()} ${operation.method === "get" ? "queryResponse" : "mutationResponse"}`)),
|
|
205
|
-
description: operation.getResponseAsJSONSchema(responseStatusCode)?.at(0)?.description,
|
|
206
141
|
operation,
|
|
207
142
|
operationName: transformers.pascalCase(`${operation.getOperationId()}`),
|
|
208
|
-
schema:
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
143
|
+
schema: {
|
|
144
|
+
oneOf: hasResponses ? statusCodes.filter((item) => item.statusCode?.toString().startsWith("2")).map((item) => {
|
|
145
|
+
return {
|
|
146
|
+
...item.schema,
|
|
147
|
+
$ref: resolveName(transformers.pascalCase(`${operation.getOperationId()} ${item.statusCode}`))
|
|
148
|
+
};
|
|
149
|
+
}) : void 0
|
|
150
|
+
}
|
|
215
151
|
},
|
|
152
|
+
responses: statusCodes.filter((item) => item.statusCode?.toString().startsWith("2")),
|
|
216
153
|
errors: statusCodes.filter((item) => item.statusCode?.toString().startsWith("4") || item.statusCode?.toString().startsWith("5")),
|
|
217
154
|
statusCodes
|
|
218
155
|
};
|
|
219
156
|
}
|
|
220
|
-
|
|
157
|
+
#methods = ["get", "post", "patch", "put", "delete"];
|
|
158
|
+
async build(...generators) {
|
|
221
159
|
const { oas } = this.context;
|
|
222
160
|
const paths = oas.getPaths();
|
|
223
161
|
this.operationsByMethod = Object.entries(paths).reduce((acc, [path2, method]) => {
|
|
224
162
|
const methods = Object.keys(method);
|
|
225
163
|
methods.forEach((method2) => {
|
|
226
164
|
const operation = oas.operation(path2, method2);
|
|
227
|
-
if (operation &&
|
|
228
|
-
const isExcluded =
|
|
229
|
-
const isIncluded = this.context.include ?
|
|
165
|
+
if (operation && [this.#methods].some((methods2) => method2 === operation.method)) {
|
|
166
|
+
const isExcluded = this.#isExcluded(operation, method2);
|
|
167
|
+
const isIncluded = this.context.include ? this.#isIncluded(operation, method2) : true;
|
|
230
168
|
if (isIncluded && !isExcluded) {
|
|
231
169
|
if (!acc[path2]) {
|
|
232
170
|
acc[path2] = {};
|
|
@@ -247,26 +185,53 @@ var OperationGenerator = class extends Generator {
|
|
|
247
185
|
const methods = this.operationsByMethod[path2] ? Object.keys(this.operationsByMethod[path2]) : [];
|
|
248
186
|
methods.forEach((method) => {
|
|
249
187
|
const { operation } = this.operationsByMethod[path2]?.[method];
|
|
250
|
-
const options =
|
|
251
|
-
const
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
188
|
+
const options = this.#getOptions(operation, method);
|
|
189
|
+
const methodToCall = this[method];
|
|
190
|
+
if (typeof methodToCall === "function") {
|
|
191
|
+
const promiseMethod = methodToCall?.call(this, operation, {
|
|
192
|
+
...this.options,
|
|
193
|
+
...options
|
|
194
|
+
});
|
|
195
|
+
if (promiseMethod) {
|
|
196
|
+
acc.push(promiseMethod);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
255
199
|
const promiseOperation = this.operation.call(this, operation, {
|
|
256
200
|
...this.options,
|
|
257
201
|
...options
|
|
258
202
|
});
|
|
259
|
-
if (promiseMethod) {
|
|
260
|
-
acc.push(promiseMethod);
|
|
261
|
-
}
|
|
262
203
|
if (promiseOperation) {
|
|
263
204
|
acc.push(promiseOperation);
|
|
264
205
|
}
|
|
206
|
+
generators?.forEach((generator) => {
|
|
207
|
+
const promise = generator.operation?.({
|
|
208
|
+
instance: this,
|
|
209
|
+
operation,
|
|
210
|
+
options: {
|
|
211
|
+
...this.options,
|
|
212
|
+
...options
|
|
213
|
+
}
|
|
214
|
+
});
|
|
215
|
+
if (promise) {
|
|
216
|
+
acc.push(promise);
|
|
217
|
+
}
|
|
218
|
+
});
|
|
265
219
|
});
|
|
266
220
|
return acc;
|
|
267
221
|
}, []);
|
|
268
222
|
const operations = Object.values(this.operationsByMethod).map((item) => Object.values(item).map((item2) => item2.operation));
|
|
269
223
|
promises.push(this.all(operations.flat().filter(Boolean), this.operationsByMethod));
|
|
224
|
+
generators?.forEach((generator) => {
|
|
225
|
+
const promise = generator.operations?.({
|
|
226
|
+
instance: this,
|
|
227
|
+
operations: operations.flat().filter(Boolean),
|
|
228
|
+
operationsByMethod: this.operationsByMethod,
|
|
229
|
+
options: this.options
|
|
230
|
+
});
|
|
231
|
+
if (promise) {
|
|
232
|
+
promises.push(promise);
|
|
233
|
+
}
|
|
234
|
+
});
|
|
270
235
|
const files = await Promise.all(promises);
|
|
271
236
|
return files.flat().filter(Boolean);
|
|
272
237
|
}
|
|
@@ -274,134 +239,149 @@ var OperationGenerator = class extends Generator {
|
|
|
274
239
|
* Operation
|
|
275
240
|
*/
|
|
276
241
|
async operation(operation, options) {
|
|
277
|
-
return
|
|
242
|
+
return [];
|
|
278
243
|
}
|
|
279
244
|
/**
|
|
280
245
|
* GET
|
|
281
246
|
*/
|
|
282
247
|
async get(operation, options) {
|
|
283
|
-
return
|
|
248
|
+
return [];
|
|
284
249
|
}
|
|
285
250
|
/**
|
|
286
251
|
* POST
|
|
287
252
|
*/
|
|
288
253
|
async post(operation, options) {
|
|
289
|
-
return
|
|
254
|
+
return [];
|
|
290
255
|
}
|
|
291
256
|
/**
|
|
292
257
|
* PATCH
|
|
293
258
|
*/
|
|
294
259
|
async patch(operation, options) {
|
|
295
|
-
return
|
|
260
|
+
return [];
|
|
296
261
|
}
|
|
297
262
|
/**
|
|
298
263
|
* PUT
|
|
299
264
|
*/
|
|
300
265
|
async put(operation, options) {
|
|
301
|
-
return
|
|
266
|
+
return [];
|
|
302
267
|
}
|
|
303
268
|
/**
|
|
304
269
|
* DELETE
|
|
305
270
|
*/
|
|
306
271
|
async delete(operation, options) {
|
|
307
|
-
return
|
|
272
|
+
return [];
|
|
308
273
|
}
|
|
309
274
|
/**
|
|
310
275
|
* Combination of GET, POST, PATCH, PUT, DELETE
|
|
311
276
|
*/
|
|
312
277
|
async all(operations, paths) {
|
|
313
|
-
return
|
|
278
|
+
return [];
|
|
314
279
|
}
|
|
315
280
|
};
|
|
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
|
-
isExcluded_fn = function(operation, method) {
|
|
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);
|
|
375
|
-
}
|
|
376
|
-
if (type === "method" && !matched) {
|
|
377
|
-
matched = !!method.match(pattern);
|
|
281
|
+
var pluginOasName = "plugin-oas";
|
|
282
|
+
var pluginOas = createPlugin((options) => {
|
|
283
|
+
const {
|
|
284
|
+
output = {
|
|
285
|
+
path: "schemas"
|
|
286
|
+
},
|
|
287
|
+
validate = true,
|
|
288
|
+
generators = [jsonGenerator],
|
|
289
|
+
serverIndex,
|
|
290
|
+
contentType,
|
|
291
|
+
oasClass
|
|
292
|
+
} = options;
|
|
293
|
+
const getOas = async ({ config, logger }) => {
|
|
294
|
+
try {
|
|
295
|
+
const oas = await parseFromConfig(config, oasClass);
|
|
296
|
+
if (validate) {
|
|
297
|
+
await oas.valdiate();
|
|
298
|
+
}
|
|
299
|
+
return oas;
|
|
300
|
+
} catch (e) {
|
|
301
|
+
const error = e;
|
|
302
|
+
logger.emit("warning", error?.message);
|
|
303
|
+
return parseFromConfig(config, oasClass);
|
|
378
304
|
}
|
|
379
|
-
}
|
|
380
|
-
return matched;
|
|
381
|
-
};
|
|
382
|
-
methods_get = function() {
|
|
305
|
+
};
|
|
383
306
|
return {
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
307
|
+
name: pluginOasName,
|
|
308
|
+
options: {
|
|
309
|
+
output,
|
|
310
|
+
...options
|
|
311
|
+
},
|
|
312
|
+
context() {
|
|
313
|
+
const { config, logger } = this;
|
|
314
|
+
return {
|
|
315
|
+
getOas() {
|
|
316
|
+
return getOas({ config, logger });
|
|
317
|
+
},
|
|
318
|
+
async getSchemas({ includes } = {}) {
|
|
319
|
+
const oas = await this.getOas();
|
|
320
|
+
return getSchemas({ oas, contentType, includes });
|
|
321
|
+
},
|
|
322
|
+
async getBaseURL() {
|
|
323
|
+
const oasInstance = await this.getOas();
|
|
324
|
+
if (serverIndex) {
|
|
325
|
+
return oasInstance.api.servers?.at(serverIndex)?.url;
|
|
326
|
+
}
|
|
327
|
+
return void 0;
|
|
328
|
+
},
|
|
329
|
+
contentType
|
|
330
|
+
};
|
|
331
|
+
},
|
|
332
|
+
resolvePath(baseName, pathMode, options2) {
|
|
333
|
+
const root = path.resolve(this.config.root, this.config.output.path);
|
|
334
|
+
const mode = pathMode ?? FileManager.getMode(path.resolve(root, output.path));
|
|
335
|
+
if (mode === "single") {
|
|
336
|
+
return path.resolve(root, output.path);
|
|
337
|
+
}
|
|
338
|
+
return path.resolve(root, output.path, baseName);
|
|
339
|
+
},
|
|
340
|
+
async buildStart() {
|
|
341
|
+
if (!output) {
|
|
342
|
+
return;
|
|
343
|
+
}
|
|
344
|
+
const oas = await getOas({
|
|
345
|
+
config: this.config,
|
|
346
|
+
logger: this.logger
|
|
347
|
+
});
|
|
348
|
+
await oas.dereference();
|
|
349
|
+
const schemaGenerator = new SchemaGenerator(
|
|
350
|
+
{
|
|
351
|
+
unknownType: "unknown",
|
|
352
|
+
dateType: "date",
|
|
353
|
+
transformers: {},
|
|
354
|
+
...this.plugin.options
|
|
355
|
+
},
|
|
356
|
+
{
|
|
357
|
+
oas,
|
|
358
|
+
pluginManager: this.pluginManager,
|
|
359
|
+
plugin: this.plugin,
|
|
360
|
+
contentType,
|
|
361
|
+
include: void 0,
|
|
362
|
+
override: void 0,
|
|
363
|
+
mode: "split",
|
|
364
|
+
output: output.path
|
|
365
|
+
}
|
|
366
|
+
);
|
|
367
|
+
const schemaFiles = await schemaGenerator.build(...generators);
|
|
368
|
+
await this.addFile(...schemaFiles);
|
|
369
|
+
const operationGenerator = new OperationGenerator(this.plugin.options, {
|
|
370
|
+
oas,
|
|
371
|
+
pluginManager: this.pluginManager,
|
|
372
|
+
plugin: this.plugin,
|
|
373
|
+
contentType,
|
|
374
|
+
exclude: void 0,
|
|
375
|
+
include: void 0,
|
|
376
|
+
override: void 0,
|
|
377
|
+
mode: "split"
|
|
378
|
+
});
|
|
379
|
+
const operationFiles = await operationGenerator.build(...generators);
|
|
380
|
+
await this.addFile(...operationFiles);
|
|
381
|
+
}
|
|
392
382
|
};
|
|
393
|
-
};
|
|
383
|
+
});
|
|
394
384
|
|
|
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
|
-
};
|
|
385
|
+
export { OperationGenerator, pluginOas, pluginOasName };
|
|
386
|
+
//# sourceMappingURL=index.js.map
|
|
407
387
|
//# sourceMappingURL=index.js.map
|