@kubb/plugin-oas 4.4.1 → 4.5.1

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 (102) hide show
  1. package/dist/{SchemaGenerator-b7XixzRv.js → SchemaGenerator-BwYbrh7a.js} +93 -36
  2. package/dist/SchemaGenerator-BwYbrh7a.js.map +1 -0
  3. package/dist/{SchemaGenerator-DWj6buY0.cjs → SchemaGenerator-C81yEgKY.cjs} +114 -37
  4. package/dist/SchemaGenerator-C81yEgKY.cjs.map +1 -0
  5. package/dist/{SchemaMapper-DoL-a6qq.cjs → SchemaMapper-BUV8vhg0.cjs} +1 -1
  6. package/dist/SchemaMapper-BUV8vhg0.cjs.map +1 -0
  7. package/dist/{SchemaMapper-CtfTw3hq.d.ts → SchemaMapper-CgGWx6jF.d.cts} +14 -2
  8. package/dist/{SchemaMapper-CX7sIIuZ.d.cts → SchemaMapper-Cj3vjPGs.d.ts} +14 -2
  9. package/dist/{SchemaMapper-Cx4X1al6.js → SchemaMapper-D30tqRoX.js} +1 -1
  10. package/dist/SchemaMapper-D30tqRoX.js.map +1 -0
  11. package/dist/{OperationGenerator-CRZpkIpZ.d.ts → createGenerator-BvCDyuKS.d.ts} +112 -176
  12. package/dist/{OperationGenerator-S_1PevQN.d.cts → createGenerator-CPNglV1d.d.cts} +113 -177
  13. package/dist/{generators-C61FxVIj.js → generators-CJDEf8Kn.js} +6 -6
  14. package/dist/{generators-C61FxVIj.js.map → generators-CJDEf8Kn.js.map} +1 -1
  15. package/dist/{generators-B27La9Vd.cjs → generators-udGOxdUV.cjs} +6 -6
  16. package/dist/{generators-B27La9Vd.cjs.map → generators-udGOxdUV.cjs.map} +1 -1
  17. package/dist/generators.cjs +2 -7
  18. package/dist/generators.d.cts +8 -3
  19. package/dist/generators.d.ts +8 -3
  20. package/dist/generators.js +3 -5
  21. package/dist/{getFooter-D5MdeUVv.js → getFooter-CV73pVXj.js} +2 -2
  22. package/dist/{getFooter-D5MdeUVv.js.map → getFooter-CV73pVXj.js.map} +1 -1
  23. package/dist/{getFooter-CwjCW4h5.cjs → getFooter-DPh4lxBH.cjs} +3 -3
  24. package/dist/{getFooter-CwjCW4h5.cjs.map → getFooter-DPh4lxBH.cjs.map} +1 -1
  25. package/dist/getSchemas-32BHoMO-.js +100 -0
  26. package/dist/getSchemas-32BHoMO-.js.map +1 -0
  27. package/dist/getSchemas-Cl0TZ4XY.cjs +113 -0
  28. package/dist/getSchemas-Cl0TZ4XY.cjs.map +1 -0
  29. package/dist/hooks.cjs +4 -29
  30. package/dist/hooks.cjs.map +1 -1
  31. package/dist/hooks.d.cts +4 -18
  32. package/dist/hooks.d.ts +4 -18
  33. package/dist/hooks.js +6 -29
  34. package/dist/hooks.js.map +1 -1
  35. package/dist/index.cjs +37 -32
  36. package/dist/index.cjs.map +1 -1
  37. package/dist/index.d.cts +58 -3
  38. package/dist/index.d.ts +58 -3
  39. package/dist/index.js +32 -24
  40. package/dist/index.js.map +1 -1
  41. package/dist/mocks.cjs +1 -1
  42. package/dist/mocks.d.cts +1 -1
  43. package/dist/mocks.d.ts +1 -1
  44. package/dist/mocks.js +1 -1
  45. package/dist/{parseFromConfig-CqiiLCPe.js → parseFromConfig-BkUoWC2U.js} +1 -1
  46. package/dist/parseFromConfig-BkUoWC2U.js.map +1 -0
  47. package/dist/{parseFromConfig-RR31a98-.cjs → parseFromConfig-EjsCZ0-8.cjs} +1 -1
  48. package/dist/parseFromConfig-EjsCZ0-8.cjs.map +1 -0
  49. package/dist/utils.cjs +3 -3
  50. package/dist/utils.cjs.map +1 -1
  51. package/dist/utils.d.cts +28 -24
  52. package/dist/utils.d.ts +28 -24
  53. package/dist/utils.js +3 -3
  54. package/dist/utils.js.map +1 -1
  55. package/package.json +5 -12
  56. package/src/OperationGenerator.ts +26 -13
  57. package/src/SchemaGenerator.ts +24 -46
  58. package/src/SchemaMapper.ts +2 -0
  59. package/src/generators/index.ts +0 -1
  60. package/src/generators/jsonGenerator.ts +4 -4
  61. package/src/generators/types.ts +13 -14
  62. package/src/hooks/index.ts +0 -2
  63. package/src/hooks/useOperationManager.ts +2 -4
  64. package/src/index.ts +1 -1
  65. package/src/utils/getBanner.ts +1 -1
  66. package/src/utils/getParams.ts +1 -2
  67. package/src/utils/getSchemaFactory.ts +1 -2
  68. package/src/utils/getSchemas.ts +89 -15
  69. package/src/utils/index.ts +3 -4
  70. package/src/utils/parseFromConfig.ts +2 -6
  71. package/src/utils.tsx +101 -0
  72. package/dist/Oas-CHC1IC5D.js +0 -56
  73. package/dist/Oas-CHC1IC5D.js.map +0 -1
  74. package/dist/Oas-CQrRP_NH.cjs +0 -76
  75. package/dist/Oas-CQrRP_NH.cjs.map +0 -1
  76. package/dist/Schema-CZsDEhET.d.cts +0 -38
  77. package/dist/Schema-DBvtiLS7.d.ts +0 -38
  78. package/dist/SchemaGenerator-DWj6buY0.cjs.map +0 -1
  79. package/dist/SchemaGenerator-b7XixzRv.js.map +0 -1
  80. package/dist/SchemaMapper-Cx4X1al6.js.map +0 -1
  81. package/dist/SchemaMapper-DoL-a6qq.cjs.map +0 -1
  82. package/dist/components.cjs +0 -5
  83. package/dist/components.d.cts +0 -38
  84. package/dist/components.d.ts +0 -38
  85. package/dist/components.js +0 -3
  86. package/dist/getSchemas-Bdg6n9Qk.js +0 -55
  87. package/dist/getSchemas-Bdg6n9Qk.js.map +0 -1
  88. package/dist/getSchemas-DY8s2CSl.cjs +0 -68
  89. package/dist/getSchemas-DY8s2CSl.cjs.map +0 -1
  90. package/dist/parseFromConfig-CqiiLCPe.js.map +0 -1
  91. package/dist/parseFromConfig-RR31a98-.cjs.map +0 -1
  92. package/dist/utils-DYf-j63H.cjs +0 -115
  93. package/dist/utils-DYf-j63H.cjs.map +0 -1
  94. package/dist/utils-DaV25sy8.js +0 -95
  95. package/dist/utils-DaV25sy8.js.map +0 -1
  96. package/src/components/Oas.tsx +0 -30
  97. package/src/components/Operation.tsx +0 -20
  98. package/src/components/Schema.tsx +0 -38
  99. package/src/components/index.ts +0 -3
  100. package/src/generators/utils.tsx +0 -114
  101. package/src/hooks/useOperation.ts +0 -18
  102. package/src/hooks/useSchema.ts +0 -16
