@kubb/plugin-oas 3.0.0-alpha.2 → 3.0.0-alpha.4
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 -153
- 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 -135
- 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/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,113 +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
|
-
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;
|
|
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 buildStart() {
|
|
82
|
-
if (!output) {
|
|
83
|
-
return;
|
|
84
|
-
}
|
|
85
|
-
const oas = await getOas({
|
|
86
|
-
config: this.config,
|
|
87
|
-
logger: this.logger,
|
|
88
|
-
formatOptions: {
|
|
89
|
-
filterSet: filter,
|
|
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;
|
|
29
|
+
var _operationsByMethod, _OperationGenerator_instances, getOptions_fn, isExcluded_fn, isIncluded_fn;
|
|
128
30
|
var OperationGenerator = class extends _core.Generator {
|
|
129
31
|
constructor() {
|
|
130
32
|
super(...arguments);
|
|
@@ -137,7 +39,10 @@ var OperationGenerator = class extends _core.Generator {
|
|
|
137
39
|
set operationsByMethod(paths) {
|
|
138
40
|
_chunkP42X362Ucjs.__privateSet.call(void 0, this, _operationsByMethod, paths);
|
|
139
41
|
}
|
|
140
|
-
getSchemas(operation, {
|
|
42
|
+
getSchemas(operation, {
|
|
43
|
+
forStatusCode,
|
|
44
|
+
resolveName = (name) => name
|
|
45
|
+
} = {}) {
|
|
141
46
|
const pathParamsSchema = this.context.oas.getParametersSchema(operation, "path");
|
|
142
47
|
const queryParamsSchema = this.context.oas.getParametersSchema(operation, "query");
|
|
143
48
|
const headerParamsSchema = this.context.oas.getParametersSchema(operation, "header");
|
|
@@ -152,12 +57,12 @@ var OperationGenerator = class extends _core.Generator {
|
|
|
152
57
|
const schema = this.context.oas.getResponseSchema(operation, statusCode);
|
|
153
58
|
return {
|
|
154
59
|
name: resolveName(_transformers2.default.pascalCase(`${operation.getOperationId()} ${name}`)),
|
|
155
|
-
description: _optionalChain([operation, 'access',
|
|
60
|
+
description: _optionalChain([operation, 'access', _ => _.getResponseByStatusCode, 'call', _2 => _2(statusCode), 'optionalAccess', _3 => _3.description]),
|
|
156
61
|
schema,
|
|
157
62
|
operation,
|
|
158
63
|
operationName: _transformers2.default.pascalCase(`${operation.getOperationId()}`),
|
|
159
64
|
statusCode: name === "error" ? void 0 : Number(statusCode),
|
|
160
|
-
keys: _optionalChain([schema, 'optionalAccess',
|
|
65
|
+
keys: _optionalChain([schema, 'optionalAccess', _4 => _4.properties]) ? Object.keys(schema.properties) : void 0
|
|
161
66
|
};
|
|
162
67
|
});
|
|
163
68
|
return {
|
|
@@ -184,41 +89,41 @@ var OperationGenerator = class extends _core.Generator {
|
|
|
184
89
|
} : void 0,
|
|
185
90
|
request: requestSchema ? {
|
|
186
91
|
name: resolveName(_transformers2.default.pascalCase(`${operation.getOperationId()} ${operation.method === "get" ? "queryRequest" : "mutationRequest"}`)),
|
|
187
|
-
description: _optionalChain([operation, 'access',
|
|
92
|
+
description: _optionalChain([operation, 'access', _5 => _5.schema, 'access', _6 => _6.requestBody, 'optionalAccess', _7 => _7.description]),
|
|
188
93
|
operation,
|
|
189
94
|
operationName: _transformers2.default.pascalCase(`${operation.getOperationId()}`),
|
|
190
95
|
schema: requestSchema,
|
|
191
96
|
keys: requestSchema.properties ? Object.keys(requestSchema.properties) : void 0,
|
|
192
97
|
keysToOmit: requestSchema.properties ? Object.keys(requestSchema.properties).filter((key) => {
|
|
193
|
-
const item = _optionalChain([requestSchema, 'access',
|
|
194
|
-
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]);
|
|
195
100
|
}) : void 0
|
|
196
101
|
} : void 0,
|
|
197
102
|
response: {
|
|
198
103
|
name: resolveName(_transformers2.default.pascalCase(`${operation.getOperationId()} ${operation.method === "get" ? "queryResponse" : "mutationResponse"}`)),
|
|
199
|
-
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]),
|
|
200
105
|
operation,
|
|
201
106
|
operationName: _transformers2.default.pascalCase(`${operation.getOperationId()}`),
|
|
202
107
|
schema: responseSchema,
|
|
203
108
|
statusCode: Number(responseStatusCode),
|
|
204
|
-
keys: _optionalChain([responseSchema, 'optionalAccess',
|
|
205
|
-
keysToOmit: _optionalChain([responseSchema, 'optionalAccess',
|
|
206
|
-
const item = _optionalChain([responseSchema, 'access',
|
|
207
|
-
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]);
|
|
208
113
|
}) : void 0
|
|
209
114
|
},
|
|
210
|
-
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")])),
|
|
211
116
|
statusCodes
|
|
212
117
|
};
|
|
213
118
|
}
|
|
214
|
-
async build() {
|
|
119
|
+
async build(...parsers) {
|
|
215
120
|
const { oas } = this.context;
|
|
216
121
|
const paths = oas.getPaths();
|
|
217
122
|
this.operationsByMethod = Object.entries(paths).reduce((acc, [path2, method]) => {
|
|
218
123
|
const methods = Object.keys(method);
|
|
219
124
|
methods.forEach((method2) => {
|
|
220
125
|
const operation = oas.operation(path2, method2);
|
|
221
|
-
if (operation
|
|
126
|
+
if (operation) {
|
|
222
127
|
const isExcluded = _chunkP42X362Ucjs.__privateMethod.call(void 0, this, _OperationGenerator_instances, isExcluded_fn).call(this, operation, method2);
|
|
223
128
|
const isIncluded = this.context.include ? _chunkP42X362Ucjs.__privateMethod.call(void 0, this, _OperationGenerator_instances, isIncluded_fn).call(this, operation, method2) : true;
|
|
224
129
|
if (isIncluded && !isExcluded) {
|
|
@@ -240,27 +145,54 @@ var OperationGenerator = class extends _core.Generator {
|
|
|
240
145
|
const promises = Object.keys(this.operationsByMethod).reduce((acc, path2) => {
|
|
241
146
|
const methods = this.operationsByMethod[path2] ? Object.keys(this.operationsByMethod[path2]) : [];
|
|
242
147
|
methods.forEach((method) => {
|
|
243
|
-
const { operation } = _optionalChain([this, 'access',
|
|
148
|
+
const { operation } = _optionalChain([this, 'access', _31 => _31.operationsByMethod, 'access', _32 => _32[path2], 'optionalAccess', _33 => _33[method]]);
|
|
244
149
|
const options = _chunkP42X362Ucjs.__privateMethod.call(void 0, this, _OperationGenerator_instances, getOptions_fn).call(this, operation, method);
|
|
245
|
-
const
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
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
|
+
}
|
|
249
160
|
const promiseOperation = this.operation.call(this, operation, {
|
|
250
161
|
...this.options,
|
|
251
162
|
...options
|
|
252
163
|
});
|
|
253
|
-
if (promiseMethod) {
|
|
254
|
-
acc.push(promiseMethod);
|
|
255
|
-
}
|
|
256
164
|
if (promiseOperation) {
|
|
257
165
|
acc.push(promiseOperation);
|
|
258
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
|
+
})]);
|
|
259
180
|
});
|
|
260
181
|
return acc;
|
|
261
182
|
}, []);
|
|
262
183
|
const operations = Object.values(this.operationsByMethod).map((item) => Object.values(item).map((item2) => item2.operation));
|
|
263
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
|
+
})]);
|
|
264
196
|
const files = await Promise.all(promises);
|
|
265
197
|
return files.flat().filter(Boolean);
|
|
266
198
|
}
|
|
@@ -268,52 +200,52 @@ var OperationGenerator = class extends _core.Generator {
|
|
|
268
200
|
* Operation
|
|
269
201
|
*/
|
|
270
202
|
async operation(operation, options) {
|
|
271
|
-
return
|
|
203
|
+
return [];
|
|
272
204
|
}
|
|
273
205
|
/**
|
|
274
206
|
* GET
|
|
275
207
|
*/
|
|
276
208
|
async get(operation, options) {
|
|
277
|
-
return
|
|
209
|
+
return [];
|
|
278
210
|
}
|
|
279
211
|
/**
|
|
280
212
|
* POST
|
|
281
213
|
*/
|
|
282
214
|
async post(operation, options) {
|
|
283
|
-
return
|
|
215
|
+
return [];
|
|
284
216
|
}
|
|
285
217
|
/**
|
|
286
218
|
* PATCH
|
|
287
219
|
*/
|
|
288
220
|
async patch(operation, options) {
|
|
289
|
-
return
|
|
221
|
+
return [];
|
|
290
222
|
}
|
|
291
223
|
/**
|
|
292
224
|
* PUT
|
|
293
225
|
*/
|
|
294
226
|
async put(operation, options) {
|
|
295
|
-
return
|
|
227
|
+
return [];
|
|
296
228
|
}
|
|
297
229
|
/**
|
|
298
230
|
* DELETE
|
|
299
231
|
*/
|
|
300
232
|
async delete(operation, options) {
|
|
301
|
-
return
|
|
233
|
+
return [];
|
|
302
234
|
}
|
|
303
235
|
/**
|
|
304
236
|
* Combination of GET, POST, PATCH, PUT, DELETE
|
|
305
237
|
*/
|
|
306
238
|
async all(operations, paths) {
|
|
307
|
-
return
|
|
239
|
+
return [];
|
|
308
240
|
}
|
|
309
241
|
};
|
|
310
242
|
_operationsByMethod = new WeakMap();
|
|
311
243
|
_OperationGenerator_instances = new WeakSet();
|
|
312
244
|
getOptions_fn = function(operation, method) {
|
|
313
245
|
const { override = [] } = this.context;
|
|
314
|
-
return _optionalChain([override, 'access',
|
|
246
|
+
return _optionalChain([override, 'access', _44 => _44.find, 'call', _45 => _45(({ pattern, type }) => {
|
|
315
247
|
if (type === "tag") {
|
|
316
|
-
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)]);
|
|
317
249
|
}
|
|
318
250
|
if (type === "operationId") {
|
|
319
251
|
return !!operation.getOperationId().match(pattern);
|
|
@@ -325,7 +257,7 @@ getOptions_fn = function(operation, method) {
|
|
|
325
257
|
return !!method.match(pattern);
|
|
326
258
|
}
|
|
327
259
|
return false;
|
|
328
|
-
}), 'optionalAccess',
|
|
260
|
+
}), 'optionalAccess', _52 => _52.options]) || {};
|
|
329
261
|
};
|
|
330
262
|
/**
|
|
331
263
|
*
|
|
@@ -336,7 +268,7 @@ isExcluded_fn = function(operation, method) {
|
|
|
336
268
|
let matched = false;
|
|
337
269
|
exclude.forEach(({ pattern, type }) => {
|
|
338
270
|
if (type === "tag" && !matched) {
|
|
339
|
-
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)]);
|
|
340
272
|
}
|
|
341
273
|
if (type === "operationId" && !matched) {
|
|
342
274
|
matched = !!operation.getOperationId().match(pattern);
|
|
@@ -359,7 +291,7 @@ isIncluded_fn = function(operation, method) {
|
|
|
359
291
|
let matched = false;
|
|
360
292
|
include.forEach(({ pattern, type }) => {
|
|
361
293
|
if (type === "tag" && !matched) {
|
|
362
|
-
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)]);
|
|
363
295
|
}
|
|
364
296
|
if (type === "operationId" && !matched) {
|
|
365
297
|
matched = !!operation.getOperationId().match(pattern);
|
|
@@ -373,22 +305,162 @@ isIncluded_fn = function(operation, method) {
|
|
|
373
305
|
});
|
|
374
306
|
return matched;
|
|
375
307
|
};
|
|
376
|
-
|
|
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) {
|
|
377
419
|
return {
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
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
|
+
}
|
|
386
461
|
};
|
|
387
|
-
}
|
|
462
|
+
}
|
|
388
463
|
|
|
389
|
-
// src/index.ts
|
|
390
|
-
var definePluginDefault = pluginOas;
|
|
391
|
-
var src_default = definePluginDefault;
|
|
392
464
|
|
|
393
465
|
|
|
394
466
|
|
|
@@ -397,5 +469,5 @@ var src_default = definePluginDefault;
|
|
|
397
469
|
|
|
398
470
|
|
|
399
471
|
|
|
400
|
-
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;
|
|
401
473
|
//# sourceMappingURL=index.cjs.map
|