@kubb/plugin-oas 0.0.0-canary-20240804130641 → 0.0.0-canary-20241104172400
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-D41ItX9C.d.ts → Schema-4FwWfdim.d.cts} +2 -13
- package/dist/{Schema-FGI5VPqc.d.cts → Schema-BlGtSgNB.d.ts} +2 -13
- 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 -99
- 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/SchemaMapper-CsBQ6eEx.d.cts +0 -248
- package/dist/SchemaMapper-CsBQ6eEx.d.ts +0 -248
- package/dist/chunk-CCPZYOTX.cjs +0 -695
- package/dist/chunk-CCPZYOTX.cjs.map +0 -1
- package/dist/chunk-CO7DS2KL.cjs +0 -35
- package/dist/chunk-CO7DS2KL.cjs.map +0 -1
- package/dist/chunk-EK7UO5ZW.js +0 -35
- package/dist/chunk-EK7UO5ZW.js.map +0 -1
- package/dist/chunk-KI3GNEKH.js +0 -3265
- package/dist/chunk-KI3GNEKH.js.map +0 -1
- package/dist/chunk-LRJFQCDO.js +0 -101
- package/dist/chunk-LRJFQCDO.js.map +0 -1
- package/dist/chunk-PFN2GSIC.cjs +0 -101
- package/dist/chunk-PFN2GSIC.cjs.map +0 -1
- package/dist/chunk-TL7TBM2U.cjs +0 -3265
- package/dist/chunk-TL7TBM2U.cjs.map +0 -1
- package/dist/chunk-UZLE6NIY.js +0 -695
- package/dist/chunk-UZLE6NIY.js.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.cjs
CHANGED
|
@@ -1,155 +1,91 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkABOQ73FL_cjs = require('./chunk-ABOQ73FL.cjs');
|
|
4
|
+
var chunk2TGWPVZN_cjs = require('./chunk-2TGWPVZN.cjs');
|
|
5
|
+
require('./chunk-PADR76WZ.cjs');
|
|
6
|
+
var chunkA3ROGKLW_cjs = require('./chunk-A3ROGKLW.cjs');
|
|
7
|
+
var chunkQAFBZLJA_cjs = require('./chunk-QAFBZLJA.cjs');
|
|
8
|
+
require('./chunk-ZWHQ54JM.cjs');
|
|
9
|
+
var core = require('@kubb/core');
|
|
10
|
+
var transformers = require('@kubb/core/transformers');
|
|
11
|
+
var path = require('path');
|
|
4
12
|
|
|
13
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
5
14
|
|
|
15
|
+
var transformers__default = /*#__PURE__*/_interopDefault(transformers);
|
|
16
|
+
var path__default = /*#__PURE__*/_interopDefault(path);
|
|
6
17
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
// src/plugin.ts
|
|
22
|
-
_chunkPFN2GSICcjs.init_cjs_shims.call(void 0, );
|
|
23
|
-
var _path = require('path'); var _path2 = _interopRequireDefault(_path);
|
|
24
|
-
var _core = require('@kubb/core');
|
|
25
|
-
var _transformers = require('@kubb/core/transformers'); var _transformers2 = _interopRequireDefault(_transformers);
|
|
26
|
-
var pluginOasName = "plugin-oas";
|
|
27
|
-
var pluginOas = _core.createPlugin.call(void 0, (options) => {
|
|
28
|
-
const {
|
|
29
|
-
output = { path: "schemas", export: false },
|
|
30
|
-
experimentalFilter: filter,
|
|
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 _chunkCO7DS2KLcjs.parseFromConfig.call(void 0, config, formatOptions, oasClass);
|
|
40
|
-
if (validate) {
|
|
41
|
-
await oas.valdiate();
|
|
18
|
+
var OperationGenerator = class extends core.BaseGenerator {
|
|
19
|
+
#operationsByMethod = {};
|
|
20
|
+
get operationsByMethod() {
|
|
21
|
+
return this.#operationsByMethod;
|
|
22
|
+
}
|
|
23
|
+
set operationsByMethod(paths) {
|
|
24
|
+
this.#operationsByMethod = paths;
|
|
25
|
+
}
|
|
26
|
+
#getOptions(operation, method) {
|
|
27
|
+
const { override = [] } = this.context;
|
|
28
|
+
return override.find(({ pattern, type }) => {
|
|
29
|
+
if (type === "tag") {
|
|
30
|
+
return !!operation.getTags()[0]?.name.match(pattern);
|
|
42
31
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
const error = e;
|
|
46
|
-
logger.emit("warning", _optionalChain([error, 'optionalAccess', _ => _.message]));
|
|
47
|
-
return _chunkCO7DS2KLcjs.parseFromConfig.call(void 0, 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 _chunkPFN2GSICcjs.getSchemas.call(void 0, { oas, contentType, includes });
|
|
62
|
-
},
|
|
63
|
-
async getBaseURL() {
|
|
64
|
-
const oasInstance = await this.getOas();
|
|
65
|
-
const baseURL = _optionalChain([oasInstance, 'access', _2 => _2.api, 'access', _3 => _3.servers, 'optionalAccess', _4 => _4.at, 'call', _5 => _5(serverIndex), 'optionalAccess', _6 => _6.url]);
|
|
66
|
-
return baseURL;
|
|
67
|
-
},
|
|
68
|
-
contentType
|
|
69
|
-
};
|
|
70
|
-
},
|
|
71
|
-
resolvePath(baseName) {
|
|
72
|
-
if (output === false) {
|
|
73
|
-
return void 0;
|
|
32
|
+
if (type === "operationId") {
|
|
33
|
+
return !!operation.getOperationId().match(pattern);
|
|
74
34
|
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
},
|
|
78
|
-
resolveName(name, type) {
|
|
79
|
-
return _transformers.camelCase.call(void 0, name, { isFile: type === "file" });
|
|
80
|
-
},
|
|
81
|
-
async writeFile(path2, source) {
|
|
82
|
-
if (!path2.endsWith(".json") || !source) {
|
|
83
|
-
return;
|
|
35
|
+
if (type === "path") {
|
|
36
|
+
return !!operation.path.match(pattern);
|
|
84
37
|
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
async buildStart() {
|
|
88
|
-
if (!output) {
|
|
89
|
-
return;
|
|
38
|
+
if (type === "method") {
|
|
39
|
+
return !!method.match(pattern);
|
|
90
40
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
logger: this.logger,
|
|
94
|
-
formatOptions: {
|
|
95
|
-
filterSet: filter,
|
|
96
|
-
sortSet: sort
|
|
97
|
-
}
|
|
98
|
-
});
|
|
99
|
-
await oas.dereference();
|
|
100
|
-
const schemas = _chunkPFN2GSICcjs.getSchemas.call(void 0, { 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
|
-
_chunkPFN2GSICcjs.init_cjs_shims.call(void 0, );
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
var _operationsByMethod, _OperationGenerator_instances, getOptions_fn, isExcluded_fn, isIncluded_fn, methods_get;
|
|
134
|
-
var OperationGenerator = class extends _core.Generator {
|
|
135
|
-
constructor() {
|
|
136
|
-
super(...arguments);
|
|
137
|
-
_chunkPFN2GSICcjs.__privateAdd.call(void 0, this, _OperationGenerator_instances);
|
|
138
|
-
_chunkPFN2GSICcjs.__privateAdd.call(void 0, this, _operationsByMethod, {});
|
|
41
|
+
return false;
|
|
42
|
+
})?.options || {};
|
|
139
43
|
}
|
|
140
|
-
|
|
141
|
-
|
|
44
|
+
#isExcluded(operation, method) {
|
|
45
|
+
const { exclude = [] } = this.context;
|
|
46
|
+
let matched = false;
|
|
47
|
+
exclude.forEach(({ pattern, type }) => {
|
|
48
|
+
if (type === "tag" && !matched) {
|
|
49
|
+
matched = !!operation.getTags()[0]?.name.match(pattern);
|
|
50
|
+
}
|
|
51
|
+
if (type === "operationId" && !matched) {
|
|
52
|
+
matched = !!operation.getOperationId().match(pattern);
|
|
53
|
+
}
|
|
54
|
+
if (type === "path" && !matched) {
|
|
55
|
+
matched = !!operation.path.match(pattern);
|
|
56
|
+
}
|
|
57
|
+
if (type === "method" && !matched) {
|
|
58
|
+
matched = !!method.match(pattern);
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
return matched;
|
|
142
62
|
}
|
|
143
|
-
|
|
144
|
-
|
|
63
|
+
#isIncluded(operation, method) {
|
|
64
|
+
const { include = [] } = this.context;
|
|
65
|
+
let matched = false;
|
|
66
|
+
include.forEach(({ pattern, type }) => {
|
|
67
|
+
if (type === "tag" && !matched) {
|
|
68
|
+
matched = !!operation.getTags()[0]?.name.match(pattern);
|
|
69
|
+
}
|
|
70
|
+
if (type === "operationId" && !matched) {
|
|
71
|
+
matched = !!operation.getOperationId().match(pattern);
|
|
72
|
+
}
|
|
73
|
+
if (type === "path" && !matched) {
|
|
74
|
+
matched = !!operation.path.match(pattern);
|
|
75
|
+
}
|
|
76
|
+
if (type === "method" && !matched) {
|
|
77
|
+
matched = !!method.match(pattern);
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
return matched;
|
|
145
81
|
}
|
|
146
|
-
getSchemas(operation, {
|
|
82
|
+
getSchemas(operation, {
|
|
83
|
+
resolveName = (name) => name
|
|
84
|
+
} = {}) {
|
|
147
85
|
const pathParamsSchema = this.context.oas.getParametersSchema(operation, "path");
|
|
148
86
|
const queryParamsSchema = this.context.oas.getParametersSchema(operation, "query");
|
|
149
87
|
const headerParamsSchema = this.context.oas.getParametersSchema(operation, "header");
|
|
150
88
|
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
89
|
const statusCodes = operation.getResponseStatusCodes().map((statusCode) => {
|
|
154
90
|
let name = statusCode;
|
|
155
91
|
if (name === "default") {
|
|
@@ -157,76 +93,83 @@ var OperationGenerator = class extends _core.Generator {
|
|
|
157
93
|
}
|
|
158
94
|
const schema = this.context.oas.getResponseSchema(operation, statusCode);
|
|
159
95
|
return {
|
|
160
|
-
name: resolveName(
|
|
161
|
-
description:
|
|
96
|
+
name: resolveName(transformers__default.default.pascalCase(`${operation.getOperationId()} ${name}`)),
|
|
97
|
+
description: operation.getResponseByStatusCode(statusCode)?.description,
|
|
162
98
|
schema,
|
|
163
99
|
operation,
|
|
164
|
-
operationName:
|
|
100
|
+
operationName: transformers__default.default.pascalCase(`${operation.getOperationId()}`),
|
|
165
101
|
statusCode: name === "error" ? void 0 : Number(statusCode),
|
|
166
|
-
keys:
|
|
102
|
+
keys: schema?.properties ? Object.keys(schema.properties) : void 0,
|
|
103
|
+
keysToOmit: schema?.properties ? Object.keys(schema.properties).filter((key) => {
|
|
104
|
+
const item = schema.properties?.[key];
|
|
105
|
+
return item?.writeOnly;
|
|
106
|
+
}) : void 0
|
|
167
107
|
};
|
|
168
108
|
});
|
|
109
|
+
const hasResponses = statusCodes.some((item) => item.statusCode?.toString().startsWith("2"));
|
|
169
110
|
return {
|
|
170
111
|
pathParams: pathParamsSchema ? {
|
|
171
|
-
name: resolveName(
|
|
112
|
+
name: resolveName(transformers__default.default.pascalCase(`${operation.getOperationId()} PathParams`)),
|
|
172
113
|
operation,
|
|
173
|
-
operationName:
|
|
114
|
+
operationName: transformers__default.default.pascalCase(`${operation.getOperationId()}`),
|
|
174
115
|
schema: pathParamsSchema,
|
|
175
116
|
keys: pathParamsSchema.properties ? Object.keys(pathParamsSchema.properties) : void 0
|
|
176
117
|
} : void 0,
|
|
177
118
|
queryParams: queryParamsSchema ? {
|
|
178
|
-
name: resolveName(
|
|
119
|
+
name: resolveName(transformers__default.default.pascalCase(`${operation.getOperationId()} QueryParams`)),
|
|
179
120
|
operation,
|
|
180
|
-
operationName:
|
|
121
|
+
operationName: transformers__default.default.pascalCase(`${operation.getOperationId()}`),
|
|
181
122
|
schema: queryParamsSchema,
|
|
182
123
|
keys: queryParamsSchema.properties ? Object.keys(queryParamsSchema.properties) : []
|
|
183
124
|
} : void 0,
|
|
184
125
|
headerParams: headerParamsSchema ? {
|
|
185
|
-
name: resolveName(
|
|
126
|
+
name: resolveName(transformers__default.default.pascalCase(`${operation.getOperationId()} HeaderParams`)),
|
|
186
127
|
operation,
|
|
187
|
-
operationName:
|
|
128
|
+
operationName: transformers__default.default.pascalCase(`${operation.getOperationId()}`),
|
|
188
129
|
schema: headerParamsSchema,
|
|
189
130
|
keys: headerParamsSchema.properties ? Object.keys(headerParamsSchema.properties) : void 0
|
|
190
131
|
} : void 0,
|
|
191
132
|
request: requestSchema ? {
|
|
192
|
-
name: resolveName(
|
|
193
|
-
description:
|
|
133
|
+
name: resolveName(transformers__default.default.pascalCase(`${operation.getOperationId()} ${operation.method === "get" ? "queryRequest" : "mutationRequest"}`)),
|
|
134
|
+
description: operation.schema.requestBody?.description,
|
|
194
135
|
operation,
|
|
195
|
-
operationName:
|
|
136
|
+
operationName: transformers__default.default.pascalCase(`${operation.getOperationId()}`),
|
|
196
137
|
schema: requestSchema,
|
|
197
138
|
keys: requestSchema.properties ? Object.keys(requestSchema.properties) : void 0,
|
|
198
139
|
keysToOmit: requestSchema.properties ? Object.keys(requestSchema.properties).filter((key) => {
|
|
199
|
-
const item =
|
|
200
|
-
return
|
|
140
|
+
const item = requestSchema.properties?.[key];
|
|
141
|
+
return item?.readOnly;
|
|
201
142
|
}) : void 0
|
|
202
143
|
} : void 0,
|
|
203
144
|
response: {
|
|
204
|
-
name: resolveName(
|
|
205
|
-
description: _optionalChain([operation, 'access', _17 => _17.getResponseAsJSONSchema, 'call', _18 => _18(responseStatusCode), 'optionalAccess', _19 => _19.at, 'call', _20 => _20(0), 'optionalAccess', _21 => _21.description]),
|
|
145
|
+
name: resolveName(transformers__default.default.pascalCase(`${operation.getOperationId()} ${operation.method === "get" ? "queryResponse" : "mutationResponse"}`)),
|
|
206
146
|
operation,
|
|
207
|
-
operationName:
|
|
208
|
-
schema:
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
147
|
+
operationName: transformers__default.default.pascalCase(`${operation.getOperationId()}`),
|
|
148
|
+
schema: {
|
|
149
|
+
oneOf: hasResponses ? statusCodes.filter((item) => item.statusCode?.toString().startsWith("2")).map((item) => {
|
|
150
|
+
return {
|
|
151
|
+
...item.schema,
|
|
152
|
+
$ref: resolveName(transformers__default.default.pascalCase(`${operation.getOperationId()} ${item.statusCode}`))
|
|
153
|
+
};
|
|
154
|
+
}) : void 0
|
|
155
|
+
}
|
|
215
156
|
},
|
|
216
|
-
|
|
157
|
+
responses: statusCodes.filter((item) => item.statusCode?.toString().startsWith("2")),
|
|
158
|
+
errors: statusCodes.filter((item) => item.statusCode?.toString().startsWith("4") || item.statusCode?.toString().startsWith("5")),
|
|
217
159
|
statusCodes
|
|
218
160
|
};
|
|
219
161
|
}
|
|
220
|
-
|
|
162
|
+
#methods = ["get", "post", "patch", "put", "delete"];
|
|
163
|
+
async build(...generators) {
|
|
221
164
|
const { oas } = this.context;
|
|
222
165
|
const paths = oas.getPaths();
|
|
223
166
|
this.operationsByMethod = Object.entries(paths).reduce((acc, [path2, method]) => {
|
|
224
167
|
const methods = Object.keys(method);
|
|
225
168
|
methods.forEach((method2) => {
|
|
226
169
|
const operation = oas.operation(path2, method2);
|
|
227
|
-
if (operation &&
|
|
228
|
-
const isExcluded =
|
|
229
|
-
const isIncluded = this.context.include ?
|
|
170
|
+
if (operation && [this.#methods].some((methods2) => method2 === operation.method)) {
|
|
171
|
+
const isExcluded = this.#isExcluded(operation, method2);
|
|
172
|
+
const isIncluded = this.context.include ? this.#isIncluded(operation, method2) : true;
|
|
230
173
|
if (isIncluded && !isExcluded) {
|
|
231
174
|
if (!acc[path2]) {
|
|
232
175
|
acc[path2] = {};
|
|
@@ -246,27 +189,54 @@ var OperationGenerator = class extends _core.Generator {
|
|
|
246
189
|
const promises = Object.keys(this.operationsByMethod).reduce((acc, path2) => {
|
|
247
190
|
const methods = this.operationsByMethod[path2] ? Object.keys(this.operationsByMethod[path2]) : [];
|
|
248
191
|
methods.forEach((method) => {
|
|
249
|
-
const { operation } =
|
|
250
|
-
const options =
|
|
251
|
-
const
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
192
|
+
const { operation } = this.operationsByMethod[path2]?.[method];
|
|
193
|
+
const options = this.#getOptions(operation, method);
|
|
194
|
+
const methodToCall = this[method];
|
|
195
|
+
if (typeof methodToCall === "function") {
|
|
196
|
+
const promiseMethod = methodToCall?.call(this, operation, {
|
|
197
|
+
...this.options,
|
|
198
|
+
...options
|
|
199
|
+
});
|
|
200
|
+
if (promiseMethod) {
|
|
201
|
+
acc.push(promiseMethod);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
255
204
|
const promiseOperation = this.operation.call(this, operation, {
|
|
256
205
|
...this.options,
|
|
257
206
|
...options
|
|
258
207
|
});
|
|
259
|
-
if (promiseMethod) {
|
|
260
|
-
acc.push(promiseMethod);
|
|
261
|
-
}
|
|
262
208
|
if (promiseOperation) {
|
|
263
209
|
acc.push(promiseOperation);
|
|
264
210
|
}
|
|
211
|
+
generators?.forEach((generator) => {
|
|
212
|
+
const promise = generator.operation?.({
|
|
213
|
+
instance: this,
|
|
214
|
+
operation,
|
|
215
|
+
options: {
|
|
216
|
+
...this.options,
|
|
217
|
+
...options
|
|
218
|
+
}
|
|
219
|
+
});
|
|
220
|
+
if (promise) {
|
|
221
|
+
acc.push(promise);
|
|
222
|
+
}
|
|
223
|
+
});
|
|
265
224
|
});
|
|
266
225
|
return acc;
|
|
267
226
|
}, []);
|
|
268
227
|
const operations = Object.values(this.operationsByMethod).map((item) => Object.values(item).map((item2) => item2.operation));
|
|
269
228
|
promises.push(this.all(operations.flat().filter(Boolean), this.operationsByMethod));
|
|
229
|
+
generators?.forEach((generator) => {
|
|
230
|
+
const promise = generator.operations?.({
|
|
231
|
+
instance: this,
|
|
232
|
+
operations: operations.flat().filter(Boolean),
|
|
233
|
+
operationsByMethod: this.operationsByMethod,
|
|
234
|
+
options: this.options
|
|
235
|
+
});
|
|
236
|
+
if (promise) {
|
|
237
|
+
promises.push(promise);
|
|
238
|
+
}
|
|
239
|
+
});
|
|
270
240
|
const files = await Promise.all(promises);
|
|
271
241
|
return files.flat().filter(Boolean);
|
|
272
242
|
}
|
|
@@ -274,134 +244,171 @@ var OperationGenerator = class extends _core.Generator {
|
|
|
274
244
|
* Operation
|
|
275
245
|
*/
|
|
276
246
|
async operation(operation, options) {
|
|
277
|
-
return
|
|
247
|
+
return [];
|
|
278
248
|
}
|
|
279
249
|
/**
|
|
280
250
|
* GET
|
|
281
251
|
*/
|
|
282
252
|
async get(operation, options) {
|
|
283
|
-
return
|
|
253
|
+
return [];
|
|
284
254
|
}
|
|
285
255
|
/**
|
|
286
256
|
* POST
|
|
287
257
|
*/
|
|
288
258
|
async post(operation, options) {
|
|
289
|
-
return
|
|
259
|
+
return [];
|
|
290
260
|
}
|
|
291
261
|
/**
|
|
292
262
|
* PATCH
|
|
293
263
|
*/
|
|
294
264
|
async patch(operation, options) {
|
|
295
|
-
return
|
|
265
|
+
return [];
|
|
296
266
|
}
|
|
297
267
|
/**
|
|
298
268
|
* PUT
|
|
299
269
|
*/
|
|
300
270
|
async put(operation, options) {
|
|
301
|
-
return
|
|
271
|
+
return [];
|
|
302
272
|
}
|
|
303
273
|
/**
|
|
304
274
|
* DELETE
|
|
305
275
|
*/
|
|
306
276
|
async delete(operation, options) {
|
|
307
|
-
return
|
|
277
|
+
return [];
|
|
308
278
|
}
|
|
309
279
|
/**
|
|
310
280
|
* Combination of GET, POST, PATCH, PUT, DELETE
|
|
311
281
|
*/
|
|
312
282
|
async all(operations, paths) {
|
|
313
|
-
return
|
|
283
|
+
return [];
|
|
314
284
|
}
|
|
315
285
|
};
|
|
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 = !!_optionalChain([operation, 'access', _52 => _52.getTags, 'call', _53 => _53(), 'access', _54 => _54[0], 'optionalAccess', _55 => _55.name, 'access', _56 => _56.match, 'call', _57 => _57(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 = !!_optionalChain([operation, 'access', _58 => _58.getTags, 'call', _59 => _59(), 'access', _60 => _60[0], 'optionalAccess', _61 => _61.name, 'access', _62 => _62.match, 'call', _63 => _63(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);
|
|
286
|
+
var pluginOasName = "plugin-oas";
|
|
287
|
+
var pluginOas = core.createPlugin((options) => {
|
|
288
|
+
const {
|
|
289
|
+
output = {
|
|
290
|
+
path: "schemas"
|
|
291
|
+
},
|
|
292
|
+
validate = true,
|
|
293
|
+
generators = [chunk2TGWPVZN_cjs.jsonGenerator],
|
|
294
|
+
serverIndex,
|
|
295
|
+
contentType,
|
|
296
|
+
oasClass
|
|
297
|
+
} = options;
|
|
298
|
+
const getOas = async ({ config, logger }) => {
|
|
299
|
+
try {
|
|
300
|
+
const oas = await chunkABOQ73FL_cjs.parseFromConfig(config, oasClass);
|
|
301
|
+
if (validate) {
|
|
302
|
+
await oas.valdiate();
|
|
303
|
+
}
|
|
304
|
+
return oas;
|
|
305
|
+
} catch (e) {
|
|
306
|
+
const error = e;
|
|
307
|
+
logger.emit("warning", error?.message);
|
|
308
|
+
return chunkABOQ73FL_cjs.parseFromConfig(config, oasClass);
|
|
378
309
|
}
|
|
379
|
-
}
|
|
380
|
-
return matched;
|
|
381
|
-
};
|
|
382
|
-
methods_get = function() {
|
|
310
|
+
};
|
|
383
311
|
return {
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
312
|
+
name: pluginOasName,
|
|
313
|
+
options: {
|
|
314
|
+
output,
|
|
315
|
+
...options
|
|
316
|
+
},
|
|
317
|
+
context() {
|
|
318
|
+
const { config, logger } = this;
|
|
319
|
+
return {
|
|
320
|
+
getOas() {
|
|
321
|
+
return getOas({ config, logger });
|
|
322
|
+
},
|
|
323
|
+
async getSchemas({ includes } = {}) {
|
|
324
|
+
const oas = await this.getOas();
|
|
325
|
+
return chunkQAFBZLJA_cjs.getSchemas({ oas, contentType, includes });
|
|
326
|
+
},
|
|
327
|
+
async getBaseURL() {
|
|
328
|
+
const oasInstance = await this.getOas();
|
|
329
|
+
if (serverIndex) {
|
|
330
|
+
return oasInstance.api.servers?.at(serverIndex)?.url;
|
|
331
|
+
}
|
|
332
|
+
return void 0;
|
|
333
|
+
},
|
|
334
|
+
contentType
|
|
335
|
+
};
|
|
336
|
+
},
|
|
337
|
+
resolvePath(baseName, pathMode, options2) {
|
|
338
|
+
const root = path__default.default.resolve(this.config.root, this.config.output.path);
|
|
339
|
+
const mode = pathMode ?? core.FileManager.getMode(path__default.default.resolve(root, output.path));
|
|
340
|
+
if (mode === "single") {
|
|
341
|
+
return path__default.default.resolve(root, output.path);
|
|
342
|
+
}
|
|
343
|
+
return path__default.default.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
|
+
});
|
|
353
|
+
await oas.dereference();
|
|
354
|
+
const schemaGenerator = new chunkA3ROGKLW_cjs.SchemaGenerator(
|
|
355
|
+
{
|
|
356
|
+
unknownType: "unknown",
|
|
357
|
+
dateType: "date",
|
|
358
|
+
transformers: {},
|
|
359
|
+
...this.plugin.options
|
|
360
|
+
},
|
|
361
|
+
{
|
|
362
|
+
oas,
|
|
363
|
+
pluginManager: this.pluginManager,
|
|
364
|
+
plugin: this.plugin,
|
|
365
|
+
contentType,
|
|
366
|
+
include: void 0,
|
|
367
|
+
override: void 0,
|
|
368
|
+
mode: "split",
|
|
369
|
+
output: output.path
|
|
370
|
+
}
|
|
371
|
+
);
|
|
372
|
+
const schemaFiles = await schemaGenerator.build(...generators);
|
|
373
|
+
await this.addFile(...schemaFiles);
|
|
374
|
+
const operationGenerator = new OperationGenerator(this.plugin.options, {
|
|
375
|
+
oas,
|
|
376
|
+
pluginManager: this.pluginManager,
|
|
377
|
+
plugin: this.plugin,
|
|
378
|
+
contentType,
|
|
379
|
+
exclude: void 0,
|
|
380
|
+
include: void 0,
|
|
381
|
+
override: void 0,
|
|
382
|
+
mode: "split"
|
|
383
|
+
});
|
|
384
|
+
const operationFiles = await operationGenerator.build(...generators);
|
|
385
|
+
await this.addFile(...operationFiles);
|
|
386
|
+
}
|
|
392
387
|
};
|
|
393
|
-
};
|
|
394
|
-
|
|
395
|
-
// src/index.ts
|
|
396
|
-
var definePluginDefault = pluginOas;
|
|
397
|
-
var src_default = definePluginDefault;
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
388
|
+
});
|
|
405
389
|
|
|
406
|
-
|
|
390
|
+
Object.defineProperty(exports, "createGenerator", {
|
|
391
|
+
enumerable: true,
|
|
392
|
+
get: function () { return chunk2TGWPVZN_cjs.createGenerator; }
|
|
393
|
+
});
|
|
394
|
+
Object.defineProperty(exports, "createReactGenerator", {
|
|
395
|
+
enumerable: true,
|
|
396
|
+
get: function () { return chunk2TGWPVZN_cjs.createReactGenerator; }
|
|
397
|
+
});
|
|
398
|
+
Object.defineProperty(exports, "SchemaGenerator", {
|
|
399
|
+
enumerable: true,
|
|
400
|
+
get: function () { return chunkA3ROGKLW_cjs.SchemaGenerator; }
|
|
401
|
+
});
|
|
402
|
+
Object.defineProperty(exports, "isKeyword", {
|
|
403
|
+
enumerable: true,
|
|
404
|
+
get: function () { return chunkA3ROGKLW_cjs.isKeyword; }
|
|
405
|
+
});
|
|
406
|
+
Object.defineProperty(exports, "schemaKeywords", {
|
|
407
|
+
enumerable: true,
|
|
408
|
+
get: function () { return chunkA3ROGKLW_cjs.schemaKeywords; }
|
|
409
|
+
});
|
|
410
|
+
exports.OperationGenerator = OperationGenerator;
|
|
411
|
+
exports.pluginOas = pluginOas;
|
|
412
|
+
exports.pluginOasName = pluginOasName;
|
|
413
|
+
//# sourceMappingURL=index.cjs.map
|
|
407
414
|
//# sourceMappingURL=index.cjs.map
|