@@ -0,0 +1,100 @@
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
+ /**
24
+ * Collect all schema $ref dependencies recursively.
25
+ */
26
+ function collectRefs(schema, refs = /* @__PURE__ */ new Set()) {
27
+ if (Array.isArray(schema)) {
28
+ for (const item of schema) collectRefs(item, refs);
29
+ return refs;
30
+ }
31
+ if (schema && typeof schema === "object") for (const [key, value] of Object.entries(schema)) if (key === "$ref" && typeof value === "string") {
32
+ const match = value.match(/^#\/components\/schemas\/(.+)$/);
33
+ if (match) refs.add(match[1]);
34
+ } else collectRefs(value, refs);
35
+ return refs;
36
+ }
37
+ /**
38
+ * Sort schemas topologically so referenced schemas appear first.
39
+ */
40
+ function sortSchemas(schemas) {
41
+ const deps = /* @__PURE__ */ new Map();
42
+ for (const [name, schema] of Object.entries(schemas)) deps.set(name, Array.from(collectRefs(schema)));
43
+ const sorted = [];
44
+ const visited = /* @__PURE__ */ new Set();
45
+ function visit(name, stack = /* @__PURE__ */ new Set()) {
46
+ if (visited.has(name)) return;
47
+ if (stack.has(name)) return;
48
+ stack.add(name);
49
+ const children = deps.get(name) || [];
50
+ for (const child of children) if (deps.has(child)) visit(child, stack);
51
+ stack.delete(name);
52
+ visited.add(name);
53
+ sorted.push(name);
54
+ }
55
+ for (const name of Object.keys(schemas)) visit(name);
56
+ const sortedSchemas = {};
57
+ for (const name of sorted) sortedSchemas[name] = schemas[name];
58
+ return sortedSchemas;
59
+ }
60
+ /**
61
+ * Collect schemas from OpenAPI components (schemas, responses, requestBodies)
62
+ * and return them in dependency order.
63
+ */
64
+ function getSchemas({ oas, contentType, includes = [
65
+ "schemas",
66
+ "requestBodies",
67
+ "responses"
68
+ ] }) {
69
+ const components = oas.getDefinition().components;
70
+ let schemas = {};
71
+ if (includes.includes("schemas")) schemas = {
72
+ ...schemas,
73
+ ...components?.schemas || {}
74
+ };
75
+ if (includes.includes("responses")) {
76
+ const responses = components?.responses || {};
77
+ for (const [name, response] of Object.entries(responses)) {
78
+ const r = response;
79
+ if (r.content && !schemas[name]) {
80
+ const firstContentType = Object.keys(r.content)[0] || "application/json";
81
+ schemas[name] = r.content?.[contentType || firstContentType]?.schema;
82
+ }
83
+ }
84
+ }
85
+ if (includes.includes("requestBodies")) {
86
+ const requestBodies = components?.requestBodies || {};
87
+ for (const [name, request] of Object.entries(requestBodies)) {
88
+ const r = request;
89
+ if (r.content && !schemas[name]) {
90
+ const firstContentType = Object.keys(r.content)[0] || "application/json";
91
+ schemas[name] = r.content?.[contentType || firstContentType]?.schema;
92
+ }
93
+ }
94
+ }
95
+ return sortSchemas(schemas);
96
+ }
97
+
98
+ //#endregion
99
+ export { getSchemaFactory as n, getSchemas as t };
100
+ //# sourceMappingURL=getSchemas-32BHoMO-.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getSchemas-32BHoMO-.js","names":["sorted: string[]","sortedSchemas: Record<string, OasTypes.SchemaObject>","schemas: Record<string, OasTypes.SchemaObject>"],"sources":["../src/utils/getSchemaFactory.ts","../src/utils/getSchemas.ts"],"sourcesContent":["import type { Oas, OpenAPIV3, OpenAPIV3_1, SchemaObject } from '@kubb/oas'\nimport { isOpenApiV3_1Document } 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 { contentType, Oas, OasTypes } from '@kubb/oas'\n\ntype Mode = 'schemas' | 'responses' | 'requestBodies'\n\ntype GetSchemasProps = {\n oas: Oas\n contentType?: contentType\n includes?: Mode[]\n}\n\n/**\n * Collect all schema $ref dependencies recursively.\n */\nfunction collectRefs(schema: unknown, refs = new Set<string>()): Set<string> {\n if (Array.isArray(schema)) {\n for (const item of schema) {\n collectRefs(item, refs)\n }\n return refs\n }\n\n if (schema && typeof schema === 'object') {\n for (const [key, value] of Object.entries(schema)) {\n if (key === '$ref' && typeof value === 'string') {\n const match = value.match(/^#\\/components\\/schemas\\/(.+)$/)\n if (match) {\n refs.add(match[1]!)\n }\n } else {\n collectRefs(value, refs)\n }\n }\n }\n\n return refs\n}\n\n/**\n * Sort schemas topologically so referenced schemas appear first.\n */\nfunction sortSchemas(schemas: Record<string, OasTypes.SchemaObject>): Record<string, OasTypes.SchemaObject> {\n const deps = new Map<string, string[]>()\n\n for (const [name, schema] of Object.entries(schemas)) {\n deps.set(name, Array.from(collectRefs(schema)))\n }\n\n const sorted: string[] = []\n const visited = new Set<string>()\n\n function visit(name: string, stack = new Set<string>()) {\n if (visited.has(name)) {\n return\n }\n if (stack.has(name)) {\n return\n } // circular refs, ignore\n stack.add(name)\n const children = deps.get(name) || []\n for (const child of children) {\n if (deps.has(child)) {\n visit(child, stack)\n }\n }\n stack.delete(name)\n visited.add(name)\n sorted.push(name)\n }\n\n for (const name of Object.keys(schemas)) {\n visit(name)\n }\n\n const sortedSchemas: Record<string, OasTypes.SchemaObject> = {}\n for (const name of sorted) {\n sortedSchemas[name] = schemas[name]!\n }\n return sortedSchemas\n}\n\n/**\n * Collect schemas from OpenAPI components (schemas, responses, requestBodies)\n * and return them in dependency order.\n */\nexport function getSchemas({ oas, contentType, includes = ['schemas', 'requestBodies', 'responses'] }: GetSchemasProps): Record<string, OasTypes.SchemaObject> {\n const components = oas.getDefinition().components\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 if (includes.includes('responses')) {\n const responses = components?.responses || {}\n for (const [name, response] of Object.entries(responses)) {\n const r = response as OasTypes.ResponseObject\n if (r.content && !schemas[name]) {\n const firstContentType = Object.keys(r.content)[0] || 'application/json'\n schemas[name] = r.content?.[contentType || firstContentType]?.schema as OasTypes.SchemaObject\n }\n }\n }\n\n if (includes.includes('requestBodies')) {\n const requestBodies = components?.requestBodies || {}\n for (const [name, request] of Object.entries(requestBodies)) {\n const r = request as OasTypes.RequestBodyObject\n if (r.content && !schemas[name]) {\n const firstContentType = Object.keys(r.content)[0] || 'application/json'\n schemas[name] = r.content?.[contentType || firstContentType]?.schema as OasTypes.SchemaObject\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AK,MAAM,QAAQ,OAAO,KAAK,QAAQ,CACrC,OAAM,KAAK;CAGb,MAAMC,gBAAuD,EAAE;AAC/D,MAAK,MAAM,QAAQ,OACjB,eAAc,QAAQ,QAAQ;AAEhC,QAAO;;;;;;AAOT,SAAgB,WAAW,EAAE,KAAK,aAAa,WAAW;CAAC;CAAW;CAAiB;CAAY,IAA4D;CAC7J,MAAM,aAAa,IAAI,eAAe,CAAC;CACvC,IAAIC,UAAiD,EAAE;AAEvD,KAAI,SAAS,SAAS,UAAU,CAC9B,WAAU;EACR,GAAG;EACH,GAAK,YAAY,WAAqD,EAAE;EACzE;AAGH,KAAI,SAAS,SAAS,YAAY,EAAE;EAClC,MAAM,YAAY,YAAY,aAAa,EAAE;AAC7C,OAAK,MAAM,CAAC,MAAM,aAAa,OAAO,QAAQ,UAAU,EAAE;GACxD,MAAM,IAAI;AACV,OAAI,EAAE,WAAW,CAAC,QAAQ,OAAO;IAC/B,MAAM,mBAAmB,OAAO,KAAK,EAAE,QAAQ,CAAC,MAAM;AACtD,YAAQ,QAAQ,EAAE,UAAU,eAAe,mBAAmB;;;;AAKpE,KAAI,SAAS,SAAS,gBAAgB,EAAE;EACtC,MAAM,gBAAgB,YAAY,iBAAiB,EAAE;AACrD,OAAK,MAAM,CAAC,MAAM,YAAY,OAAO,QAAQ,cAAc,EAAE;GAC3D,MAAM,IAAI;AACV,OAAI,EAAE,WAAW,CAAC,QAAQ,OAAO;IAC/B,MAAM,mBAAmB,OAAO,KAAK,EAAE,QAAQ,CAAC,MAAM;AACtD,YAAQ,QAAQ,EAAE,UAAU,eAAe,mBAAmB;;;;AAKpE,QAAO,YAAY,QAAQ"}
@@ -0,0 +1,113 @@
1
+ const require_chunk = require('./chunk-CUT6urMc.cjs');
2
+ let __kubb_oas = require("@kubb/oas");
3
+ __kubb_oas = require_chunk.__toESM(__kubb_oas);
4
+
5
+ //#region src/utils/getSchemaFactory.ts
6
+ /**
7
+ * Creates a factory function that generates a versioned OpenAPI schema result.
8
+ *
9
+ * 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').
10
+ *
11
+ * @returns A function that takes an optional schema and returns a versioned schema result.
12
+ */
13
+ function getSchemaFactory(oas) {
14
+ return (schema) => {
15
+ const version = (0, __kubb_oas.isOpenApiV3_1Document)(oas.api) ? "3.1" : "3.0";
16
+ return {
17
+ schemaObject: oas.dereferenceWithRef(schema),
18
+ version
19
+ };
20
+ };
21
+ }
22
+
23
+ //#endregion
24
+ //#region src/utils/getSchemas.ts
25
+ /**
26
+ * Collect all schema $ref dependencies recursively.
27
+ */
28
+ function collectRefs(schema, refs = /* @__PURE__ */ new Set()) {
29
+ if (Array.isArray(schema)) {
30
+ for (const item of schema) collectRefs(item, refs);
31
+ return refs;
32
+ }
33
+ if (schema && typeof schema === "object") for (const [key, value] of Object.entries(schema)) if (key === "$ref" && typeof value === "string") {
34
+ const match = value.match(/^#\/components\/schemas\/(.+)$/);
35
+ if (match) refs.add(match[1]);
36
+ } else collectRefs(value, refs);
37
+ return refs;
38
+ }
39
+ /**
40
+ * Sort schemas topologically so referenced schemas appear first.
41
+ */
42
+ function sortSchemas(schemas) {
43
+ const deps = /* @__PURE__ */ new Map();
44
+ for (const [name, schema] of Object.entries(schemas)) deps.set(name, Array.from(collectRefs(schema)));
45
+ const sorted = [];
46
+ const visited = /* @__PURE__ */ new Set();
47
+ function visit(name, stack = /* @__PURE__ */ new Set()) {
48
+ if (visited.has(name)) return;
49
+ if (stack.has(name)) return;
50
+ stack.add(name);
51
+ const children = deps.get(name) || [];
52
+ for (const child of children) if (deps.has(child)) visit(child, stack);
53
+ stack.delete(name);
54
+ visited.add(name);
55
+ sorted.push(name);
56
+ }
57
+ for (const name of Object.keys(schemas)) visit(name);
58
+ const sortedSchemas = {};
59
+ for (const name of sorted) sortedSchemas[name] = schemas[name];
60
+ return sortedSchemas;
61
+ }
62
+ /**
63
+ * Collect schemas from OpenAPI components (schemas, responses, requestBodies)
64
+ * and return them in dependency order.
65
+ */
66
+ function getSchemas({ oas, contentType, includes = [
67
+ "schemas",
68
+ "requestBodies",
69
+ "responses"
70
+ ] }) {
71
+ const components = oas.getDefinition().components;
72
+ let schemas = {};
73
+ if (includes.includes("schemas")) schemas = {
74
+ ...schemas,
75
+ ...components?.schemas || {}
76
+ };
77
+ if (includes.includes("responses")) {
78
+ const responses = components?.responses || {};
79
+ for (const [name, response] of Object.entries(responses)) {
80
+ const r = response;
81
+ if (r.content && !schemas[name]) {
82
+ const firstContentType = Object.keys(r.content)[0] || "application/json";
83
+ schemas[name] = r.content?.[contentType || firstContentType]?.schema;
84
+ }
85
+ }
86
+ }
87
+ if (includes.includes("requestBodies")) {
88
+ const requestBodies = components?.requestBodies || {};
89
+ for (const [name, request] of Object.entries(requestBodies)) {
90
+ const r = request;
91
+ if (r.content && !schemas[name]) {
92
+ const firstContentType = Object.keys(r.content)[0] || "application/json";
93
+ schemas[name] = r.content?.[contentType || firstContentType]?.schema;
94
+ }
95
+ }
96
+ }
97
+ return sortSchemas(schemas);
98
+ }
99
+
100
+ //#endregion
101
+ Object.defineProperty(exports, 'getSchemaFactory', {
102
+ enumerable: true,
103
+ get: function () {
104
+ return getSchemaFactory;
105
+ }
106
+ });
107
+ Object.defineProperty(exports, 'getSchemas', {
108
+ enumerable: true,
109
+ get: function () {
110
+ return getSchemas;
111
+ }
112
+ });
113
+ //# sourceMappingURL=getSchemas-Cl0TZ4XY.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getSchemas-Cl0TZ4XY.cjs","names":["sorted: string[]","sortedSchemas: Record<string, OasTypes.SchemaObject>","schemas: Record<string, OasTypes.SchemaObject>"],"sources":["../src/utils/getSchemaFactory.ts","../src/utils/getSchemas.ts"],"sourcesContent":["import type { Oas, OpenAPIV3, OpenAPIV3_1, SchemaObject } from '@kubb/oas'\nimport { isOpenApiV3_1Document } 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 { contentType, Oas, OasTypes } from '@kubb/oas'\n\ntype Mode = 'schemas' | 'responses' | 'requestBodies'\n\ntype GetSchemasProps = {\n oas: Oas\n contentType?: contentType\n includes?: Mode[]\n}\n\n/**\n * Collect all schema $ref dependencies recursively.\n */\nfunction collectRefs(schema: unknown, refs = new Set<string>()): Set<string> {\n if (Array.isArray(schema)) {\n for (const item of schema) {\n collectRefs(item, refs)\n }\n return refs\n }\n\n if (schema && typeof schema === 'object') {\n for (const [key, value] of Object.entries(schema)) {\n if (key === '$ref' && typeof value === 'string') {\n const match = value.match(/^#\\/components\\/schemas\\/(.+)$/)\n if (match) {\n refs.add(match[1]!)\n }\n } else {\n collectRefs(value, refs)\n }\n }\n }\n\n return refs\n}\n\n/**\n * Sort schemas topologically so referenced schemas appear first.\n */\nfunction sortSchemas(schemas: Record<string, OasTypes.SchemaObject>): Record<string, OasTypes.SchemaObject> {\n const deps = new Map<string, string[]>()\n\n for (const [name, schema] of Object.entries(schemas)) {\n deps.set(name, Array.from(collectRefs(schema)))\n }\n\n const sorted: string[] = []\n const visited = new Set<string>()\n\n function visit(name: string, stack = new Set<string>()) {\n if (visited.has(name)) {\n return\n }\n if (stack.has(name)) {\n return\n } // circular refs, ignore\n stack.add(name)\n const children = deps.get(name) || []\n for (const child of children) {\n if (deps.has(child)) {\n visit(child, stack)\n }\n }\n stack.delete(name)\n visited.add(name)\n sorted.push(name)\n }\n\n for (const name of Object.keys(schemas)) {\n visit(name)\n }\n\n const sortedSchemas: Record<string, OasTypes.SchemaObject> = {}\n for (const name of sorted) {\n sortedSchemas[name] = schemas[name]!\n }\n return sortedSchemas\n}\n\n/**\n * Collect schemas from OpenAPI components (schemas, responses, requestBodies)\n * and return them in dependency order.\n */\nexport function getSchemas({ oas, contentType, includes = ['schemas', 'requestBodies', 'responses'] }: GetSchemasProps): Record<string, OasTypes.SchemaObject> {\n const components = oas.getDefinition().components\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 if (includes.includes('responses')) {\n const responses = components?.responses || {}\n for (const [name, response] of Object.entries(responses)) {\n const r = response as OasTypes.ResponseObject\n if (r.content && !schemas[name]) {\n const firstContentType = Object.keys(r.content)[0] || 'application/json'\n schemas[name] = r.content?.[contentType || firstContentType]?.schema as OasTypes.SchemaObject\n }\n }\n }\n\n if (includes.includes('requestBodies')) {\n const requestBodies = components?.requestBodies || {}\n for (const [name, request] of Object.entries(requestBodies)) {\n const r = request as OasTypes.RequestBodyObject\n if (r.content && !schemas[name]) {\n const firstContentType = Object.keys(r.content)[0] || 'application/json'\n schemas[name] = r.content?.[contentType || firstContentType]?.schema as OasTypes.SchemaObject\n }\n }\n }\n\n return sortSchemas(schemas)\n}\n"],"mappings":";;;;;;;;;;;;AA6BA,SA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AuD,EAAE;AAC/D,MAAK,MAAM,QAAQ,OACjB,eAAc,QAAQ,QAAQ;AAEhC,QAAO;;;;;;AAOT,SAAgB,WAAW,EAAE,KAAK,aAAa,WAAW;CAAC;CAAW;CAAiB;CAAY,IAA4D;CAC7J,MAAM,aAAa,IAAI,eAAe,CAAC;CACvC,IAAIC,UAAiD,EAAE;AAEvD,KAAI,SAAS,SAAS,UAAU,CAC9B,WAAU;EACR,GAAG;EACH,GAAK,YAAY,WAAqD,EAAE;EACzE;AAGH,KAAI,SAAS,SAAS,YAAY,EAAE;EAClC,MAAM,YAAY,YAAY,aAAa,EAAE;AAC7C,OAAK,MAAM,CAAC,MAAM,aAAa,OAAO,QAAQ,UAAU,EAAE;GACxD,MAAM,IAAI;AACV,OAAI,EAAE,WAAW,CAAC,QAAQ,OAAO;IAC/B,MAAM,mBAAmB,OAAO,KAAK,EAAE,QAAQ,CAAC,MAAM;AACtD,YAAQ,QAAQ,EAAE,UAAU,eAAe,mBAAmB;;;;AAKpE,KAAI,SAAS,SAAS,gBAAgB,EAAE;EACtC,MAAM,gBAAgB,YAAY,iBAAiB,EAAE;AACrD,OAAK,MAAM,CAAC,MAAM,YAAY,OAAO,QAAQ,cAAc,EAAE;GAC3D,MAAM,IAAI;AACV,OAAI,EAAE,WAAW,CAAC,QAAQ,OAAO;IAC/B,MAAM,mBAAmB,OAAO,KAAK,EAAE,QAAQ,CAAC,MAAM;AACtD,YAAQ,QAAQ,EAAE,UAAU,eAAe,mBAAmB;;;;AAKpE,QAAO,YAAY,QAAQ"}
package/dist/hooks.cjs CHANGED
@@ -1,9 +1,7 @@
1
1
  const require_chunk = require('./chunk-CUT6urMc.cjs');
2
- const require_Oas = require('./Oas-CQrRP_NH.cjs');
3
- require('./utils-DYf-j63H.cjs');
4
- const require_SchemaGenerator = require('./SchemaGenerator-DWj6buY0.cjs');
5
- const require_SchemaMapper = require('./SchemaMapper-DoL-a6qq.cjs');
6
- require('./getSchemas-DY8s2CSl.cjs');
2
+ const require_SchemaGenerator = require('./SchemaGenerator-C81yEgKY.cjs');
3
+ const require_SchemaMapper = require('./SchemaMapper-BUV8vhg0.cjs');
4
+ require('./getSchemas-Cl0TZ4XY.cjs');
7
5
  let __kubb_react_fabric = require("@kubb/react-fabric");
8
6
  __kubb_react_fabric = require_chunk.__toESM(__kubb_react_fabric);
9
7
  let __kubb_core_hooks = require("@kubb/core/hooks");
@@ -15,26 +13,14 @@ function useOas() {
15
13
  return meta.oas;
16
14
  }
17
15
 
18
- //#endregion
19
- //#region src/hooks/useOperation.ts
20
- /**
21
- * `useOperation` will return the current `Operation`
22
- */
23
- function useOperation() {
24
- const { operation } = (0, __kubb_react_fabric.useContext)(require_Oas.Operation.Context);
25
- if (!operation) throw new Error("Operation is not defined");
26
- return operation;
27
- }
28
-
29
16
  //#endregion
30
17
  //#region src/hooks/useOperationManager.ts
31
18
  /**
32
19
  * `useOperationManager` will return some helper functions that can be used to get the operation file, get the operation name.
33
20
  */
34
- function useOperationManager() {
21
+ function useOperationManager(generator) {
35
22
  const plugin = (0, __kubb_core_hooks.usePlugin)();
36
23
  const pluginManager = (0, __kubb_core_hooks.usePluginManager)();
37
- const { generator } = (0, __kubb_react_fabric.useContext)(require_Oas.Oas.Context);
38
24
  const getName = (operation, { prefix = "", suffix = "", pluginKey = plugin.key, type }) => {
39
25
  return pluginManager.resolveName({
40
26
  name: `${prefix} ${operation.getOperationId()} ${suffix}`,
@@ -149,15 +135,6 @@ function useOperationManager() {
149
135
  };
150
136
  }
151
137
 
152
- //#endregion
153
- //#region src/hooks/useSchema.ts
154
- /**
155
- * `useSchema` will return the current `schema properties`
156
- */
157
- function useSchema() {
158
- return (0, __kubb_react_fabric.useContext)(require_Oas.Schema.Context);
159
- }
160
-
161
138
  //#endregion
162
139
  //#region src/hooks/useSchemaManager.ts
163
140
  /**
@@ -215,8 +192,6 @@ function useSchemaManager() {
215
192
 
216
193
  //#endregion
217
194
  exports.useOas = useOas;
218
- exports.useOperation = useOperation;
219
195
  exports.useOperationManager = useOperationManager;
220
- exports.useSchema = useSchema;
221
196
  exports.useSchemaManager = useSchemaManager;
222
197
  //# sourceMappingURL=hooks.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"hooks.cjs","names":["Operation","Oas","getName: UseOperationManagerResult['getName']","getGroup: UseOperationManagerResult['getGroup']","getSchemas: UseOperationManagerResult['getSchemas']","getFile: UseOperationManagerResult['getFile']","groupSchemasByName: UseOperationManagerResult['groupSchemasByName']","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/useSchema.ts","../src/hooks/useSchemaManager.ts"],"sourcesContent":["import type { Oas } from '@kubb/oas'\n\nimport { useApp } from '@kubb/react-fabric'\n\nexport function useOas(): Oas {\n const { meta } = useApp<{ oas: Oas }>()\n\n return meta.oas\n}\n","import { useContext } from '@kubb/react-fabric'\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 type { FileMetaBase, Plugin, ResolveNameParams } from '@kubb/core'\nimport { usePlugin, usePluginManager } from '@kubb/core/hooks'\nimport type { KubbFile } from '@kubb/fabric-core/types'\nimport type { Operation, Operation as OperationType } from '@kubb/oas'\nimport { useContext } from '@kubb/react-fabric'\nimport { Oas } from '../components/Oas.tsx'\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 = usePlugin()\n const pluginManager = usePluginManager()\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-fabric'\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 type { FileMetaBase, Plugin, ResolveNameParams } from '@kubb/core'\nimport { usePlugin, usePluginManager } from '@kubb/core/hooks'\nimport type { KubbFile } from '@kubb/fabric-core/types'\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 = usePlugin()\n const pluginManager = usePluginManager()\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":";;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yDAAkC;CAExC,MAAMC,WAA8C,MAAM,EAAE,YAAY,OAAO,KAAK,WAAW;AAC7F,SAAO,cAAc,YAAY;GAC/B;GACA;GACA;GACD,CAAC;;CAGJ,MAAMC,WAA8C,MAAM,EAAE,OAAO,SAAS,YAAY,OAAO,KAAK,UAAU,OAAO,UAAU,EAAE,KAAK;EACpI,MAAM,eAAe,SAAS,WAAW,KAAK,QAAQ,MAAM;GAAE,MAAM;GAAQ;GAAW,CAAC;EAExF,MAAM,OAAO,cAAc,QAAQ;GACjC,MAAM;GACN;GACA;GACA,SAAS;IAAE,MAAM;IAAQ;IAAW;IAAO;GAC5C,CAAC;AAEF,SAAO;GACL,GAAG;GACH,MAAM;IACJ,GAAG,KAAK;IACR,MAAM;IACN;IACD;GACF;;CAGH,MAAMC,cAAoD,SAAS;AAGjE,SAFaC,wCAAgB,WAAW,MAAMC,oCAAe,IAAI,EAG7D,KAAK,SAAS;AACd,OAAI,CAAC,KAAK,KAAK,QAAQ,CAAC,KAAK,KAAK,aAChC;AAGF,UAAO;IACL,MAAM,CAAC,KAAK,KAAK,KAAK;IACtB,MAAM,KAAK,KAAK;IACjB;IACD,CACD,OAAO,QAAQ;;AAGpB,QAAO;EACL;EACA;EACA;EACD"}
1
+ {"version":3,"file":"hooks.cjs","names":["getName: UseOperationManagerResult['getName']","getGroup: UseOperationManagerResult['getGroup']","getSchemas: UseOperationManagerResult['getSchemas']","getFile: UseOperationManagerResult['getFile']","groupSchemasByName: UseOperationManagerResult['groupSchemasByName']","getName: UseSchemaManagerResult['getName']","getFile: UseSchemaManagerResult['getFile']","getImports: UseSchemaManagerResult['getImports']","SchemaGenerator","schemaKeywords"],"sources":["../src/hooks/useOas.ts","../src/hooks/useOperationManager.ts","../src/hooks/useSchemaManager.ts"],"sourcesContent":["import type { Oas } from '@kubb/oas'\n\nimport { useApp } from '@kubb/react-fabric'\n\nexport function useOas(): Oas {\n const { meta } = useApp<{ oas: Oas }>()\n\n return meta.oas\n}\n","import type { FileMetaBase, Plugin, ResolveNameParams } from '@kubb/core'\nimport { usePlugin, usePluginManager } from '@kubb/core/hooks'\nimport type { KubbFile } from '@kubb/fabric-core/types'\nimport type { Operation, Operation as OperationType } from '@kubb/oas'\nimport type { OperationGenerator } from '../OperationGenerator.ts'\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(generator: Omit<OperationGenerator, 'build'>): UseOperationManagerResult {\n const plugin = usePlugin()\n const pluginManager = usePluginManager()\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 type { FileMetaBase, Plugin, ResolveNameParams } from '@kubb/core'\nimport { usePlugin, usePluginManager } from '@kubb/core/hooks'\nimport type { KubbFile } from '@kubb/fabric-core/types'\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 = usePlugin()\n const pluginManager = usePluginManager()\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":";;;;;;;;;;AAIA,SAAgB,SAAc;CAC5B,MAAM,EAAE,0CAA+B;AAEvC,QAAO,KAAK;;;;;;;;ACyDd,SAAgB,oBAAoB,WAAyE;CAC3G,MAAM,2CAAoB;CAC1B,MAAM,yDAAkC;CAExC,MAAMA,WAAiD,WAAW,EAAE,SAAS,IAAI,SAAS,IAAI,YAAY,OAAO,KAAK,WAAW;AAC/H,SAAO,cAAc,YAAY;GAC/B,MAAM,GAAG,OAAO,GAAG,UAAU,gBAAgB,CAAC,GAAG;GACjD;GACA;GACD,CAAC;;CAGJ,MAAMC,YAAmD,cAAc;AACrE,SAAO;GACL,KAAK,UAAU,SAAS,CAAC,GAAG,EAAE,EAAE;GAChC,MAAM,UAAU;GACjB;;CAGH,MAAMC,cAAuD,WAAW,WAAW;AACjF,MAAI,CAAC,UACH,OAAM,IAAI,MAAM,6BAA6B;AAG/C,SAAO,UAAU,WAAW,WAAW,EACrC,cAAc,SACZ,cAAc,YAAY;GACxB;GACA,WAAW,QAAQ;GACnB,MAAM,QAAQ;GACf,CAAC,EACL,CAAC;;CAGJ,MAAMC,WAAiD,WAAW,EAAE,QAAQ,QAAQ,YAAY,OAAO,KAAK,UAAU,UAAU,EAAE,KAAK;EACrI,MAAM,OAAO,QAAQ,WAAW;GAAE,MAAM;GAAQ;GAAW;GAAQ;GAAQ,CAAC;EAC5E,MAAM,QAAQ,SAAS,UAAU;EAEjC,MAAM,OAAO,cAAc,QAAQ;GACjC;GACA;GACA;GACA,SAAS;IAAE,MAAM;IAAQ;IAAW;IAAO;GAC5C,CAAC;AAEF,SAAO;GACL,GAAG;GACH,MAAM;IACJ,GAAG,KAAK;IACR;IACA;IACA;IACD;GACF;;CAGH,MAAMC,sBAAuE,WAAW,EAAE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YAAY;GAC/B;GACA;GACA;GACD,CAAC;;CAGJ,MAAMC,WAA8C,MAAM,EAAE,OAAO,SAAS,YAAY,OAAO,KAAK,UAAU,OAAO,UAAU,EAAE,KAAK;EACpI,MAAM,eAAe,SAAS,WAAW,KAAK,QAAQ,MAAM;GAAE,MAAM;GAAQ;GAAW,CAAC;EAExF,MAAM,OAAO,cAAc,QAAQ;GACjC,MAAM;GACN;GACA;GACA,SAAS;IAAE,MAAM;IAAQ;IAAW;IAAO;GAC5C,CAAC;AAEF,SAAO;GACL,GAAG;GACH,MAAM;IACJ,GAAG,KAAK;IACR,MAAM;IACN;IACD;GACF;;CAGH,MAAMC,cAAoD,SAAS;AAGjE,SAFaC,wCAAgB,WAAW,MAAMC,oCAAe,IAAI,EAG7D,KAAK,SAAS;AACd,OAAI,CAAC,KAAK,KAAK,QAAQ,CAAC,KAAK,KAAK,aAChC;AAGF,UAAO;IACL,MAAM,CAAC,KAAK,KAAK,KAAK;IACtB,MAAM,KAAK,KAAK;IACjB;IACD,CACD,OAAO,QAAQ;;AAGpB,QAAO;EACL;EACA;EACA;EACD"}
package/dist/hooks.d.cts CHANGED
@@ -1,17 +1,10 @@
1
- import { M as Plugin, N as ResolveNameParams, P as Oas, R as Operation, k as FileMetaBase, y as OperationSchemas } from "./OperationGenerator-S_1PevQN.cjs";
2
- import { t as Schema } from "./SchemaMapper-CX7sIIuZ.cjs";
3
- import { n as SchemaContextProps } from "./Schema-CZsDEhET.cjs";
1
+ import { E as FileMetaBase, T as Oas, _ as OperationSchemas, d as OperationGenerator, j as ResolveNameParams, k as Plugin } from "./createGenerator-CPNglV1d.cjs";
2
+ import { p as Operation, t as Schema } from "./SchemaMapper-CgGWx6jF.cjs";
4
3
  import { KubbFile } from "@kubb/fabric-core/types";
5
4
 
6
5
  //#region src/hooks/useOas.d.ts
7
6
  declare function useOas(): Oas;
8
7
  //#endregion
9
- //#region src/hooks/useOperation.d.ts
10
- /**
11
- * `useOperation` will return the current `Operation`
12
- */
13
- declare function useOperation(): Operation;
14
- //#endregion
15
8
  //#region src/hooks/useOperationManager.d.ts
16
9
  type FileMeta$1 = FileMetaBase & {
17
10
  pluginKey: Plugin['key'];
@@ -63,14 +56,7 @@ type UseOperationManagerResult = {
63
56
  /**
64
57
  * `useOperationManager` will return some helper functions that can be used to get the operation file, get the operation name.
65
58
  */
66
- declare function useOperationManager(): UseOperationManagerResult;
67
- //#endregion
68
- //#region src/hooks/useSchema.d.ts
69
- type UseSchemaResult = SchemaContextProps;
70
- /**
71
- * `useSchema` will return the current `schema properties`
72
- */
73
- declare function useSchema(): UseSchemaResult;
59
+ declare function useOperationManager(generator: Omit<OperationGenerator, 'build'>): UseOperationManagerResult;
74
60
  //#endregion
75
61
  //#region src/hooks/useSchemaManager.d.ts
76
62
  type FileMeta = FileMetaBase & {
@@ -102,5 +88,5 @@ type UseSchemaManagerResult = {
102
88
  */
103
89
  declare function useSchemaManager(): UseSchemaManagerResult;
104
90
  //#endregion
105
- export { type SchemaNames, useOas, useOperation, useOperationManager, useSchema, useSchemaManager };
91
+ export { type SchemaNames, useOas, useOperationManager, useSchemaManager };
106
92
  //# sourceMappingURL=hooks.d.cts.map
package/dist/hooks.d.ts CHANGED
@@ -1,17 +1,10 @@
1
- import { M as Plugin, N as ResolveNameParams, P as Oas, R as Operation, k as FileMetaBase, y as OperationSchemas } from "./OperationGenerator-CRZpkIpZ.js";
2
- import { t as Schema } from "./SchemaMapper-CtfTw3hq.js";
3
- import { n as SchemaContextProps } from "./Schema-DBvtiLS7.js";
1
+ import { E as FileMetaBase, T as Oas, _ as OperationSchemas, d as OperationGenerator, j as ResolveNameParams, k as Plugin } from "./createGenerator-BvCDyuKS.js";
2
+ import { p as Operation, t as Schema } from "./SchemaMapper-Cj3vjPGs.js";
4
3
  import { KubbFile } from "@kubb/fabric-core/types";
5
4
 
6
5
  //#region src/hooks/useOas.d.ts
7
6
  declare function useOas(): Oas;
8
7
  //#endregion
9
- //#region src/hooks/useOperation.d.ts
10
- /**
11
- * `useOperation` will return the current `Operation`
12
- */
13
- declare function useOperation(): Operation;
14
- //#endregion
15
8
  //#region src/hooks/useOperationManager.d.ts
16
9
  type FileMeta$1 = FileMetaBase & {
17
10
  pluginKey: Plugin['key'];
@@ -63,14 +56,7 @@ type UseOperationManagerResult = {
63
56
  /**
64
57
  * `useOperationManager` will return some helper functions that can be used to get the operation file, get the operation name.
65
58
  */
66
- declare function useOperationManager(): UseOperationManagerResult;
67
- //#endregion
68
- //#region src/hooks/useSchema.d.ts
69
- type UseSchemaResult = SchemaContextProps;
70
- /**
71
- * `useSchema` will return the current `schema properties`
72
- */
73
- declare function useSchema(): UseSchemaResult;
59
+ declare function useOperationManager(generator: Omit<OperationGenerator, 'build'>): UseOperationManagerResult;
74
60
  //#endregion
75
61
  //#region src/hooks/useSchemaManager.d.ts
76
62
  type FileMeta = FileMetaBase & {
@@ -102,5 +88,5 @@ type UseSchemaManagerResult = {
102
88
  */
103
89
  declare function useSchemaManager(): UseSchemaManagerResult;
104
90
  //#endregion
105
- export { type SchemaNames, useOas, useOperation, useOperationManager, useSchema, useSchemaManager };
91
+ export { type SchemaNames, useOas, useOperationManager, useSchemaManager };
106
92
  //# sourceMappingURL=hooks.d.ts.map
package/dist/hooks.js CHANGED
@@ -1,9 +1,7 @@
1
- import { n as Schema, r as Operation, t as Oas } from "./Oas-CHC1IC5D.js";
2
- import "./utils-DaV25sy8.js";
3
- import { t as SchemaGenerator } from "./SchemaGenerator-b7XixzRv.js";
4
- import { n as schemaKeywords } from "./SchemaMapper-Cx4X1al6.js";
5
- import "./getSchemas-Bdg6n9Qk.js";
6
- import { useApp, useContext } from "@kubb/react-fabric";
1
+ import { t as SchemaGenerator } from "./SchemaGenerator-BwYbrh7a.js";
2
+ import { n as schemaKeywords } from "./SchemaMapper-D30tqRoX.js";
3
+ import "./getSchemas-32BHoMO-.js";
4
+ import { useApp } from "@kubb/react-fabric";
7
5
  import { usePlugin, usePluginManager } from "@kubb/core/hooks";
8
6
 
9
7
  //#region src/hooks/useOas.ts
@@ -12,26 +10,14 @@ function useOas() {
12
10
  return meta.oas;
13
11
  }
14
12
 
15
- //#endregion
16
- //#region src/hooks/useOperation.ts
17
- /**
18
- * `useOperation` will return the current `Operation`
19
- */
20
- function useOperation() {
21
- const { operation } = useContext(Operation.Context);
22
- if (!operation) throw new Error("Operation is not defined");
23
- return operation;
24
- }
25
-
26
13
  //#endregion
27
14
  //#region src/hooks/useOperationManager.ts
28
15
  /**
29
16
  * `useOperationManager` will return some helper functions that can be used to get the operation file, get the operation name.
30
17
  */
31
- function useOperationManager() {
18
+ function useOperationManager(generator) {
32
19
  const plugin = usePlugin();
33
20
  const pluginManager = usePluginManager();
34
- const { generator } = useContext(Oas.Context);
35
21
  const getName = (operation, { prefix = "", suffix = "", pluginKey = plugin.key, type }) => {
36
22
  return pluginManager.resolveName({
37
23
  name: `${prefix} ${operation.getOperationId()} ${suffix}`,
@@ -146,15 +132,6 @@ function useOperationManager() {
146
132
  };
147
133
  }
148
134
 
149
- //#endregion
150
- //#region src/hooks/useSchema.ts
151
- /**
152
- * `useSchema` will return the current `schema properties`
153
- */
154
- function useSchema() {
155
- return useContext(Schema.Context);
156
- }
157
-
158
135
  //#endregion
159
136
  //#region src/hooks/useSchemaManager.ts
160
137
  /**
@@ -211,5 +188,5 @@ function useSchemaManager() {
211
188
  }
212
189
 
213
190
  //#endregion
214
- export { useOas, useOperation, useOperationManager, useSchema, useSchemaManager };
191
+ export { useOas, useOperationManager, useSchemaManager };
215
192
  //# sourceMappingURL=hooks.js.map
package/dist/hooks.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"hooks.js","names":["getName: UseOperationManagerResult['getName']","getGroup: UseOperationManagerResult['getGroup']","getSchemas: UseOperationManagerResult['getSchemas']","getFile: UseOperationManagerResult['getFile']","groupSchemasByName: UseOperationManagerResult['groupSchemasByName']","getName: UseSchemaManagerResult['getName']","getFile: UseSchemaManagerResult['getFile']","getImports: UseSchemaManagerResult['getImports']"],"sources":["../src/hooks/useOas.ts","../src/hooks/useOperation.ts","../src/hooks/useOperationManager.ts","../src/hooks/useSchema.ts","../src/hooks/useSchemaManager.ts"],"sourcesContent":["import type { Oas } from '@kubb/oas'\n\nimport { useApp } from '@kubb/react-fabric'\n\nexport function useOas(): Oas {\n const { meta } = useApp<{ oas: Oas }>()\n\n return meta.oas\n}\n","import { useContext } from '@kubb/react-fabric'\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 type { FileMetaBase, Plugin, ResolveNameParams } from '@kubb/core'\nimport { usePlugin, usePluginManager } from '@kubb/core/hooks'\nimport type { KubbFile } from '@kubb/fabric-core/types'\nimport type { Operation, Operation as OperationType } from '@kubb/oas'\nimport { useContext } from '@kubb/react-fabric'\nimport { Oas } from '../components/Oas.tsx'\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 = usePlugin()\n const pluginManager = usePluginManager()\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-fabric'\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 type { FileMetaBase, Plugin, ResolveNameParams } from '@kubb/core'\nimport { usePlugin, usePluginManager } from '@kubb/core/hooks'\nimport type { KubbFile } from '@kubb/fabric-core/types'\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 = usePlugin()\n const pluginManager = usePluginManager()\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":";;;;;;;;;AAIA,SAAgB,SAAc;CAC5B,MAAM,EAAE,SAAS,QAAsB;AAEvC,QAAO,KAAK;;;;;;;;ACEd,SAAgB,eAA8B;CAC5C,MAAM,EAAE,cAAc,WAAW,UAAU,QAAQ;AAEnD,KAAI,CAAC,UACH,OAAM,IAAI,MAAM,2BAA2B;AAG7C,QAAO;;;;;;;;ACiDT,SAAgB,sBAAiD;CAC/D,MAAM,SAAS,WAAW;CAC1B,MAAM,gBAAgB,kBAAkB;CACxC,MAAM,EAAE,cAAc,WAAW,IAAI,QAAQ;CAE7C,MAAMA,WAAiD,WAAW,EAAE,SAAS,IAAI,S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AAM;IAAQ;IAAW;IAAO;GAC5C,CAAC;AAEF,SAAO;GACL,GAAG;GACH,MAAM;IACJ,GAAG,KAAK;IACR,MAAM;IACN;IACD;GACF;;CAGH,MAAMC,cAAoD,SAAS;AAGjE,SAFa,gBAAgB,WAAW,MAAM,eAAe,IAAI,EAG7D,KAAK,SAAS;AACd,OAAI,CAAC,KAAK,KAAK,QAAQ,CAAC,KAAK,KAAK,aAChC;AAGF,UAAO;IACL,MAAM,CAAC,KAAK,KAAK,KAAK;IACtB,MAAM,KAAK,KAAK;IACjB;IACD,CACD,OAAO,QAAQ;;AAGpB,QAAO;EACL;EACA;EACA;EACD"}
1
+ {"version":3,"file":"hooks.js","names":["getName: UseOperationManagerResult['getName']","getGroup: UseOperationManagerResult['getGroup']","getSchemas: UseOperationManagerResult['getSchemas']","getFile: UseOperationManagerResult['getFile']","groupSchemasByName: UseOperationManagerResult['groupSchemasByName']","getName: UseSchemaManagerResult['getName']","getFile: UseSchemaManagerResult['getFile']","getImports: UseSchemaManagerResult['getImports']"],"sources":["../src/hooks/useOas.ts","../src/hooks/useOperationManager.ts","../src/hooks/useSchemaManager.ts"],"sourcesContent":["import type { Oas } from '@kubb/oas'\n\nimport { useApp } from '@kubb/react-fabric'\n\nexport function useOas(): Oas {\n const { meta } = useApp<{ oas: Oas }>()\n\n return meta.oas\n}\n","import type { FileMetaBase, Plugin, ResolveNameParams } from '@kubb/core'\nimport { usePlugin, usePluginManager } from '@kubb/core/hooks'\nimport type { KubbFile } from '@kubb/fabric-core/types'\nimport type { Operation, Operation as OperationType } from '@kubb/oas'\nimport type { OperationGenerator } from '../OperationGenerator.ts'\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(generator: Omit<OperationGenerator, 'build'>): UseOperationManagerResult {\n const plugin = usePlugin()\n const pluginManager = usePluginManager()\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 type { FileMetaBase, Plugin, ResolveNameParams } from '@kubb/core'\nimport { usePlugin, usePluginManager } from '@kubb/core/hooks'\nimport type { KubbFile } from '@kubb/fabric-core/types'\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 = usePlugin()\n const pluginManager = usePluginManager()\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":";;;;;;;AAIA,SAAgB,SAAc;CAC5B,MAAM,EAAE,SAAS,QAAsB;AAEvC,QAAO,KAAK;;;;;;;;ACyDd,SAAgB,oBAAoB,WAAyE;CAC3G,MAAM,SAAS,WAAW;CAC1B,MAAM,gBAAgB,kBAAkB;CAExC,MAAMA,WAAiD,WAAW,EAAE,SAAS,IAAI,SAAS,IAAI,YAAY,OAA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