@kubb/plugin-oas 2.26.2 → 2.26.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/dist/{OperationGenerator-BV6QRtkW.d.cts → OperationGenerator-8tADySO6.d.cts} +1 -1
  2. package/dist/{OperationGenerator-DO5tNGuT.d.ts → OperationGenerator-DvyNt6Xi.d.ts} +1 -1
  3. package/dist/{chunk-P42X362U.cjs → chunk-2BGY3BRC.cjs} +3 -3
  4. package/dist/{chunk-P42X362U.cjs.map → chunk-2BGY3BRC.cjs.map} +1 -1
  5. package/dist/{chunk-UB552H4J.js → chunk-2YX4XBMY.js} +3 -3
  6. package/dist/{chunk-UB552H4J.js.map → chunk-2YX4XBMY.js.map} +1 -1
  7. package/dist/{chunk-CB4BJMGC.cjs → chunk-7R4J27KH.cjs} +25 -22
  8. package/dist/chunk-7R4J27KH.cjs.map +1 -0
  9. package/dist/{chunk-Y4V7HHX7.js → chunk-B3QCCJ62.js} +9 -9
  10. package/dist/chunk-B3QCCJ62.js.map +1 -0
  11. package/dist/{chunk-QLJIL3U5.cjs → chunk-HUFRXC4N.cjs} +9 -9
  12. package/dist/chunk-HUFRXC4N.cjs.map +1 -0
  13. package/dist/{chunk-KEVZ6FD5.js → chunk-QOM3GBVG.js} +6 -3
  14. package/dist/{chunk-KEVZ6FD5.js.map → chunk-QOM3GBVG.js.map} +1 -1
  15. package/dist/{chunk-7N7ULYN2.cjs → chunk-WA7WV7KK.cjs} +23 -23
  16. package/dist/{chunk-7N7ULYN2.cjs.map → chunk-WA7WV7KK.cjs.map} +1 -1
  17. package/dist/{chunk-VNSF4EQP.js → chunk-YJ3OFCLL.js} +3 -3
  18. package/dist/components.cjs +5 -5
  19. package/dist/components.d.cts +2 -3
  20. package/dist/components.d.ts +2 -3
  21. package/dist/components.js +3 -3
  22. package/dist/hooks.cjs +13 -13
  23. package/dist/hooks.d.cts +1 -2
  24. package/dist/hooks.d.ts +1 -2
  25. package/dist/hooks.js +3 -3
  26. package/dist/index.cjs +25 -37
  27. package/dist/index.cjs.map +1 -1
  28. package/dist/index.d.cts +3 -4
  29. package/dist/index.d.ts +3 -4
  30. package/dist/index.js +11 -23
  31. package/dist/index.js.map +1 -1
  32. package/dist/{types-Db0qp8u-.d.cts → types-RVAPVtNi.d.cts} +1 -4
  33. package/dist/{types-Db0qp8u-.d.ts → types-RVAPVtNi.d.ts} +1 -4
  34. package/dist/utils.cjs +8 -8
  35. package/dist/utils.d.cts +3 -4
  36. package/dist/utils.d.ts +3 -4
  37. package/dist/utils.js +3 -3
  38. package/package.json +13 -13
  39. package/src/SchemaGenerator.ts +1 -1
  40. package/src/plugin.ts +7 -20
  41. package/src/types.ts +1 -4
  42. package/src/utils/parseFromConfig.ts +7 -7
  43. package/dist/chunk-CB4BJMGC.cjs.map +0 -1
  44. package/dist/chunk-QLJIL3U5.cjs.map +0 -1
  45. package/dist/chunk-Y4V7HHX7.js.map +0 -1
  46. /package/dist/{chunk-VNSF4EQP.js.map → chunk-YJ3OFCLL.js.map} +0 -0
@@ -1,12 +1,12 @@
1
1
  import {
2
2
  SchemaGenerator,
3
3
  schemaKeywords
4
- } from "./chunk-KEVZ6FD5.js";
4
+ } from "./chunk-QOM3GBVG.js";
5
5
  import {
6
6
  __commonJS,
7
7
  __toESM,
8
8
  init_esm_shims
9
- } from "./chunk-UB552H4J.js";
9
+ } from "./chunk-2YX4XBMY.js";
10
10
 
11
11
  // ../../node_modules/.pnpm/react@18.3.1/node_modules/react/cjs/react.production.min.js
