@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.cjs CHANGED
@@ -1,155 +1,91 @@
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 _chunkCO7DS2KLcjs = require('./chunk-CO7DS2KL.cjs');
3
+ var chunkABOQ73FL_cjs = require('./chunk-ABOQ73FL.cjs');
4
+ var chunk2TGWPVZN_cjs = require('./chunk-2TGWPVZN.cjs');
5
+ require('./chunk-PADR76WZ.cjs');
6
+ var chunkA3ROGKLW_cjs = require('./chunk-A3ROGKLW.cjs');
7
+ var chunkQAFBZLJA_cjs = require('./chunk-QAFBZLJA.cjs');
8
+ require('./chunk-ZWHQ54JM.cjs');
9
+ var core = require('@kubb/core');
10
+ var transformers = require('@kubb/core/transformers');
11
+ var path = require('path');
4
12
 
13
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
5
14
 
15
+ var transformers__default = /*#__PURE__*/_interopDefault(transformers);
16
+ var path__default = /*#__PURE__*/_interopDefault(path);
6
17
 
7
-
8
- var _chunkCCPZYOTXcjs = require('./chunk-CCPZYOTX.cjs');
9
-
10
-
11
-
12
-
13
-
14
-
15
-
16
- var _chunkPFN2GSICcjs = require('./chunk-PFN2GSIC.cjs');
17
-
18
- // src/index.ts
19
- _chunkPFN2GSICcjs.init_cjs_shims.call(void 0, );
20
-
21
- // src/plugin.ts
22
- _chunkPFN2GSICcjs.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 _chunkCO7DS2KLcjs.parseFromConfig.call(void 0, config, formatOptions, oasClass);
40
- if (validate) {
41
- await oas.valdiate();
18
+ var OperationGenerator = class extends core.BaseGenerator {
19
+ #operationsByMethod = {};
20
+ get operationsByMethod() {
21
+ return this.#operationsByMethod;
22
+ }
23
+ set operationsByMethod(paths) {
24
+ this.#operationsByMethod = paths;
25
+ }
26
+ #getOptions(operation, method) {
27
+ const { override = [] } = this.context;
28
+ return override.find(({ pattern, type }) => {
29
+ if (type === "tag") {
30
+ return !!operation.getTags()[0]?.name.match(pattern);
42
31
  }
43
- return oas;
44
- } catch (e) {
45
- const error = e;
46
- logger.emit("warning", _optionalChain([error, 'optionalAccess', _ => _.message]));
47
- return _chunkCO7DS2KLcjs.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 _chunkPFN2GSICcjs.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;
32
+ if (type === "operationId") {
33
+ return !!operation.getOperationId().match(pattern);
74
34
  }
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;
35
+ if (type === "path") {
36
+ return !!operation.path.match(pattern);
84
37
  }
85
- return this.fileManager.write(path2, source, { sanity: false });
86
- },
87
- async buildStart() {
88
- if (!output) {
89
- return;
38
+ if (type === "method") {
39
+ return !!method.match(pattern);
90
40
  }
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 = _chunkPFN2GSICcjs.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
- _chunkPFN2GSICcjs.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
- _chunkPFN2GSICcjs.__privateAdd.call(void 0, this, _OperationGenerator_instances);
138
- _chunkPFN2GSICcjs.__privateAdd.call(void 0, this, _operationsByMethod, {});
41
+ return false;
42
+ })?.options || {};
139
43
  }
140
- get operationsByMethod() {
141
- return _chunkPFN2GSICcjs.__privateGet.call(void 0, this, _operationsByMethod);
44
+ #isExcluded(operation, method) {
45
+ const { exclude = [] } = this.context;
46
+ let matched = false;
47
+ exclude.forEach(({ pattern, type }) => {
48
+ if (type === "tag" && !matched) {
49
+ matched = !!operation.getTags()[0]?.name.match(pattern);
50
+ }
51
+ if (type === "operationId" && !matched) {
52
+ matched = !!operation.getOperationId().match(pattern);
53
+ }
54
+ if (type === "path" && !matched) {
55
+ matched = !!operation.path.match(pattern);
56
+ }
57
+ if (type === "method" && !matched) {
58
+ matched = !!method.match(pattern);
59
+ }
60
+ });
61
+ return matched;
142
62
  }
143
- set operationsByMethod(paths) {
144
- _chunkPFN2GSICcjs.__privateSet.call(void 0, this, _operationsByMethod, paths);
63
+ #isIncluded(operation, method) {
64
+ const { include = [] } = this.context;
65
+ let matched = false;
66
+ include.forEach(({ pattern, type }) => {
67
+ if (type === "tag" && !matched) {
68
+ matched = !!operation.getTags()[0]?.name.match(pattern);
69
+ }
70
+ if (type === "operationId" && !matched) {
71
+ matched = !!operation.getOperationId().match(pattern);
72
+ }
73
+ if (type === "path" && !matched) {
74
+ matched = !!operation.path.match(pattern);
75
+ }
76
+ if (type === "method" && !matched) {
77
+ matched = !!method.match(pattern);
78
+ }
79
+ });
80
+ return matched;
145
81
  }
146
- getSchemas(operation, { forStatusCode, resolveName = (name) => name } = {}) {
82
+ getSchemas(operation, {
83
+ resolveName = (name) => name
84
+ } = {}) {
147
85
  const pathParamsSchema = this.context.oas.getParametersSchema(operation, "path");
148
86
  const queryParamsSchema = this.context.oas.getParametersSchema(operation, "query");
149
87
  const headerParamsSchema = this.context.oas.getParametersSchema(operation, "header");
150
88
  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
89
  const statusCodes = operation.getResponseStatusCodes().map((statusCode) => {
154
90
  let name = statusCode;
155
91
  if (name === "default") {
@@ -157,76 +93,83 @@ var OperationGenerator = class extends _core.Generator {
157
93
  }
158
94
  const schema = this.context.oas.getResponseSchema(operation, statusCode);
159
95
  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]),
96
+ name: resolveName(transformers__default.default.pascalCase(`${operation.getOperationId()} ${name}`)),
97
+ description: operation.getResponseByStatusCode(statusCode)?.description,
162
98
  schema,
163
99
  operation,
164
- operationName: _transformers2.default.pascalCase(`${operation.getOperationId()}`),
100
+ operationName: transformers__default.default.pascalCase(`${operation.getOperationId()}`),
165
101
  statusCode: name === "error" ? void 0 : Number(statusCode),
166
- keys: _optionalChain([schema, 'optionalAccess', _10 => _10.properties]) ? Object.keys(schema.properties) : void 0
102
+ keys: schema?.properties ? Object.keys(schema.properties) : void 0,
103
+ keysToOmit: schema?.properties ? Object.keys(schema.properties).filter((key) => {
104
+ const item = schema.properties?.[key];
105
+ return item?.writeOnly;
106
+ }) : void 0
167
107
  };
168
108
  });
109
+ const hasResponses = statusCodes.some((item) => item.statusCode?.toString().startsWith("2"));
169
110
  return {
170
111
  pathParams: pathParamsSchema ? {
171
- name: resolveName(_transformers2.default.pascalCase(`${operation.getOperationId()} PathParams`)),
112
+ name: resolveName(transformers__default.default.pascalCase(`${operation.getOperationId()} PathParams`)),
172
113
  operation,
173
- operationName: _transformers2.default.pascalCase(`${operation.getOperationId()}`),
114
+ operationName: transformers__default.default.pascalCase(`${operation.getOperationId()}`),
174
115
  schema: pathParamsSchema,
175
116
  keys: pathParamsSchema.properties ? Object.keys(pathParamsSchema.properties) : void 0
176
117
  } : void 0,
177
118
  queryParams: queryParamsSchema ? {
178
- name: resolveName(_transformers2.default.pascalCase(`${operation.getOperationId()} QueryParams`)),
119
+ name: resolveName(transformers__default.default.pascalCase(`${operation.getOperationId()} QueryParams`)),
179
120
  operation,
180
- operationName: _transformers2.default.pascalCase(`${operation.getOperationId()}`),
121
+ operationName: transformers__default.default.pascalCase(`${operation.getOperationId()}`),
181
122
  schema: queryParamsSchema,
182
123
  keys: queryParamsSchema.properties ? Object.keys(queryParamsSchema.properties) : []
183
124
  } : void 0,
184
125
  headerParams: headerParamsSchema ? {
185
- name: resolveName(_transformers2.default.pascalCase(`${operation.getOperationId()} HeaderParams`)),
126
+ name: resolveName(transformers__default.default.pascalCase(`${operation.getOperationId()} HeaderParams`)),
186
127
  operation,
187
- operationName: _transformers2.default.pascalCase(`${operation.getOperationId()}`),
128
+ operationName: transformers__default.default.pascalCase(`${operation.getOperationId()}`),
188
129
  schema: headerParamsSchema,
189
130
  keys: headerParamsSchema.properties ? Object.keys(headerParamsSchema.properties) : void 0
190
131
  } : void 0,
191
132
  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]),
133
+ name: resolveName(transformers__default.default.pascalCase(`${operation.getOperationId()} ${operation.method === "get" ? "queryRequest" : "mutationRequest"}`)),
134
+ description: operation.schema.requestBody?.description,
194
135
  operation,
195
- operationName: _transformers2.default.pascalCase(`${operation.getOperationId()}`),
136
+ operationName: transformers__default.default.pascalCase(`${operation.getOperationId()}`),
196
137
  schema: requestSchema,
197
138
  keys: requestSchema.properties ? Object.keys(requestSchema.properties) : void 0,
198
139
  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]);
