@kubb/plugin-oas 3.16.1 → 3.16.3

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 (111) hide show
  1. package/dist/Oas-CuqAnIw-.js +60 -0
  2. package/dist/Oas-CuqAnIw-.js.map +1 -0
  3. package/dist/Oas-Cv_pyXRM.cjs +78 -0
  4. package/dist/Oas-Cv_pyXRM.cjs.map +1 -0
  5. package/dist/OperationGenerator-CgbXErhW.d.cts +900 -0
  6. package/dist/OperationGenerator-OtLcGk2y.d.ts +900 -0
  7. package/dist/Schema-DJshqHto.d.cts +38 -0
  8. package/dist/Schema-DOXGUW1m.d.ts +38 -0
  9. package/dist/SchemaGenerator-8205BXCp.cjs +942 -0
  10. package/dist/SchemaGenerator-8205BXCp.cjs.map +1 -0
  11. package/dist/SchemaGenerator-B8Io6kky.js +930 -0
  12. package/dist/SchemaGenerator-B8Io6kky.js.map +1 -0
  13. package/dist/SchemaMapper-BaZQKrQB.js +54 -0
  14. package/dist/SchemaMapper-BaZQKrQB.js.map +1 -0
  15. package/dist/SchemaMapper-BiagBQN4.d.cts +388 -0
  16. package/dist/SchemaMapper-C2J2d3o4.d.ts +388 -0
  17. package/dist/SchemaMapper-D8J0V9Pj.cjs +66 -0
  18. package/dist/SchemaMapper-D8J0V9Pj.cjs.map +1 -0
  19. package/dist/chunk-CUT6urMc.cjs +30 -0
  20. package/dist/components.cjs +4 -19
  21. package/dist/components.d.cts +42 -35
  22. package/dist/components.d.ts +42 -35
  23. package/dist/components.js +3 -3
  24. package/dist/generators-BhLMlRNk.js +137 -0
  25. package/dist/generators-BhLMlRNk.js.map +1 -0
  26. package/dist/generators-DLH2kvlh.cjs +155 -0
  27. package/dist/generators-DLH2kvlh.cjs.map +1 -0
  28. package/dist/generators.cjs +4 -13
  29. package/dist/generators.d.cts +5 -7
  30. package/dist/generators.d.ts +5 -7
  31. package/dist/generators.js +5 -5
  32. package/dist/getFooter-BChY2kC1.cjs +43 -0
  33. package/dist/getFooter-BChY2kC1.cjs.map +1 -0
  34. package/dist/getFooter-T7_pZ6f8.js +31 -0
  35. package/dist/getFooter-T7_pZ6f8.js.map +1 -0
  36. package/dist/getSchemas-D8mP129c.cjs +67 -0
  37. package/dist/getSchemas-D8mP129c.cjs.map +1 -0
  38. package/dist/getSchemas-WoSBIxG8.js +55 -0
  39. package/dist/getSchemas-WoSBIxG8.js.map +1 -0
  40. package/dist/hooks.cjs +213 -195
  41. package/dist/hooks.cjs.map +1 -1
  42. package/dist/hooks.d.cts +91 -86
  43. package/dist/hooks.d.ts +91 -86
  44. package/dist/hooks.js +212 -193
  45. package/dist/hooks.js.map +1 -1
  46. package/dist/index.cjs +280 -344
  47. package/dist/index.cjs.map +1 -1
  48. package/dist/index.d.cts +7 -10
  49. package/dist/index.d.ts +7 -10
  50. package/dist/index.js +274 -318
  51. package/dist/index.js.map +1 -1
  52. package/dist/mocks.cjs +802 -737
  53. package/dist/mocks.cjs.map +1 -1
  54. package/dist/mocks.d.cts +12 -11
  55. package/dist/mocks.d.ts +12 -11
  56. package/dist/mocks.js +802 -735
  57. package/dist/mocks.js.map +1 -1
  58. package/dist/parseFromConfig-CMNGsef2.cjs +33 -0
  59. package/dist/parseFromConfig-CMNGsef2.cjs.map +1 -0
  60. package/dist/parseFromConfig-yAiFK03V.js +27 -0
  61. package/dist/parseFromConfig-yAiFK03V.js.map +1 -0
  62. package/dist/utils.cjs +58 -74
  63. package/dist/utils.cjs.map +1 -1
  64. package/dist/utils.d.cts +96 -42
  65. package/dist/utils.d.ts +96 -42
  66. package/dist/utils.js +47 -46
  67. package/dist/utils.js.map +1 -1
  68. package/package.json +28 -36
  69. package/src/SchemaGenerator.ts +6 -1
  70. package/src/components/Operation.tsx +1 -2
  71. package/src/mocks/schemas.ts +39 -0
  72. package/src/utils/getBanner.ts +5 -5
  73. package/src/utils/getFooter.ts +4 -4
  74. package/dist/OperationGenerator-C7NPZtOM.d.ts +0 -288
  75. package/dist/OperationGenerator-DJE2XQ83.d.cts +0 -288
  76. package/dist/Schema-AjebpeVY.d.ts +0 -32
  77. package/dist/Schema-M6983FL1.d.cts +0 -32
  78. package/dist/SchemaMapper-B21ZmWag.d.cts +0 -275
  79. package/dist/SchemaMapper-B21ZmWag.d.ts +0 -275
  80. package/dist/chunk-6S7YFY6F.js +0 -33
  81. package/dist/chunk-6S7YFY6F.js.map +0 -1
  82. package/dist/chunk-76E35IZ2.js +0 -56
  83. package/dist/chunk-76E35IZ2.js.map +0 -1
  84. package/dist/chunk-7RFNM43R.cjs +0 -41
  85. package/dist/chunk-7RFNM43R.cjs.map +0 -1
  86. package/dist/chunk-DTD4ZUDA.cjs +0 -36
  87. package/dist/chunk-DTD4ZUDA.cjs.map +0 -1
  88. package/dist/chunk-G3FDK7YW.js +0 -35
  89. package/dist/chunk-G3FDK7YW.js.map +0 -1
  90. package/dist/chunk-JNN4JPWK.js +0 -28
  91. package/dist/chunk-JNN4JPWK.js.map +0 -1
  92. package/dist/chunk-MBX66JAT.js +0 -93
  93. package/dist/chunk-MBX66JAT.js.map +0 -1
  94. package/dist/chunk-NFLZLRQS.cjs +0 -869
  95. package/dist/chunk-NFLZLRQS.cjs.map +0 -1
  96. package/dist/chunk-P2VXWGXZ.js +0 -862
  97. package/dist/chunk-P2VXWGXZ.js.map +0 -1
  98. package/dist/chunk-PORSNYI5.js +0 -47
  99. package/dist/chunk-PORSNYI5.js.map +0 -1
  100. package/dist/chunk-QJMOOF2A.cjs +0 -97
  101. package/dist/chunk-QJMOOF2A.cjs.map +0 -1
  102. package/dist/chunk-YWMMI3MO.cjs +0 -59
  103. package/dist/chunk-YWMMI3MO.cjs.map +0 -1
  104. package/dist/chunk-Z2NREI4X.cjs +0 -32
  105. package/dist/chunk-Z2NREI4X.cjs.map +0 -1
  106. package/dist/chunk-ZVFL3NXX.cjs +0 -50
  107. package/dist/chunk-ZVFL3NXX.cjs.map +0 -1
  108. package/dist/components.cjs.map +0 -1
  109. package/dist/components.js.map +0 -1
  110. package/dist/generators.cjs.map +0 -1
  111. package/dist/generators.js.map +0 -1
