@kubb/plugin-oas 0.0.0-canary-20251103125929 → 0.0.0-canary-20251103140549
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.
- package/dist/{SchemaGenerator-ChoBQWm5.js → SchemaGenerator-BwYbrh7a.js} +2 -23
- package/dist/SchemaGenerator-BwYbrh7a.js.map +1 -0
- package/dist/{SchemaGenerator-B8Reay1m.cjs → SchemaGenerator-C81yEgKY.cjs} +2 -23
- package/dist/SchemaGenerator-C81yEgKY.cjs.map +1 -0
- package/dist/{createGenerator-PIseu7v9.d.cts → createGenerator-BZv3BSD_.d.cts} +1 -4
- package/dist/{createGenerator-DlSlv4sR.d.ts → createGenerator-DoZXEhFy.d.ts} +1 -4
- package/dist/generators.d.cts +1 -1
- package/dist/generators.d.ts +1 -1
- package/dist/getSchemas-32BHoMO-.js +100 -0
- package/dist/getSchemas-32BHoMO-.js.map +1 -0
- package/dist/getSchemas-Cl0TZ4XY.cjs +113 -0
- package/dist/getSchemas-Cl0TZ4XY.cjs.map +1 -0
- package/dist/hooks.cjs +2 -2
- package/dist/hooks.d.cts +1 -1
- package/dist/hooks.d.ts +1 -1
- package/dist/hooks.js +2 -2
- package/dist/index.cjs +2 -2
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +2 -2
- package/dist/utils.cjs +1 -1
- package/dist/utils.d.cts +5 -1
- package/dist/utils.d.ts +5 -1
- package/dist/utils.js +1 -1
- package/package.json +3 -3
- package/src/SchemaGenerator.ts +6 -36
- package/src/utils/getSchemas.ts +88 -14
- package/dist/SchemaGenerator-B8Reay1m.cjs.map +0 -1
- package/dist/SchemaGenerator-ChoBQWm5.js.map +0 -1
- package/dist/getSchemas-CP_YS4_2.cjs +0 -68
- package/dist/getSchemas-CP_YS4_2.cjs.map +0 -1
- package/dist/getSchemas-CTi8zYew.js +0 -55
- package/dist/getSchemas-CTi8zYew.js.map +0 -1
|
@@ -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,SAAgB,iBAAmD,KAA6D;AAC9H,SAAQ,WAA0B;EAChC,MAAM,gDAAgC,IAAI,IAAI,GAAG,QAAQ;AAEzD,SAAO;GACL,cAAc,IAAI,mBAAmB,OAAO;GAC5C;GACD;;;;;;;;;ACvBL,SAAS,YAAY,QAAiB,uBAAO,IAAI,KAAa,EAAe;AAC3E,KAAI,MAAM,QAAQ,OAAO,EAAE;AACzB,OAAK,MAAM,QAAQ,OACjB,aAAY,MAAM,KAAK;AAEzB,SAAO;;AAGT,KAAI,UAAU,OAAO,WAAW,SAC9B,MAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,OAAO,CAC/C,KAAI,QAAQ,UAAU,OAAO,UAAU,UAAU;EAC/C,MAAM,QAAQ,MAAM,MAAM,iCAAiC;AAC3D,MAAI,MACF,MAAK,IAAI,MAAM,GAAI;OAGrB,aAAY,OAAO,KAAK;AAK9B,QAAO;;;;;AAMT,SAAS,YAAY,SAAuF;CAC1G,MAAM,uBAAO,IAAI,KAAuB;AAExC,MAAK,MAAM,CAAC,MAAM,WAAW,OAAO,QAAQ,QAAQ,CAClD,MAAK,IAAI,MAAM,MAAM,KAAK,YAAY,OAAO,CAAC,CAAC;CAGjD,MAAMA,SAAmB,EAAE;CAC3B,MAAM,0BAAU,IAAI,KAAa;CAEjC,SAAS,MAAM,MAAc,wBAAQ,IAAI,KAAa,EAAE;AACtD,MAAI,QAAQ,IAAI,KAAK,CACnB;AAEF,MAAI,MAAM,IAAI,KAAK,CACjB;AAEF,QAAM,IAAI,KAAK;EACf,MAAM,WAAW,KAAK,IAAI,KAAK,IAAI,EAAE;AACrC,OAAK,MAAM,SAAS,SAClB,KAAI,KAAK,IAAI,MAAM,CACjB,OAAM,OAAO,MAAM;AAGvB,QAAM,OAAO,KAAK;AAClB,UAAQ,IAAI,KAAK;AACjB,SAAO,KAAK,KAAK;;AAGnB,MAAK,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"}
|
package/dist/hooks.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const require_chunk = require('./chunk-CUT6urMc.cjs');
|
|
2
|
-
const require_SchemaGenerator = require('./SchemaGenerator-
|
|
2
|
+
const require_SchemaGenerator = require('./SchemaGenerator-C81yEgKY.cjs');
|
|
3
3
|
const require_SchemaMapper = require('./SchemaMapper-BUV8vhg0.cjs');
|
|
4
|
-
require('./getSchemas-
|
|
4
|
+
require('./getSchemas-Cl0TZ4XY.cjs');
|
|
5
5
|
let __kubb_react_fabric = require("@kubb/react-fabric");
|
|
6
6
|
__kubb_react_fabric = require_chunk.__toESM(__kubb_react_fabric);
|
|
7
7
|
let __kubb_core_hooks = require("@kubb/core/hooks");
|
package/dist/hooks.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { F as Plugin, L as ResolveNameParams, M as FileMetaBase, T as Oas, _ as OperationSchemas, d as OperationGenerator, k as Operation } from "./createGenerator-
|
|
1
|
+
import { F as Plugin, L as ResolveNameParams, M as FileMetaBase, T as Oas, _ as OperationSchemas, d as OperationGenerator, k as Operation } from "./createGenerator-BZv3BSD_.cjs";
|
|
2
2
|
import { t as Schema } from "./SchemaMapper-CX7sIIuZ.cjs";
|
|
3
3
|
import { KubbFile } from "@kubb/fabric-core/types";
|
|
4
4
|
|
package/dist/hooks.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { F as Plugin, L as ResolveNameParams, M as FileMetaBase, T as Oas, _ as OperationSchemas, d as OperationGenerator, k as Operation } from "./createGenerator-
|
|
1
|
+
import { F as Plugin, L as ResolveNameParams, M as FileMetaBase, T as Oas, _ as OperationSchemas, d as OperationGenerator, k as Operation } from "./createGenerator-DoZXEhFy.js";
|
|
2
2
|
import { t as Schema } from "./SchemaMapper-m5TKynWt.js";
|
|
3
3
|
import { KubbFile } from "@kubb/fabric-core/types";
|
|
4
4
|
|
package/dist/hooks.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { t as SchemaGenerator } from "./SchemaGenerator-
|
|
1
|
+
import { t as SchemaGenerator } from "./SchemaGenerator-BwYbrh7a.js";
|
|
2
2
|
import { n as schemaKeywords } from "./SchemaMapper-D30tqRoX.js";
|
|
3
|
-
import "./getSchemas-
|
|
3
|
+
import "./getSchemas-32BHoMO-.js";
|
|
4
4
|
import { useApp } from "@kubb/react-fabric";
|
|
5
5
|
import { usePlugin, usePluginManager } from "@kubb/core/hooks";
|
|
6
6
|
|
package/dist/index.cjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
const require_chunk = require('./chunk-CUT6urMc.cjs');
|
|
2
|
-
const require_SchemaGenerator = require('./SchemaGenerator-
|
|
2
|
+
const require_SchemaGenerator = require('./SchemaGenerator-C81yEgKY.cjs');
|
|
3
3
|
const require_generators = require('./generators-udGOxdUV.cjs');
|
|
4
4
|
require('./getFooter-DPh4lxBH.cjs');
|
|
5
5
|
const require_SchemaMapper = require('./SchemaMapper-BUV8vhg0.cjs');
|
|
6
|
-
require('./getSchemas-
|
|
6
|
+
require('./getSchemas-Cl0TZ4XY.cjs');
|
|
7
7
|
const require_parseFromConfig = require('./parseFromConfig-EjsCZ0-8.cjs');
|
|
8
8
|
let __kubb_core = require("@kubb/core");
|
|
9
9
|
__kubb_core = require_chunk.__toESM(__kubb_core);
|
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { A as SchemaObject, C as ResolvePathOptions, F as Plugin, I as PluginFactoryOptions, N as Config, R as UserPluginWithLifeCycle, S as Refs, _ as OperationSchemas, b as PluginOas, c as SchemaGeneratorBuildOptions, d as OperationGenerator, f as OperationMethodResult, g as OperationSchema, h as Include, i as ReactGenerator, k as Operation, l as SchemaGeneratorOptions, m as Exclude, o as GetSchemaGeneratorOptions, p as API, s as SchemaGenerator, u as SchemaMethodResult, v as Options, w as Resolver, x as Ref, y as Override } from "./createGenerator-
|
|
1
|
+
import { A as SchemaObject, C as ResolvePathOptions, F as Plugin, I as PluginFactoryOptions, N as Config, R as UserPluginWithLifeCycle, S as Refs, _ as OperationSchemas, b as PluginOas, c as SchemaGeneratorBuildOptions, d as OperationGenerator, f as OperationMethodResult, g as OperationSchema, h as Include, i as ReactGenerator, k as Operation, l as SchemaGeneratorOptions, m as Exclude, o as GetSchemaGeneratorOptions, p as API, s as SchemaGenerator, u as SchemaMethodResult, v as Options, w as Resolver, x as Ref, y as Override } from "./createGenerator-BZv3BSD_.cjs";
|
|
2
2
|
import { a as SchemaMapper, c as schemaKeywords, i as SchemaKeywordMapper, n as SchemaKeyword, o as SchemaTree, r as SchemaKeywordBase, s as isKeyword, t as Schema } from "./SchemaMapper-CX7sIIuZ.cjs";
|
|
3
3
|
import { Fabric } from "@kubb/react-fabric";
|
|
4
4
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { A as SchemaObject, C as ResolvePathOptions, F as Plugin, I as PluginFactoryOptions, N as Config, R as UserPluginWithLifeCycle, S as Refs, _ as OperationSchemas, b as PluginOas, c as SchemaGeneratorBuildOptions, d as OperationGenerator, f as OperationMethodResult, g as OperationSchema, h as Include, i as ReactGenerator, k as Operation, l as SchemaGeneratorOptions, m as Exclude, o as GetSchemaGeneratorOptions, p as API, s as SchemaGenerator, u as SchemaMethodResult, v as Options, w as Resolver, x as Ref, y as Override } from "./createGenerator-
|
|
1
|
+
import { A as SchemaObject, C as ResolvePathOptions, F as Plugin, I as PluginFactoryOptions, N as Config, R as UserPluginWithLifeCycle, S as Refs, _ as OperationSchemas, b as PluginOas, c as SchemaGeneratorBuildOptions, d as OperationGenerator, f as OperationMethodResult, g as OperationSchema, h as Include, i as ReactGenerator, k as Operation, l as SchemaGeneratorOptions, m as Exclude, o as GetSchemaGeneratorOptions, p as API, s as SchemaGenerator, u as SchemaMethodResult, v as Options, w as Resolver, x as Ref, y as Override } from "./createGenerator-DoZXEhFy.js";
|
|
2
2
|
import { a as SchemaMapper, c as schemaKeywords, i as SchemaKeywordMapper, n as SchemaKeyword, o as SchemaTree, r as SchemaKeywordBase, s as isKeyword, t as Schema } from "./SchemaMapper-m5TKynWt.js";
|
|
3
3
|
import { Fabric } from "@kubb/react-fabric";
|
|
4
4
|
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { a as pLimit, i as buildSchema, n as buildOperation, r as buildOperations, t as SchemaGenerator } from "./SchemaGenerator-
|
|
1
|
+
import { a as pLimit, i as buildSchema, n as buildOperation, r as buildOperations, t as SchemaGenerator } from "./SchemaGenerator-BwYbrh7a.js";
|
|
2
2
|
import { t as jsonGenerator } from "./generators-CJDEf8Kn.js";
|
|
3
3
|
import "./getFooter-CV73pVXj.js";
|
|
4
4
|
import { n as schemaKeywords, t as isKeyword } from "./SchemaMapper-D30tqRoX.js";
|
|
5
|
-
import "./getSchemas-
|
|
5
|
+
import "./getSchemas-32BHoMO-.js";
|
|
6
6
|
import { t as parseFromConfig } from "./parseFromConfig-BkUoWC2U.js";
|
|
7
7
|
import { BaseGenerator, createPlugin, getMode } from "@kubb/core";
|
|
8
8
|
import transformers, { camelCase } from "@kubb/core/transformers";
|
package/dist/utils.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const require_chunk = require('./chunk-CUT6urMc.cjs');
|
|
2
2
|
const require_getFooter = require('./getFooter-DPh4lxBH.cjs');
|
|
3
|
-
const require_getSchemas = require('./getSchemas-
|
|
3
|
+
const require_getSchemas = require('./getSchemas-Cl0TZ4XY.cjs');
|
|
4
4
|
const require_parseFromConfig = require('./parseFromConfig-EjsCZ0-8.cjs');
|
|
5
5
|
let __kubb_core_transformers = require("@kubb/core/transformers");
|
|
6
6
|
__kubb_core_transformers = require_chunk.__toESM(__kubb_core_transformers);
|
package/dist/utils.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { A as SchemaObject$1, D as OpenAPIV3$1, E as OasTypes, N as Config, O as OpenAPIV3_1, P as Output, T as Oas, g as OperationSchema, j as contentType, k as Operation } from "./createGenerator-
|
|
1
|
+
import { A as SchemaObject$1, D as OpenAPIV3$1, E as OasTypes, N as Config, O as OpenAPIV3_1, P as Output, T as Oas, g as OperationSchema, j as contentType, k as Operation } from "./createGenerator-BZv3BSD_.cjs";
|
|
2
2
|
import "./SchemaMapper-CX7sIIuZ.cjs";
|
|
3
3
|
import { OASDocument, SchemaObject } from "oas/types";
|
|
4
4
|
import { OpenAPIV3 } from "openapi-types";
|
|
@@ -105,6 +105,10 @@ type GetSchemasProps = {
|
|
|
105
105
|
contentType?: contentType;
|
|
106
106
|
includes?: Mode[];
|
|
107
107
|
};
|
|
108
|
+
/**
|
|
109
|
+
* Collect schemas from OpenAPI components (schemas, responses, requestBodies)
|
|
110
|
+
* and return them in dependency order.
|
|
111
|
+
*/
|
|
108
112
|
declare function getSchemas({
|
|
109
113
|
oas,
|
|
110
114
|
contentType,
|
package/dist/utils.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { A as SchemaObject$1, D as OpenAPIV3$1, E as OasTypes, N as Config, O as OpenAPIV3_1, P as Output, T as Oas, g as OperationSchema, j as contentType, k as Operation } from "./createGenerator-
|
|
1
|
+
import { A as SchemaObject$1, D as OpenAPIV3$1, E as OasTypes, N as Config, O as OpenAPIV3_1, P as Output, T as Oas, g as OperationSchema, j as contentType, k as Operation } from "./createGenerator-DoZXEhFy.js";
|
|
2
2
|
import "./SchemaMapper-m5TKynWt.js";
|
|
3
3
|
import { OASDocument, SchemaObject } from "oas/types";
|
|
4
4
|
import { OpenAPIV3 } from "openapi-types";
|
|
@@ -105,6 +105,10 @@ type GetSchemasProps = {
|
|
|
105
105
|
contentType?: contentType;
|
|
106
106
|
includes?: Mode[];
|
|
107
107
|
};
|
|
108
|
+
/**
|
|
109
|
+
* Collect schemas from OpenAPI components (schemas, responses, requestBodies)
|
|
110
|
+
* and return them in dependency order.
|
|
111
|
+
*/
|
|
108
112
|
declare function getSchemas({
|
|
109
113
|
oas,
|
|
110
114
|
contentType,
|
package/dist/utils.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { n as getBanner, t as getFooter } from "./getFooter-CV73pVXj.js";
|
|
2
|
-
import { n as getSchemaFactory, t as getSchemas } from "./getSchemas-
|
|
2
|
+
import { n as getSchemaFactory, t as getSchemas } from "./getSchemas-32BHoMO-.js";
|
|
3
3
|
import { t as parseFromConfig } from "./parseFromConfig-BkUoWC2U.js";
|
|
4
4
|
import transformers, { camelCase, isValidVarName } from "@kubb/core/transformers";
|
|
5
5
|
import { URLPath } from "@kubb/core/utils";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/plugin-oas",
|
|
3
|
-
"version": "0.0.0-canary-
|
|
3
|
+
"version": "0.0.0-canary-20251103140549",
|
|
4
4
|
"description": "OpenAPI Specification (OAS) plugin for Kubb, providing core functionality for parsing and processing OpenAPI/Swagger schemas for code generation.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"openapi",
|
|
@@ -83,8 +83,8 @@
|
|
|
83
83
|
"@stoplight/yaml": "^4.3.0",
|
|
84
84
|
"p-limit": "^7.2.0",
|
|
85
85
|
"remeda": "^2.32.0",
|
|
86
|
-
"@kubb/core": "0.0.0-canary-
|
|
87
|
-
"@kubb/oas": "0.0.0-canary-
|
|
86
|
+
"@kubb/core": "0.0.0-canary-20251103140549",
|
|
87
|
+
"@kubb/oas": "0.0.0-canary-20251103140549"
|
|
88
88
|
},
|
|
89
89
|
"devDependencies": {},
|
|
90
90
|
"peerDependencies": {
|
package/src/SchemaGenerator.ts
CHANGED
|
@@ -91,14 +91,6 @@ export class SchemaGenerator<
|
|
|
91
91
|
return uniqueWith(schemas, isDeepEqual)
|
|
92
92
|
}
|
|
93
93
|
|
|
94
|
-
deepSearch<T extends keyof SchemaKeywordMapper>(tree: Schema[] | undefined, keyword: T): Array<SchemaKeywordMapper[T]> {
|
|
95
|
-
return SchemaGenerator.deepSearch<T>(tree, keyword)
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
find<T extends keyof SchemaKeywordMapper>(tree: Schema[] | undefined, keyword: T): SchemaKeywordMapper[T] | undefined {
|
|
99
|
-
return SchemaGenerator.find<T>(tree, keyword)
|
|
100
|
-
}
|
|
101
|
-
|
|
102
94
|
static deepSearch<T extends keyof SchemaKeywordMapper>(tree: Schema[] | undefined, keyword: T): Array<SchemaKeywordMapper[T]> {
|
|
103
95
|
const foundItems: SchemaKeywordMapper[T][] = []
|
|
104
96
|
|
|
@@ -145,32 +137,6 @@ export class SchemaGenerator<
|
|
|
145
137
|
return foundItems
|
|
146
138
|
}
|
|
147
139
|
|
|
148
|
-
static findInObject<T extends keyof SchemaKeywordMapper>(tree: Schema[] | undefined, keyword: T): SchemaKeywordMapper[T] | undefined {
|
|
149
|
-
let foundItem: SchemaKeywordMapper[T] | undefined
|
|
150
|
-
|
|
151
|
-
tree?.forEach((schema) => {
|
|
152
|
-
if (!foundItem && schema.keyword === keyword) {
|
|
153
|
-
foundItem = schema as SchemaKeywordMapper[T]
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
if (isKeyword(schema, schemaKeywords.object)) {
|
|
157
|
-
Object.values(schema.args?.properties || {}).forEach((entrySchema) => {
|
|
158
|
-
if (!foundItem) {
|
|
159
|
-
foundItem = SchemaGenerator.find<T>(entrySchema, keyword)
|
|
160
|
-
}
|
|
161
|
-
})
|
|
162
|
-
|
|
163
|
-
Object.values(schema.args?.additionalProperties || {}).forEach((entrySchema) => {
|
|
164
|
-
if (!foundItem) {
|
|
165
|
-
foundItem = SchemaGenerator.find<T>([entrySchema], keyword)
|
|
166
|
-
}
|
|
167
|
-
})
|
|
168
|
-
}
|
|
169
|
-
})
|
|
170
|
-
|
|
171
|
-
return foundItem
|
|
172
|
-
}
|
|
173
|
-
|
|
174
140
|
static find<T extends keyof SchemaKeywordMapper>(tree: Schema[] | undefined, keyword: T): SchemaKeywordMapper[T] | undefined {
|
|
175
141
|
let foundItem: SchemaKeywordMapper[T] | undefined
|
|
176
142
|
|
|
@@ -563,13 +529,17 @@ export class SchemaGenerator<
|
|
|
563
529
|
if (max !== undefined) {
|
|
564
530
|
if (exclusiveMaximum) {
|
|
565
531
|
baseItems.unshift({ keyword: schemaKeywords.exclusiveMaximum, args: max })
|
|
566
|
-
} else
|
|
532
|
+
} else {
|
|
533
|
+
baseItems.unshift({ keyword: schemaKeywords.max, args: max })
|
|
534
|
+
}
|
|
567
535
|
}
|
|
568
536
|
|
|
569
537
|
if (min !== undefined) {
|
|
570
538
|
if (exclusiveMinimum) {
|
|
571
539
|
baseItems.unshift({ keyword: schemaKeywords.exclusiveMinimum, args: min })
|
|
572
|
-
} else
|
|
540
|
+
} else {
|
|
541
|
+
baseItems.unshift({ keyword: schemaKeywords.min, args: min })
|
|
542
|
+
}
|
|
573
543
|
}
|
|
574
544
|
|
|
575
545
|
if (typeof exclusiveMaximum === 'number') {
|
package/src/utils/getSchemas.ts
CHANGED
|
@@ -8,9 +8,82 @@ type GetSchemasProps = {
|
|
|
8
8
|
includes?: Mode[]
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
+
/**
|
|
12
|
+
* Collect all schema $ref dependencies recursively.
|
|
13
|
+
*/
|
|
14
|
+
function collectRefs(schema: unknown, refs = new Set<string>()): Set<string> {
|
|
15
|
+
if (Array.isArray(schema)) {
|
|
16
|
+
for (const item of schema) {
|
|
17
|
+
collectRefs(item, refs)
|
|
18
|
+
}
|
|
19
|
+
return refs
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
if (schema && typeof schema === 'object') {
|
|
23
|
+
for (const [key, value] of Object.entries(schema)) {
|
|
24
|
+
if (key === '$ref' && typeof value === 'string') {
|
|
25
|
+
const match = value.match(/^#\/components\/schemas\/(.+)$/)
|
|
26
|
+
if (match) {
|
|
27
|
+
refs.add(match[1]!)
|
|
28
|
+
}
|
|
29
|
+
} else {
|
|
30
|
+
collectRefs(value, refs)
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return refs
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Sort schemas topologically so referenced schemas appear first.
|
|
40
|
+
*/
|
|
41
|
+
function sortSchemas(schemas: Record<string, OasTypes.SchemaObject>): Record<string, OasTypes.SchemaObject> {
|
|
42
|
+
const deps = new Map<string, string[]>()
|
|
43
|
+
|
|
44
|
+
for (const [name, schema] of Object.entries(schemas)) {
|
|
45
|
+
deps.set(name, Array.from(collectRefs(schema)))
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const sorted: string[] = []
|
|
49
|
+
const visited = new Set<string>()
|
|
50
|
+
|
|
51
|
+
function visit(name: string, stack = new Set<string>()) {
|
|
52
|
+
if (visited.has(name)) {
|
|
53
|
+
return
|
|
54
|
+
}
|
|
55
|
+
if (stack.has(name)) {
|
|
56
|
+
return
|
|
57
|
+
} // circular refs, ignore
|
|
58
|
+
stack.add(name)
|
|
59
|
+
const children = deps.get(name) || []
|
|
60
|
+
for (const child of children) {
|
|
61
|
+
if (deps.has(child)) {
|
|
62
|
+
visit(child, stack)
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
stack.delete(name)
|
|
66
|
+
visited.add(name)
|
|
67
|
+
sorted.push(name)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
for (const name of Object.keys(schemas)) {
|
|
71
|
+
visit(name)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const sortedSchemas: Record<string, OasTypes.SchemaObject> = {}
|
|
75
|
+
for (const name of sorted) {
|
|
76
|
+
sortedSchemas[name] = schemas[name]!
|
|
77
|
+
}
|
|
78
|
+
return sortedSchemas
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Collect schemas from OpenAPI components (schemas, responses, requestBodies)
|
|
83
|
+
* and return them in dependency order.
|
|
84
|
+
*/
|
|
11
85
|
export function getSchemas({ oas, contentType, includes = ['schemas', 'requestBodies', 'responses'] }: GetSchemasProps): Record<string, OasTypes.SchemaObject> {
|
|
12
86
|
const components = oas.getDefinition().components
|
|
13
|
-
|
|
14
87
|
let schemas: Record<string, OasTypes.SchemaObject> = {}
|
|
15
88
|
|
|
16
89
|
if (includes.includes('schemas')) {
|
|
@@ -20,26 +93,27 @@ export function getSchemas({ oas, contentType, includes = ['schemas', 'requestBo
|
|
|
20
93
|
}
|
|
21
94
|
}
|
|
22
95
|
|
|
23
|
-
const requestBodies = components?.requestBodies || {}
|
|
24
96
|
if (includes.includes('responses')) {
|
|
25
97
|
const responses = components?.responses || {}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
if (
|
|
29
|
-
const firstContentType = Object.keys(
|
|
30
|
-
schemas[name] =
|
|
98
|
+
for (const [name, response] of Object.entries(responses)) {
|
|
99
|
+
const r = response as OasTypes.ResponseObject
|
|
100
|
+
if (r.content && !schemas[name]) {
|
|
101
|
+
const firstContentType = Object.keys(r.content)[0] || 'application/json'
|
|
102
|
+
schemas[name] = r.content?.[contentType || firstContentType]?.schema as OasTypes.SchemaObject
|
|
31
103
|
}
|
|
32
|
-
}
|
|
104
|
+
}
|
|
33
105
|
}
|
|
34
106
|
|
|
35
107
|
if (includes.includes('requestBodies')) {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
108
|
+
const requestBodies = components?.requestBodies || {}
|
|
109
|
+
for (const [name, request] of Object.entries(requestBodies)) {
|
|
110
|
+
const r = request as OasTypes.RequestBodyObject
|
|
111
|
+
if (r.content && !schemas[name]) {
|
|
112
|
+
const firstContentType = Object.keys(r.content)[0] || 'application/json'
|
|
113
|
+
schemas[name] = r.content?.[contentType || firstContentType]?.schema as OasTypes.SchemaObject
|
|
40
114
|
}
|
|
41
|
-
}
|
|
115
|
+
}
|
|
42
116
|
}
|
|
43
117
|
|
|
44
|
-
return schemas
|
|
118
|
+
return sortSchemas(schemas)
|
|
45
119
|
}
|