140
+ const item = requestSchema.properties?.[key];
141
+ return item?.readOnly;
201
142
  }) : void 0
202
143
  } : void 0,
203
144
  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]),
145
+ name: resolveName(transformers__default.default.pascalCase(`${operation.getOperationId()} ${operation.method === "get" ? "queryResponse" : "mutationResponse"}`)),
206
146
  operation,
207
- operationName: _transformers2.default.pascalCase(`${operation.getOperationId()}`),
208
- schema: responseSchema,
209
- 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]);
214
- }) : void 0
147
+ operationName: transformers__default.default.pascalCase(`${operation.getOperationId()}`),
148
+ schema: {
149
+ oneOf: hasResponses ? statusCodes.filter((item) => item.statusCode?.toString().startsWith("2")).map((item) => {
150
+ return {
151
+ ...item.schema,
152
+ $ref: resolveName(transformers__default.default.pascalCase(`${operation.getOperationId()} ${item.statusCode}`))
153
+ };
154
+ }) : void 0
155
+ }
215
156
  },
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")])),
157
+ responses: statusCodes.filter((item) => item.statusCode?.toString().startsWith("2")),
158
+ errors: statusCodes.filter((item) => item.statusCode?.toString().startsWith("4") || item.statusCode?.toString().startsWith("5")),
217
159
  statusCodes