@@ -0,0 +1,55 @@
1
+ import { isOpenApiV3_1Document } from "@kubb/oas";
2
+
3
+ //#region src/utils/getSchemaFactory.ts
4
+ /**
5
+ * Creates a factory function that generates a versioned OpenAPI schema result.
6
+ *
7
+ * The returned function accepts an optional schema object and produces a {@link SchemaResult} containing the dereferenced schema and the OpenAPI version ('3.0' or '3.1').
8
+ *
9
+ * @returns A function that takes an optional schema and returns a versioned schema result.
10
+ */
11
+ function getSchemaFactory(oas) {
12
+ return (schema) => {
13
+ const version = isOpenApiV3_1Document(oas.api) ? "3.1" : "3.0";
14
+ return {
15
+ schemaObject: oas.dereferenceWithRef(schema),
16
+ version
17
+ };
18
+ };
19
+ }
20
+
21
+ //#endregion
22
+ //#region src/utils/getSchemas.ts
23
+ function getSchemas({ oas, contentType, includes = [
24
+ "schemas",
25
+ "requestBodies",
26
+ "responses"
27
+ ] }) {
28
+ const components = oas.getDefinition().components;
29
+ let schemas = {};
30
+ if (includes.includes("schemas")) schemas = {
31
+ ...schemas,
32
+ ...components?.schemas || {}
33
+ };
34
+ const requestBodies = components?.requestBodies || {};
35
+ if (includes.includes("responses")) {
36
+ const responses = components?.responses || {};
37
+ Object.entries(responses).forEach(([name, response]) => {
38
+ if (response.content && !schemas[name]) {
39
+ const firstContentType = Object.keys(response.content)[0] || "application/json";
40
+ schemas[name] = response.content?.[contentType || firstContentType]?.schema;
41
+ }
42
+ });
43
+ }
44
+ if (includes.includes("requestBodies")) Object.entries(requestBodies).forEach(([name, request]) => {
45
+ if (request.content && !schemas[name]) {
46
+ const firstContentType = Object.keys(request.content)[0] || "application/json";
47
+ schemas[name] = request.content?.[contentType || firstContentType]?.schema;
48
+ }
49
+ });
50
+ return schemas;
51
+ }
52
+
53
+ //#endregion
54
+ export { getSchemaFactory, getSchemas };
55
+ //# sourceMappingURL=getSchemas-WoSBIxG8.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getSchemas-WoSBIxG8.js","names":["oas: Oas","schema?: SchemaObject","schemas: Record<string, OasTypes.SchemaObject>"],"sources":["../src/utils/getSchemaFactory.ts","../src/utils/getSchemas.ts"],"sourcesContent":["import { isOpenApiV3_1Document } from '@kubb/oas'\n\nimport type { Oas, OpenAPIV3, OpenAPIV3_1, SchemaObject } from '@kubb/oas'\n\n/**\n * Make it possible to narrow down the schema based on a specific version(3 or 3.1)\n */\ntype SchemaResult<TWithRef extends boolean = false> =\n | {\n schemaObject?: (TWithRef extends true ? OpenAPIV3.SchemaObject | OpenAPIV3.ReferenceObject : OpenAPIV3.SchemaObject) & {\n nullable?: boolean\n 'x-nullable'?: boolean\n }\n version: '3.0'\n }\n | {\n schemaObject?: (TWithRef extends true ? OpenAPIV3_1.SchemaObject | OpenAPIV3_1.ReferenceObject : OpenAPIV3_1.SchemaObject) & {\n nullable?: boolean\n 'x-nullable'?: boolean\n }\n version: '3.1'\n }\n\n/**\n * Creates a factory function that generates a versioned OpenAPI schema result.\n *\n * The returned function accepts an optional schema object and produces a {@link SchemaResult} containing the dereferenced schema and the OpenAPI version ('3.0' or '3.1').\n *\n * @returns A function that takes an optional schema and returns a versioned schema result.\n */\nexport function getSchemaFactory<TWithRef extends boolean = false>(oas: Oas): (schema?: SchemaObject) => SchemaResult<TWithRef> {\n return (schema?: SchemaObject) => {\n const version = isOpenApiV3_1Document(oas.api) ? '3.1' : '3.0'\n\n return {\n schemaObject: oas.dereferenceWithRef(schema),\n version,\n } as SchemaResult<TWithRef>\n }\n}\n","import type { Oas, OasTypes, contentType } from '@kubb/oas'\n\ntype Mode = 'schemas' | 'responses' | 'requestBodies'\n\ntype GetSchemasProps = {\n oas: Oas\n contentType?: contentType\n includes?: Mode[]\n}\n\nexport function getSchemas({ oas, contentType, includes = ['schemas', 'requestBodies', 'responses'] }: GetSchemasProps): Record<string, OasTypes.SchemaObject> {\n const components = oas.getDefinition().components\n\n let schemas: Record<string, OasTypes.SchemaObject> = {}\n\n if (includes.includes('schemas')) {\n schemas = {\n ...schemas,\n ...((components?.schemas as Record<string, OasTypes.SchemaObject>) || {}),\n }\n }\n\n const requestBodies = components?.requestBodies || {}\n if (includes.includes('responses')) {\n const responses = components?.responses || {}\n\n Object.entries(responses).forEach(([name, response]: [string, OasTypes.ResponseObject]) => {\n if (response.content && !schemas[name]) {\n const firstContentType = Object.keys(response.content)[0] || 'application/json'\n schemas[name] = response.content?.[contentType || firstContentType]?.schema as OasTypes.SchemaObject\n }\n })\n }\n\n if (includes.includes('requestBodies')) {\n Object.entries(requestBodies).forEach(([name, request]: [string, OasTypes.RequestBodyObject]) => {\n if (request.content && !schemas[name]) {\n const firstContentType = Object.keys(request.content)[0] || 'application/json'\n schemas[name] = request.content?.[contentType || firstContentType]?.schema as OasTypes.SchemaObject\n }\n })\n }\n\n return schemas\n}\n"],"mappings":";;;;;;;;;;AA8BA,SAAgB,iBAAmDA,KAA6D;AAC9H,QAAO,CAACC,WAA0B;EAChC,MAAM,UAAU,sBAAsB,IAAI,IAAI,GAAG,QAAQ;AAEzD,SAAO;GACL,cAAc,IAAI,mBAAmB,OAAO;GAC5C;EACD;CACF;AACF;;;;AC7BD,SAAgB,WAAW,EAAE,KAAK,aAAa,WAAW;CAAC;CAAW;CAAiB;AAAY,GAAmB,EAAyC;CAC7J,MAAM,aAAa,IAAI,eAAe,CAAC;CAEvC,IAAIC,UAAiD,CAAE;AAEvD,KAAI,SAAS,SAAS,UAAU,EAC9B,UAAU;EACR,GAAG;EACH,GAAK,YAAY,WAAqD,CAAE;CACzE;CAGH,MAAM,gBAAgB,YAAY,iBAAiB,CAAE;AACrD,KAAI,SAAS,SAAS,YAAY,EAAE;EAClC,MAAM,YAAY,YAAY,aAAa,CAAE;EAE7C,OAAO,QAAQ,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,SAA4C,KAAK;AACzF,OAAI,SAAS,WAAW,CAAC,QAAQ,OAAO;IACtC,MAAM,mBAAmB,OAAO,KAAK,SAAS,QAAQ,CAAC,MAAM;IAC7D,QAAQ,QAAQ,SAAS,UAAU,eAAe,mBAAmB;GACtE;EACF,EAAC;CACH;AAED,KAAI,SAAS,SAAS,gBAAgB,EACpC,OAAO,QAAQ,cAAc,CAAC,QAAQ,CAAC,CAAC,MAAM,QAA8C,KAAK;AAC/F,MAAI,QAAQ,WAAW,CAAC,QAAQ,OAAO;GACrC,MAAM,mBAAmB,OAAO,KAAK,QAAQ,QAAQ,CAAC,MAAM;GAC5D,QAAQ,QAAQ,QAAQ,UAAU,eAAe,mBAAmB;EACrE;CACF,EAAC;AAGJ,QAAO;AACR"}
package/dist/hooks.cjs CHANGED
@@ -1,216 +1,234 @@
1
- 'use strict';
2
-
3
- var chunkNFLZLRQS_cjs = require('./chunk-NFLZLRQS.cjs');
4
- var chunkYWMMI3MO_cjs = require('./chunk-YWMMI3MO.cjs');
5
- require('./chunk-ZVFL3NXX.cjs');
6
- var chunkZ2NREI4X_cjs = require('./chunk-Z2NREI4X.cjs');
7
- var react = require('@kubb/react');
1
+ const require_chunk = require('./chunk-CUT6urMc.cjs');
2
+ const require_SchemaGenerator = require('./SchemaGenerator-8205BXCp.cjs');
3
+ const require_Oas = require('./Oas-Cv_pyXRM.cjs');
4
+ const require_SchemaMapper = require('./SchemaMapper-D8J0V9Pj.cjs');
5
+ require('./getSchemas-D8mP129c.cjs');
6
+ const __kubb_react = require_chunk.__toESM(require("@kubb/react"));
8
7
 
