@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.
Files changed (76) 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-LEACSHKT.js → chunk-2X5GZFQP.js} +712 -44
  8. package/dist/chunk-2X5GZFQP.js.map +1 -0
  9. package/dist/{chunk-DRLYORTT.cjs → chunk-47SNBYWH.cjs} +750 -69
  10. package/dist/chunk-47SNBYWH.cjs.map +1 -0
  11. package/dist/{chunk-UB552H4J.js → chunk-4VKHSKYX.js} +7 -24
  12. package/dist/{chunk-UB552H4J.js.map → chunk-4VKHSKYX.js.map} +1 -1
  13. package/dist/{chunk-Y4V7HHX7.js → chunk-4WUMV7QX.js} +9 -12
  14. package/dist/chunk-4WUMV7QX.js.map +1 -0
  15. package/dist/chunk-6AVEWDKE.cjs +8 -0
  16. package/dist/chunk-6AVEWDKE.cjs.map +1 -0
  17. package/dist/chunk-S6RFFHLW.cjs +38 -0
  18. package/dist/chunk-S6RFFHLW.cjs.map +1 -0
  19. package/dist/chunk-WN5S6RCU.js +6 -0
  20. package/dist/chunk-WN5S6RCU.js.map +1 -0
  21. package/dist/chunk-XQPCA75E.cjs +90 -0
  22. package/dist/chunk-XQPCA75E.cjs.map +1 -0
  23. package/dist/components.cjs +21 -17
  24. package/dist/components.cjs.map +1 -1
  25. package/dist/components.d.cts +13 -7
  26. package/dist/components.d.ts +13 -7
  27. package/dist/components.js +4 -17
  28. package/dist/components.js.map +1 -1
  29. package/dist/hooks.cjs +30 -35
  30. package/dist/hooks.cjs.map +1 -1
  31. package/dist/hooks.d.cts +4 -4
  32. package/dist/hooks.d.ts +4 -4
  33. package/dist/hooks.js +10 -23
  34. package/dist/hooks.js.map +1 -1
  35. package/dist/index.cjs +315 -262
  36. package/dist/index.cjs.map +1 -1
  37. package/dist/index.d.cts +8 -77
  38. package/dist/index.d.ts +8 -77
  39. package/dist/index.js +270 -239
  40. package/dist/index.js.map +1 -1
  41. package/dist/{types-Dte3MA6H.d.cts → types-CZTUCaE5.d.cts} +3 -1
  42. package/dist/{types-Dte3MA6H.d.ts → types-CZTUCaE5.d.ts} +3 -1
  43. package/dist/utils.cjs +39 -73
  44. package/dist/utils.cjs.map +1 -1
  45. package/dist/utils.d.cts +7 -33
  46. package/dist/utils.d.ts +7 -33
  47. package/dist/utils.js +10 -67
  48. package/dist/utils.js.map +1 -1
  49. package/package.json +11 -10
  50. package/src/OperationGenerator.ts +68 -32
  51. package/src/SchemaGenerator.ts +32 -15
  52. package/src/SchemaMapper.ts +1 -1
  53. package/src/components/Oas.tsx +9 -3
  54. package/src/components/Operation.tsx +1 -1
  55. package/src/components/Schema.tsx +29 -31
  56. package/src/generator.tsx +125 -0
  57. package/src/hooks/useOperationManager.ts +1 -0
  58. package/src/index.ts +3 -9
  59. package/src/plugin.ts +25 -38
  60. package/src/types.ts +2 -0
  61. package/src/utils/getParams.ts +1 -1
  62. package/src/utils/index.ts +2 -1
  63. package/dist/OperationGenerator-CeM_9pxW.d.cts +0 -60
  64. package/dist/OperationGenerator-DhUhvRJE.d.ts +0 -60
  65. package/dist/chunk-CJXRFYEF.cjs +0 -698
  66. package/dist/chunk-CJXRFYEF.cjs.map +0 -1
  67. package/dist/chunk-DRLYORTT.cjs.map +0 -1
  68. package/dist/chunk-K6KUETAI.js +0 -698
  69. package/dist/chunk-K6KUETAI.js.map +0 -1
  70. package/dist/chunk-LEACSHKT.js.map +0 -1
  71. package/dist/chunk-P42X362U.cjs +0 -101
  72. package/dist/chunk-P42X362U.cjs.map +0 -1
  73. package/dist/chunk-QLJIL3U5.cjs +0 -35
  74. package/dist/chunk-QLJIL3U5.cjs.map +0 -1
  75. package/dist/chunk-Y4V7HHX7.js.map +0 -1
  76. package/src/utils/getGroupedByTagFiles.ts +0 -82
package/dist/index.cjs CHANGED
@@ -1,149 +1,100 @@
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; }
1
+ 'use strict';
2
2
 
3
- var _chunkQLJIL3U5cjs = require('./chunk-QLJIL3U5.cjs');
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
- _chunkP42X362Ucjs.init_cjs_shims.call(void 0, );
18
+ chunkXQPCA75E_cjs.init_cjs_shims();
20
19
 