218
160
  };
219
161
  }
220
- async build() {
162
+ #methods = ["get", "post", "patch", "put", "delete"];
163
+ async build(...generators) {
221
164
  const { oas } = this.context;
222
165
  const paths = oas.getPaths();
223
166
  this.operationsByMethod = Object.entries(paths).reduce((acc, [path2, method]) => {
224
167
  const methods = Object.keys(method);
225
168
  methods.forEach((method2) => {
226
169
  const operation = oas.operation(path2, method2);
227
- if (operation && _chunkPFN2GSICcjs.__privateGet.call(void 0, this, _OperationGenerator_instances, methods_get)[method2]) {
228
- const isExcluded = _chunkPFN2GSICcjs.__privateMethod.call(void 0, this, _OperationGenerator_instances, isExcluded_fn).call(this, operation, method2);
229
- const isIncluded = this.context.include ? _chunkPFN2GSICcjs.__privateMethod.call(void 0, this, _OperationGenerator_instances, isIncluded_fn).call(this, operation, method2) : true;
170
+ if (operation && [this.#methods].some((methods2) => method2 === operation.method)) {
171
+ const isExcluded = this.#isExcluded(operation, method2);
172
+ const isIncluded = this.context.include ? this.#isIncluded(operation, method2) : true;
230
173
  if (isIncluded && !isExcluded) {
231
174
  if (!acc[path2]) {
232
175
  acc[path2] = {};
@@ -246,27 +189,54 @@ var OperationGenerator = class extends _core.Generator {
246
189
  const promises = Object.keys(this.operationsByMethod).reduce((acc, path2) => {
247
190
  const methods = this.operationsByMethod[path2] ? Object.keys(this.operationsByMethod[path2]) : [];
248
191
  methods.forEach((method) => {
249
- const { operation } = _optionalChain([this, 'access', _37 => _37.operationsByMethod, 'access', _38 => _38[path2], 'optionalAccess', _39 => _39[method]]);
250
- const options = _chunkPFN2GSICcjs.__privateMethod.call(void 0, this, _OperationGenerator_instances, getOptions_fn).call(this, operation, method);
251
- const promiseMethod = _optionalChain([_chunkPFN2GSICcjs.__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
- })]);
192
+ const { operation } = this.operationsByMethod[path2]?.[method];
193
+ const options = this.#getOptions(operation, method);
194
+ const methodToCall = this[method];
195
+ if (typeof methodToCall === "function") {
196
+ const promiseMethod = methodToCall?.call(this, operation, {
197
+ ...this.options,
198
+ ...options
199
+ });
200
+ if (promiseMethod) {
201
+ acc.push(promiseMethod);
202
+ }
203
+ }
255
204
  const promiseOperation = this.operation.call(this, operation, {
256
205
  ...this.options,
257
206
  ...options
258
207
  });
259
- if (promiseMethod) {
260
- acc.push(promiseMethod);
261
- }
262
208
  if (promiseOperation) {
263
209
  acc.push(promiseOperation);
264
210
  }
211
+ generators?.forEach((generator) => {
212
+ const promise = generator.operation?.({
213
+ instance: this,
214
+ operation,
215
+ options: {
216
+ ...this.options,
217
+ ...options
218
+ }
219
+ });
220
+ if (promise) {
221
+ acc.push(promise);
222
+ }
223
+ });
265
224
  });
266
225
  return acc;
267
226
  }, []);
268
227
  const operations = Object.values(this.operationsByMethod).map((item) => Object.values(item).map((item2) => item2.operation));
269
228
  promises.push(this.all(operations.flat().filter(Boolean), this.operationsByMethod));
229
+ generators?.forEach((generator) => {
230
+ const promise = generator.operations?.({
231
+ instance: this,
232
+ operations: operations.flat().filter(Boolean),
233
+ operationsByMethod: this.operationsByMethod,
234
+ options: this.options
235
+ });
236
+ if (promise) {
237
+ promises.push(promise);
238
+ }
239
+ });
270
240
  const files = await Promise.all(promises);
271
241
  return files.flat().filter(Boolean);
272
242
  }
@@ -274,134 +244,171 @@ var OperationGenerator = class extends _core.Generator {
274
244
  * Operation
275
245
  */
276
246
  async operation(operation, options) {
277
- return null;
247
+ return [];
278
248
  }
279
249
  /**
280
250
  * GET
281
251
  */
282
252
  async get(operation, options) {
283
- return null;
253
+ return [];
284
254
  }
285
255
  /**
286
256
  * POST
287
257
  */
288
258
  async post(operation, options) {
289
- return null;
259
+ return [];
290
260
  }
291
261
  /**
292
262
  * PATCH
293
263
  */
294
264
  async patch(operation, options) {
295
- return null;
265
+ return [];
296
266
  }
297
267
  /**
298
268
  * PUT
299
269
  */
300
270
  async put(operation, options) {
301
- return null;
271
+ return [];
302
272
  }
303
273
  /**
304
274
  * DELETE
305
275
  */
306
276
  async delete(operation, options) {
307
- return null;
277
+ return [];
308
278
  }
309
279
  /**
310
280
  * Combination of GET, POST, PATCH, PUT, DELETE
311
281
  */
312
282
  async all(operations, paths) {
313
- return null;
283
+ return [];
314
284
  }
315
285
  };
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);
286
+ var pluginOasName = "plugin-oas";
287
+ var pluginOas = core.createPlugin((options) => {
288
+ const {
289
+ output = {
290
+ path: "schemas"
291
+ },
292
+ validate = true,
293
+ generators = [chunk2TGWPVZN_cjs.jsonGenerator],
294
+ serverIndex,
295
+ contentType,
296
+ oasClass
297
+ } = options;
298
+ const getOas = async ({ config, logger }) => {
299
+ try {
300
+ const oas = await chunkABOQ73FL_cjs.parseFromConfig(config, oasClass);
301
+ if (validate) {
302
+ await oas.valdiate();
303
+ }
304
+ return oas;
305
+ } catch (e) {
306
+ const error = e;
307
+ logger.emit("warning", error?.message);
308
+ return chunkABOQ73FL_cjs.parseFromConfig(config, oasClass);
378
309
  }
379
- });
380
- return matched;
381
- };
382
- methods_get = function() {
310
+ };
383
311
  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
312
+ name: pluginOasName,
313
+ options: {
314
+ output,
315
+ ...options
316
+ },
317
+ context() {
318
+ const { config, logger } = this;
319
+ return {
320
+ getOas() {
321
+ return getOas({ config, logger });
322
+ },
323
+ async getSchemas({ includes } = {}) {
324
+ const oas = await this.getOas();
325
+ return chunkQAFBZLJA_cjs.getSchemas({ oas, contentType, includes });
326
+ },
327
+ async getBaseURL() {
328
+ const oasInstance = await this.getOas();
329
+ if (serverIndex) {
330
+ return oasInstance.api.servers?.at(serverIndex)?.url;
331
+ }
332
+ return void 0;
333
+ },
334
+ contentType
335
+ };
336
+ },
337
+ resolvePath(baseName, pathMode, options2) {
338
+ const root = path__default.default.resolve(this.config.root, this.config.output.path);
339
+ const mode = pathMode ?? core.FileManager.getMode(path__default.default.resolve(root, output.path));
340
+ if (mode === "single") {
341
+ return path__default.default.resolve(root, output.path);
342
+ }
343
+ return path__default.default.resolve(root, output.path, baseName);
344
+ },
345
+ async buildStart() {
346
+ if (!output) {
347
+ return;
348
+ }
349
+ const oas = await getOas({
350
+ config: this.config,
351
+ logger: this.logger
352
+ });
353
+ await oas.dereference();
354
+ const schemaGenerator = new chunkA3ROGKLW_cjs.SchemaGenerator(
355
+ {
356
+ unknownType: "unknown",
357
+ dateType: "date",
358
+ transformers: {},
359
+ ...this.plugin.options
360
+ },
361
+ {
362
+ oas,
363
+ pluginManager: this.pluginManager,
364
+ plugin: this.plugin,
365
+ contentType,
366
+ include: void 0,
367
+ override: void 0,
368
+ mode: "split",
369
+ output: output.path
370
+ }
371
+ );
372
+ const schemaFiles = await schemaGenerator.build(...generators);
373
+ await this.addFile(...schemaFiles);
374
+ const operationGenerator = new OperationGenerator(this.plugin.options, {
375
+ oas,
376
+ pluginManager: this.pluginManager,
377
+ plugin: this.plugin,
378
+ contentType,
379
+ exclude: void 0,
380
+ include: void 0,
381
+ override: void 0,
382
+ mode: "split"
383
+ });
384
+ const operationFiles = await operationGenerator.build(...generators);
385
+ await this.addFile(...operationFiles);
386
+ }
392
387
  };
393
- };
394
-
395
- // src/index.ts
396
- var definePluginDefault = pluginOas;
397
- var src_default = definePluginDefault;
398
-
399
-
400
-
401
-
402
-
403
-
404
-
388
+ });
405
389
 
406
- exports.OperationGenerator = OperationGenerator; exports.SchemaGenerator = _chunkCCPZYOTXcjs.SchemaGenerator; exports.default = src_default; exports.isKeyword = _chunkCCPZYOTXcjs.isKeyword; exports.pluginOas = pluginOas; exports.pluginOasName = pluginOasName; exports.schemaKeywords = _chunkCCPZYOTXcjs.schemaKeywords;
390
+ Object.defineProperty(exports, "createGenerator", {
391
+ enumerable: true,
392
+ get: function () { return chunk2TGWPVZN_cjs.createGenerator; }
393
+ });
394
+ Object.defineProperty(exports, "createReactGenerator", {
395
+ enumerable: true,
396
+ get: function () { return chunk2TGWPVZN_cjs.createReactGenerator; }
397
+ });
398
+ Object.defineProperty(exports, "SchemaGenerator", {
399
+ enumerable: true,
400
+ get: function () { return chunkA3ROGKLW_cjs.SchemaGenerator; }
401
+ });
402
+ Object.defineProperty(exports, "isKeyword", {
403
+ enumerable: true,
404
+ get: function () { return chunkA3ROGKLW_cjs.isKeyword; }
405
+ });
406
+ Object.defineProperty(exports, "schemaKeywords", {
407
+ enumerable: true,
408
+ get: function () { return chunkA3ROGKLW_cjs.schemaKeywords; }
409
+ });
410
+ exports.OperationGenerator = OperationGenerator;
411
+ exports.pluginOas = pluginOas;
412
+ exports.pluginOasName = pluginOasName;
413
+ //# sourceMappingURL=index.cjs.map
407
414
  //# sourceMappingURL=index.cjs.map