12
12
  var require_react_production_min = __commonJS({
@@ -3262,4 +3262,4 @@ react/cjs/react-jsx-runtime.development.js:
3262
3262
  * LICENSE file in the root directory of this source tree.
3263
3263
  *)
3264
3264
  */
3265
- //# sourceMappingURL=chunk-VNSF4EQP.js.map
3265
+ //# sourceMappingURL=chunk-YJ3OFCLL.js.map
@@ -2,17 +2,17 @@
2
2
 
3
3
 
4
4
 
5
- var _chunk7N7ULYN2cjs = require('./chunk-7N7ULYN2.cjs');
6
- require('./chunk-CB4BJMGC.cjs');
5
+ var _chunkWA7WV7KKcjs = require('./chunk-WA7WV7KK.cjs');
6
+ require('./chunk-7R4J27KH.cjs');
7
7
 
8
8
 
9
- var _chunkP42X362Ucjs = require('./chunk-P42X362U.cjs');
9
+ var _chunk2BGY3BRCcjs = require('./chunk-2BGY3BRC.cjs');
10
10
 
11
11
  // src/components/index.ts
12
- _chunkP42X362Ucjs.init_cjs_shims.call(void 0, );
12
+ _chunk2BGY3BRCcjs.init_cjs_shims.call(void 0, );
13
13
 
14
14
 
15
15
 
16
16
 
17
- exports.Oas = _chunk7N7ULYN2cjs.Oas; exports.Operation = _chunk7N7ULYN2cjs.Operation; exports.Schema = _chunk7N7ULYN2cjs.Schema;
17
+ exports.Oas = _chunkWA7WV7KKcjs.Oas; exports.Operation = _chunkWA7WV7KKcjs.Operation; exports.Schema = _chunkWA7WV7KKcjs.Schema;
18
18
  //# sourceMappingURL=components.cjs.map
@@ -2,12 +2,11 @@ import { S as Schema } from './Schema-CxKiczSe.cjs';
2
2
  import * as react from 'react';
3
3
  import { Operation as Operation$1, Oas as Oas$1 } from '@kubb/oas';
4
4
  import { KubbNode } from '@kubb/react';
5
- import { a as OperationGenerator } from './OperationGenerator-BV6QRtkW.cjs';
5
+ import { a as OperationGenerator } from './OperationGenerator-8tADySO6.cjs';
6
6
  import '@kubb/fs/types';
7
7
  import './SchemaMapper-BLcXlDBz.cjs';
8
8
  import '@kubb/core';
9
- import './types-Db0qp8u-.cjs';
10
- import '@kubb/oas/parser';
9
+ import './types-RVAPVtNi.cjs';
11
10
 
12
11
  type Props$1 = {
13
12
  operation: Operation$1;
@@ -2,12 +2,11 @@ import { S as Schema } from './Schema-CkGDfE-r.js';
2
2
  import * as react from 'react';
3
3
  import { Operation as Operation$1, Oas as Oas$1 } from '@kubb/oas';
4
4
  import { KubbNode } from '@kubb/react';
5
- import { a as OperationGenerator } from './OperationGenerator-DO5tNGuT.js';
5
+ import { a as OperationGenerator } from './OperationGenerator-DvyNt6Xi.js';
6
6
  import '@kubb/fs/types';
7
7
  import './SchemaMapper-BLcXlDBz.js';
8
8
  import '@kubb/core';
9
- import './types-Db0qp8u-.js';
10
- import '@kubb/oas/parser';
9
+ import './types-RVAPVtNi.js';
11
10
 
12
11
  type Props$1 = {
13
12
  operation: Operation$1;
@@ -2,11 +2,11 @@ import {
2
2
  Oas,
3
3
  Operation,
4
4
  Schema
5
- } from "./chunk-VNSF4EQP.js";
6
- import "./chunk-KEVZ6FD5.js";
5
+ } from "./chunk-YJ3OFCLL.js";
6
+ import "./chunk-QOM3GBVG.js";
7
7
  import {
8
8
  init_esm_shims
9
- } from "./chunk-UB552H4J.js";
9
+ } from "./chunk-2YX4XBMY.js";
10
10
 
11
11
  // src/components/index.ts
12
12
  init_esm_shims();
package/dist/hooks.cjs CHANGED
@@ -2,20 +2,20 @@
2
2
 
3
3
 
4
4
 
5
- var _chunk7N7ULYN2cjs = require('./chunk-7N7ULYN2.cjs');
6
- require('./chunk-CB4BJMGC.cjs');
5
+ var _chunkWA7WV7KKcjs = require('./chunk-WA7WV7KK.cjs');
6
+ require('./chunk-7R4J27KH.cjs');
7
7
 
8
8
 
9
- var _chunkP42X362Ucjs = require('./chunk-P42X362U.cjs');
9
+ var _chunk2BGY3BRCcjs = require('./chunk-2BGY3BRC.cjs');
10
10
 
11
11
  // src/hooks/index.ts
12
- _chunkP42X362Ucjs.init_cjs_shims.call(void 0, );
12
+ _chunk2BGY3BRCcjs.init_cjs_shims.call(void 0, );
13
13
 
14
14
  // src/hooks/useOas.ts
15
- _chunkP42X362Ucjs.init_cjs_shims.call(void 0, );
15
+ _chunk2BGY3BRCcjs.init_cjs_shims.call(void 0, );
16
16
  var _react = require('@kubb/react');
17
17
  function useOas() {
18
- const { oas } = _react.useContext.call(void 0, _chunk7N7ULYN2cjs.Oas.Context);
18
+ const { oas } = _react.useContext.call(void 0, _chunkWA7WV7KKcjs.Oas.Context);
19
19
  if (!oas) {
20
20
  throw new Error("Oas is not defined");
21
21
  }
@@ -23,10 +23,10 @@ function useOas() {
23
23
  }
24
24
 
25
25
  // src/hooks/useOperation.ts
26
- _chunkP42X362Ucjs.init_cjs_shims.call(void 0, );
26
+ _chunk2BGY3BRCcjs.init_cjs_shims.call(void 0, );
27
27
 
28
28
  function useOperation() {
29
- const { operation } = _react.useContext.call(void 0, _chunk7N7ULYN2cjs.Operation.Context);
29
+ const { operation } = _react.useContext.call(void 0, _chunkWA7WV7KKcjs.Operation.Context);
30
30
  if (!operation) {
31
31
  throw new Error("Operation is not defined");
32
32
  }
@@ -34,11 +34,11 @@ function useOperation() {
34
34
  }
35
35
 
36
36
  // src/hooks/useOperationManager.ts
37
- _chunkP42X362Ucjs.init_cjs_shims.call(void 0, );
37
+ _chunk2BGY3BRCcjs.init_cjs_shims.call(void 0, );
38
38
 
39
39
  function useOperationManager() {
40
40
  const { plugin, pluginManager } = _react.useApp.call(void 0, );
41
- const { generator } = _react.useContext.call(void 0, _chunk7N7ULYN2cjs.Oas.Context);
41
+ const { generator } = _react.useContext.call(void 0, _chunkWA7WV7KKcjs.Oas.Context);
42
42
  if (!generator) {
43
43
  throw new Error(`'generator' is not defined`);
44
44
  }
@@ -139,10 +139,10 @@ function useOperationManager() {
139
139
  }
140
140
 
141
141
  // src/hooks/useOperations.ts
142
- _chunkP42X362Ucjs.init_cjs_shims.call(void 0, );
142
+ _chunk2BGY3BRCcjs.init_cjs_shims.call(void 0, );
143
143
 
144
144
  function useOperations({ method, path } = {}) {
145
- const { operations } = _react.useContext.call(void 0, _chunk7N7ULYN2cjs.Oas.Context);
145
+ const { operations } = _react.useContext.call(void 0, _chunkWA7WV7KKcjs.Oas.Context);
146
146
  if (!operations) {
147
147
  throw new Error("Operations is not defined");
148
148
  }
@@ -161,5 +161,5 @@ function useOperations({ method, path } = {}) {
161
161
 
162
162
 
163
163
 
164
- exports.useOas = useOas; exports.useOperation = useOperation; exports.useOperationManager = useOperationManager; exports.useOperations = useOperations; exports.useSchema = _chunk7N7ULYN2cjs.useSchema;
164
+ exports.useOas = useOas; exports.useOperation = useOperation; exports.useOperationManager = useOperationManager; exports.useOperations = useOperations; exports.useSchema = _chunkWA7WV7KKcjs.useSchema;
165
165
  //# sourceMappingURL=hooks.cjs.map
package/dist/hooks.d.cts CHANGED
@@ -1,9 +1,8 @@
1
1
  import { Oas, Operation, HttpMethod } from '@kubb/oas';
2
2
  import { Plugin, ResolveNameParams, FileMetaBase } from '@kubb/core';
3
3
  import * as KubbFile from '@kubb/fs/types';
4
- import { f as OperationSchemas } from './types-Db0qp8u-.cjs';
4
+ import { f as OperationSchemas } from './types-RVAPVtNi.cjs';
5
5
  import { a as SchemaContextProps } from './Schema-CxKiczSe.cjs';
6
- import '@kubb/oas/parser';
7
6
  import 'react';
8
7
  import '@kubb/react';
9
8
  import './SchemaMapper-BLcXlDBz.cjs';
package/dist/hooks.d.ts CHANGED
@@ -1,9 +1,8 @@
1
1
  import { Oas, Operation, HttpMethod } from '@kubb/oas';
2
2
  import { Plugin, ResolveNameParams, FileMetaBase } from '@kubb/core';
3
3
  import * as KubbFile from '@kubb/fs/types';
4
- import { f as OperationSchemas } from './types-Db0qp8u-.js';
4
+ import { f as OperationSchemas } from './types-RVAPVtNi.js';
5
5
  import { a as SchemaContextProps } from './Schema-CkGDfE-r.js';
6
- import '@kubb/oas/parser';
7
6
  import 'react';
8
7
  import '@kubb/react';
9
8
  import './SchemaMapper-BLcXlDBz.js';
package/dist/hooks.js CHANGED
@@ -2,11 +2,11 @@ import {
2
2
  Oas,
3
3
  Operation,
4
4
  useSchema
5
- } from "./chunk-VNSF4EQP.js";
6
- import "./chunk-KEVZ6FD5.js";
5
+ } from "./chunk-YJ3OFCLL.js";
6
+ import "./chunk-QOM3GBVG.js";
7
7
  import {
8
8
  init_esm_shims
9
- } from "./chunk-UB552H4J.js";
9
+ } from "./chunk-2YX4XBMY.js";
10
10
 
11
11
  // src/hooks/index.ts
12
12
  init_esm_shims();
package/dist/index.cjs CHANGED
@@ -1,11 +1,11 @@
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 _chunkHUFRXC4Ncjs = require('./chunk-HUFRXC4N.cjs');
4
4
 
5
5
 
6
6
 
7
7
 
8
- var _chunkCB4BJMGCcjs = require('./chunk-CB4BJMGC.cjs');
8
+ var _chunk7R4J27KHcjs = require('./chunk-7R4J27KH.cjs');
9
9
 
10
10
 
11
11
 
@@ -13,30 +13,22 @@ var _chunkCB4BJMGCcjs = require('./chunk-CB4BJMGC.cjs');
13
13
 
14
14
 
15
15
 
16
- var _chunkP42X362Ucjs = require('./chunk-P42X362U.cjs');
16
+ var _chunk2BGY3BRCcjs = require('./chunk-2BGY3BRC.cjs');
17
17
 
18
18
  // src/index.ts
19
- _chunkP42X362Ucjs.init_cjs_shims.call(void 0, );
19
+ _chunk2BGY3BRCcjs.init_cjs_shims.call(void 0, );
20
20
 
21
21
  // src/plugin.ts
22
- _chunkP42X362Ucjs.init_cjs_shims.call(void 0, );
22
+ _chunk2BGY3BRCcjs.init_cjs_shims.call(void 0, );
23
23
  var _path = require('path'); var _path2 = _interopRequireDefault(_path);
24
24
  var _core = require('@kubb/core');
25
25
  var _transformers = require('@kubb/core/transformers'); var _transformers2 = _interopRequireDefault(_transformers);
26
26
  var pluginOasName = "plugin-oas";
27
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 }) => {
28
+ const { output = { path: "schemas", export: false }, validate = true, serverIndex = 0, contentType, oasClass } = options;
29
+ const getOas = async ({ config, logger }) => {
38
30
  try {
39
- const oas = await _chunkQLJIL3U5cjs.parseFromConfig.call(void 0, config, formatOptions, oasClass);
31
+ const oas = await _chunkHUFRXC4Ncjs.parseFromConfig.call(void 0, config, oasClass);
40
32
  if (validate) {
41
33
  await oas.valdiate();
42
34
  }
@@ -44,7 +36,7 @@ var pluginOas = _core.createPlugin.call(void 0, (options) => {
44
36
  } catch (e) {
45
37
  const error = e;
46
38
  logger.emit("warning", _optionalChain([error, 'optionalAccess', _ => _.message]));
47
- return _chunkQLJIL3U5cjs.parseFromConfig.call(void 0, config, {}, oasClass);
39
+ return _chunkHUFRXC4Ncjs.parseFromConfig.call(void 0, config, oasClass);
48
40
  }
49
41
  };
50
42
  return {
@@ -53,12 +45,12 @@ var pluginOas = _core.createPlugin.call(void 0, (options) => {
53
45
  api() {
54
46
  const { config, logger } = this;
55
47
  return {
56
- getOas(formatOptions) {
57
- return getOas({ config, logger, formatOptions });
48
+ getOas() {
49
+ return getOas({ config, logger });
58
50
  },
59
51
  async getSchemas({ includes } = {}) {
60
52
  const oas = await this.getOas();
61
- return _chunkP42X362Ucjs.getSchemas.call(void 0, { oas, contentType, includes });
53
+ return _chunk2BGY3BRCcjs.getSchemas.call(void 0, { oas, contentType, includes });
62
54
  },
63
55
  async getBaseURL() {
64
56
  const oasInstance = await this.getOas();
@@ -90,14 +82,10 @@ var pluginOas = _core.createPlugin.call(void 0, (options) => {
90
82
  }
91
83
  const oas = await getOas({
92
84
  config: this.config,
93
- logger: this.logger,
94
- formatOptions: {
95
- filterSet: filter,
96
- sortSet: sort
97
- }
85
+ logger: this.logger
98
86
  });
99
87
  await oas.dereference();
100
- const schemas = _chunkP42X362Ucjs.getSchemas.call(void 0, { oas, contentType });
88
+ const schemas = _chunk2BGY3BRCcjs.getSchemas.call(void 0, { oas, contentType });
101
89
  const mapSchema = async ([name, schema]) => {
102
90
  const resolvedPath = this.resolvePath({
103
91
  baseName: `${name}.json`,
@@ -127,21 +115,21 @@ var pluginOas = _core.createPlugin.call(void 0, (options) => {
127
115
  });
128
116
 
129
117
  // src/OperationGenerator.ts
130
- _chunkP42X362Ucjs.init_cjs_shims.call(void 0, );
118
+ _chunk2BGY3BRCcjs.init_cjs_shims.call(void 0, );
131
119
 
132
120
 
133
121
  var _operationsByMethod, _OperationGenerator_instances, getOptions_fn, isExcluded_fn, isIncluded_fn, methods_get;
134
122
  var OperationGenerator = class extends _core.Generator {
135
123
  constructor() {
136
124
  super(...arguments);
137
- _chunkP42X362Ucjs.__privateAdd.call(void 0, this, _OperationGenerator_instances);
138
- _chunkP42X362Ucjs.__privateAdd.call(void 0, this, _operationsByMethod, {});
125
+ _chunk2BGY3BRCcjs.__privateAdd.call(void 0, this, _OperationGenerator_instances);
126
+ _chunk2BGY3BRCcjs.__privateAdd.call(void 0, this, _operationsByMethod, {});
139
127
  }
140
128
  get operationsByMethod() {
141
- return _chunkP42X362Ucjs.__privateGet.call(void 0, this, _operationsByMethod);
129
+ return _chunk2BGY3BRCcjs.__privateGet.call(void 0, this, _operationsByMethod);
142
130
  }
143
131
  set operationsByMethod(paths) {
144
- _chunkP42X362Ucjs.__privateSet.call(void 0, this, _operationsByMethod, paths);
132
+ _chunk2BGY3BRCcjs.__privateSet.call(void 0, this, _operationsByMethod, paths);
145
133
  }
146
134
  getSchemas(operation, { forStatusCode, resolveName = (name) => name } = {}) {
147
135
  const pathParamsSchema = this.context.oas.getParametersSchema(operation, "path");
@@ -224,9 +212,9 @@ var OperationGenerator = class extends _core.Generator {
224
212
  const methods = Object.keys(method);
225
213
  methods.forEach((method2) => {
226
214
  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;
215
+ if (operation && _chunk2BGY3BRCcjs.__privateGet.call(void 0, this, _OperationGenerator_instances, methods_get)[method2]) {
216
+ const isExcluded = _chunk2BGY3BRCcjs.__privateMethod.call(void 0, this, _OperationGenerator_instances, isExcluded_fn).call(this, operation, method2);
217
+ const isIncluded = this.context.include ? _chunk2BGY3BRCcjs.__privateMethod.call(void 0, this, _OperationGenerator_instances, isIncluded_fn).call(this, operation, method2) : true;
230
218
  if (isIncluded && !isExcluded) {
231
219
  if (!acc[path2]) {
232
220
  acc[path2] = {};
@@ -247,8 +235,8 @@ var OperationGenerator = class extends _core.Generator {
247
235
  const methods = this.operationsByMethod[path2] ? Object.keys(this.operationsByMethod[path2]) : [];
248
236
  methods.forEach((method) => {
249
237
  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, {
238
+ const options = _chunk2BGY3BRCcjs.__privateMethod.call(void 0, this, _OperationGenerator_instances, getOptions_fn).call(this, operation, method);
239
+ const promiseMethod = _optionalChain([_chunk2BGY3BRCcjs.__privateGet.call(void 0, this, _OperationGenerator_instances, methods_get), 'access', _40 => _40[method], 'optionalAccess', _41 => _41.call, 'call', _42 => _42(this, operation, {
252
240
  ...this.options,
253
241
  ...options
254
242
  })]);
@@ -403,5 +391,5 @@ var src_default = definePluginDefault;
403
391
 
404
392
 
405
393
 
406
- exports.OperationGenerator = OperationGenerator; exports.SchemaGenerator = _chunkCB4BJMGCcjs.SchemaGenerator; exports.default = src_default; exports.isKeyword = _chunkCB4BJMGCcjs.isKeyword; exports.pluginOas = pluginOas; exports.pluginOasName = pluginOasName; exports.schemaKeywords = _chunkCB4BJMGCcjs.schemaKeywords;
394
+ exports.OperationGenerator = OperationGenerator; exports.SchemaGenerator = _chunk7R4J27KHcjs.SchemaGenerator; exports.default = src_default; exports.isKeyword = _chunk7R4J27KHcjs.isKeyword; exports.pluginOas = pluginOas; exports.pluginOasName = pluginOasName; exports.schemaKeywords = _chunk7R4J27KHcjs.schemaKeywords;
407
395
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["/home/runner/work/kubb/kubb/packages/plugin-oas/dist/index.cjs","../src/index.ts","../src/plugin.ts","../src/OperationGenerator.ts"],"names":["path","method"],"mappings":"AAAA;AACE;AACF,wDAA6B;AAC7B;AACE;AACA;AACA;AACF,wDAA6B;AAC7B;AACE;AACA;AACA;AACA;AACA;AACA;AACF,wDAA6B;AAC7B;AACA;ACjBA,8CAAA,CAAA;ADmBA;AACA;AEpBA,8CAAA,CAAA;AAAA,wEAAiB;AAEjB,kCAA6B;AAC7B,mHAA0B;AAWnB,IAAM,cAAA,EAAgB,YAAA;AAEtB,IAAM,UAAA,EAAY,gCAAA,CAAyB,OAAA,EAAA,GAAY;AAC5D,EAAA,MAAM;AAAA,IACJ,OAAA,EAAS,EAAE,IAAA,EAAM,SAAA,EAAW,MAAA,EAAQ,MAAM,CAAA;AAAA,IAC1C,kBAAA,EAAoB,MAAA;AAAA,IACpB,gBAAA,EAAkB,IAAA;AAAA,IAClB,SAAA,EAAW,IAAA;AAAA,IACX,YAAA,EAAc,CAAA;AAAA,IACd,WAAA;AAAA,IACA;AAAA,EACF,EAA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;AACF,IAAA;AACT,EAAA;AAAA;AAAA;AAAA;AAIY,EAAA;AACH,IAAA;AACT,EAAA;AAAA;AAAA;AAAA;AAKU,EAAA;AACD,IAAA;AACT,EAAA;AAAA;AAAA;AAAA;AAKa,EAAA;AACJ,IAAA;AACT,EAAA;AAAA;AAAA;AAAA;AAKU,EAAA;AACD,IAAA;AACT,EAAA;AACF;AAzTE;AALK;AAcM;AACU,EAAA;AAGR,EAAA;AACM,IAAA;AACF,MAAA;AACX,IAAA;AAEa,IAAA;AACF,MAAA;AACX,IAAA;AAEa,IAAA;AACF,MAAA;AACX,IAAA;AAEa,IAAA;AACF,MAAA;AACX,IAAA;AAEO,IAAA;AACO,EAAA;AAEpB;AAAA;AAAA;AAAA;AAAA;AAKW;AACU,EAAA;AACL,EAAA;AAEK,EAAA;AACJ,IAAA;AACC,MAAA;AACd,IAAA;AAEa,IAAA;AACC,MAAA;AACd,IAAA;AAEa,IAAA;AACC,MAAA;AACd,IAAA;AAEa,IAAA;AACC,MAAA;AACd,IAAA;AACD,EAAA;AAEM,EAAA;AACT;AAAA;AAAA;AAAA;AAAA;AAKW;AACU,EAAA;AACL,EAAA;AAEK,EAAA;AACJ,IAAA;AACC,MAAA;AACd,IAAA;AAEa,IAAA;AACC,MAAA;AACd,IAAA;AAEa,IAAA;AACC,MAAA;AACd,IAAA;AAEa,IAAA;AACC,MAAA;AACd,IAAA;AACD,EAAA;AAEM,EAAA;AACT;AAiGY;AACH,EAAA;AACK,IAAA;AACC,IAAA;AACC,IAAA;AACF,IAAA;AACG,IAAA;AACP,IAAA;AACG,IAAA;AACF,IAAA;AACT,EAAA;AACF;AHmKmB;AACA;AC9Wf;AAES;AD+WM;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","file":"/home/runner/work/kubb/kubb/packages/plugin-oas/dist/index.cjs","sourcesContent":[null,"import { pluginOas } from './plugin.ts'\n\nexport type {\n GetOperationGeneratorOptions,\n OperationMethodResult,\n} from './OperationGenerator.ts'\nexport { OperationGenerator } from './OperationGenerator.ts'\nexport { pluginOas, pluginOasName } from './plugin.ts'\nexport type {\n GetSchemaGeneratorOptions,\n SchemaGeneratorBuildOptions,\n SchemaGeneratorOptions,\n} from './SchemaGenerator.ts'\nexport type { SchemaMethodResult } from './SchemaGenerator.ts'\nexport { SchemaGenerator } from './SchemaGenerator.ts'\nexport type {\n Schema,\n SchemaKeyword,\n SchemaKeywordBase,\n SchemaKeywordMapper,\n SchemaMapper,\n} from './SchemaMapper.ts'\nexport { isKeyword, schemaKeywords } from './SchemaMapper.ts'\nexport type * from './types.ts'\n\n/**\n * @deprecated Use `import { pluginOas } from '@kubb/plugin-oas'` instead\n */\nconst definePluginDefault = pluginOas\n\nexport default definePluginDefault\n","import path from 'node:path'\n\nimport { createPlugin } from '@kubb/core'\nimport { camelCase } from '@kubb/core/transformers'\n\nimport { getSchemas } from './utils/getSchemas.ts'\n\nimport type { Config } from '@kubb/core'\nimport type { Logger } from '@kubb/core/logger'\nimport type { Oas, OasTypes } from '@kubb/oas'\nimport type { FormatOptions } from '@kubb/oas/parser'\nimport type { PluginOas } from './types.ts'\nimport { parseFromConfig } from './utils/parseFromConfig.ts'\n\nexport const pluginOasName = 'plugin-oas' satisfies PluginOas['name']\n\nexport const pluginOas = createPlugin<PluginOas>((options) => {\n const {\n output = { path: 'schemas', export: false },\n experimentalFilter: filter,\n experimentalSort: sort,\n validate = true,\n serverIndex = 0,\n contentType,\n oasClass,\n } = options\n\n const getOas = async ({ config, logger, formatOptions }: { config: Config; logger: Logger; formatOptions?: FormatOptions }): Promise<Oas> => {\n try {\n // needs to be in a different variable or the catch here will not work(return of a promise instead)\n const oas = await parseFromConfig(config, formatOptions, oasClass)\n\n if (validate) {\n await oas.valdiate()\n }\n\n return oas\n } catch (e) {\n const error = e as Error\n\n logger.emit('warning', error?.message)\n return parseFromConfig(config, {}, oasClass)\n }\n }\n\n return {\n name: pluginOasName,\n options,\n\n api() {\n const { config, logger } = this\n\n return {\n getOas(formatOptions) {\n return getOas({ config, logger, formatOptions })\n },\n async getSchemas({ includes } = {}) {\n const oas = await this.getOas()\n return getSchemas({ oas, contentType, includes })\n },\n async getBaseURL() {\n const oasInstance = await this.getOas()\n const baseURL = oasInstance.api.servers?.at(serverIndex)?.url\n return baseURL\n },\n contentType,\n }\n },\n resolvePath(baseName) {\n if (output === false) {\n return undefined\n }\n\n const root = path.resolve(this.config.root, this.config.output.path)\n\n return path.resolve(root, output.path, baseName)\n },\n resolveName(name, type) {\n return camelCase(name, { isFile: type === 'file' })\n },\n async writeFile(path, source) {\n if (!path.endsWith('.json') || !source) {\n return\n }\n\n return this.fileManager.write(path, source, { sanity: false })\n },\n async buildStart() {\n if (!output) {\n return\n }\n\n const oas = await getOas({\n config: this.config,\n logger: this.logger,\n formatOptions: {\n filterSet: filter,\n sortSet: sort,\n },\n })\n await oas.dereference()\n const schemas = getSchemas({ oas, contentType })\n\n const mapSchema = async ([name, schema]: [string, OasTypes.SchemaObject]) => {\n const resolvedPath = this.resolvePath({\n baseName: `${name}.json`,\n pluginKey: this.plugin.key,\n })\n\n const resvoledFileName = this.resolveName({\n name: `${name}.json`,\n pluginKey: [pluginOasName],\n type: 'file',\n }) as `${string}.json`\n\n if (!resolvedPath) {\n return\n }\n\n await this.addFile({\n path: resolvedPath,\n baseName: resvoledFileName,\n source: JSON.stringify(schema),\n meta: {\n pluginKey: this.plugin.key,\n },\n })\n }\n\n const promises = Object.entries(schemas).map(mapSchema)\n await Promise.all(promises)\n },\n }\n})\n","import { type FileMetaBase, Generator } from '@kubb/core'\nimport transformers from '@kubb/core/transformers'\n\nimport type { PluginFactoryOptions, PluginManager } from '@kubb/core'\nimport type * as KubbFile from '@kubb/fs/types'\n\nimport type { Plugin } from '@kubb/core'\nimport type { HttpMethod, Oas, OasTypes, Operation, contentType } from '@kubb/oas'\nimport type { Exclude, Include, OperationSchemas, OperationsByMethod, Override } from './types.ts'\n\nexport type GetOperationGeneratorOptions<T extends OperationGenerator<any, any, any>> = T extends OperationGenerator<infer Options, any, any> ? Options : never\n\nexport type OperationMethodResult<TFileMeta extends FileMetaBase> = Promise<KubbFile.File<TFileMeta> | Array<KubbFile.File<TFileMeta>> | null>\n\ntype Context<TOptions, TPluginOptions extends PluginFactoryOptions> = {\n oas: Oas\n exclude: Array<Exclude> | undefined\n include: Array<Include> | undefined\n override: Array<Override<TOptions>> | undefined\n contentType: contentType | undefined\n pluginManager: PluginManager\n /**\n * Current plugin\n */\n plugin: Plugin<TPluginOptions>\n mode: KubbFile.Mode\n}\n\nexport abstract class OperationGenerator<\n TOptions = unknown,\n TPluginOptions extends PluginFactoryOptions = PluginFactoryOptions,\n TFileMeta extends FileMetaBase = FileMetaBase,\n> extends Generator<TOptions, Context<TOptions, TPluginOptions>> {\n #operationsByMethod: OperationsByMethod = {}\n get operationsByMethod(): OperationsByMethod {\n return this.#operationsByMethod\n }\n\n set operationsByMethod(paths: OperationsByMethod) {\n this.#operationsByMethod = paths\n }\n\n #getOptions(operation: Operation, method: HttpMethod): Partial<TOptions> {\n const { override = [] } = this.context\n\n return (\n override.find(({ pattern, type }) => {\n if (type === 'tag') {\n return !!operation.getTags()[0]?.name.match(pattern)\n }\n\n if (type === 'operationId') {\n return !!operation.getOperationId().match(pattern)\n }\n\n if (type === 'path') {\n return !!operation.path.match(pattern)\n }\n\n if (type === 'method') {\n return !!method.match(pattern)\n }\n\n return false\n })?.options || {}\n )\n }\n /**\n *\n * @deprecated\n */\n #isExcluded(operation: Operation, method: HttpMethod): boolean {\n const { exclude = [] } = this.context\n let matched = false\n\n exclude.forEach(({ pattern, type }) => {\n if (type === 'tag' && !matched) {\n matched = !!operation.getTags()[0]?.name.match(pattern)\n }\n\n if (type === 'operationId' && !matched) {\n matched = !!operation.getOperationId().match(pattern)\n }\n\n if (type === 'path' && !matched) {\n matched = !!operation.path.match(pattern)\n }\n\n if (type === 'method' && !matched) {\n matched = !!method.match(pattern)\n }\n })\n\n return matched\n }\n /**\n *\n * @deprecated\n */\n #isIncluded(operation: Operation, method: HttpMethod): boolean {\n const { include = [] } = this.context\n let matched = false\n\n include.forEach(({ pattern, type }) => {\n if (type === 'tag' && !matched) {\n matched = !!operation.getTags()[0]?.name.match(pattern)\n }\n\n if (type === 'operationId' && !matched) {\n matched = !!operation.getOperationId().match(pattern)\n }\n\n if (type === 'path' && !matched) {\n matched = !!operation.path.match(pattern)\n }\n\n if (type === 'method' && !matched) {\n matched = !!method.match(pattern)\n }\n })\n\n return matched\n }\n\n getSchemas(\n operation: Operation,\n { forStatusCode, resolveName = (name) => name }: { forStatusCode?: string | number; resolveName?: (name: string) => string } = {},\n ): OperationSchemas {\n const pathParamsSchema = this.context.oas.getParametersSchema(operation, 'path')\n const queryParamsSchema = this.context.oas.getParametersSchema(operation, 'query')\n const headerParamsSchema = this.context.oas.getParametersSchema(operation, 'header')\n const requestSchema = this.context.oas.getRequestSchema(operation)\n const responseStatusCode =\n forStatusCode || (operation.schema.responses && Object.keys(operation.schema.responses).find((key) => key.startsWith('2'))) || 200\n const responseSchema = this.context.oas.getResponseSchema(operation, responseStatusCode)\n const statusCodes = operation.getResponseStatusCodes().map((statusCode) => {\n let name = statusCode\n if (name === 'default') {\n name = 'error'\n }\n\n const schema = this.context.oas.getResponseSchema(operation, statusCode)\n\n return {\n name: resolveName(transformers.pascalCase(`${operation.getOperationId()} ${name}`)),\n description: (operation.getResponseByStatusCode(statusCode) as OasTypes.ResponseObject)?.description,\n schema,\n operation,\n operationName: transformers.pascalCase(`${operation.getOperationId()}`),\n statusCode: name === 'error' ? undefined : Number(statusCode),\n keys: schema?.properties ? Object.keys(schema.properties) : undefined,\n }\n })\n\n return {\n pathParams: pathParamsSchema\n ? {\n name: resolveName(transformers.pascalCase(`${operation.getOperationId()} PathParams`)),\n operation,\n operationName: transformers.pascalCase(`${operation.getOperationId()}`),\n schema: pathParamsSchema,\n keys: pathParamsSchema.properties ? Object.keys(pathParamsSchema.properties) : undefined,\n }\n : undefined,\n queryParams: queryParamsSchema\n ? {\n name: resolveName(transformers.pascalCase(`${operation.getOperationId()} QueryParams`)),\n operation,\n operationName: transformers.pascalCase(`${operation.getOperationId()}`),\n schema: queryParamsSchema,\n keys: queryParamsSchema.properties ? Object.keys(queryParamsSchema.properties) : [],\n }\n : undefined,\n headerParams: headerParamsSchema\n ? {\n name: resolveName(transformers.pascalCase(`${operation.getOperationId()} HeaderParams`)),\n operation,\n operationName: transformers.pascalCase(`${operation.getOperationId()}`),\n schema: headerParamsSchema,\n keys: headerParamsSchema.properties ? Object.keys(headerParamsSchema.properties) : undefined,\n }\n : undefined,\n request: requestSchema\n ? {\n name: resolveName(transformers.pascalCase(`${operation.getOperationId()} ${operation.method === 'get' ? 'queryRequest' : 'mutationRequest'}`)),\n description: (operation.schema.requestBody as OasTypes.RequestBodyObject)?.description,\n operation,\n operationName: transformers.pascalCase(`${operation.getOperationId()}`),\n schema: requestSchema,\n keys: requestSchema.properties ? Object.keys(requestSchema.properties) : undefined,\n keysToOmit: requestSchema.properties\n ? Object.keys(requestSchema.properties).filter((key) => {\n const item = requestSchema.properties?.[key] as OasTypes.SchemaObject\n\n return item?.readOnly\n })\n : undefined,\n }\n : undefined,\n response: {\n name: resolveName(transformers.pascalCase(`${operation.getOperationId()} ${operation.method === 'get' ? 'queryResponse' : 'mutationResponse'}`)),\n description: operation.getResponseAsJSONSchema(responseStatusCode)?.at(0)?.description,\n operation,\n operationName: transformers.pascalCase(`${operation.getOperationId()}`),\n schema: responseSchema,\n statusCode: Number(responseStatusCode),\n keys: responseSchema?.properties ? Object.keys(responseSchema.properties) : undefined,\n keysToOmit: responseSchema?.properties\n ? Object.keys(responseSchema.properties).filter((key) => {\n const item = responseSchema.properties?.[key] as OasTypes.SchemaObject\n return item?.writeOnly\n })\n : undefined,\n },\n errors: statusCodes.filter((item) => item.statusCode?.toString().startsWith('4') || item.statusCode?.toString().startsWith('5')),\n statusCodes,\n }\n }\n\n get #methods() {\n return {\n get: this.get,\n post: this.post,\n patch: this.patch,\n put: this.put,\n delete: this.delete,\n head: undefined,\n options: undefined,\n trace: undefined,\n } as const\n }\n\n async build(): Promise<Array<KubbFile.File<TFileMeta>>> {\n const { oas } = this.context\n\n const paths = oas.getPaths()\n this.operationsByMethod = Object.entries(paths).reduce((acc, [path, method]) => {\n const methods = Object.keys(method) as HttpMethod[]\n\n methods.forEach((method) => {\n const operation = oas.operation(path, method)\n if (operation && this.#methods[method]) {\n const isExcluded = this.#isExcluded(operation, method)\n const isIncluded = this.context.include ? this.#isIncluded(operation, method) : true\n\n if (isIncluded && !isExcluded) {\n if (!acc[path]) {\n acc[path] = {} as OperationsByMethod['get']\n }\n acc[path] = {\n ...acc[path],\n [method]: {\n operation,\n schemas: this.getSchemas(operation),\n },\n } as OperationsByMethod['get']\n }\n }\n })\n\n return acc\n }, {} as OperationsByMethod)\n\n const promises = Object.keys(this.operationsByMethod).reduce((acc, path) => {\n const methods = this.operationsByMethod[path] ? (Object.keys(this.operationsByMethod[path]!) as HttpMethod[]) : []\n\n methods.forEach((method) => {\n const { operation } = this.operationsByMethod[path]?.[method]!\n const options = this.#getOptions(operation, method)\n const promiseMethod = this.#methods[method]?.call(this, operation, {\n ...this.options,\n ...options,\n })\n const promiseOperation = this.operation.call(this, operation, {\n ...this.options,\n ...options,\n })\n\n if (promiseMethod) {\n acc.push(promiseMethod)\n }\n if (promiseOperation) {\n acc.push(promiseOperation)\n }\n })\n\n return acc\n }, [] as OperationMethodResult<TFileMeta>[])\n\n const operations = Object.values(this.operationsByMethod).map((item) => Object.values(item).map((item) => item.operation))\n\n promises.push(this.all(operations.flat().filter(Boolean), this.operationsByMethod))\n\n const files = await Promise.all(promises)\n\n // using .flat because operationGenerator[method] can return a array of files or just one file\n return files.flat().filter(Boolean)\n }\n\n /**\n * Operation\n */\n async operation(operation: Operation, options: TOptions): OperationMethodResult<TFileMeta> {\n return null\n }\n\n /**\n * GET\n */\n async get(operation: Operation, options: TOptions): OperationMethodResult<TFileMeta> {\n return null\n }\n\n /**\n * POST\n */\n async post(operation: Operation, options: TOptions): OperationMethodResult<TFileMeta> {\n return null\n }\n /**\n * PATCH\n */\n async patch(operation: Operation, options: TOptions): OperationMethodResult<TFileMeta> {\n return null\n }\n\n /**\n * PUT\n */\n async put(operation: Operation, options: TOptions): OperationMethodResult<TFileMeta> {\n return null\n }\n\n /**\n * DELETE\n */\n async delete(operation: Operation, options: TOptions): OperationMethodResult<TFileMeta> {\n return null\n }\n\n /**\n * Combination of GET, POST, PATCH, PUT, DELETE\n */\n async all(operations: Operation[], paths: OperationsByMethod): OperationMethodResult<TFileMeta> {\n return null\n }\n}\n"]}
1
+ {"version":3,"sources":["/home/runner/work/kubb/kubb/packages/plugin-oas/dist/index.cjs","../src/index.ts","../src/plugin.ts","../src/OperationGenerator.ts"],"names":["path","method"],"mappings":"AAAA;AACE;AACF,wDAA6B;AAC7B;AACE;AACA;AACA;AACF,wDAA6B;AAC7B;AACE;AACA;AACA;AACA;AACA;AACA;AACF,wDAA6B;AAC7B;AACA;ACjBA,8CAAA,CAAA;ADmBA;AACA;AEpBA,8CAAA,CAAA;AAAA,wEAAiB;AAEjB,kCAA6B;AAC7B,mHAA0B;AAUnB,IAAM,cAAA,EAAgB,YAAA;AAEtB,IAAM,UAAA,EAAY,gCAAA,CAAyB,OAAA,EAAA,GAAY;AAC5D,EAAA,MAAM,EAAE,OAAA,EAAS,EAAE,IAAA,EAAM,SAAA,EAAW,MAAA,EAAQ,MAAM,CAAA,EAAG,SAAA,EAAW,IAAA,EAAM,YAAA,EAAc,CAAA,EAAG,WAAA,EAAa,SAAS,EAAA,EAAI,OAAA;AAEjH,EAAA,MAAM,OAAA,EAAS,MAAA,CAAO,EAAE,MAAA,EAAQ,OAAO,CAAA,EAAA,GAAwD;AAC7F,IAAA,IAAI;AAEF,MAAA,MAAM,IAAA,EAAM,MAAM,+CAAA,MAAgB,EAAQ,QAAQ,CAAA;AAElD,MAAA,GAAA,CAAI,QAAA,EAAU;AACZ,QAAA,MAAM,GAAA,CAAI,QAAA,CAA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,EAAA;AAEpB;AAAA;AAAA;AAAA;AAAA;AAKW;AACU,EAAA;AACL,EAAA;AAEK,EAAA;AACJ,IAAA;AACC,MAAA;AACd,IAAA;AAEa,IAAA;AACC,MAAA;AACd,IAAA;AAEa,IAAA;AACC,MAAA;AACd,IAAA;AAEa,IAAA;AACC,MAAA;AACd,IAAA;AACD,EAAA;AAEM,EAAA;AACT;AAAA;AAAA;AAAA;AAAA;AAKW;AACU,EAAA;AACL,EAAA;AAEK,EAAA;AACJ,IAAA;AACC,MAAA;AACd,IAAA;AAEa,IAAA;AACC,MAAA;AACd,IAAA;AAEa,IAAA;AACC,MAAA;AACd,IAAA;AAEa,IAAA;AACC,MAAA;AACd,IAAA;AACD,EAAA;AAEM,EAAA;AACT;AAiGY;AACH,EAAA;AACK,IAAA;AACC,IAAA;AACC,IAAA;AACF,IAAA;AACG,IAAA;AACP,IAAA;AACG,IAAA;AACF,IAAA;AACT,EAAA;AACF;AHuJmB;AACA;AClWf;AAES;ADmWM;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","file":"/home/runner/work/kubb/kubb/packages/plugin-oas/dist/index.cjs","sourcesContent":[null,"import { pluginOas } from './plugin.ts'\n\nexport type {\n GetOperationGeneratorOptions,\n OperationMethodResult,\n} from './OperationGenerator.ts'\nexport { OperationGenerator } from './OperationGenerator.ts'\nexport { pluginOas, pluginOasName } from './plugin.ts'\nexport type {\n GetSchemaGeneratorOptions,\n SchemaGeneratorBuildOptions,\n SchemaGeneratorOptions,\n} from './SchemaGenerator.ts'\nexport type { SchemaMethodResult } from './SchemaGenerator.ts'\nexport { SchemaGenerator } from './SchemaGenerator.ts'\nexport type {\n Schema,\n SchemaKeyword,\n SchemaKeywordBase,\n SchemaKeywordMapper,\n SchemaMapper,\n} from './SchemaMapper.ts'\nexport { isKeyword, schemaKeywords } from './SchemaMapper.ts'\nexport type * from './types.ts'\n\n/**\n * @deprecated Use `import { pluginOas } from '@kubb/plugin-oas'` instead\n */\nconst definePluginDefault = pluginOas\n\nexport default definePluginDefault\n","import path from 'node:path'\n\nimport { createPlugin } from '@kubb/core'\nimport { camelCase } from '@kubb/core/transformers'\n\nimport { getSchemas } from './utils/getSchemas.ts'\n\nimport type { Config } from '@kubb/core'\nimport type { Logger } from '@kubb/core/logger'\nimport type { Oas, OasTypes } from '@kubb/oas'\nimport type { PluginOas } from './types.ts'\nimport { parseFromConfig } from './utils/parseFromConfig.ts'\n\nexport const pluginOasName = 'plugin-oas' satisfies PluginOas['name']\n\nexport const pluginOas = createPlugin<PluginOas>((options) => {\n const { output = { path: 'schemas', export: false }, validate = true, serverIndex = 0, contentType, oasClass } = options\n\n const getOas = async ({ config, logger }: { config: Config; logger: Logger }): Promise<Oas> => {\n try {\n // needs to be in a different variable or the catch here will not work(return of a promise instead)\n const oas = await parseFromConfig(config, oasClass)\n\n if (validate) {\n await oas.valdiate()\n }\n\n return oas\n } catch (e) {\n const error = e as Error\n\n logger.emit('warning', error?.message)\n return parseFromConfig(config, oasClass)\n }\n }\n\n return {\n name: pluginOasName,\n options,\n\n api() {\n const { config, logger } = this\n\n return {\n getOas() {\n return getOas({ config, logger })\n },\n async getSchemas({ includes } = {}) {\n const oas = await this.getOas()\n return getSchemas({ oas, contentType, includes })\n },\n async getBaseURL() {\n const oasInstance = await this.getOas()\n const baseURL = oasInstance.api.servers?.at(serverIndex)?.url\n return baseURL\n },\n contentType,\n }\n },\n resolvePath(baseName) {\n if (output === false) {\n return undefined\n }\n\n const root = path.resolve(this.config.root, this.config.output.path)\n\n return path.resolve(root, output.path, baseName)\n },\n resolveName(name, type) {\n return camelCase(name, { isFile: type === 'file' })\n },\n async writeFile(path, source) {\n if (!path.endsWith('.json') || !source) {\n return\n }\n\n return this.fileManager.write(path, source, { sanity: false })\n },\n async buildStart() {\n if (!output) {\n return\n }\n\n const oas = await getOas({\n config: this.config,\n logger: this.logger,\n })\n await oas.dereference()\n const schemas = getSchemas({ oas, contentType })\n\n const mapSchema = async ([name, schema]: [string, OasTypes.SchemaObject]) => {\n const resolvedPath = this.resolvePath({\n baseName: `${name}.json`,\n pluginKey: this.plugin.key,\n })\n\n const resvoledFileName = this.resolveName({\n name: `${name}.json`,\n pluginKey: [pluginOasName],\n type: 'file',\n }) as `${string}.json`\n\n if (!resolvedPath) {\n return\n }\n\n await this.addFile({\n path: resolvedPath,\n baseName: resvoledFileName,\n source: JSON.stringify(schema),\n meta: {\n pluginKey: this.plugin.key,\n },\n })\n }\n\n const promises = Object.entries(schemas).map(mapSchema)\n await Promise.all(promises)\n },\n }\n})\n","import { type FileMetaBase, Generator } from '@kubb/core'\nimport transformers from '@kubb/core/transformers'\n\nimport type { PluginFactoryOptions, PluginManager } from '@kubb/core'\nimport type * as KubbFile from '@kubb/fs/types'\n\nimport type { Plugin } from '@kubb/core'\nimport type { HttpMethod, Oas, OasTypes, Operation, contentType } from '@kubb/oas'\nimport type { Exclude, Include, OperationSchemas, OperationsByMethod, Override } from './types.ts'\n\nexport type GetOperationGeneratorOptions<T extends OperationGenerator<any, any, any>> = T extends OperationGenerator<infer Options, any, any> ? Options : never\n\nexport type OperationMethodResult<TFileMeta extends FileMetaBase> = Promise<KubbFile.File<TFileMeta> | Array<KubbFile.File<TFileMeta>> | null>\n\ntype Context<TOptions, TPluginOptions extends PluginFactoryOptions> = {\n oas: Oas\n exclude: Array<Exclude> | undefined\n include: Array<Include> | undefined\n override: Array<Override<TOptions>> | undefined\n contentType: contentType | undefined\n pluginManager: PluginManager\n /**\n * Current plugin\n */\n plugin: Plugin<TPluginOptions>\n mode: KubbFile.Mode\n}\n\nexport abstract class OperationGenerator<\n TOptions = unknown,\n TPluginOptions extends PluginFactoryOptions = PluginFactoryOptions,\n TFileMeta extends FileMetaBase = FileMetaBase,\n> extends Generator<TOptions, Context<TOptions, TPluginOptions>> {\n #operationsByMethod: OperationsByMethod = {}\n get operationsByMethod(): OperationsByMethod {\n return this.#operationsByMethod\n }\n\n set operationsByMethod(paths: OperationsByMethod) {\n this.#operationsByMethod = paths\n }\n\n #getOptions(operation: Operation, method: HttpMethod): Partial<TOptions> {\n const { override = [] } = this.context\n\n return (\n override.find(({ pattern, type }) => {\n if (type === 'tag') {\n return !!operation.getTags()[0]?.name.match(pattern)\n }\n\n if (type === 'operationId') {\n return !!operation.getOperationId().match(pattern)\n }\n\n if (type === 'path') {\n return !!operation.path.match(pattern)\n }\n\n if (type === 'method') {\n return !!method.match(pattern)\n }\n\n return false\n })?.options || {}\n )\n }\n /**\n *\n * @deprecated\n */\n #isExcluded(operation: Operation, method: HttpMethod): boolean {\n const { exclude = [] } = this.context\n let matched = false\n\n exclude.forEach(({ pattern, type }) => {\n if (type === 'tag' && !matched) {\n matched = !!operation.getTags()[0]?.name.match(pattern)\n }\n\n if (type === 'operationId' && !matched) {\n matched = !!operation.getOperationId().match(pattern)\n }\n\n if (type === 'path' && !matched) {\n matched = !!operation.path.match(pattern)\n }\n\n if (type === 'method' && !matched) {\n matched = !!method.match(pattern)\n }\n })\n\n return matched\n }\n /**\n *\n * @deprecated\n */\n #isIncluded(operation: Operation, method: HttpMethod): boolean {\n const { include = [] } = this.context\n let matched = false\n\n include.forEach(({ pattern, type }) => {\n if (type === 'tag' && !matched) {\n matched = !!operation.getTags()[0]?.name.match(pattern)\n }\n\n if (type === 'operationId' && !matched) {\n matched = !!operation.getOperationId().match(pattern)\n }\n\n if (type === 'path' && !matched) {\n matched = !!operation.path.match(pattern)\n }\n\n if (type === 'method' && !matched) {\n matched = !!method.match(pattern)\n }\n })\n\n return matched\n }\n\n getSchemas(\n operation: Operation,\n { forStatusCode, resolveName = (name) => name }: { forStatusCode?: string | number; resolveName?: (name: string) => string } = {},\n ): OperationSchemas {\n const pathParamsSchema = this.context.oas.getParametersSchema(operation, 'path')\n const queryParamsSchema = this.context.oas.getParametersSchema(operation, 'query')\n const headerParamsSchema = this.context.oas.getParametersSchema(operation, 'header')\n const requestSchema = this.context.oas.getRequestSchema(operation)\n const responseStatusCode =\n forStatusCode || (operation.schema.responses && Object.keys(operation.schema.responses).find((key) => key.startsWith('2'))) || 200\n const responseSchema = this.context.oas.getResponseSchema(operation, responseStatusCode)\n const statusCodes = operation.getResponseStatusCodes().map((statusCode) => {\n let name = statusCode\n if (name === 'default') {\n name = 'error'\n }\n\n const schema = this.context.oas.getResponseSchema(operation, statusCode)\n\n return {\n name: resolveName(transformers.pascalCase(`${operation.getOperationId()} ${name}`)),\n description: (operation.getResponseByStatusCode(statusCode) as OasTypes.ResponseObject)?.description,\n schema,\n operation,\n operationName: transformers.pascalCase(`${operation.getOperationId()}`),\n statusCode: name === 'error' ? undefined : Number(statusCode),\n keys: schema?.properties ? Object.keys(schema.properties) : undefined,\n }\n })\n\n return {\n pathParams: pathParamsSchema\n ? {\n name: resolveName(transformers.pascalCase(`${operation.getOperationId()} PathParams`)),\n operation,\n operationName: transformers.pascalCase(`${operation.getOperationId()}`),\n schema: pathParamsSchema,\n keys: pathParamsSchema.properties ? Object.keys(pathParamsSchema.properties) : undefined,\n }\n : undefined,\n queryParams: queryParamsSchema\n ? {\n name: resolveName(transformers.pascalCase(`${operation.getOperationId()} QueryParams`)),\n operation,\n operationName: transformers.pascalCase(`${operation.getOperationId()}`),\n schema: queryParamsSchema,\n keys: queryParamsSchema.properties ? Object.keys(queryParamsSchema.properties) : [],\n }\n : undefined,\n headerParams: headerParamsSchema\n ? {\n name: resolveName(transformers.pascalCase(`${operation.getOperationId()} HeaderParams`)),\n operation,\n operationName: transformers.pascalCase(`${operation.getOperationId()}`),\n schema: headerParamsSchema,\n keys: headerParamsSchema.properties ? Object.keys(headerParamsSchema.properties) : undefined,\n }\n : undefined,\n request: requestSchema\n ? {\n name: resolveName(transformers.pascalCase(`${operation.getOperationId()} ${operation.method === 'get' ? 'queryRequest' : 'mutationRequest'}`)),\n description: (operation.schema.requestBody as OasTypes.RequestBodyObject)?.description,\n operation,\n operationName: transformers.pascalCase(`${operation.getOperationId()}`),\n schema: requestSchema,\n keys: requestSchema.properties ? Object.keys(requestSchema.properties) : undefined,\n keysToOmit: requestSchema.properties\n ? Object.keys(requestSchema.properties).filter((key) => {\n const item = requestSchema.properties?.[key] as OasTypes.SchemaObject\n\n return item?.readOnly\n })\n : undefined,\n }\n : undefined,\n response: {\n name: resolveName(transformers.pascalCase(`${operation.getOperationId()} ${operation.method === 'get' ? 'queryResponse' : 'mutationResponse'}`)),\n description: operation.getResponseAsJSONSchema(responseStatusCode)?.at(0)?.description,\n operation,\n operationName: transformers.pascalCase(`${operation.getOperationId()}`),\n schema: responseSchema,\n statusCode: Number(responseStatusCode),\n keys: responseSchema?.properties ? Object.keys(responseSchema.properties) : undefined,\n keysToOmit: responseSchema?.properties\n ? Object.keys(responseSchema.properties).filter((key) => {\n const item = responseSchema.properties?.[key] as OasTypes.SchemaObject\n return item?.writeOnly\n })\n : undefined,\n },\n errors: statusCodes.filter((item) => item.statusCode?.toString().startsWith('4') || item.statusCode?.toString().startsWith('5')),\n statusCodes,\n }\n }\n\n get #methods() {\n return {\n get: this.get,\n post: this.post,\n patch: this.patch,\n put: this.put,\n delete: this.delete,\n head: undefined,\n options: undefined,\n trace: undefined,\n } as const\n }\n\n async build(): Promise<Array<KubbFile.File<TFileMeta>>> {\n const { oas } = this.context\n\n const paths = oas.getPaths()\n this.operationsByMethod = Object.entries(paths).reduce((acc, [path, method]) => {\n const methods = Object.keys(method) as HttpMethod[]\n\n methods.forEach((method) => {\n const operation = oas.operation(path, method)\n if (operation && this.#methods[method]) {\n const isExcluded = this.#isExcluded(operation, method)\n const isIncluded = this.context.include ? this.#isIncluded(operation, method) : true\n\n if (isIncluded && !isExcluded) {\n if (!acc[path]) {\n acc[path] = {} as OperationsByMethod['get']\n }\n acc[path] = {\n ...acc[path],\n [method]: {\n operation,\n schemas: this.getSchemas(operation),\n },\n } as OperationsByMethod['get']\n }\n }\n })\n\n return acc\n }, {} as OperationsByMethod)\n\n const promises = Object.keys(this.operationsByMethod).reduce((acc, path) => {\n const methods = this.operationsByMethod[path] ? (Object.keys(this.operationsByMethod[path]!) as HttpMethod[]) : []\n\n methods.forEach((method) => {\n const { operation } = this.operationsByMethod[path]?.[method]!\n const options = this.#getOptions(operation, method)\n const promiseMethod = this.#methods[method]?.call(this, operation, {\n ...this.options,\n ...options,\n })\n const promiseOperation = this.operation.call(this, operation, {\n ...this.options,\n ...options,\n })\n\n if (promiseMethod) {\n acc.push(promiseMethod)\n }\n if (promiseOperation) {\n acc.push(promiseOperation)\n }\n })\n\n return acc\n }, [] as OperationMethodResult<TFileMeta>[])\n\n const operations = Object.values(this.operationsByMethod).map((item) => Object.values(item).map((item) => item.operation))\n\n promises.push(this.all(operations.flat().filter(Boolean), this.operationsByMethod))\n\n const files = await Promise.all(promises)\n\n // using .flat because operationGenerator[method] can return a array of files or just one file\n return files.flat().filter(Boolean)\n }\n\n /**\n * Operation\n */\n async operation(operation: Operation, options: TOptions): OperationMethodResult<TFileMeta> {\n return null\n }\n\n /**\n * GET\n */\n async get(operation: Operation, options: TOptions): OperationMethodResult<TFileMeta> {\n return null\n }\n\n /**\n * POST\n */\n async post(operation: Operation, options: TOptions): OperationMethodResult<TFileMeta> {\n return null\n }\n /**\n * PATCH\n */\n async patch(operation: Operation, options: TOptions): OperationMethodResult<TFileMeta> {\n return null\n }\n\n /**\n * PUT\n */\n async put(operation: Operation, options: TOptions): OperationMethodResult<TFileMeta> {\n return null\n }\n\n /**\n * DELETE\n */\n async delete(operation: Operation, options: TOptions): OperationMethodResult<TFileMeta> {\n return null\n }\n\n /**\n * Combination of GET, POST, PATCH, PUT, DELETE\n */\n async all(operations: Operation[], paths: OperationsByMethod): OperationMethodResult<TFileMeta> {\n return null\n }\n}\n"]}
package/dist/index.d.cts CHANGED
@@ -1,13 +1,12 @@
1
1
  import * as _kubb_core from '@kubb/core';
2
2
  import { FileMetaBase, ResolveNameParams, PluginFactoryOptions, Generator, PluginManager, Plugin } from '@kubb/core';
3
- import { O as Options, P as PluginOas, a as OperationSchema, R as Refs, b as Override } from './types-Db0qp8u-.cjs';
4
- export { A as API, E as Exclude, I as Include, f as OperationSchemas, g as OperationsByMethod, d as Ref, c as ResolvePathOptions, e as Resolver } from './types-Db0qp8u-.cjs';
5
- export { G as GetOperationGeneratorOptions, a as OperationGenerator, O as OperationMethodResult } from './OperationGenerator-BV6QRtkW.cjs';
3
+ import { O as Options, P as PluginOas, a as OperationSchema, R as Refs, b as Override } from './types-RVAPVtNi.cjs';
4
+ export { A as API, E as Exclude, I as Include, f as OperationSchemas, g as OperationsByMethod, d as Ref, c as ResolvePathOptions, e as Resolver } from './types-RVAPVtNi.cjs';
5
+ export { G as GetOperationGeneratorOptions, a as OperationGenerator, O as OperationMethodResult } from './OperationGenerator-8tADySO6.cjs';
6
6
  import * as KubbFile from '@kubb/fs/types';
7
7
  import { SchemaObject, Oas, contentType } from '@kubb/oas';
8
8
  import { S as Schema, a as SchemaKeywordMapper } from './SchemaMapper-BLcXlDBz.cjs';
9
9
  export { b as SchemaKeyword, c as SchemaKeywordBase, d as SchemaMapper, i as isKeyword, s as schemaKeywords } from './SchemaMapper-BLcXlDBz.cjs';
10
- import '@kubb/oas/parser';
11
10
 
12
11
  declare const pluginOasName = "plugin-oas";
13
12
  declare const pluginOas: (options?: Options | undefined) => _kubb_core.UserPluginWithLifeCycle<PluginOas>;
package/dist/index.d.ts CHANGED
@@ -1,13 +1,12 @@
1
1
  import * as _kubb_core from '@kubb/core';
2
2
  import { FileMetaBase, ResolveNameParams, PluginFactoryOptions, Generator, PluginManager, Plugin } from '@kubb/core';
3
- import { O as Options, P as PluginOas, a as OperationSchema, R as Refs, b as Override } from './types-Db0qp8u-.js';
4
- export { A as API, E as Exclude, I as Include, f as OperationSchemas, g as OperationsByMethod, d as Ref, c as ResolvePathOptions, e as Resolver } from './types-Db0qp8u-.js';
5
- export { G as GetOperationGeneratorOptions, a as OperationGenerator, O as OperationMethodResult } from './OperationGenerator-DO5tNGuT.js';
3
+ import { O as Options, P as PluginOas, a as OperationSchema, R as Refs, b as Override } from './types-RVAPVtNi.js';
4
+ export { A as API, E as Exclude, I as Include, f as OperationSchemas, g as OperationsByMethod, d as Ref, c as ResolvePathOptions, e as Resolver } from './types-RVAPVtNi.js';
5
+ export { G as GetOperationGeneratorOptions, a as OperationGenerator, O as OperationMethodResult } from './OperationGenerator-DvyNt6Xi.js';
6
6
  import * as KubbFile from '@kubb/fs/types';
7
7
  import { SchemaObject, Oas, contentType } from '@kubb/oas';
8
8
  import { S as Schema, a as SchemaKeywordMapper } from './SchemaMapper-BLcXlDBz.js';
9
9
  export { b as SchemaKeyword, c as SchemaKeywordBase, d as SchemaMapper, i as isKeyword, s as schemaKeywords } from './SchemaMapper-BLcXlDBz.js';
10
- import '@kubb/oas/parser';
11
10
 
12
11
  declare const pluginOasName = "plugin-oas";
13
12
  declare const pluginOas: (options?: Options | undefined) => _kubb_core.UserPluginWithLifeCycle<PluginOas>;
package/dist/index.js CHANGED
@@ -1,11 +1,11 @@
1
1
  import {
2
2
  parseFromConfig
3
- } from "./chunk-Y4V7HHX7.js";
3
+ } from "./chunk-B3QCCJ62.js";
4
4
  import {
5
5
  SchemaGenerator,
6
6
  isKeyword,
7
7
  schemaKeywords
8
- } from "./chunk-KEVZ6FD5.js";
8
+ } from "./chunk-QOM3GBVG.js";
9
9
  import {
10
10
  __privateAdd,
11
11
  __privateGet,
@@ -13,30 +13,22 @@ import {
13
13
  __privateSet,
14
14
  getSchemas,
15
15
  init_esm_shims
16
- } from "./chunk-UB552H4J.js";
16
+ } from "./chunk-2YX4XBMY.js";
17
17
 
18
18
  // src/index.ts
19
19
  init_esm_shims();
20
20
 
21
21
  // src/plugin.ts
22
22
  init_esm_shims();
23
- import path from "path";
23
+ import path from "node:path";
24
24
  import { createPlugin } from "@kubb/core";
25
25
  import { camelCase } from "@kubb/core/transformers";
26
26
  var pluginOasName = "plugin-oas";
27
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 }) => {
28
+ const { output = { path: "schemas", export: false }, validate = true, serverIndex = 0, contentType, oasClass } = options;
29
+ const getOas = async ({ config, logger }) => {
38
30
  try {
39
- const oas = await parseFromConfig(config, formatOptions, oasClass);
31
+ const oas = await parseFromConfig(config, oasClass);
40
32
  if (validate) {
41
33
  await oas.valdiate();
42
34
  }
@@ -44,7 +36,7 @@ var pluginOas = createPlugin((options) => {
44
36
  } catch (e) {
45
37
  const error = e;
46
38
  logger.emit("warning", error?.message);
47
- return parseFromConfig(config, {}, oasClass);
39
+ return parseFromConfig(config, oasClass);
48
40
  }
49
41
  };
50
42
  return {
@@ -53,8 +45,8 @@ var pluginOas = createPlugin((options) => {
53
45
  api() {
54
46
  const { config, logger } = this;
55
47
  return {
56
- getOas(formatOptions) {
57
- return getOas({ config, logger, formatOptions });
48
+ getOas() {
49
+ return getOas({ config, logger });
58
50
  },
59
51
  async getSchemas({ includes } = {}) {
60
52
  const oas = await this.getOas();
@@ -90,11 +82,7 @@ var pluginOas = createPlugin((options) => {
90
82
  }
91
83
  const oas = await getOas({
92
84
  config: this.config,
93
- logger: this.logger,
94
- formatOptions: {
95
- filterSet: filter,
96
- sortSet: sort
97
- }
85
+ logger: this.logger
98
86
  });
99
87
  await oas.dereference();
100
88
  const schemas = getSchemas({ oas, contentType });