21
- // src/plugin.ts
22
- _chunkP42X362Ucjs.init_cjs_shims.call(void 0, );
23
- var _path = require('path'); var _path2 = _interopRequireDefault(_path);
24
- var _core = require('@kubb/core');
25
- var _transformers = require('@kubb/core/transformers'); var _transformers2 = _interopRequireDefault(_transformers);
26
- var pluginOasName = "plugin-oas";
27
- var pluginOas = _core.createPlugin.call(void 0, (options) => {
28
- const {
29
- output = { path: "schemas", export: false },
30
- experimentalFilter: filter,
31
- experimentalSort: sort,
32
- validate = true,
33
- serverIndex = 0,
34
- contentType,
35
- oasClass
36
- } = options;
37
- const getOas = async ({ config, logger, formatOptions }) => {
38
- try {
39
- const oas = await _chunkQLJIL3U5cjs.parseFromConfig.call(void 0, config, formatOptions, oasClass);
40
- if (validate) {
41
- await oas.valdiate();
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
- 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;
36
+ if (type === "operationId") {
37
+ return !!operation.getOperationId().match(pattern);
74
38
  }
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;
39
+ if (type === "path") {
40
+ return !!operation.path.match(pattern);
84
41
  }
85
- return this.fileManager.write(path2, source, { sanity: false });
86
- },
87
- async buildStart() {
88
- if (!output) {
89
- return;
42
+ if (type === "method") {
43
+ return !!method.match(pattern);
90
44
  }
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, {});
45
+ return false;
46
+ })?.options || {};
139
47
  }
140
- get operationsByMethod() {
141
- return _chunkP42X362Ucjs.__privateGet.call(void 0, this, _operationsByMethod);
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
- set operationsByMethod(paths) {
144
- _chunkP42X362Ucjs.__privateSet.call(void 0, this, _operationsByMethod, paths);
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, { forStatusCode, resolveName = (name) => name } = {}) {
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(_transformers2.default.pascalCase(`${operation.getOperationId()} ${name}`)),
161
- description: _optionalChain([operation, 'access', _7 => _7.getResponseByStatusCode, 'call', _8 => _8(statusCode), 'optionalAccess', _9 => _9.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: _transformers2.default.pascalCase(`${operation.getOperationId()}`),
115
+ operationName: transformers__default.default.pascalCase(`${operation.getOperationId()}`),
165
116
  statusCode: name === "error" ? void 0 : Number(statusCode),
166
- keys: _optionalChain([schema, 'optionalAccess', _10 => _10.properties]) ? Object.keys(schema.properties) : void 0
117
+ keys: schema?.properties ? Object.keys(schema.properties) : void 0
167
118
  };
168
119
  });
169
120
  return {
170
121
  pathParams: pathParamsSchema ? {
171
- name: resolveName(_transformers2.default.pascalCase(`${operation.getOperationId()} PathParams`)),
122
+ name: resolveName(transformers__default.default.pascalCase(`${operation.getOperationId()} PathParams`)),
172
123
  operation,
173
- operationName: _transformers2.default.pascalCase(`${operation.getOperationId()}`),
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(_transformers2.default.pascalCase(`${operation.getOperationId()} QueryParams`)),
129
+ name: resolveName(transformers__default.default.pascalCase(`${operation.getOperationId()} QueryParams`)),
179
130
  operation,
180
- operationName: _transformers2.default.pascalCase(`${operation.getOperationId()}`),
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(_transformers2.default.pascalCase(`${operation.getOperationId()} HeaderParams`)),
136
+ name: resolveName(transformers__default.default.pascalCase(`${operation.getOperationId()} HeaderParams`)),
186
137
  operation,
187
- operationName: _transformers2.default.pascalCase(`${operation.getOperationId()}`),
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(_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]),
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: _transformers2.default.pascalCase(`${operation.getOperationId()}`),
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 = _optionalChain([requestSchema, 'access', _14 => _14.properties, 'optionalAccess', _15 => _15[key]]);
200
- return _optionalChain([item, 'optionalAccess', _16 => _16.readOnly]);
150
+ const item = requestSchema.properties?.[key];
151
+ return item?.readOnly;
201
152
  }) : void 0
202
153
  } : void 0,
203
154
  response: {
204
- 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]),
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: _transformers2.default.pascalCase(`${operation.getOperationId()}`),
158
+ operationName: transformers__default.default.pascalCase(`${operation.getOperationId()}`),
208
159
  schema: responseSchema,
209
160
  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]);
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) => _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")])),
167
+ errors: statusCodes.filter((item) => item.statusCode?.toString().startsWith("4") || item.statusCode?.toString().startsWith("5")),
217
168
  statusCodes
218
169
  };
219
170
  }
220
- async build() {
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 && _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;
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 } = _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
- })]);
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 null;
256
+ return [];
278
257
  }
279
258
  /**
280
259
  * GET
281
260
  */
282
261
  async get(operation, options) {
283
- return null;
262
+ return [];
284
263
  }
285
264
  /**
286
265
  * POST
287
266
  */
288
267
  async post(operation, options) {
289
- return null;
268
+ return [];
290
269
  }
291
270
  /**
292
271
  * PATCH
293
272
  */
294
273
  async patch(operation, options) {
295
- return null;
274
+ return [];
296
275
  }
297
276
  /**
298
277
  * PUT
299
278
  */
300
279
  async put(operation, options) {
301
- return null;
280
+ return [];
302
281
  }
303
282
  /**
304
283
  * DELETE
305
284
  */
306
285
  async delete(operation, options) {
307
- return null;
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 null;
292
+ return [];
314
293
  }
315
294
  };
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);
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
- 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
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
- 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;
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