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