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