8
+ //#region src/hooks/useOas.ts
9
9
  function useOas() {
10
- const { oas } = react.useContext(chunkZ2NREI4X_cjs.Oas.Context);
11
- if (!oas) {
12
- throw new Error("Oas is not defined");
13
- }
14
- return oas;
10
+ const { oas } = (0, __kubb_react.useContext)(require_Oas.Oas.Context);
11
+ if (!oas) throw new Error("Oas is not defined");
12
+ return oas;
15
13
  }
14
+
15
+ //#endregion
16
+ //#region src/hooks/useOperation.ts
17
+ /**
18
+ * `useOperation` will return the current `Operation`
19
+ */
16
20
  function useOperation() {
17
- const { operation } = react.useContext(chunkZ2NREI4X_cjs.Operation.Context);
18
- if (!operation) {
19
- throw new Error("Operation is not defined");
20
- }
21
- return operation;
21
+ const { operation } = (0, __kubb_react.useContext)(require_Oas.Operation.Context);
22
+ if (!operation) throw new Error("Operation is not defined");
23
+ return operation;
22
24
  }
25
+
26
+ //#endregion
27
+ //#region src/hooks/useOperationManager.ts
28
+ /**
29
+ * `useOperationManager` will return some helper functions that can be used to get the operation file, get the operation name.
30
+ */
23
31
  function useOperationManager() {
24
- const { plugin, pluginManager } = react.useApp();
25
- const { generator } = react.useContext(chunkZ2NREI4X_cjs.Oas.Context);
26
- const getName = (operation, { prefix = "", suffix = "", pluginKey = plugin.key, type }) => {
27
- return pluginManager.resolveName({
28
- name: `${prefix} ${operation.getOperationId()} ${suffix}`,
29
- pluginKey,
30
- type
31
- });
32
- };
33
- const getGroup = (operation) => {
34
- return {
35
- tag: operation.getTags().at(0)?.name,
36
- path: operation.path
37
- };
38
- };
39
- const getSchemas = (operation, params) => {
40
- if (!generator) {
41
- throw new Error(`'generator' is not defined`);
42
- }
43
- return generator.getSchemas(operation, {
44
- resolveName: (name) => pluginManager.resolveName({
45
- name,
46
- pluginKey: params?.pluginKey,
47
- type: params?.type
48
- })
49
- });
50
- };
51
- const getFile = (operation, { prefix, suffix, pluginKey = plugin.key, extname = ".ts" } = {}) => {
52
- const name = getName(operation, { type: "file", pluginKey, prefix, suffix });
53
- const group = getGroup(operation);
54
- const file = pluginManager.getFile({
55
- name,
56
- extname,
57
- pluginKey,
58
- options: { type: "file", pluginKey, group }
59
- });
60
- return {
61
- ...file,
62
- meta: {
63
- ...file.meta,
64
- name,
65
- pluginKey,
66
- group
67
- }
68
- };
69
- };
70
- const groupSchemasByName = (operation, { pluginKey = plugin.key, type }) => {
71
- if (!generator) {
72
- throw new Error(`'generator' is not defined`);
73
- }
74
- const schemas = generator.getSchemas(operation);
75
- const errors = (schemas.errors || []).reduce(
76
- (prev, acc) => {
77
- if (!acc.statusCode) {
78
- return prev;
79
- }
80
- prev[acc.statusCode] = pluginManager.resolveName({
81
- name: acc.name,
82
- pluginKey,
83
- type
84
- });
85
- return prev;
86
- },
87
- {}
88
- );
89
- const responses = (schemas.responses || []).reduce(
90
- (prev, acc) => {
91
- if (!acc.statusCode) {
92
- return prev;
93
- }
94
- prev[acc.statusCode] = pluginManager.resolveName({
95
- name: acc.name,
96
- pluginKey,
97
- type
98
- });
99
- return prev;
100
- },
101
- {}
102
- );
103
- return {
104
- request: schemas.request?.name ? pluginManager.resolveName({
105
- name: schemas.request.name,
106
- pluginKey,
107
- type
108
- }) : void 0,
109
- parameters: {
110
- path: schemas.pathParams?.name ? pluginManager.resolveName({
111
- name: schemas.pathParams.name,
112
- pluginKey,
113
- type
114
- }) : void 0,
115
- query: schemas.queryParams?.name ? pluginManager.resolveName({
116
- name: schemas.queryParams.name,
117
- pluginKey,
118
- type
119
- }) : void 0,
120
- header: schemas.headerParams?.name ? pluginManager.resolveName({
121
- name: schemas.headerParams.name,
122
- pluginKey,
123
- type
124
- }) : void 0
125
- },
126
- responses: {
127
- ...responses,
128
- ["default"]: pluginManager.resolveName({
129
- name: schemas.response.name,
130
- pluginKey,
131
- type
132
- }),
133
- ...errors
134
- },
135
- errors
136
- };
137
- };
138
- return {
139
- getName,
140
- getFile,
141
- getSchemas,
142
- groupSchemasByName,
143
- getGroup
144
- };
32
+ const { plugin, pluginManager } = (0, __kubb_react.useApp)();
33
+ const { generator } = (0, __kubb_react.useContext)(require_Oas.Oas.Context);
34
+ const getName = (operation, { prefix = "", suffix = "", pluginKey = plugin.key, type }) => {
35
+ return pluginManager.resolveName({
36
+ name: `${prefix} ${operation.getOperationId()} ${suffix}`,
37
+ pluginKey,
38
+ type
39
+ });
40
+ };
41
+ const getGroup = (operation) => {
42
+ return {
43
+ tag: operation.getTags().at(0)?.name,
44
+ path: operation.path
45
+ };
46
+ };
47
+ const getSchemas = (operation, params) => {
48
+ if (!generator) throw new Error(`'generator' is not defined`);
49
+ return generator.getSchemas(operation, { resolveName: (name) => pluginManager.resolveName({
50
+ name,
51
+ pluginKey: params?.pluginKey,
52
+ type: params?.type
53
+ }) });
54
+ };
55
+ const getFile = (operation, { prefix, suffix, pluginKey = plugin.key, extname = ".ts" } = {}) => {
56
+ const name = getName(operation, {
57
+ type: "file",
58
+ pluginKey,
59
+ prefix,
60
+ suffix
61
+ });
62
+ const group = getGroup(operation);
63
+ const file = pluginManager.getFile({
64
+ name,
65
+ extname,
66
+ pluginKey,
67
+ options: {
68
+ type: "file",
69
+ pluginKey,
70
+ group
71
+ }
72
+ });
73
+ return {
74
+ ...file,
75
+ meta: {
76
+ ...file.meta,
77
+ name,
78
+ pluginKey,
79
+ group
80
+ }
81
+ };
82
+ };
83
+ const groupSchemasByName = (operation, { pluginKey = plugin.key, type }) => {
84
+ if (!generator) throw new Error(`'generator' is not defined`);
85
+ const schemas = generator.getSchemas(operation);
86
+ const errors = (schemas.errors || []).reduce((prev, acc) => {
87
+ if (!acc.statusCode) return prev;
88
+ prev[acc.statusCode] = pluginManager.resolveName({
89
+ name: acc.name,
90
+ pluginKey,
91
+ type
92
+ });
93
+ return prev;
94
+ }, {});
95
+ const responses = (schemas.responses || []).reduce((prev, acc) => {
96
+ if (!acc.statusCode) return prev;
97
+ prev[acc.statusCode] = pluginManager.resolveName({
98
+ name: acc.name,
99
+ pluginKey,
100
+ type
101
+ });
102
+ return prev;
103
+ }, {});
104
+ return {
105
+ request: schemas.request?.name ? pluginManager.resolveName({
106
+ name: schemas.request.name,
107
+ pluginKey,
108
+ type
109
+ }) : void 0,
110
+ parameters: {
111
+ path: schemas.pathParams?.name ? pluginManager.resolveName({
112
+ name: schemas.pathParams.name,
113
+ pluginKey,
114
+ type
115
+ }) : void 0,
116
+ query: schemas.queryParams?.name ? pluginManager.resolveName({
117
+ name: schemas.queryParams.name,
118
+ pluginKey,
119
+ type
120
+ }) : void 0,
121
+ header: schemas.headerParams?.name ? pluginManager.resolveName({
122
+ name: schemas.headerParams.name,
123
+ pluginKey,
124
+ type
125
+ }) : void 0
126
+ },
127
+ responses: {
128
+ ...responses,
129
+ ["default"]: pluginManager.resolveName({
130
+ name: schemas.response.name,
131
+ pluginKey,
132
+ type
133
+ }),
134
+ ...errors
135
+ },
136
+ errors
137
+ };
138
+ };
139
+ return {
140
+ getName,
141
+ getFile,
142
+ getSchemas,
143
+ groupSchemasByName,
144
+ getGroup
145
+ };
145
146
  }
