@kubb/plugin-oas 0.0.0-canary-20240804130641 → 0.0.0-canary-20241104172400

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 (103) hide show
  1. package/README.md +14 -5
  2. package/dist/OperationGenerator-Bw6sj3Eb.d.cts +560 -0
  3. package/dist/OperationGenerator-Bw6sj3Eb.d.ts +560 -0
  4. package/dist/{Schema-D41ItX9C.d.ts → Schema-4FwWfdim.d.cts} +2 -13
  5. package/dist/{Schema-FGI5VPqc.d.cts → Schema-BlGtSgNB.d.ts} +2 -13
  6. package/dist/chunk-2TGWPVZN.cjs +92 -0
  7. package/dist/chunk-2TGWPVZN.cjs.map +1 -0
  8. package/dist/chunk-A3ROGKLW.cjs +752 -0
  9. package/dist/chunk-A3ROGKLW.cjs.map +1 -0
  10. package/dist/chunk-ABOQ73FL.cjs +36 -0
  11. package/dist/chunk-ABOQ73FL.cjs.map +1 -0
  12. package/dist/chunk-BG77DP54.js +30 -0
  13. package/dist/chunk-BG77DP54.js.map +1 -0
  14. package/dist/chunk-GF26SDHQ.js +28 -0
  15. package/dist/chunk-GF26SDHQ.js.map +1 -0
  16. package/dist/chunk-JA75IPYU.js +744 -0
  17. package/dist/chunk-JA75IPYU.js.map +1 -0
  18. package/dist/chunk-PADR76WZ.cjs +4 -0
  19. package/dist/chunk-PADR76WZ.cjs.map +1 -0
  20. package/dist/chunk-QAFBZLJA.cjs +48 -0
  21. package/dist/chunk-QAFBZLJA.cjs.map +1 -0
  22. package/dist/chunk-R47XMJ32.js +3 -0
  23. package/dist/chunk-R47XMJ32.js.map +1 -0
  24. package/dist/chunk-TNWNNVQW.js +88 -0
  25. package/dist/chunk-TNWNNVQW.js.map +1 -0
  26. package/dist/chunk-XNCEFOE6.js +45 -0
  27. package/dist/chunk-XNCEFOE6.js.map +1 -0
  28. package/dist/chunk-ZWHQ54JM.cjs +32 -0
  29. package/dist/chunk-ZWHQ54JM.cjs.map +1 -0
  30. package/dist/components.cjs +20 -17
  31. package/dist/components.cjs.map +1 -1
  32. package/dist/components.d.cts +12 -9
  33. package/dist/components.d.ts +12 -9
  34. package/dist/components.js +3 -17
  35. package/dist/components.js.map +1 -1
  36. package/dist/generators.cjs +14 -0
  37. package/dist/generators.cjs.map +1 -0
  38. package/dist/generators.d.cts +9 -0
  39. package/dist/generators.d.ts +9 -0
  40. package/dist/generators.js +5 -0
  41. package/dist/generators.js.map +1 -0
  42. package/dist/hooks.cjs +90 -58
  43. package/dist/hooks.cjs.map +1 -1
  44. package/dist/hooks.d.cts +37 -10
  45. package/dist/hooks.d.ts +37 -10
  46. package/dist/hooks.js +79 -54
  47. package/dist/hooks.js.map +1 -1
  48. package/dist/index.cjs +277 -270
  49. package/dist/index.cjs.map +1 -1
  50. package/dist/index.d.cts +6 -78
  51. package/dist/index.d.ts +6 -78
  52. package/dist/index.js +235 -255
  53. package/dist/index.js.map +1 -1
  54. package/dist/utils.cjs +32 -87
  55. package/dist/utils.cjs.map +1 -1
  56. package/dist/utils.d.cts +8 -43
  57. package/dist/utils.d.ts +8 -43
  58. package/dist/utils.js +8 -86
  59. package/dist/utils.js.map +1 -1
  60. package/package.json +21 -15
  61. package/src/OperationGenerator.ts +91 -64
  62. package/src/SchemaGenerator.ts +102 -22
  63. package/src/SchemaMapper.ts +24 -5
  64. package/src/components/Oas.tsx +9 -3
  65. package/src/components/Operation.tsx +1 -1
  66. package/src/components/Schema.tsx +2 -99
  67. package/src/generator.tsx +129 -0
  68. package/src/generators/index.ts +1 -0
  69. package/src/generators/jsonGenerator.ts +32 -0
  70. package/src/hooks/index.ts +2 -0
  71. package/src/hooks/useOperationManager.ts +56 -30
  72. package/src/hooks/useSchemaManager.ts +77 -0
  73. package/src/index.ts +5 -13
  74. package/src/plugin.ts +73 -69
  75. package/src/types.ts +29 -27
  76. package/src/utils/getParams.ts +2 -2
  77. package/src/utils/getSchemaFactory.ts +1 -1
  78. package/src/utils/index.ts +2 -2
  79. package/src/utils/parseFromConfig.ts +7 -7
  80. package/dist/OperationGenerator-BV6QRtkW.d.cts +0 -60
  81. package/dist/OperationGenerator-DO5tNGuT.d.ts +0 -60
  82. package/dist/SchemaMapper-CsBQ6eEx.d.cts +0 -248
  83. package/dist/SchemaMapper-CsBQ6eEx.d.ts +0 -248
  84. package/dist/chunk-CCPZYOTX.cjs +0 -695
  85. package/dist/chunk-CCPZYOTX.cjs.map +0 -1
  86. package/dist/chunk-CO7DS2KL.cjs +0 -35
  87. package/dist/chunk-CO7DS2KL.cjs.map +0 -1
  88. package/dist/chunk-EK7UO5ZW.js +0 -35
  89. package/dist/chunk-EK7UO5ZW.js.map +0 -1
  90. package/dist/chunk-KI3GNEKH.js +0 -3265
  91. package/dist/chunk-KI3GNEKH.js.map +0 -1
  92. package/dist/chunk-LRJFQCDO.js +0 -101
  93. package/dist/chunk-LRJFQCDO.js.map +0 -1
  94. package/dist/chunk-PFN2GSIC.cjs +0 -101
  95. package/dist/chunk-PFN2GSIC.cjs.map +0 -1
  96. package/dist/chunk-TL7TBM2U.cjs +0 -3265
  97. package/dist/chunk-TL7TBM2U.cjs.map +0 -1
  98. package/dist/chunk-UZLE6NIY.js +0 -695
  99. package/dist/chunk-UZLE6NIY.js.map +0 -1
  100. package/dist/types-Db0qp8u-.d.cts +0 -148
  101. package/dist/types-Db0qp8u-.d.ts +0 -148
  102. package/src/utils/getGroupedByTagFiles.ts +0 -82
  103. package/src/utils/refSorter.ts +0 -13
