@kubb/plugin-oas 3.0.0-alpha.1 → 3.0.0-alpha.3
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-D7rSlflc.d.cts +158 -0
- package/dist/OperationGenerator-vw0Zf-Mi.d.ts +158 -0
- package/dist/{Schema-an5hOrjZ.d.cts → Schema-DxyOIX7q.d.cts} +1 -1
- package/dist/{Schema-DefwBJMc.d.ts → Schema-gHgN14i2.d.ts} +1 -1
- package/dist/{SchemaMapper-CsBQ6eEx.d.cts → SchemaMapper-BM1IGWqD.d.cts} +1 -1
- package/dist/{SchemaMapper-CsBQ6eEx.d.ts → SchemaMapper-BM1IGWqD.d.ts} +1 -1
- package/dist/{chunk-DRLYORTT.cjs → chunk-264TCCJF.cjs} +715 -7
- package/dist/chunk-264TCCJF.cjs.map +1 -0
- package/dist/chunk-7KIEQOVZ.cjs +7 -0
- package/dist/chunk-7KIEQOVZ.cjs.map +1 -0
- package/dist/{chunk-LEACSHKT.js → chunk-FZN3PBEK.js} +713 -5
- package/dist/chunk-FZN3PBEK.js.map +1 -0
- package/dist/chunk-TWKZEVSM.js +7 -0
- package/dist/chunk-TWKZEVSM.js.map +1 -0
- package/dist/components.cjs +4 -9
- package/dist/components.cjs.map +1 -1
- package/dist/components.d.cts +12 -6
- package/dist/components.d.ts +12 -6
- package/dist/components.js +3 -8
- package/dist/components.js.map +1 -1
- package/dist/hooks.cjs +6 -7
- package/dist/hooks.cjs.map +1 -1
- package/dist/hooks.d.cts +3 -3
- package/dist/hooks.d.ts +3 -3
- package/dist/hooks.js +1 -2
- package/dist/hooks.js.map +1 -1
- package/dist/index.cjs +225 -159
- 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 +207 -141
- package/dist/index.js.map +1 -1
- package/dist/{types-Dte3MA6H.d.cts → types-C2RXaY0_.d.cts} +1 -1
- package/dist/{types-Dte3MA6H.d.ts → types-C2RXaY0_.d.ts} +1 -1
- package/dist/utils.d.cts +2 -2
- package/dist/utils.d.ts +2 -2
- package/package.json +9 -9
- package/src/OperationGenerator.ts +62 -31
- package/src/SchemaGenerator.ts +23 -4
- package/src/components/Oas.tsx +8 -2
- package/src/index.ts +3 -9
- package/src/parser.tsx +120 -0
- package/src/plugin.ts +1 -9
- 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/index.cjs
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
2
|
|
|
3
3
|
var _chunkQLJIL3U5cjs = require('./chunk-QLJIL3U5.cjs');
|
|
4
|
+
require('./chunk-7KIEQOVZ.cjs');
|
|
4
5
|
|
|
5
6
|
|
|
6
7
|
|
|
7
8
|
|
|
8
|
-
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
var _chunk264TCCJFcjs = require('./chunk-264TCCJF.cjs');
|
|
12
|
+
|
|
9
13
|
|
|
10
14
|
|
|
11
15
|
|
|
@@ -18,119 +22,11 @@ var _chunkP42X362Ucjs = require('./chunk-P42X362U.cjs');
|
|
|
18
22
|
// src/index.ts
|
|
19
23
|
_chunkP42X362Ucjs.init_cjs_shims.call(void 0, );
|
|
20
24
|
|
|
21
|
-
// src/
|
|
25
|
+
// src/OperationGenerator.ts
|
|
22
26
|
_chunkP42X362Ucjs.init_cjs_shims.call(void 0, );
|
|
23
|
-
var _path = require('path'); var _path2 = _interopRequireDefault(_path);
|
|
24
27
|
var _core = require('@kubb/core');
|
|
25
28
|
var _transformers = require('@kubb/core/transformers'); var _transformers2 = _interopRequireDefault(_transformers);
|
|
26
|
-
var
|
|
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();
|
|
42
|
-
}
|
|
43
|
-
return oas;
|
|
44
|
-
} catch (e) {
|
|
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;
|
|
74
|
-
}
|
|
75
|
-
const root = _path2.default.resolve(this.config.root, this.config.output.path);
|
|
76
|
-
return _path2.default.resolve(root, output.path, baseName);
|
|
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;
|
|
84
|
-
}
|
|
85
|
-
return this.fileManager.write(path2, source, { sanity: false });
|
|
86
|
-
},
|
|
87
|
-
async buildStart() {
|
|
88
|
-
if (!output) {
|
|
89
|
-
return;
|
|
90
|
-
}
|
|
91
|
-
const oas = await getOas({
|
|
92
|
-
config: this.config,
|
|
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;
|
|
29
|
+
var _operationsByMethod, _OperationGenerator_instances, getOptions_fn, isExcluded_fn, isIncluded_fn;
|
|
134
30
|
var OperationGenerator = class extends _core.Generator {
|
|
135
31
|
constructor() {
|
|
136
32
|
super(...arguments);
|
|
@@ -143,7 +39,10 @@ var OperationGenerator = class extends _core.Generator {
|
|
|
143
39
|
set operationsByMethod(paths) {
|
|
144
40
|
_chunkP42X362Ucjs.__privateSet.call(void 0, this, _operationsByMethod, paths);
|
|
145
41
|
}
|
|
146
|
-
getSchemas(operation, {
|
|
42
|
+
getSchemas(operation, {
|
|
43
|
+
forStatusCode,
|
|
44
|
+
resolveName = (name) => name
|
|
45
|
+
} = {}) {
|
|
147
46
|
const pathParamsSchema = this.context.oas.getParametersSchema(operation, "path");
|
|
148
47
|
const queryParamsSchema = this.context.oas.getParametersSchema(operation, "query");
|
|
149
48
|
const headerParamsSchema = this.context.oas.getParametersSchema(operation, "header");
|
|
@@ -158,12 +57,12 @@ var OperationGenerator = class extends _core.Generator {
|
|
|
158
57
|
const schema = this.context.oas.getResponseSchema(operation, statusCode);
|
|
159
58
|
return {
|
|
160
59
|
name: resolveName(_transformers2.default.pascalCase(`${operation.getOperationId()} ${name}`)),
|
|
161
|
-
description: _optionalChain([operation, 'access',
|
|
60
|
+
description: _optionalChain([operation, 'access', _ => _.getResponseByStatusCode, 'call', _2 => _2(statusCode), 'optionalAccess', _3 => _3.description]),
|
|
162
61
|
schema,
|
|
163
62
|
operation,
|
|
164
63
|
operationName: _transformers2.default.pascalCase(`${operation.getOperationId()}`),
|
|
165
64
|
statusCode: name === "error" ? void 0 : Number(statusCode),
|
|
166
|
-
keys: _optionalChain([schema, 'optionalAccess',
|
|
65
|
+
keys: _optionalChain([schema, 'optionalAccess', _4 => _4.properties]) ? Object.keys(schema.properties) : void 0
|
|
167
66
|
};
|
|
168
67
|
});
|
|
169
68
|
return {
|
|
@@ -190,41 +89,41 @@ var OperationGenerator = class extends _core.Generator {
|
|
|
190
89
|
} : void 0,
|
|
191
90
|
request: requestSchema ? {
|
|
192
91
|
name: resolveName(_transformers2.default.pascalCase(`${operation.getOperationId()} ${operation.method === "get" ? "queryRequest" : "mutationRequest"}`)),
|
|
193
|
-
description: _optionalChain([operation, 'access',
|
|
92
|
+
description: _optionalChain([operation, 'access', _5 => _5.schema, 'access', _6 => _6.requestBody, 'optionalAccess', _7 => _7.description]),
|
|
194
93
|
operation,
|
|
195
94
|
operationName: _transformers2.default.pascalCase(`${operation.getOperationId()}`),
|
|
196
95
|
schema: requestSchema,
|
|
197
96
|
keys: requestSchema.properties ? Object.keys(requestSchema.properties) : void 0,
|
|
198
97
|
keysToOmit: requestSchema.properties ? Object.keys(requestSchema.properties).filter((key) => {
|
|
199
|
-
const item = _optionalChain([requestSchema, 'access',
|
|
200
|
-
return _optionalChain([item, 'optionalAccess',
|
|
98
|
+
const item = _optionalChain([requestSchema, 'access', _8 => _8.properties, 'optionalAccess', _9 => _9[key]]);
|
|
99
|
+
return _optionalChain([item, 'optionalAccess', _10 => _10.readOnly]);
|
|
201
100
|
}) : void 0
|
|
202
101
|
} : void 0,
|
|
203
102
|
response: {
|
|
204
103
|
name: resolveName(_transformers2.default.pascalCase(`${operation.getOperationId()} ${operation.method === "get" ? "queryResponse" : "mutationResponse"}`)),
|
|
205
|
-
description: _optionalChain([operation, 'access',
|
|
104
|
+
description: _optionalChain([operation, 'access', _11 => _11.getResponseAsJSONSchema, 'call', _12 => _12(responseStatusCode), 'optionalAccess', _13 => _13.at, 'call', _14 => _14(0), 'optionalAccess', _15 => _15.description]),
|
|
206
105
|
operation,
|
|
207
106
|
operationName: _transformers2.default.pascalCase(`${operation.getOperationId()}`),
|
|
208
107
|
schema: responseSchema,
|
|
209
108
|
statusCode: Number(responseStatusCode),
|
|
210
|
-
keys: _optionalChain([responseSchema, 'optionalAccess',
|
|
211
|
-
keysToOmit: _optionalChain([responseSchema, 'optionalAccess',
|
|
212
|
-
const item = _optionalChain([responseSchema, 'access',
|
|
213
|
-
return _optionalChain([item, 'optionalAccess',
|
|
109
|
+
keys: _optionalChain([responseSchema, 'optionalAccess', _16 => _16.properties]) ? Object.keys(responseSchema.properties) : void 0,
|
|
110
|
+
keysToOmit: _optionalChain([responseSchema, 'optionalAccess', _17 => _17.properties]) ? Object.keys(responseSchema.properties).filter((key) => {
|
|
111
|
+
const item = _optionalChain([responseSchema, 'access', _18 => _18.properties, 'optionalAccess', _19 => _19[key]]);
|
|
112
|
+
return _optionalChain([item, 'optionalAccess', _20 => _20.writeOnly]);
|
|
214
113
|
}) : void 0
|
|
215
114
|
},
|
|
216
|
-
errors: statusCodes.filter((item) => _optionalChain([item, 'access',
|
|
115
|
+
errors: statusCodes.filter((item) => _optionalChain([item, 'access', _21 => _21.statusCode, 'optionalAccess', _22 => _22.toString, 'call', _23 => _23(), 'access', _24 => _24.startsWith, 'call', _25 => _25("4")]) || _optionalChain([item, 'access', _26 => _26.statusCode, 'optionalAccess', _27 => _27.toString, 'call', _28 => _28(), 'access', _29 => _29.startsWith, 'call', _30 => _30("5")])),
|
|
217
116
|
statusCodes
|
|
218
117
|
};
|
|
219
118
|
}
|
|
220
|
-
async build() {
|
|
119
|
+
async build(...parsers) {
|
|
221
120
|
const { oas } = this.context;
|
|
222
121
|
const paths = oas.getPaths();
|
|
223
122
|
this.operationsByMethod = Object.entries(paths).reduce((acc, [path2, method]) => {
|
|
224
123
|
const methods = Object.keys(method);
|
|
225
124
|
methods.forEach((method2) => {
|
|
226
125
|
const operation = oas.operation(path2, method2);
|
|
227
|
-
if (operation
|
|
126
|
+
if (operation) {
|
|
228
127
|
const isExcluded = _chunkP42X362Ucjs.__privateMethod.call(void 0, this, _OperationGenerator_instances, isExcluded_fn).call(this, operation, method2);
|
|
229
128
|
const isIncluded = this.context.include ? _chunkP42X362Ucjs.__privateMethod.call(void 0, this, _OperationGenerator_instances, isIncluded_fn).call(this, operation, method2) : true;
|
|
230
129
|
if (isIncluded && !isExcluded) {
|
|
@@ -246,27 +145,54 @@ var OperationGenerator = class extends _core.Generator {
|
|
|
246
145
|
const promises = Object.keys(this.operationsByMethod).reduce((acc, path2) => {
|
|
247
146
|
const methods = this.operationsByMethod[path2] ? Object.keys(this.operationsByMethod[path2]) : [];
|
|
248
147
|
methods.forEach((method) => {
|
|
249
|
-
const { operation } = _optionalChain([this, 'access',
|
|
148
|
+
const { operation } = _optionalChain([this, 'access', _31 => _31.operationsByMethod, 'access', _32 => _32[path2], 'optionalAccess', _33 => _33[method]]);
|
|
250
149
|
const options = _chunkP42X362Ucjs.__privateMethod.call(void 0, this, _OperationGenerator_instances, getOptions_fn).call(this, operation, method);
|
|
251
|
-
const
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
150
|
+
const methodToCall = this[method];
|
|
151
|
+
if (typeof methodToCall === "function") {
|
|
152
|
+
const promiseMethod = _optionalChain([methodToCall, 'optionalAccess', _34 => _34.call, 'call', _35 => _35(this, operation, {
|
|
153
|
+
...this.options,
|
|
154
|
+
...options
|
|
155
|
+
})]);
|
|
156
|
+
if (promiseMethod) {
|
|
157
|
+
acc.push(promiseMethod);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
255
160
|
const promiseOperation = this.operation.call(this, operation, {
|
|
256
161
|
...this.options,
|
|
257
162
|
...options
|
|
258
163
|
});
|
|
259
|
-
if (promiseMethod) {
|
|
260
|
-
acc.push(promiseMethod);
|
|
261
|
-
}
|
|
262
164
|
if (promiseOperation) {
|
|
263
165
|
acc.push(promiseOperation);
|
|
264
166
|
}
|
|
167
|
+
_optionalChain([parsers, 'optionalAccess', _36 => _36.forEach, 'call', _37 => _37((parser) => {
|
|
168
|
+
const promise = _optionalChain([parser, 'access', _38 => _38.operation, 'optionalCall', _39 => _39({
|
|
169
|
+
instance: this,
|
|
170
|
+
operation,
|
|
171
|
+
options: {
|
|
172
|
+
...this.options,
|
|
173
|
+
...options
|
|
174
|
+
}
|
|
175
|
+
})]);
|
|
176
|
+
if (promise) {
|
|
177
|
+
acc.push(promise);
|
|
178
|
+
}
|
|
179
|
+
})]);
|
|
265
180
|
});
|
|
266
181
|
return acc;
|
|
267
182
|
}, []);
|
|
268
183
|
const operations = Object.values(this.operationsByMethod).map((item) => Object.values(item).map((item2) => item2.operation));
|
|
269
184
|
promises.push(this.all(operations.flat().filter(Boolean), this.operationsByMethod));
|
|
185
|
+
_optionalChain([parsers, 'optionalAccess', _40 => _40.forEach, 'call', _41 => _41((parser) => {
|
|
186
|
+
const promise = _optionalChain([parser, 'access', _42 => _42.operations, 'optionalCall', _43 => _43({
|
|
187
|
+
instance: this,
|
|
188
|
+
operations: operations.flat().filter(Boolean),
|
|
189
|
+
operationsByMethod: this.operationsByMethod,
|
|
190
|
+
options: this.options
|
|
191
|
+
})]);
|
|
192
|
+
if (promise) {
|
|
193
|
+
promises.push(promise);
|
|
194
|
+
}
|
|
195
|
+
})]);
|
|
270
196
|
const files = await Promise.all(promises);
|
|
271
197
|
return files.flat().filter(Boolean);
|
|
272
198
|
}
|
|
@@ -274,52 +200,52 @@ var OperationGenerator = class extends _core.Generator {
|
|
|
274
200
|
* Operation
|
|
275
201
|
*/
|
|
276
202
|
async operation(operation, options) {
|
|
277
|
-
return
|
|
203
|
+
return [];
|
|
278
204
|
}
|
|
279
205
|
/**
|
|
280
206
|
* GET
|
|
281
207
|
*/
|
|
282
208
|
async get(operation, options) {
|
|
283
|
-
return
|
|
209
|
+
return [];
|
|
284
210
|
}
|
|
285
211
|
/**
|
|
286
212
|
* POST
|
|
287
213
|
*/
|
|
288
214
|
async post(operation, options) {
|
|
289
|
-
return
|
|
215
|
+
return [];
|
|
290
216
|
}
|
|
291
217
|
/**
|
|
292
218
|
* PATCH
|
|
293
219
|
*/
|
|
294
220
|
async patch(operation, options) {
|
|
295
|
-
return
|
|
221
|
+
return [];
|
|
296
222
|
}
|
|
297
223
|
/**
|
|
298
224
|
* PUT
|
|
299
225
|
*/
|
|
300
226
|
async put(operation, options) {
|
|
301
|
-
return
|
|
227
|
+
return [];
|
|
302
228
|
}
|
|
303
229
|
/**
|
|
304
230
|
* DELETE
|
|
305
231
|
*/
|
|
306
232
|
async delete(operation, options) {
|
|
307
|
-
return
|
|
233
|
+
return [];
|
|
308
234
|
}
|
|
309
235
|
/**
|
|
310
236
|
* Combination of GET, POST, PATCH, PUT, DELETE
|
|
311
237
|
*/
|
|
312
238
|
async all(operations, paths) {
|
|
313
|
-
return
|
|
239
|
+
return [];
|
|
314
240
|
}
|
|
315
241
|
};
|
|
316
242
|
_operationsByMethod = new WeakMap();
|
|
317
243
|
_OperationGenerator_instances = new WeakSet();
|
|
318
244
|
getOptions_fn = function(operation, method) {
|
|
319
245
|
const { override = [] } = this.context;
|
|
320
|
-
return _optionalChain([override, 'access',
|
|
246
|
+
return _optionalChain([override, 'access', _44 => _44.find, 'call', _45 => _45(({ pattern, type }) => {
|
|
321
247
|
if (type === "tag") {
|
|
322
|
-
return !!_optionalChain([operation, 'access',
|
|
248
|
+
return !!_optionalChain([operation, 'access', _46 => _46.getTags, 'call', _47 => _47(), 'access', _48 => _48[0], 'optionalAccess', _49 => _49.name, 'access', _50 => _50.match, 'call', _51 => _51(pattern)]);
|
|
323
249
|
}
|
|
324
250
|
if (type === "operationId") {
|
|
325
251
|
return !!operation.getOperationId().match(pattern);
|
|
@@ -331,7 +257,7 @@ getOptions_fn = function(operation, method) {
|
|
|
331
257
|
return !!method.match(pattern);
|
|
332
258
|
}
|
|
333
259
|
return false;
|
|
334
|
-
}), 'optionalAccess',
|
|
260
|
+
}), 'optionalAccess', _52 => _52.options]) || {};
|
|
335
261
|
};
|
|
336
262
|
/**
|
|
337
263
|
*
|
|
@@ -342,7 +268,7 @@ isExcluded_fn = function(operation, method) {
|
|
|
342
268
|
let matched = false;
|
|
343
269
|
exclude.forEach(({ pattern, type }) => {
|
|
344
270
|
if (type === "tag" && !matched) {
|
|
345
|
-
matched = !!_optionalChain([operation, 'access',
|
|
271
|
+
matched = !!_optionalChain([operation, 'access', _53 => _53.getTags, 'call', _54 => _54(), 'access', _55 => _55[0], 'optionalAccess', _56 => _56.name, 'access', _57 => _57.match, 'call', _58 => _58(pattern)]);
|
|
346
272
|
}
|
|
347
273
|
if (type === "operationId" && !matched) {
|
|
348
274
|
matched = !!operation.getOperationId().match(pattern);
|
|
@@ -365,7 +291,7 @@ isIncluded_fn = function(operation, method) {
|
|
|
365
291
|
let matched = false;
|
|
366
292
|
include.forEach(({ pattern, type }) => {
|
|
367
293
|
if (type === "tag" && !matched) {
|
|
368
|
-
matched = !!_optionalChain([operation, 'access',
|
|
294
|
+
matched = !!_optionalChain([operation, 'access', _59 => _59.getTags, 'call', _60 => _60(), 'access', _61 => _61[0], 'optionalAccess', _62 => _62.name, 'access', _63 => _63.match, 'call', _64 => _64(pattern)]);
|
|
369
295
|
}
|
|
370
296
|
if (type === "operationId" && !matched) {
|
|
371
297
|
matched = !!operation.getOperationId().match(pattern);
|
|
@@ -379,22 +305,162 @@ isIncluded_fn = function(operation, method) {
|
|
|
379
305
|
});
|
|
380
306
|
return matched;
|
|
381
307
|
};
|
|
382
|
-
|
|
308
|
+
|
|
309
|
+
// src/plugin.ts
|
|
310
|
+
_chunkP42X362Ucjs.init_cjs_shims.call(void 0, );
|
|
311
|
+
var _path = require('path'); var _path2 = _interopRequireDefault(_path);
|
|
312
|
+
|
|
313
|
+
|
|
314
|
+
var pluginOasName = "plugin-oas";
|
|
315
|
+
var pluginOas = _core.createPlugin.call(void 0, (options) => {
|
|
316
|
+
const {
|
|
317
|
+
output = { path: "schemas", export: false },
|
|
318
|
+
experimentalFilter: filter,
|
|
319
|
+
experimentalSort: sort,
|
|
320
|
+
validate = true,
|
|
321
|
+
serverIndex = 0,
|
|
322
|
+
contentType,
|
|
323
|
+
oasClass
|
|
324
|
+
} = options;
|
|
325
|
+
const getOas = async ({ config, logger, formatOptions }) => {
|
|
326
|
+
try {
|
|
327
|
+
const oas = await _chunkQLJIL3U5cjs.parseFromConfig.call(void 0, config, formatOptions, oasClass);
|
|
328
|
+
if (validate) {
|
|
329
|
+
await oas.valdiate();
|
|
330
|
+
}
|
|
331
|
+
return oas;
|
|
332
|
+
} catch (e) {
|
|
333
|
+
const error = e;
|
|
334
|
+
logger.emit("warning", _optionalChain([error, 'optionalAccess', _65 => _65.message]));
|
|
335
|
+
return _chunkQLJIL3U5cjs.parseFromConfig.call(void 0, config, {}, oasClass);
|
|
336
|
+
}
|
|
337
|
+
};
|
|
338
|
+
return {
|
|
339
|
+
name: pluginOasName,
|
|
340
|
+
options,
|
|
341
|
+
context() {
|
|
342
|
+
const { config, logger } = this;
|
|
343
|
+
return {
|
|
344
|
+
getOas(formatOptions) {
|
|
345
|
+
return getOas({ config, logger, formatOptions });
|
|
346
|
+
},
|
|
347
|
+
async getSchemas({ includes } = {}) {
|
|
348
|
+
const oas = await this.getOas();
|
|
349
|
+
return _chunkP42X362Ucjs.getSchemas.call(void 0, { oas, contentType, includes });
|
|
350
|
+
},
|
|
351
|
+
async getBaseURL() {
|
|
352
|
+
const oasInstance = await this.getOas();
|
|
353
|
+
const baseURL = _optionalChain([oasInstance, 'access', _66 => _66.api, 'access', _67 => _67.servers, 'optionalAccess', _68 => _68.at, 'call', _69 => _69(serverIndex), 'optionalAccess', _70 => _70.url]);
|
|
354
|
+
return baseURL;
|
|
355
|
+
},
|
|
356
|
+
contentType
|
|
357
|
+
};
|
|
358
|
+
},
|
|
359
|
+
resolvePath(baseName) {
|
|
360
|
+
if (output === false) {
|
|
361
|
+
return void 0;
|
|
362
|
+
}
|
|
363
|
+
const root = _path2.default.resolve(this.config.root, this.config.output.path);
|
|
364
|
+
return _path2.default.resolve(root, output.path, baseName);
|
|
365
|
+
},
|
|
366
|
+
resolveName(name, type) {
|
|
367
|
+
return _transformers.camelCase.call(void 0, name, { isFile: type === "file" });
|
|
368
|
+
},
|
|
369
|
+
async buildStart() {
|
|
370
|
+
if (!output) {
|
|
371
|
+
return;
|
|
372
|
+
}
|
|
373
|
+
const oas = await getOas({
|
|
374
|
+
config: this.config,
|
|
375
|
+
logger: this.logger,
|
|
376
|
+
formatOptions: {
|
|
377
|
+
filterSet: filter,
|
|
378
|
+
sortSet: sort
|
|
379
|
+
}
|
|
380
|
+
});
|
|
381
|
+
await oas.dereference();
|
|
382
|
+
const schemas = _chunkP42X362Ucjs.getSchemas.call(void 0, { oas, contentType });
|
|
383
|
+
const mapSchema = async ([name, schema]) => {
|
|
384
|
+
const resolvedPath = this.resolvePath({
|
|
385
|
+
baseName: `${name}.json`,
|
|
386
|
+
pluginKey: this.plugin.key
|
|
387
|
+
});
|
|
388
|
+
const resvoledFileName = this.resolveName({
|
|
389
|
+
name: `${name}.json`,
|
|
390
|
+
pluginKey: [pluginOasName],
|
|
391
|
+
type: "file"
|
|
392
|
+
});
|
|
393
|
+
if (!resolvedPath) {
|
|
394
|
+
return;
|
|
395
|
+
}
|
|
396
|
+
await this.addFile({
|
|
397
|
+
path: resolvedPath,
|
|
398
|
+
baseName: resvoledFileName,
|
|
399
|
+
source: JSON.stringify(schema),
|
|
400
|
+
meta: {
|
|
401
|
+
pluginKey: this.plugin.key
|
|
402
|
+
}
|
|
403
|
+
});
|
|
404
|
+
};
|
|
405
|
+
const promises = Object.entries(schemas).map(mapSchema);
|
|
406
|
+
await Promise.all(promises);
|
|
407
|
+
}
|
|
408
|
+
};
|
|
409
|
+
});
|
|
410
|
+
|
|
411
|
+
// src/parser.tsx
|
|
412
|
+
_chunkP42X362Ucjs.init_cjs_shims.call(void 0, );
|
|
413
|
+
var _react = require('@kubb/react');
|
|
414
|
+
var import_jsx_runtime = _chunkP42X362Ucjs.__toESM.call(void 0, _chunk264TCCJFcjs.require_jsx_runtime.call(void 0, ), 1);
|
|
415
|
+
function createParser(parseOptions) {
|
|
416
|
+
return parseOptions;
|
|
417
|
+
}
|
|
418
|
+
function createReactParser(parseOptions) {
|
|
383
419
|
return {
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
420
|
+
...parseOptions,
|
|
421
|
+
async operations({ instance, options, operations, operationsByMethod }) {
|
|
422
|
+
if (!parseOptions.Operations) {
|
|
423
|
+
return [];
|
|
424
|
+
}
|
|
425
|
+
const { pluginManager, oas, plugin, mode } = instance.context;
|
|
426
|
+
const root = _react.createRoot.call(void 0, {
|
|
427
|
+
logger: pluginManager.logger
|
|
428
|
+
});
|
|
429
|
+
root.render(
|
|
430
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(_react.App, { pluginManager, plugin, mode, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(_chunk264TCCJFcjs.Oas, { oas, operations, generator: instance, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(parseOptions.Operations, { operations, instance, operationsByMethod, options }) }) })
|
|
431
|
+
);
|
|
432
|
+
return root.files;
|
|
433
|
+
},
|
|
434
|
+
async operation({ instance, operation, options }) {
|
|
435
|
+
if (!parseOptions.Operation) {
|
|
436
|
+
return [];
|
|
437
|
+
}
|
|
438
|
+
const { pluginManager, oas, plugin, mode } = instance.context;
|
|
439
|
+
const root = _react.createRoot.call(void 0, {
|
|
440
|
+
logger: pluginManager.logger
|
|
441
|
+
});
|
|
442
|
+
root.render(
|
|
443
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(_react.App, { pluginManager, plugin: { ...plugin, options }, mode, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(_chunk264TCCJFcjs.Oas, { oas, operations: [operation], generator: instance, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(_chunk264TCCJFcjs.Oas.Operation, { operation, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(parseOptions.Operation, { operation, options, instance }) }) }) })
|
|
444
|
+
);
|
|
445
|
+
return root.files;
|
|
446
|
+
},
|
|
447
|
+
async schema({ instance, schema, name, options }) {
|
|
448
|
+
if (!parseOptions.Schema) {
|
|
449
|
+
return [];
|
|
450
|
+
}
|
|
451
|
+
const { pluginManager, oas, plugin, mode } = instance.context;
|
|
452
|
+
const root = _react.createRoot.call(void 0, {
|
|
453
|
+
logger: pluginManager.logger
|
|
454
|
+
});
|
|
455
|
+
const tree = instance.parse({ schema, name });
|
|
456
|
+
root.render(
|
|
457
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(_react.App, { pluginManager, plugin: { ...plugin, options }, mode, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(_chunk264TCCJFcjs.Oas, { oas, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(_chunk264TCCJFcjs.Oas.Schema, { name, value: schema, tree, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(parseOptions.Schema, { schema, options, instance, name }) }) }) })
|
|
458
|
+
);
|
|
459
|
+
return root.files;
|
|
460
|
+
}
|
|
392
461
|
};
|
|
393
|
-
}
|
|
462
|
+
}
|
|
394
463
|
|
|
395
|
-
// src/index.ts
|
|
396
|
-
var definePluginDefault = pluginOas;
|
|
397
|
-
var src_default = definePluginDefault;
|
|
398
464
|
|
|
399
465
|
|
|
400
466
|
|
|
@@ -403,5 +469,5 @@ var src_default = definePluginDefault;
|
|
|
403
469
|
|
|
404
470
|
|
|
405
471
|
|
|
406
|
-
exports.OperationGenerator = OperationGenerator; exports.SchemaGenerator =
|
|
472
|
+
exports.OperationGenerator = OperationGenerator; exports.SchemaGenerator = _chunk264TCCJFcjs.SchemaGenerator; exports.createParser = createParser; exports.createReactParser = createReactParser; exports.isKeyword = _chunk264TCCJFcjs.isKeyword; exports.pluginOas = pluginOas; exports.pluginOasName = pluginOasName; exports.schemaKeywords = _chunk264TCCJFcjs.schemaKeywords;
|
|
407
473
|
//# sourceMappingURL=index.cjs.map
|