147
+
148
+ //#endregion
149
+ //#region src/hooks/useOperations.ts
150
+ /**
151
+ * `useOperations` will return all the Operations
152
+ */
146
153
  function useOperations({ method, path } = {}) {
147
- const { operations } = react.useContext(chunkZ2NREI4X_cjs.Oas.Context);
148
- if (!operations) {
149
- throw new Error("Operations is not defined");
150
- }
151
- let items = operations;
152
- if (path) {
153
- items = items.filter((item) => item.path === path);
154
- }
155
- if (method) {
156
- items = items.filter((item) => item.method === method);
157
- }
158
- return items;
154
+ const { operations } = (0, __kubb_react.useContext)(require_Oas.Oas.Context);
155
+ if (!operations) throw new Error("Operations is not defined");
156
+ let items = operations;
157
+ if (path) items = items.filter((item) => item.path === path);
158
+ if (method) items = items.filter((item) => item.method === method);
159
+ return items;
159
160
  }
161
+
162
+ //#endregion
163
+ //#region src/hooks/useSchema.ts
164
+ /**
165
+ * `useSchema` will return the current `schema properties`
166
+ */
160
167
  function useSchema() {
161
- const props = react.useContext(chunkZ2NREI4X_cjs.Schema.Context);
162
- return props;
168
+ const props = (0, __kubb_react.useContext)(require_Oas.Schema.Context);
169
+ return props;
163
170
  }
