@kubb/plugin-oas 3.0.0-alpha.1 → 3.0.0-alpha.10

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