package/dist/index.js CHANGED
@@ -1,155 +1,86 @@
1
- import {
2
- parseFromConfig
3
- } from "./chunk-EK7UO5ZW.js";
4
- import {
5
- SchemaGenerator,
6
- isKeyword,
7
- schemaKeywords
8
- } from "./chunk-UZLE6NIY.js";
9
- import {
10
- __privateAdd,
11
- __privateGet,
12
- __privateMethod,
13
- __privateSet,
14
- getSchemas,
15
- init_esm_shims
16
- } from "./chunk-LRJFQCDO.js";
1
+ import { parseFromConfig } from './chunk-BG77DP54.js';
2
+ import { jsonGenerator } from './chunk-TNWNNVQW.js';
3
+ export { createGenerator, createReactGenerator } from './chunk-TNWNNVQW.js';
4
+ import './chunk-R47XMJ32.js';
5
+ import { SchemaGenerator } from './chunk-JA75IPYU.js';
6
+ export { SchemaGenerator, isKeyword, schemaKeywords } from './chunk-JA75IPYU.js';
7
+ import { getSchemas } from './chunk-XNCEFOE6.js';
8
+ import './chunk-GF26SDHQ.js';
9
+ import { createPlugin, FileManager, BaseGenerator } from '@kubb/core';
10
+ import transformers from '@kubb/core/transformers';
11
+ import path from 'node:path';
17
12
 