171
+
172
+ //#endregion
173
+ //#region src/hooks/useSchemaManager.ts
174
+ /**
175
+ * `useSchemaManager` will return some helper functions that can be used to get the schema file, get the schema name.
176
+ */
164
177
  function useSchemaManager() {
165
- const { plugin, pluginManager } = react.useApp();
166
- const getName = (name, { pluginKey = plugin.key, type }) => {
167
- return pluginManager.resolveName({
168
- name,
169
- pluginKey,
170
- type
171
- });
172
- };
173
- const getFile = (name, { mode = "split", pluginKey = plugin.key, extname = ".ts", group } = {}) => {
174
- const resolvedName = mode === "single" ? "" : getName(name, { type: "file", pluginKey });
175
- const file = pluginManager.getFile({
176
- name: resolvedName,
177
- extname,
178
- pluginKey,
179
- options: { type: "file", pluginKey, group }
180
- });
181
- return {
182
- ...file,
183
- meta: {
184
- ...file.meta,
185
- name: resolvedName,
186
- pluginKey
187
- }
188
- };
189
- };
190
- const getImports = (tree) => {
191
- const refs = chunkNFLZLRQS_cjs.SchemaGenerator.deepSearch(tree, chunkYWMMI3MO_cjs.schemaKeywords.ref);
192
- return refs?.map((item) => {
193
- if (!item.args.path || !item.args.isImportable) {
194
- return void 0;
195
- }
196
- return {
197
- name: [item.args.name],
198
- path: item.args.path
199
- };
200
- }).filter(Boolean);
201
- };
202
- return {
203
- getName,
204
- getFile,
205
- getImports
206
- };
178
+ const { plugin, pluginManager } = (0, __kubb_react.useApp)();
179
+ const getName = (name, { pluginKey = plugin.key, type }) => {
180
+ return pluginManager.resolveName({
181
+ name,
182
+ pluginKey,
183
+ type
184
+ });
185
+ };
186
+ const getFile = (name, { mode = "split", pluginKey = plugin.key, extname = ".ts", group } = {}) => {
187
+ const resolvedName = mode === "single" ? "" : getName(name, {
188
+ type: "file",
189
+ pluginKey
190
+ });
191
+ const file = pluginManager.getFile({
192
+ name: resolvedName,
193
+ extname,
194
+ pluginKey,
195
+ options: {
196
+ type: "file",
197
+ pluginKey,
198
+ group
199
+ }
200
+ });
201
+ return {
202
+ ...file,
203
+ meta: {
204
+ ...file.meta,
205
+ name: resolvedName,
206
+ pluginKey
207
+ }
208
+ };
209
+ };
210
+ const getImports = (tree) => {
211
+ const refs = require_SchemaGenerator.SchemaGenerator.deepSearch(tree, require_SchemaMapper.schemaKeywords.ref);
212
+ return refs?.map((item) => {
213
+ if (!item.args.path || !item.args.isImportable) return void 0;
214
+ return {
215
+ name: [item.args.name],
216
+ path: item.args.path
217
+ };
218
+ }).filter(Boolean);
219
+ };
220
+ return {
221
+ getName,
222
+ getFile,
223
+ getImports
224
+ };
207
225
  }
208
226
 
227
+ //#endregion
209
228
  exports.useOas = useOas;
210
229
  exports.useOperation = useOperation;
211
230
  exports.useOperationManager = useOperationManager;
212
231
  exports.useOperations = useOperations;
213
232
  exports.useSchema = useSchema;
214
233
  exports.useSchemaManager = useSchemaManager;
215
- //# sourceMappingURL=hooks.cjs.map
216
234
  //# sourceMappingURL=hooks.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/hooks/useOas.ts","../src/hooks/useOperation.ts","../src/hooks/useOperationManager.ts","../src/hooks/useOperations.ts","../src/hooks/useSchema.ts","../src/hooks/useSchemaManager.ts"],"names":["useContext","Oas","Operation","useApp","Schema","SchemaGenerator","schemaKeywords"],"mappings":";;;;;;;;AAMO,SAAS,MAAkB,GAAA;AAChC,EAAA,MAAM,EAAE,GAAA,EAAQ,GAAAA,gBAAA,CAAWC,sBAAI,OAAO,CAAA;AAEtC,EAAA,IAAI,CAAC,GAAK,EAAA;AACR,IAAM,MAAA,IAAI,MAAM,oBAAoB,CAAA;AAAA;AAGtC,EAAO,OAAA,GAAA;AACT;ACLO,SAAS,YAA8B,GAAA;AAC5C,EAAA,MAAM,EAAE,SAAA,EAAcD,GAAAA,gBAAAA,CAAWE,4BAAU,OAAO,CAAA;AAElD,EAAA,IAAI,CAAC,SAAW,EAAA;AACd,IAAM,MAAA,IAAI,MAAM,0BAA0B,CAAA;AAAA;AAG5C,EAAO,OAAA,SAAA;AACT;ACkDO,SAAS,mBAAiD,GAAA;AAC/D,EAAA,MAAM,EAAE,MAAA,EAAQ,aAAc,EAAA,GAAIC,YAAO,EAAA;AACzC,EAAA,MAAM,EAAE,SAAA,EAAcH,GAAAA,gBAAAA,CAAWC,sBAAI,OAAO,CAAA;AAE5C,EAAA,MAAM,OAAgD,GAAA,CAAC,SAAW,EAAA,EAAE,MAAS,GAAA,EAAA,EAAI,MAAS,GAAA,EAAA,EAAI,SAAY,GAAA,MAAA,CAAO,GAAK,EAAA,IAAA,EAAW,KAAA;AAC/H,IAAA,OAAO,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AQ,MAAM,EAAE,IAAA,EAAM,MAAQ,EAAA,SAAA,EAAW,CAAA;AAEvF,IAAM,MAAA,IAAA,GAAO,cAAc,OAAQ,CAAA;AAAA,MACjC,IAAM,EAAA,YAAA;AAAA,MACN,OAAA;AAAA,MACA,SAAA;AAAA,MACA,OAAS,EAAA,EAAE,IAAM,EAAA,MAAA,EAAQ,WAAW,KAAM;AAAA,KAC3C,CAAA;AAED,IAAO,OAAA;AAAA,MACL,GAAG,IAAA;AAAA,MACH,IAAM,EAAA;AAAA,QACJ,GAAG,IAAK,CAAA,IAAA;AAAA,QACR,IAAM,EAAA,YAAA;AAAA,QACN;AAAA;AACF,KACF;AAAA,GACF;AAEA,EAAM,MAAA,UAAA,GAAmD,CAAC,IAAS,KAAA;AACjE,IAAA,MAAM,IAAO,GAAAE,iCAAA,CAAgB,UAAW,CAAA,IAAA,EAAMC,iCAAe,GAAG,CAAA;AAEhE,IAAO,OAAA,IAAA,EACH,GAAI,CAAA,CAAC,IAAS,KAAA;AACd,MAAA,IAAI,CAAC,IAAK,CAAA,IAAA,CAAK,QAAQ,CAAC,IAAA,CAAK,KAAK,YAAc,EAAA;AAC9C,QAAO,OAAA,MAAA;AAAA;AAGT,MAAO,OAAA;AAAA,QACL,IAAM,EAAA,CAAC,IAAK,CAAA,IAAA,CAAK,IAAI,CAAA;AAAA,QACrB,IAAA,EAAM,KAAK,IAAK,CAAA;AAAA,OAClB;AAAA,KACD,CACA,CAAA,MAAA,CAAO,OAAO,CAAA;AAAA,GACnB;AAEA,EAAO,OAAA;AAAA,IACL,OAAA;AAAA,IACA,OAAA;AAAA,IACA;AAAA,GACF;AACF","file":"hooks.cjs","sourcesContent":["import { useContext } from '@kubb/react'\n\nimport { Oas } from '../components/Oas.tsx'\n\nimport type { Oas as OasType } from '@kubb/oas'\n\nexport function useOas(): OasType {\n const { oas } = useContext(Oas.Context)\n\n if (!oas) {\n throw new Error('Oas is not defined')\n }\n\n return oas\n}\n","import { useContext } from '@kubb/react'\n\nimport { Operation } from '../components/Operation.tsx'\n\nimport type { Operation as OperationType } from '@kubb/oas'\n\n/**\n * `useOperation` will return the current `Operation`\n */\nexport function useOperation(): OperationType {\n const { operation } = useContext(Operation.Context)\n\n if (!operation) {\n throw new Error('Operation is not defined')\n }\n\n return operation\n}\n","import { useApp, useContext } from '@kubb/react'\n\nimport { Oas } from '../components/Oas.tsx'\n\nimport type { FileMetaBase, Plugin, ResolveNameParams } from '@kubb/core'\n\nimport type { KubbFile } from '@kubb/core/fs'\nimport type { Operation, Operation as OperationType } from '@kubb/oas'\nimport type { OperationSchemas } from '../types.ts'\n\ntype FileMeta = FileMetaBase & {\n pluginKey: Plugin['key']\n name: string\n group?: {\n tag?: string\n path?: string\n }\n}\n\nexport type SchemaNames = {\n request: string | undefined\n parameters: {\n path: string | undefined\n query: string | undefined\n header: string | undefined\n }\n responses: { default?: string } & Record<number | string, string>\n errors: Record<number | string, string>\n}\n\ntype UseOperationManagerResult = {\n getName: (\n operation: OperationType,\n params: {\n prefix?: string\n suffix?: string\n pluginKey?: Plugin['key']\n type: ResolveNameParams['type']\n },\n ) => string\n getFile: (\n operation: OperationType,\n params?: {\n prefix?: string\n suffix?: string\n pluginKey?: Plugin['key']\n extname?: KubbFile.Extname\n group?: {\n tag?: string\n path?: string\n }\n },\n ) => KubbFile.File<FileMeta>\n groupSchemasByName: (\n operation: OperationType,\n params: {\n pluginKey?: Plugin['key']\n type: ResolveNameParams['type']\n },\n ) => SchemaNames\n getSchemas: (operation: Operation, params?: { pluginKey?: Plugin['key']; type?: ResolveNameParams['type'] }) => OperationSchemas\n getGroup: (operation: Operation) => FileMeta['group'] | undefined\n}\n\n/**\n * `useOperationManager` will return some helper functions that can be used to get the operation file, get the operation name.\n */\nexport function useOperationManager(): UseOperationManagerResult {\n const { plugin, pluginManager } = useApp()\n const { generator } = useContext(Oas.Context)\n\n const getName: UseOperationManagerResult['getName'] = (operation, { prefix = '', suffix = '', pluginKey = plugin.key, type }) => {\n return pluginManager.resolveName({\n name: `${prefix} ${operation.getOperationId()} ${suffix}`,\n pluginKey,\n type,\n })\n }\n\n const getGroup: UseOperationManagerResult['getGroup'] = (operation) => {\n return {\n tag: operation.getTags().at(0)?.name,\n path: operation.path,\n }\n }\n\n const getSchemas: UseOperationManagerResult['getSchemas'] = (operation, params) => {\n if (!generator) {\n throw new Error(`'generator' is not defined`)\n }\n\n return generator.getSchemas(operation, {\n resolveName: (name) =>\n pluginManager.resolveName({\n name,\n pluginKey: params?.pluginKey,\n type: params?.type,\n }),\n })\n }\n\n const getFile: UseOperationManagerResult['getFile'] = (operation, { prefix, suffix, pluginKey = plugin.key, extname = '.ts' } = {}) => {\n const name = getName(operation, { type: 'file', pluginKey, prefix, suffix })\n const group = getGroup(operation)\n\n const file = pluginManager.getFile({\n name,\n extname,\n pluginKey,\n options: { type: 'file', pluginKey, group },\n })\n\n return {\n ...file,\n meta: {\n ...file.meta,\n name,\n pluginKey,\n group,\n },\n }\n }\n\n const groupSchemasByName: UseOperationManagerResult['groupSchemasByName'] = (operation, { pluginKey = plugin.key, type }) => {\n if (!generator) {\n throw new Error(`'generator' is not defined`)\n }\n\n const schemas = generator.getSchemas(operation)\n\n const errors = (schemas.errors || []).reduce(\n (prev, acc) => {\n if (!acc.statusCode) {\n return prev\n }\n\n prev[acc.statusCode] = pluginManager.resolveName({\n name: acc.name,\n pluginKey,\n type,\n })\n\n return prev\n },\n {} as Record<number, string>,\n )\n\n const responses = (schemas.responses || []).reduce(\n (prev, acc) => {\n if (!acc.statusCode) {\n return prev\n }\n\n prev[acc.statusCode] = pluginManager.resolveName({\n name: acc.name,\n pluginKey,\n type,\n })\n\n return prev\n },\n {} as Record<number, string>,\n )\n\n return {\n request: schemas.request?.name\n ? pluginManager.resolveName({\n name: schemas.request.name,\n pluginKey,\n type,\n })\n : undefined,\n parameters: {\n path: schemas.pathParams?.name\n ? pluginManager.resolveName({\n name: schemas.pathParams.name,\n pluginKey,\n type,\n })\n : undefined,\n query: schemas.queryParams?.name\n ? pluginManager.resolveName({\n name: schemas.queryParams.name,\n pluginKey,\n type,\n })\n : undefined,\n header: schemas.headerParams?.name\n ? pluginManager.resolveName({\n name: schemas.headerParams.name,\n pluginKey,\n type,\n })\n : undefined,\n },\n responses: {\n ...responses,\n ['default']: pluginManager.resolveName({\n name: schemas.response.name,\n pluginKey,\n type,\n }),\n ...errors,\n },\n errors,\n }\n }\n\n return {\n getName,\n getFile,\n getSchemas,\n groupSchemasByName,\n getGroup,\n }\n}\n","import { useContext } from '@kubb/react'\n\nimport { Oas } from '../components/Oas.tsx'\n\nimport type { HttpMethod, Operation } from '@kubb/oas'\n\ntype UseOperationsProps = {\n /**\n * Filter based on path\n * Weight: 2\n */\n path?: string\n /**\n * Filter based on method\n * Weight: 1\n */\n method?: HttpMethod\n}\n\n/**\n * `useOperations` will return all the Operations\n */\nexport function useOperations({ method, path }: UseOperationsProps = {}): Operation[] {\n const { operations } = useContext(Oas.Context)\n\n if (!operations) {\n throw new Error('Operations is not defined')\n }\n let items = operations\n\n if (path) {\n items = items.filter((item) => item.path === path)\n }\n\n if (method) {\n items = items.filter((item) => item.method === method)\n }\n\n return items\n}\n","import { useContext } from '@kubb/react'\n\nimport { Schema } from '../components/Schema.tsx'\n\nimport type { SchemaContextProps } from '../components/Schema.tsx'\n\ntype UseSchemaResult = SchemaContextProps\n\n/**\n * `useSchema` will return the current `schema properties`\n */\nexport function useSchema(): UseSchemaResult {\n const props = useContext(Schema.Context)\n\n return props as UseSchemaResult\n}\n","import { useApp } from '@kubb/react'\n\nimport type { FileMetaBase, Plugin, ResolveNameParams } from '@kubb/core'\nimport type { KubbFile } from '@kubb/core/fs'\nimport { SchemaGenerator } from '../SchemaGenerator.ts'\nimport { type Schema, schemaKeywords } from '../SchemaMapper'\n\ntype FileMeta = FileMetaBase & {\n pluginKey: Plugin['key']\n name: string\n group?: {\n tag?: string\n path?: string\n }\n}\n\ntype UseSchemaManagerResult = {\n getName: (name: string, params: { pluginKey?: Plugin['key']; type: ResolveNameParams['type'] }) => string\n getFile: (\n name: string,\n params?: {\n pluginKey?: Plugin['key']\n mode?: KubbFile.Mode\n extname?: KubbFile.Extname\n group?: {\n tag?: string\n path?: string\n }\n },\n ) => KubbFile.File<FileMeta>\n getImports: (tree: Array<Schema>) => Array<KubbFile.Import>\n}\n\n/**\n * `useSchemaManager` will return some helper functions that can be used to get the schema file, get the schema name.\n */\nexport function useSchemaManager(): UseSchemaManagerResult {\n const { plugin, pluginManager } = useApp()\n\n const getName: UseSchemaManagerResult['getName'] = (name, { pluginKey = plugin.key, type }) => {\n return pluginManager.resolveName({\n name,\n pluginKey,\n type,\n })\n }\n\n const getFile: UseSchemaManagerResult['getFile'] = (name, { mode = 'split', pluginKey = plugin.key, extname = '.ts', group } = {}) => {\n const resolvedName = mode === 'single' ? '' : getName(name, { type: 'file', pluginKey })\n\n const file = pluginManager.getFile({\n name: resolvedName,\n extname,\n pluginKey,\n options: { type: 'file', pluginKey, group },\n })\n\n return {\n ...file,\n meta: {\n ...file.meta,\n name: resolvedName,\n pluginKey,\n },\n }\n }\n\n const getImports: UseSchemaManagerResult['getImports'] = (tree) => {\n const refs = SchemaGenerator.deepSearch(tree, schemaKeywords.ref)\n\n return refs\n ?.map((item) => {\n if (!item.args.path || !item.args.isImportable) {\n return undefined\n }\n\n return {\n name: [item.args.name],\n path: item.args.path,\n }\n })\n .filter(Boolean)\n }\n\n return {\n getName,\n getFile,\n getImports,\n }\n}\n"]}