18
- // src/index.ts
19
- init_esm_shims();
20
-
21
- // src/plugin.ts
22
- init_esm_shims();
23
- import path from "path";
24
- import { createPlugin } from "@kubb/core";
25
- import { camelCase } from "@kubb/core/transformers";
26
- var pluginOasName = "plugin-oas";
27
- var pluginOas = createPlugin((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 parseFromConfig(config, formatOptions, oasClass);
40
- if (validate) {
41
- await oas.valdiate();
13
+ var OperationGenerator = class extends BaseGenerator {
14
+ #operationsByMethod = {};
15
+ get operationsByMethod() {
16
+ return this.#operationsByMethod;
17
+ }
18
+ set operationsByMethod(paths) {
19
+ this.#operationsByMethod = paths;
20
+ }
21
+ #getOptions(operation, method) {
22
+ const { override = [] } = this.context;
23
+ return override.find(({ pattern, type }) => {
24
+ if (type === "tag") {
25
+ return !!operation.getTags()[0]?.name.match(pattern);
42
26
  }
43
- return oas;
44
- } catch (e) {
45
- const error = e;
46
- logger.emit("warning", error?.message);
47
- return parseFromConfig(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 getSchemas({ oas, contentType, includes });
62
- },
63
- async getBaseURL() {
64
- const oasInstance = await this.getOas();
65
- const baseURL = oasInstance.api.servers?.at(serverIndex)?.url;
66
- return baseURL;
67
- },
68
- contentType
69
- };
70
- },
71
- resolvePath(baseName) {
72
- if (output === false) {
73
- return void 0;
27
+ if (type === "operationId") {
28
+ return !!operation.getOperationId().match(pattern);
74
29
  }
75
- const root = path.resolve(this.config.root, this.config.output.path);
76
- return path.resolve(root, output.path, baseName);
77
- },
78
- resolveName(name, type) {
79
- return camelCase(name, { isFile: type === "file" });
80
- },
81
- async writeFile(path2, source) {
82
- if (!path2.endsWith(".json") || !source) {
83
- return;
30
+ if (type === "path") {
31
+ return !!operation.path.match(pattern);
84
32
  }
85
- return this.fileManager.write(path2, source, { sanity: false });
86
- },
87
- async buildStart() {
88
- if (!output) {
89
- return;
33
+ if (type === "method") {
34
+ return !!method.match(pattern);
90
35
  }
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 = getSchemas({ 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
- init_esm_shims();
131
- import { Generator } from "@kubb/core";
132
- import transformers from "@kubb/core/transformers";
133
- var _operationsByMethod, _OperationGenerator_instances, getOptions_fn, isExcluded_fn, isIncluded_fn, methods_get;
134
- var OperationGenerator = class extends Generator {
135
- constructor() {
136
- super(...arguments);
137
- __privateAdd(this, _OperationGenerator_instances);
138
- __privateAdd(this, _operationsByMethod, {});
36
+ return false;
37
+ })?.options || {};
139
38
  }
140
- get operationsByMethod() {
141
- return __privateGet(this, _operationsByMethod);
39
+ #isExcluded(operation, method) {
40
+ const { exclude = [] } = this.context;
41
+ let matched = false;
42
+ exclude.forEach(({ pattern, type }) => {
43
+ if (type === "tag" && !matched) {
44
+ matched = !!operation.getTags()[0]?.name.match(pattern);
45
+ }
46
+ if (type === "operationId" && !matched) {
47
+ matched = !!operation.getOperationId().match(pattern);
48
+ }
49
+ if (type === "path" && !matched) {
50
+ matched = !!operation.path.match(pattern);
51
+ }
52
+ if (type === "method" && !matched) {
53
+ matched = !!method.match(pattern);
54
+ }
55
+ });
56
+ return matched;
142
57
  }
143
- set operationsByMethod(paths) {
144
- __privateSet(this, _operationsByMethod, paths);
58
+ #isIncluded(operation, method) {
59
+ const { include = [] } = this.context;
60
+ let matched = false;
61
+ include.forEach(({ pattern, type }) => {
62
+ if (type === "tag" && !matched) {
63
+ matched = !!operation.getTags()[0]?.name.match(pattern);
64
+ }
65
+ if (type === "operationId" && !matched) {
66
+ matched = !!operation.getOperationId().match(pattern);
67
+ }
68
+ if (type === "path" && !matched) {
69
+ matched = !!operation.path.match(pattern);
70
+ }
71
+ if (type === "method" && !matched) {
72
+ matched = !!method.match(pattern);
73
+ }
74
+ });
75
+ return matched;
145
76
  }
146
- getSchemas(operation, { forStatusCode, resolveName = (name) => name } = {}) {
77
+ getSchemas(operation, {
78
+ resolveName = (name) => name
79
+ } = {}) {
147
80
  const pathParamsSchema = this.context.oas.getParametersSchema(operation, "path");
148
81
  const queryParamsSchema = this.context.oas.getParametersSchema(operation, "query");
149
82
  const headerParamsSchema = this.context.oas.getParametersSchema(operation, "header");
150
83
  const requestSchema = this.context.oas.getRequestSchema(operation);
151
- const responseStatusCode = forStatusCode || operation.schema.responses && Object.keys(operation.schema.responses).find((key) => key.startsWith("2")) || 200;
152
- const responseSchema = this.context.oas.getResponseSchema(operation, responseStatusCode);
153
84
  const statusCodes = operation.getResponseStatusCodes().map((statusCode) => {
154
85
  let name = statusCode;
155
86
  if (name === "default") {
@@ -163,9 +94,14 @@ var OperationGenerator = class extends Generator {
163
94
  operation,
164
95
  operationName: transformers.pascalCase(`${operation.getOperationId()}`),
165
96
  statusCode: name === "error" ? void 0 : Number(statusCode),
166
- keys: schema?.properties ? Object.keys(schema.properties) : void 0
97
+ keys: schema?.properties ? Object.keys(schema.properties) : void 0,
98
+ keysToOmit: schema?.properties ? Object.keys(schema.properties).filter((key) => {
99
+ const item = schema.properties?.[key];
100
+ return item?.writeOnly;
101
+ }) : void 0
167
102
  };
168
103
  });
104
+ const hasResponses = statusCodes.some((item) => item.statusCode?.toString().startsWith("2"));
169
105
  return {
170
106
  pathParams: pathParamsSchema ? {
171
107
  name: resolveName(transformers.pascalCase(`${operation.getOperationId()} PathParams`)),
@@ -202,31 +138,33 @@ var OperationGenerator = class extends Generator {
202
138
  } : void 0,
203
139
  response: {
204
140
  name: resolveName(transformers.pascalCase(`${operation.getOperationId()} ${operation.method === "get" ? "queryResponse" : "mutationResponse"}`)),
205
- description: operation.getResponseAsJSONSchema(responseStatusCode)?.at(0)?.description,
206
141
  operation,
207
142
  operationName: transformers.pascalCase(`${operation.getOperationId()}`),
208
- schema: responseSchema,
209
- statusCode: Number(responseStatusCode),
210
- keys: responseSchema?.properties ? Object.keys(responseSchema.properties) : void 0,
211
- keysToOmit: responseSchema?.properties ? Object.keys(responseSchema.properties).filter((key) => {
212
- const item = responseSchema.properties?.[key];
213
- return item?.writeOnly;
214
- }) : void 0
143
+ schema: {
144
+ oneOf: hasResponses ? statusCodes.filter((item) => item.statusCode?.toString().startsWith("2")).map((item) => {
145
+ return {
146
+ ...item.schema,
147
+ $ref: resolveName(transformers.pascalCase(`${operation.getOperationId()} ${item.statusCode}`))
148
+ };
149
+ }) : void 0
150
+ }
215
151
  },
152
+ responses: statusCodes.filter((item) => item.statusCode?.toString().startsWith("2")),
216
153
  errors: statusCodes.filter((item) => item.statusCode?.toString().startsWith("4") || item.statusCode?.toString().startsWith("5")),
217
154
  statusCodes
218
155
  };
219
156
  }
220
- async build() {
157
+ #methods = ["get", "post", "patch", "put", "delete"];
158
+ async build(...generators) {
221
159
  const { oas } = this.context;
222
160
  const paths = oas.getPaths();
223
161
  this.operationsByMethod = Object.entries(paths).reduce((acc, [path2, method]) => {
224
162
  const methods = Object.keys(method);
225
163
  methods.forEach((method2) => {
226
164
  const operation = oas.operation(path2, method2);
227
- if (operation && __privateGet(this, _OperationGenerator_instances, methods_get)[method2]) {
228
- const isExcluded = __privateMethod(this, _OperationGenerator_instances, isExcluded_fn).call(this, operation, method2);
229
- const isIncluded = this.context.include ? __privateMethod(this, _OperationGenerator_instances, isIncluded_fn).call(this, operation, method2) : true;
165
+ if (operation && [this.#methods].some((methods2) => method2 === operation.method)) {
166
+ const isExcluded = this.#isExcluded(operation, method2);
167
+ const isIncluded = this.context.include ? this.#isIncluded(operation, method2) : true;
230
168
  if (isIncluded && !isExcluded) {
231
169
  if (!acc[path2]) {
232
170
  acc[path2] = {};
@@ -247,26 +185,53 @@ var OperationGenerator = class extends Generator {
247
185
  const methods = this.operationsByMethod[path2] ? Object.keys(this.operationsByMethod[path2]) : [];
248
186
  methods.forEach((method) => {
249
187
  const { operation } = this.operationsByMethod[path2]?.[method];
250
- const options = __privateMethod(this, _OperationGenerator_instances, getOptions_fn).call(this, operation, method);
251
- const promiseMethod = __privateGet(this, _OperationGenerator_instances, methods_get)[method]?.call(this, operation, {
252
- ...this.options,
253
- ...options
254
- });
188
+ const options = this.#getOptions(operation, method);
189
+ const methodToCall = this[method];
190
+ if (typeof methodToCall === "function") {
191
+ const promiseMethod = methodToCall?.call(this, operation, {
192
+ ...this.options,
193
+ ...options
194
+ });
195
+ if (promiseMethod) {
196
+ acc.push(promiseMethod);
197
+ }
198
+ }
255
199
  const promiseOperation = this.operation.call(this, operation, {
256
200
  ...this.options,
257
201
  ...options
258
202
  });
259
- if (promiseMethod) {
260
- acc.push(promiseMethod);
261
- }
262
203
  if (promiseOperation) {
263
204
  acc.push(promiseOperation);
264
205
  }
206
+ generators?.forEach((generator) => {
207
+ const promise = generator.operation?.({
208
+ instance: this,
209
+ operation,
210
+ options: {
211
+ ...this.options,
212
+ ...options
213
+ }
214
+ });
215
+ if (promise) {
216
+ acc.push(promise);
217
+ }
218
+ });
265
219
  });
266
220
  return acc;
267
221
  }, []);
268
222
  const operations = Object.values(this.operationsByMethod).map((item) => Object.values(item).map((item2) => item2.operation));
269
223
  promises.push(this.all(operations.flat().filter(Boolean), this.operationsByMethod));
224
+ generators?.forEach((generator) => {
225
+ const promise = generator.operations?.({
226
+ instance: this,
227
+ operations: operations.flat().filter(Boolean),
228
+ operationsByMethod: this.operationsByMethod,
229
+ options: this.options
230
+ });
231
+ if (promise) {
232
+ promises.push(promise);
233
+ }
234
+ });
270
235
  const files = await Promise.all(promises);
271
236
  return files.flat().filter(Boolean);
272
237
  }
@@ -274,134 +239,149 @@ var OperationGenerator = class extends Generator {
274
239
  * Operation
275
240
  */
276
241
  async operation(operation, options) {
277
- return null;
242
+ return [];
278
243
  }
279
244
  /**
280
245
  * GET
281
246
  */
282
247
  async get(operation, options) {
283
- return null;
248
+ return [];
284
249
  }
285
250
  /**
286
251
  * POST
287
252
  */
288
253
  async post(operation, options) {
289
- return null;
254
+ return [];
290
255
  }
291
256
  /**
292
257
  * PATCH
293
258
  */
294
259
  async patch(operation, options) {
295
- return null;
260
+ return [];
296
261
  }
297
262
  /**
298
263
  * PUT
299
264
  */
300
265
  async put(operation, options) {
301
- return null;
266
+ return [];
302
267
  }
303
268
  /**
304
269
  * DELETE
305
270
  */
306
271
  async delete(operation, options) {
307
- return null;
272
+ return [];
308
273
  }
309
274
  /**
310
275
  * Combination of GET, POST, PATCH, PUT, DELETE
311
276
  */
312
277
  async all(operations, paths) {
313
- return null;
278
+ return [];
314
279
  }
315
280
  };
316
- _operationsByMethod = new WeakMap();
317
- _OperationGenerator_instances = new WeakSet();
318
- getOptions_fn = function(operation, method) {
319
- const { override = [] } = this.context;
320
- return override.find(({ pattern, type }) => {
321
- if (type === "tag") {
322
- return !!operation.getTags()[0]?.name.match(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
- })?.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 = !!operation.getTags()[0]?.name.match(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 = !!operation.getTags()[0]?.name.match(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);
281
+ var pluginOasName = "plugin-oas";
282
+ var pluginOas = createPlugin((options) => {
283
+ const {
284
+ output = {
285
+ path: "schemas"
286
+ },
287
+ validate = true,
288
+ generators = [jsonGenerator],
289
+ serverIndex,
290
+ contentType,
291
+ oasClass
292
+ } = options;
293
+ const getOas = async ({ config, logger }) => {
294
+ try {
295
+ const oas = await parseFromConfig(config, oasClass);
296
+ if (validate) {
297
+ await oas.valdiate();
298
+ }
299
+ return oas;
300
+ } catch (e) {
301
+ const error = e;
302
+ logger.emit("warning", error?.message);
303
+ return parseFromConfig(config, oasClass);
378
304
  }
379
- });
380
- return matched;
381
- };
382
- methods_get = function() {
305
+ };
383
306
  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
307
+ name: pluginOasName,
308
+ options: {
309
+ output,
310
+ ...options
311
+ },
312
+ context() {
313
+ const { config, logger } = this;
314
+ return {
315
+ getOas() {
316
+ return getOas({ config, logger });
317
+ },
318
+ async getSchemas({ includes } = {}) {
319
+ const oas = await this.getOas();
320
+ return getSchemas({ oas, contentType, includes });
321
+ },
322
+ async getBaseURL() {
323
+ const oasInstance = await this.getOas();
324
+ if (serverIndex) {
325
+ return oasInstance.api.servers?.at(serverIndex)?.url;
326
+ }
327
+ return void 0;
328
+ },
329
+ contentType
330
+ };
331
+ },
332
+ resolvePath(baseName, pathMode, options2) {
333
+ const root = path.resolve(this.config.root, this.config.output.path);
334
+ const mode = pathMode ?? FileManager.getMode(path.resolve(root, output.path));
335
+ if (mode === "single") {
336
+ return path.resolve(root, output.path);
337
+ }
338
+ return path.resolve(root, output.path, baseName);
339
+ },
340
+ async buildStart() {
341
+ if (!output) {
342
+ return;
343
+ }
344
+ const oas = await getOas({
345
+ config: this.config,
346
+ logger: this.logger
347
+ });
348
+ await oas.dereference();
349
+ const schemaGenerator = new SchemaGenerator(
350
+ {
351
+ unknownType: "unknown",
352
+ dateType: "date",
353
+ transformers: {},
354
+ ...this.plugin.options
355
+ },
356
+ {
357
+ oas,
358
+ pluginManager: this.pluginManager,
359
+ plugin: this.plugin,
360
+ contentType,
361
+ include: void 0,
362
+ override: void 0,
363
+ mode: "split",
364
+ output: output.path
365
+ }
366
+ );
367
+ const schemaFiles = await schemaGenerator.build(...generators);
368
+ await this.addFile(...schemaFiles);
369
+ const operationGenerator = new OperationGenerator(this.plugin.options, {
370
+ oas,
371
+ pluginManager: this.pluginManager,
372
+ plugin: this.plugin,
373
+ contentType,
374
+ exclude: void 0,
375
+ include: void 0,
376
+ override: void 0,
377
+ mode: "split"
378
+ });
379
+ const operationFiles = await operationGenerator.build(...generators);
380
+ await this.addFile(...operationFiles);
381
+ }
392
382
  };
393
- };
383
+ });
394
384
 
395
- // src/index.ts
396
- var definePluginDefault = pluginOas;
397
- var src_default = definePluginDefault;
398
- export {
399
- OperationGenerator,
400
- SchemaGenerator,
401
- src_default as default,
402
- isKeyword,
403
- pluginOas,
404
- pluginOasName,
405
- schemaKeywords
406
- };
385
+ export { OperationGenerator, pluginOas, pluginOasName };
386
+ //# sourceMappingURL=index.js.map
407
387
  //# sourceMappingURL=index.js.map