1
+ {"version":3,"file":"hooks.cjs","names":["Oas","Operation","Oas","getName: UseOperationManagerResult['getName']","getGroup: UseOperationManagerResult['getGroup']","getSchemas: UseOperationManagerResult['getSchemas']","getFile: UseOperationManagerResult['getFile']","groupSchemasByName: UseOperationManagerResult['groupSchemasByName']","Oas","Schema","getName: UseSchemaManagerResult['getName']","getFile: UseSchemaManagerResult['getFile']","getImports: UseSchemaManagerResult['getImports']","SchemaGenerator","schemaKeywords"],"sources":["../src/hooks/useOas.ts","../src/hooks/useOperation.ts","../src/hooks/useOperationManager.ts","../src/hooks/useOperations.ts","../src/hooks/useSchema.ts","../src/hooks/useSchemaManager.ts"],"sourcesContent":["import { useContext } from '@kubb/react'\n\nimport { Oas } from '../components/Oas.tsx'\n\nimport type { Oas as OasType } from '@kubb/oas'\n\nexport function useOas(): OasType {\n const { oas } = useContext(Oas.Context)\n\n if (!oas) {\n throw new Error('Oas is not defined')\n }\n\n return oas\n}\n","import { useContext } from '@kubb/react'\n\nimport { Operation } from '../components/Operation.tsx'\n\nimport type { Operation as OperationType } from '@kubb/oas'\n\n/**\n * `useOperation` will return the current `Operation`\n */\nexport function useOperation(): OperationType {\n const { operation } = useContext(Operation.Context)\n\n if (!operation) {\n throw new Error('Operation is not defined')\n }\n\n return operation\n}\n","import { useApp, useContext } from '@kubb/react'\n\nimport { Oas } from '../components/Oas.tsx'\n\nimport type { FileMetaBase, Plugin, ResolveNameParams } from '@kubb/core'\n\nimport type { KubbFile } from '@kubb/core/fs'\nimport type { Operation, Operation as OperationType } from '@kubb/oas'\nimport type { OperationSchemas } from '../types.ts'\n\ntype FileMeta = FileMetaBase & {\n pluginKey: Plugin['key']\n name: string\n group?: {\n tag?: string\n path?: string\n }\n}\n\nexport type SchemaNames = {\n request: string | undefined\n parameters: {\n path: string | undefined\n query: string | undefined\n header: string | undefined\n }\n responses: { default?: string } & Record<number | string, string>\n errors: Record<number | string, string>\n}\n\ntype UseOperationManagerResult = {\n getName: (\n operation: OperationType,\n params: {\n prefix?: string\n suffix?: string\n pluginKey?: Plugin['key']\n type: ResolveNameParams['type']\n },\n ) => string\n getFile: (\n operation: OperationType,\n params?: {\n prefix?: string\n suffix?: string\n pluginKey?: Plugin['key']\n extname?: KubbFile.Extname\n group?: {\n tag?: string\n path?: string\n }\n },\n ) => KubbFile.File<FileMeta>\n groupSchemasByName: (\n operation: OperationType,\n params: {\n pluginKey?: Plugin['key']\n type: ResolveNameParams['type']\n },\n ) => SchemaNames\n getSchemas: (operation: Operation, params?: { pluginKey?: Plugin['key']; type?: ResolveNameParams['type'] }) => OperationSchemas\n getGroup: (operation: Operation) => FileMeta['group'] | undefined\n}\n\n/**\n * `useOperationManager` will return some helper functions that can be used to get the operation file, get the operation name.\n */\nexport function useOperationManager(): UseOperationManagerResult {\n const { plugin, pluginManager } = useApp()\n const { generator } = useContext(Oas.Context)\n\n const getName: UseOperationManagerResult['getName'] = (operation, { prefix = '', suffix = '', pluginKey = plugin.key, type }) => {\n return pluginManager.resolveName({\n name: `${prefix} ${operation.getOperationId()} ${suffix}`,\n pluginKey,\n type,\n })\n }\n\n const getGroup: UseOperationManagerResult['getGroup'] = (operation) => {\n return {\n tag: operation.getTags().at(0)?.name,\n path: operation.path,\n }\n }\n\n const getSchemas: UseOperationManagerResult['getSchemas'] = (operation, params) => {\n if (!generator) {\n throw new Error(`'generator' is not defined`)\n }\n\n return generator.getSchemas(operation, {\n resolveName: (name) =>\n pluginManager.resolveName({\n name,\n pluginKey: params?.pluginKey,\n type: params?.type,\n }),\n })\n }\n\n const getFile: UseOperationManagerResult['getFile'] = (operation, { prefix, suffix, pluginKey = plugin.key, extname = '.ts' } = {}) => {\n const name = getName(operation, { type: 'file', pluginKey, prefix, suffix })\n const group = getGroup(operation)\n\n const file = pluginManager.getFile({\n name,\n extname,\n pluginKey,\n options: { type: 'file', pluginKey, group },\n })\n\n return {\n ...file,\n meta: {\n ...file.meta,\n name,\n pluginKey,\n group,\n },\n }\n }\n\n const groupSchemasByName: UseOperationManagerResult['groupSchemasByName'] = (operation, { pluginKey = plugin.key, type }) => {\n if (!generator) {\n throw new Error(`'generator' is not defined`)\n }\n\n const schemas = generator.getSchemas(operation)\n\n const errors = (schemas.errors || []).reduce(\n (prev, acc) => {\n if (!acc.statusCode) {\n return prev\n }\n\n prev[acc.statusCode] = pluginManager.resolveName({\n name: acc.name,\n pluginKey,\n type,\n })\n\n return prev\n },\n {} as Record<number, string>,\n )\n\n const responses = (schemas.responses || []).reduce(\n (prev, acc) => {\n if (!acc.statusCode) {\n return prev\n }\n\n prev[acc.statusCode] = pluginManager.resolveName({\n name: acc.name,\n pluginKey,\n type,\n })\n\n return prev\n },\n {} as Record<number, string>,\n )\n\n return {\n request: schemas.request?.name\n ? pluginManager.resolveName({\n name: schemas.request.name,\n pluginKey,\n type,\n })\n : undefined,\n parameters: {\n path: schemas.pathParams?.name\n ? pluginManager.resolveName({\n name: schemas.pathParams.name,\n pluginKey,\n type,\n })\n : undefined,\n query: schemas.queryParams?.name\n ? pluginManager.resolveName({\n name: schemas.queryParams.name,\n pluginKey,\n type,\n })\n : undefined,\n header: schemas.headerParams?.name\n ? pluginManager.resolveName({\n name: schemas.headerParams.name,\n pluginKey,\n type,\n })\n : undefined,\n },\n responses: {\n ...responses,\n ['default']: pluginManager.resolveName({\n name: schemas.response.name,\n pluginKey,\n type,\n }),\n ...errors,\n },\n errors,\n }\n }\n\n return {\n getName,\n getFile,\n getSchemas,\n groupSchemasByName,\n getGroup,\n }\n}\n","import { useContext } from '@kubb/react'\n\nimport { Oas } from '../components/Oas.tsx'\n\nimport type { HttpMethod, Operation } from '@kubb/oas'\n\ntype UseOperationsProps = {\n /**\n * Filter based on path\n * Weight: 2\n */\n path?: string\n /**\n * Filter based on method\n * Weight: 1\n */\n method?: HttpMethod\n}\n\n/**\n * `useOperations` will return all the Operations\n */\nexport function useOperations({ method, path }: UseOperationsProps = {}): Operation[] {\n const { operations } = useContext(Oas.Context)\n\n if (!operations) {\n throw new Error('Operations is not defined')\n }\n let items = operations\n\n if (path) {\n items = items.filter((item) => item.path === path)\n }\n\n if (method) {\n items = items.filter((item) => item.method === method)\n }\n\n return items\n}\n","import { useContext } from '@kubb/react'\n\nimport { Schema } from '../components/Schema.tsx'\n\nimport type { SchemaContextProps } from '../components/Schema.tsx'\n\ntype UseSchemaResult = SchemaContextProps\n\n/**\n * `useSchema` will return the current `schema properties`\n */\nexport function useSchema(): UseSchemaResult {\n const props = useContext(Schema.Context)\n\n return props as UseSchemaResult\n}\n","import { useApp } from '@kubb/react'\n\nimport type { FileMetaBase, Plugin, ResolveNameParams } from '@kubb/core'\nimport type { KubbFile } from '@kubb/core/fs'\nimport { SchemaGenerator } from '../SchemaGenerator.ts'\nimport { type Schema, schemaKeywords } from '../SchemaMapper'\n\ntype FileMeta = FileMetaBase & {\n pluginKey: Plugin['key']\n name: string\n group?: {\n tag?: string\n path?: string\n }\n}\n\ntype UseSchemaManagerResult = {\n getName: (name: string, params: { pluginKey?: Plugin['key']; type: ResolveNameParams['type'] }) => string\n getFile: (\n name: string,\n params?: {\n pluginKey?: Plugin['key']\n mode?: KubbFile.Mode\n extname?: KubbFile.Extname\n group?: {\n tag?: string\n path?: string\n }\n },\n ) => KubbFile.File<FileMeta>\n getImports: (tree: Array<Schema>) => Array<KubbFile.Import>\n}\n\n/**\n * `useSchemaManager` will return some helper functions that can be used to get the schema file, get the schema name.\n */\nexport function useSchemaManager(): UseSchemaManagerResult {\n const { plugin, pluginManager } = useApp()\n\n const getName: UseSchemaManagerResult['getName'] = (name, { pluginKey = plugin.key, type }) => {\n return pluginManager.resolveName({\n name,\n pluginKey,\n type,\n })\n }\n\n const getFile: UseSchemaManagerResult['getFile'] = (name, { mode = 'split', pluginKey = plugin.key, extname = '.ts', group } = {}) => {\n const resolvedName = mode === 'single' ? '' : getName(name, { type: 'file', pluginKey })\n\n const file = pluginManager.getFile({\n name: resolvedName,\n extname,\n pluginKey,\n options: { type: 'file', pluginKey, group },\n })\n\n return {\n ...file,\n meta: {\n ...file.meta,\n name: resolvedName,\n pluginKey,\n },\n }\n }\n\n const getImports: UseSchemaManagerResult['getImports'] = (tree) => {\n const refs = SchemaGenerator.deepSearch(tree, schemaKeywords.ref)\n\n return refs\n ?.map((item) => {\n if (!item.args.path || !item.args.isImportable) {\n return undefined\n }\n\n return {\n name: [item.args.name],\n path: item.args.path,\n }\n })\n .filter(Boolean)\n }\n\n return {\n getName,\n getFile,\n getImports,\n }\n}\n"],"mappings":";;;;;;;;AAMA,SAAgB,SAAkB;CAChC,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