@kubb/plugin-oas 4.18.4 → 4.19.0
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-CoV4zGpd.js → SchemaGenerator-D8GP-AGi.js} +48 -21
- package/dist/SchemaGenerator-D8GP-AGi.js.map +1 -0
- package/dist/{SchemaGenerator-tDDCI3wi.cjs → SchemaGenerator-DO3rrt_U.cjs} +49 -22
- package/dist/SchemaGenerator-DO3rrt_U.cjs.map +1 -0
- package/dist/SchemaMapper-CzH82C7C.cjs.map +1 -1
- package/dist/SchemaMapper-D-GETHNf.js.map +1 -1
- package/dist/{SchemaMapper-BBUBpcx-.d.ts → SchemaMapper-DI2vHHE0.d.ts} +72 -52
- package/dist/{SchemaMapper-CIs2VKvf.d.cts → SchemaMapper-DmB5NyNo.d.cts} +72 -52
- package/dist/{createGenerator-Cj-sXgmn.d.cts → createGenerator-BF26dp_h.d.cts} +33 -13
- package/dist/{createGenerator-CZi_gpit.d.ts → createGenerator-DhGg_jH6.d.ts} +33 -13
- package/dist/generators.d.cts +2 -2
- package/dist/generators.d.ts +2 -2
- package/dist/getSchemaFactory-CBp1me72.cjs +29 -0
- package/dist/getSchemaFactory-CBp1me72.cjs.map +1 -0
- package/dist/getSchemaFactory-DsoVRgxV.js +24 -0
- package/dist/getSchemaFactory-DsoVRgxV.js.map +1 -0
- package/dist/hooks.cjs +3 -3
- package/dist/hooks.cjs.map +1 -1
- package/dist/hooks.d.cts +4 -4
- package/dist/hooks.d.ts +4 -4
- package/dist/hooks.js +3 -3
- package/dist/hooks.js.map +1 -1
- package/dist/index.cjs +5 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +5 -4
- package/dist/index.js.map +1 -1
- package/dist/mocks.d.cts +1 -1
- package/dist/mocks.d.ts +1 -1
- package/dist/utils.cjs +26 -3
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.d.cts +25 -5
- package/dist/utils.d.ts +25 -5
- package/dist/utils.js +24 -1
- package/dist/utils.js.map +1 -1
- package/package.json +3 -3
- package/src/SchemaGenerator.ts +60 -26
- package/src/SchemaMapper.ts +3 -3
- package/src/hooks/useOperationManager.ts +1 -1
- package/src/hooks/useSchemaManager.ts +1 -1
- package/src/plugin.ts +3 -1
- package/src/types.ts +30 -10
- package/src/utils/getSchemas.ts +27 -105
- package/dist/SchemaGenerator-CoV4zGpd.js.map +0 -1
- package/dist/SchemaGenerator-tDDCI3wi.cjs.map +0 -1
- package/dist/getSchemas-BUXPwm-5.js +0 -101
- package/dist/getSchemas-BUXPwm-5.js.map +0 -1
- package/dist/getSchemas-D3YweIFO.cjs +0 -112
- package/dist/getSchemas-D3YweIFO.cjs.map +0 -1
package/dist/utils.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const require_chunk = require('./chunk-C1_xRkKa.cjs');
|
|
2
|
-
const
|
|
2
|
+
const require_getSchemaFactory = require('./getSchemaFactory-CBp1me72.cjs');
|
|
3
3
|
const require_getFooter = require('./getFooter-BvLkEWpc.cjs');
|
|
4
4
|
let _kubb_core_transformers = require("@kubb/core/transformers");
|
|
5
5
|
_kubb_core_transformers = require_chunk.__toESM(_kubb_core_transformers);
|
|
@@ -51,13 +51,36 @@ function getPathParams(operationSchema, options = {}) {
|
|
|
51
51
|
}, {});
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
+
//#endregion
|
|
55
|
+
//#region src/utils/getSchemas.ts
|
|
56
|
+
/**
|
|
57
|
+
* Collect schemas from OpenAPI components (schemas, responses, requestBodies)
|
|
58
|
+
* and return them in dependency order along with name mapping for collision resolution.
|
|
59
|
+
*
|
|
60
|
+
* This function is a wrapper around the oas.getSchemas() method for backward compatibility.
|
|
61
|
+
* New code should use oas.getSchemas() directly.
|
|
62
|
+
*
|
|
63
|
+
* @deprecated Use oas.getSchemas() instead
|
|
64
|
+
*/
|
|
65
|
+
function getSchemas({ oas, contentType, includes = [
|
|
66
|
+
"schemas",
|
|
67
|
+
"requestBodies",
|
|
68
|
+
"responses"
|
|
69
|
+
], collisionDetection }) {
|
|
70
|
+
return oas.getSchemas({
|
|
71
|
+
contentType,
|
|
72
|
+
includes,
|
|
73
|
+
collisionDetection
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
|
|
54
77
|
//#endregion
|
|
55
78
|
exports.getBanner = require_getFooter.getBanner;
|
|
56
79
|
exports.getComments = getComments;
|
|
57
80
|
exports.getFooter = require_getFooter.getFooter;
|
|
58
81
|
exports.getPathParams = getPathParams;
|
|
59
|
-
exports.getSchemaFactory =
|
|
60
|
-
exports.getSchemas =
|
|
82
|
+
exports.getSchemaFactory = require_getSchemaFactory.getSchemaFactory;
|
|
83
|
+
exports.getSchemas = getSchemas;
|
|
61
84
|
Object.defineProperty(exports, 'isOptional', {
|
|
62
85
|
enumerable: true,
|
|
63
86
|
get: function () {
|
package/dist/utils.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.cjs","names":["URLPath","transformers"],"sources":["../src/utils/getComments.ts","../src/utils/getParams.ts"],"sourcesContent":["import transformers from '@kubb/core/transformers'\nimport { URLPath } from '@kubb/core/utils'\n\nimport type { Operation } from '@kubb/oas'\n\nexport function getComments(operation: Operation): string[] {\n return [\n operation.getDescription() && `@description ${operation.getDescription()}`,\n operation.getSummary() && `@summary ${operation.getSummary()}`,\n operation.path && `{@link ${new URLPath(operation.path).URL}}`,\n operation.isDeprecated() && '@deprecated',\n ]\n .filter(Boolean)\n .map((text) => transformers.trim(text))\n .filter(Boolean)\n}\n","import { camelCase, isValidVarName } from '@kubb/core/transformers'\nimport type { FunctionParamsAST } from '@kubb/core/utils'\nimport type { OasTypes } from '@kubb/oas'\nimport type { Params } from '@kubb/react-fabric/types'\nimport type { OperationSchema } from '../types.ts'\n/**\n *\n * @deprecated\n * TODO move to operationManager hook\n */\nexport function getASTParams(\n operationSchema: OperationSchema | undefined,\n {\n typed = false,\n override,\n }: {\n typed?: boolean\n override?: (data: FunctionParamsAST) => FunctionParamsAST\n } = {},\n): FunctionParamsAST[] {\n if (!operationSchema || !operationSchema.schema.properties || !operationSchema.name) {\n return []\n }\n\n const requiredFields = Array.isArray(operationSchema.schema.required) ? operationSchema.schema.required : []\n\n return Object.entries(operationSchema.schema.properties).map(([name]: [string, OasTypes.SchemaObject]) => {\n const data: FunctionParamsAST = {\n name,\n enabled: !!name,\n required: requiredFields.includes(name),\n type: typed ? `${operationSchema.name}[\"${name}\"]` : undefined,\n }\n\n return override ? override(data) : data\n })\n}\n\nexport function getPathParams(\n operationSchema: OperationSchema | undefined,\n options: {\n typed?: boolean\n casing?: 'camelcase'\n override?: (data: FunctionParamsAST) => FunctionParamsAST\n } = {},\n) {\n return getASTParams(operationSchema, options).reduce((acc, curr) => {\n if (curr.name && curr.enabled) {\n let name = isValidVarName(curr.name) ? curr.name : camelCase(curr.name)\n\n if (options.casing === 'camelcase') {\n name = camelCase(name)\n }\n\n acc[name] = {\n default: curr.default,\n type: curr.type,\n optional: !curr.required,\n }\n }\n\n return acc\n }, {} as Params)\n}\n"],"mappings":";;;;;;;;;AAKA,SAAgB,YAAY,WAAgC;AAC1D,QAAO;EACL,UAAU,gBAAgB,IAAI,gBAAgB,UAAU,gBAAgB;EACxE,UAAU,YAAY,IAAI,YAAY,UAAU,YAAY;EAC5D,UAAU,QAAQ,UAAU,IAAIA,yBAAQ,UAAU,KAAK,CAAC,IAAI;EAC5D,UAAU,cAAc,IAAI;EAC7B,CACE,OAAO,QAAQ,CACf,KAAK,SAASC,gCAAa,KAAK,KAAK,CAAC,CACtC,OAAO,QAAQ;;;;;;;;;;ACJpB,SAAgB,aACd,iBACA,EACE,QAAQ,OACR,aAIE,EAAE,EACe;AACrB,KAAI,CAAC,mBAAmB,CAAC,gBAAgB,OAAO,cAAc,CAAC,gBAAgB,KAC7E,QAAO,EAAE;CAGX,MAAM,iBAAiB,MAAM,QAAQ,gBAAgB,OAAO,SAAS,GAAG,gBAAgB,OAAO,WAAW,EAAE;AAE5G,QAAO,OAAO,QAAQ,gBAAgB,OAAO,WAAW,CAAC,KAAK,CAAC,UAA2C;EACxG,MAAM,OAA0B;GAC9B;GACA,SAAS,CAAC,CAAC;GACX,UAAU,eAAe,SAAS,KAAK;GACvC,MAAM,QAAQ,GAAG,gBAAgB,KAAK,IAAI,KAAK,MAAM;GACtD;AAED,SAAO,WAAW,SAAS,KAAK,GAAG;GACnC;;AAGJ,SAAgB,cACd,iBACA,UAII,EAAE,EACN;AACA,QAAO,aAAa,iBAAiB,QAAQ,CAAC,QAAQ,KAAK,SAAS;AAClE,MAAI,KAAK,QAAQ,KAAK,SAAS;GAC7B,IAAI,mDAAsB,KAAK,KAAK,GAAG,KAAK,8CAAiB,KAAK,KAAK;AAEvE,OAAI,QAAQ,WAAW,YACrB,+CAAiB,KAAK;AAGxB,OAAI,QAAQ;IACV,SAAS,KAAK;IACd,MAAM,KAAK;IACX,UAAU,CAAC,KAAK;IACjB;;AAGH,SAAO;IACN,EAAE,CAAW"}
|
|
1
|
+
{"version":3,"file":"utils.cjs","names":["URLPath","transformers"],"sources":["../src/utils/getComments.ts","../src/utils/getParams.ts","../src/utils/getSchemas.ts"],"sourcesContent":["import transformers from '@kubb/core/transformers'\nimport { URLPath } from '@kubb/core/utils'\n\nimport type { Operation } from '@kubb/oas'\n\nexport function getComments(operation: Operation): string[] {\n return [\n operation.getDescription() && `@description ${operation.getDescription()}`,\n operation.getSummary() && `@summary ${operation.getSummary()}`,\n operation.path && `{@link ${new URLPath(operation.path).URL}}`,\n operation.isDeprecated() && '@deprecated',\n ]\n .filter(Boolean)\n .map((text) => transformers.trim(text))\n .filter(Boolean)\n}\n","import { camelCase, isValidVarName } from '@kubb/core/transformers'\nimport type { FunctionParamsAST } from '@kubb/core/utils'\nimport type { OasTypes } from '@kubb/oas'\nimport type { Params } from '@kubb/react-fabric/types'\nimport type { OperationSchema } from '../types.ts'\n/**\n *\n * @deprecated\n * TODO move to operationManager hook\n */\nexport function getASTParams(\n operationSchema: OperationSchema | undefined,\n {\n typed = false,\n override,\n }: {\n typed?: boolean\n override?: (data: FunctionParamsAST) => FunctionParamsAST\n } = {},\n): FunctionParamsAST[] {\n if (!operationSchema || !operationSchema.schema.properties || !operationSchema.name) {\n return []\n }\n\n const requiredFields = Array.isArray(operationSchema.schema.required) ? operationSchema.schema.required : []\n\n return Object.entries(operationSchema.schema.properties).map(([name]: [string, OasTypes.SchemaObject]) => {\n const data: FunctionParamsAST = {\n name,\n enabled: !!name,\n required: requiredFields.includes(name),\n type: typed ? `${operationSchema.name}[\"${name}\"]` : undefined,\n }\n\n return override ? override(data) : data\n })\n}\n\nexport function getPathParams(\n operationSchema: OperationSchema | undefined,\n options: {\n typed?: boolean\n casing?: 'camelcase'\n override?: (data: FunctionParamsAST) => FunctionParamsAST\n } = {},\n) {\n return getASTParams(operationSchema, options).reduce((acc, curr) => {\n if (curr.name && curr.enabled) {\n let name = isValidVarName(curr.name) ? curr.name : camelCase(curr.name)\n\n if (options.casing === 'camelcase') {\n name = camelCase(name)\n }\n\n acc[name] = {\n default: curr.default,\n type: curr.type,\n optional: !curr.required,\n }\n }\n\n return acc\n }, {} as Params)\n}\n","import type { contentType, Oas, OasTypes } from '@kubb/oas'\n\nexport type GetSchemasResult = {\n schemas: Record<string, OasTypes.SchemaObject>\n /**\n * Mapping from original component name to resolved name after collision handling\n * e.g., { 'Order': 'OrderSchema', 'variant': 'variant2' }\n */\n nameMapping: Map<string, string>\n}\n\ntype Mode = 'schemas' | 'responses' | 'requestBodies'\n\ntype GetSchemasProps = {\n oas: Oas\n contentType?: contentType\n includes?: Mode[]\n /**\n * Whether to resolve name collisions with suffixes.\n * If not provided, uses oas.options.collisionDetection\n * @default false (from oas.options or fallback)\n */\n collisionDetection?: boolean\n}\n\n/**\n * Collect schemas from OpenAPI components (schemas, responses, requestBodies)\n * and return them in dependency order along with name mapping for collision resolution.\n *\n * This function is a wrapper around the oas.getSchemas() method for backward compatibility.\n * New code should use oas.getSchemas() directly.\n *\n * @deprecated Use oas.getSchemas() instead\n */\nexport function getSchemas({ oas, contentType, includes = ['schemas', 'requestBodies', 'responses'], collisionDetection }: GetSchemasProps): GetSchemasResult {\n return oas.getSchemas({\n contentType,\n includes,\n collisionDetection,\n })\n}\n"],"mappings":";;;;;;;;;AAKA,SAAgB,YAAY,WAAgC;AAC1D,QAAO;EACL,UAAU,gBAAgB,IAAI,gBAAgB,UAAU,gBAAgB;EACxE,UAAU,YAAY,IAAI,YAAY,UAAU,YAAY;EAC5D,UAAU,QAAQ,UAAU,IAAIA,yBAAQ,UAAU,KAAK,CAAC,IAAI;EAC5D,UAAU,cAAc,IAAI;EAC7B,CACE,OAAO,QAAQ,CACf,KAAK,SAASC,gCAAa,KAAK,KAAK,CAAC,CACtC,OAAO,QAAQ;;;;;;;;;;ACJpB,SAAgB,aACd,iBACA,EACE,QAAQ,OACR,aAIE,EAAE,EACe;AACrB,KAAI,CAAC,mBAAmB,CAAC,gBAAgB,OAAO,cAAc,CAAC,gBAAgB,KAC7E,QAAO,EAAE;CAGX,MAAM,iBAAiB,MAAM,QAAQ,gBAAgB,OAAO,SAAS,GAAG,gBAAgB,OAAO,WAAW,EAAE;AAE5G,QAAO,OAAO,QAAQ,gBAAgB,OAAO,WAAW,CAAC,KAAK,CAAC,UAA2C;EACxG,MAAM,OAA0B;GAC9B;GACA,SAAS,CAAC,CAAC;GACX,UAAU,eAAe,SAAS,KAAK;GACvC,MAAM,QAAQ,GAAG,gBAAgB,KAAK,IAAI,KAAK,MAAM;GACtD;AAED,SAAO,WAAW,SAAS,KAAK,GAAG;GACnC;;AAGJ,SAAgB,cACd,iBACA,UAII,EAAE,EACN;AACA,QAAO,aAAa,iBAAiB,QAAQ,CAAC,QAAQ,KAAK,SAAS;AAClE,MAAI,KAAK,QAAQ,KAAK,SAAS;GAC7B,IAAI,mDAAsB,KAAK,KAAK,GAAG,KAAK,8CAAiB,KAAK,KAAK;AAEvE,OAAI,QAAQ,WAAW,YACrB,+CAAiB,KAAK;AAGxB,OAAI,QAAQ;IACV,SAAS,KAAK;IACd,MAAM,KAAK;IACX,UAAU,CAAC,KAAK;IACjB;;AAGH,SAAO;IACN,EAAE,CAAW;;;;;;;;;;;;;;AC5BlB,SAAgB,WAAW,EAAE,KAAK,aAAa,WAAW;CAAC;CAAW;CAAiB;CAAY,EAAE,sBAAyD;AAC5J,QAAO,IAAI,WAAW;EACpB;EACA;EACA;EACD,CAAC"}
|
package/dist/utils.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { A as __name, S as Output, _ as contentType, b as Config, f as OasTypes, g as SchemaObject, h as Operation, l as isOptional, m as OpenAPIV3_1, p as OpenAPIV3, u as Oas } from "./SchemaMapper-
|
|
2
|
-
import { h as OperationSchema, w as FunctionParamsAST } from "./createGenerator-
|
|
1
|
+
import { A as __name, S as Output, _ as contentType, b as Config, f as OasTypes, g as SchemaObject, h as Operation, l as isOptional, m as OpenAPIV3_1, p as OpenAPIV3, u as Oas } from "./SchemaMapper-DmB5NyNo.cjs";
|
|
2
|
+
import { h as OperationSchema, w as FunctionParamsAST } from "./createGenerator-BF26dp_h.cjs";
|
|
3
3
|
import { Params } from "@kubb/react-fabric/types";
|
|
4
4
|
|
|
5
5
|
//#region src/utils/getBanner.d.ts
|
|
@@ -61,21 +61,41 @@ type SchemaResult<TWithRef extends boolean = false> = {
|
|
|
61
61
|
declare function getSchemaFactory<TWithRef extends boolean = false>(oas: Oas): (schema: SchemaObject | null) => SchemaResult<TWithRef>;
|
|
62
62
|
//#endregion
|
|
63
63
|
//#region src/utils/getSchemas.d.ts
|
|
64
|
+
type GetSchemasResult = {
|
|
65
|
+
schemas: Record<string, OasTypes.SchemaObject>;
|
|
66
|
+
/**
|
|
67
|
+
* Mapping from original component name to resolved name after collision handling
|
|
68
|
+
* e.g., { 'Order': 'OrderSchema', 'variant': 'variant2' }
|
|
69
|
+
*/
|
|
70
|
+
nameMapping: Map<string, string>;
|
|
71
|
+
};
|
|
64
72
|
type Mode = 'schemas' | 'responses' | 'requestBodies';
|
|
65
73
|
type GetSchemasProps = {
|
|
66
74
|
oas: Oas;
|
|
67
75
|
contentType?: contentType;
|
|
68
76
|
includes?: Mode[];
|
|
77
|
+
/**
|
|
78
|
+
* Whether to resolve name collisions with suffixes.
|
|
79
|
+
* If not provided, uses oas.options.collisionDetection
|
|
80
|
+
* @default false (from oas.options or fallback)
|
|
81
|
+
*/
|
|
82
|
+
collisionDetection?: boolean;
|
|
69
83
|
};
|
|
70
84
|
/**
|
|
71
85
|
* Collect schemas from OpenAPI components (schemas, responses, requestBodies)
|
|
72
|
-
* and return them in dependency order.
|
|
86
|
+
* and return them in dependency order along with name mapping for collision resolution.
|
|
87
|
+
*
|
|
88
|
+
* This function is a wrapper around the oas.getSchemas() method for backward compatibility.
|
|
89
|
+
* New code should use oas.getSchemas() directly.
|
|
90
|
+
*
|
|
91
|
+
* @deprecated Use oas.getSchemas() instead
|
|
73
92
|
*/
|
|
74
93
|
declare function getSchemas({
|
|
75
94
|
oas,
|
|
76
95
|
contentType,
|
|
77
|
-
includes
|
|
78
|
-
|
|
96
|
+
includes,
|
|
97
|
+
collisionDetection
|
|
98
|
+
}: GetSchemasProps): GetSchemasResult;
|
|
79
99
|
//#endregion
|
|
80
100
|
export { getBanner, getComments, getFooter, getPathParams, getSchemaFactory, getSchemas, isOptional };
|
|
81
101
|
//# sourceMappingURL=utils.d.cts.map
|
package/dist/utils.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { t as __name } from "./chunk-iVr_oF3V.js";
|
|
2
|
-
import { S as Output, _ as contentType, b as Config, f as OasTypes, g as SchemaObject, h as Operation, l as isOptional, m as OpenAPIV3_1, p as OpenAPIV3, u as Oas } from "./SchemaMapper-
|
|
3
|
-
import { h as OperationSchema, w as FunctionParamsAST } from "./createGenerator-
|
|
2
|
+
import { S as Output, _ as contentType, b as Config, f as OasTypes, g as SchemaObject, h as Operation, l as isOptional, m as OpenAPIV3_1, p as OpenAPIV3, u as Oas } from "./SchemaMapper-DI2vHHE0.js";
|
|
3
|
+
import { h as OperationSchema, w as FunctionParamsAST } from "./createGenerator-DhGg_jH6.js";
|
|
4
4
|
import { Params } from "@kubb/react-fabric/types";
|
|
5
5
|
|
|
6
6
|
//#region src/utils/getBanner.d.ts
|
|
@@ -62,21 +62,41 @@ type SchemaResult<TWithRef extends boolean = false> = {
|
|
|
62
62
|
declare function getSchemaFactory<TWithRef extends boolean = false>(oas: Oas): (schema: SchemaObject | null) => SchemaResult<TWithRef>;
|
|
63
63
|
//#endregion
|
|
64
64
|
//#region src/utils/getSchemas.d.ts
|
|
65
|
+
type GetSchemasResult = {
|
|
66
|
+
schemas: Record<string, OasTypes.SchemaObject>;
|
|
67
|
+
/**
|
|
68
|
+
* Mapping from original component name to resolved name after collision handling
|
|
69
|
+
* e.g., { 'Order': 'OrderSchema', 'variant': 'variant2' }
|
|
70
|
+
*/
|
|
71
|
+
nameMapping: Map<string, string>;
|
|
72
|
+
};
|
|
65
73
|
type Mode = 'schemas' | 'responses' | 'requestBodies';
|
|
66
74
|
type GetSchemasProps = {
|
|
67
75
|
oas: Oas;
|
|
68
76
|
contentType?: contentType;
|
|
69
77
|
includes?: Mode[];
|
|
78
|
+
/**
|
|
79
|
+
* Whether to resolve name collisions with suffixes.
|
|
80
|
+
* If not provided, uses oas.options.collisionDetection
|
|
81
|
+
* @default false (from oas.options or fallback)
|
|
82
|
+
*/
|
|
83
|
+
collisionDetection?: boolean;
|
|
70
84
|
};
|
|
71
85
|
/**
|
|
72
86
|
* Collect schemas from OpenAPI components (schemas, responses, requestBodies)
|
|
73
|
-
* and return them in dependency order.
|
|
87
|
+
* and return them in dependency order along with name mapping for collision resolution.
|
|
88
|
+
*
|
|
89
|
+
* This function is a wrapper around the oas.getSchemas() method for backward compatibility.
|
|
90
|
+
* New code should use oas.getSchemas() directly.
|
|
91
|
+
*
|
|
92
|
+
* @deprecated Use oas.getSchemas() instead
|
|
74
93
|
*/
|
|
75
94
|
declare function getSchemas({
|
|
76
95
|
oas,
|
|
77
96
|
contentType,
|
|
78
|
-
includes
|
|
79
|
-
|
|
97
|
+
includes,
|
|
98
|
+
collisionDetection
|
|
99
|
+
}: GetSchemasProps): GetSchemasResult;
|
|
80
100
|
//#endregion
|
|
81
101
|
export { getBanner, getComments, getFooter, getPathParams, getSchemaFactory, getSchemas, isOptional };
|
|
82
102
|
//# sourceMappingURL=utils.d.ts.map
|
package/dist/utils.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t as __name } from "./chunk-iVr_oF3V.js";
|
|
2
|
-
import {
|
|
2
|
+
import { t as getSchemaFactory } from "./getSchemaFactory-DsoVRgxV.js";
|
|
3
3
|
import { n as getBanner, t as getFooter } from "./getFooter-PYWvz29J.js";
|
|
4
4
|
import transformers, { camelCase, isValidVarName } from "@kubb/core/transformers";
|
|
5
5
|
import { URLPath } from "@kubb/core/utils";
|
|
@@ -50,6 +50,29 @@ function getPathParams(operationSchema, options = {}) {
|
|
|
50
50
|
}, {});
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
+
//#endregion
|
|
54
|
+
//#region src/utils/getSchemas.ts
|
|
55
|
+
/**
|
|
56
|
+
* Collect schemas from OpenAPI components (schemas, responses, requestBodies)
|
|
57
|
+
* and return them in dependency order along with name mapping for collision resolution.
|
|
58
|
+
*
|
|
59
|
+
* This function is a wrapper around the oas.getSchemas() method for backward compatibility.
|
|
60
|
+
* New code should use oas.getSchemas() directly.
|
|
61
|
+
*
|
|
62
|
+
* @deprecated Use oas.getSchemas() instead
|
|
63
|
+
*/
|
|
64
|
+
function getSchemas({ oas, contentType, includes = [
|
|
65
|
+
"schemas",
|
|
66
|
+
"requestBodies",
|
|
67
|
+
"responses"
|
|
68
|
+
], collisionDetection }) {
|
|
69
|
+
return oas.getSchemas({
|
|
70
|
+
contentType,
|
|
71
|
+
includes,
|
|
72
|
+
collisionDetection
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
|
|
53
76
|
//#endregion
|
|
54
77
|
export { getBanner, getComments, getFooter, getPathParams, getSchemaFactory, getSchemas, isOptional };
|
|
55
78
|
//# sourceMappingURL=utils.js.map
|
package/dist/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","names":[],"sources":["../src/utils/getComments.ts","../src/utils/getParams.ts"],"sourcesContent":["import transformers from '@kubb/core/transformers'\nimport { URLPath } from '@kubb/core/utils'\n\nimport type { Operation } from '@kubb/oas'\n\nexport function getComments(operation: Operation): string[] {\n return [\n operation.getDescription() && `@description ${operation.getDescription()}`,\n operation.getSummary() && `@summary ${operation.getSummary()}`,\n operation.path && `{@link ${new URLPath(operation.path).URL}}`,\n operation.isDeprecated() && '@deprecated',\n ]\n .filter(Boolean)\n .map((text) => transformers.trim(text))\n .filter(Boolean)\n}\n","import { camelCase, isValidVarName } from '@kubb/core/transformers'\nimport type { FunctionParamsAST } from '@kubb/core/utils'\nimport type { OasTypes } from '@kubb/oas'\nimport type { Params } from '@kubb/react-fabric/types'\nimport type { OperationSchema } from '../types.ts'\n/**\n *\n * @deprecated\n * TODO move to operationManager hook\n */\nexport function getASTParams(\n operationSchema: OperationSchema | undefined,\n {\n typed = false,\n override,\n }: {\n typed?: boolean\n override?: (data: FunctionParamsAST) => FunctionParamsAST\n } = {},\n): FunctionParamsAST[] {\n if (!operationSchema || !operationSchema.schema.properties || !operationSchema.name) {\n return []\n }\n\n const requiredFields = Array.isArray(operationSchema.schema.required) ? operationSchema.schema.required : []\n\n return Object.entries(operationSchema.schema.properties).map(([name]: [string, OasTypes.SchemaObject]) => {\n const data: FunctionParamsAST = {\n name,\n enabled: !!name,\n required: requiredFields.includes(name),\n type: typed ? `${operationSchema.name}[\"${name}\"]` : undefined,\n }\n\n return override ? override(data) : data\n })\n}\n\nexport function getPathParams(\n operationSchema: OperationSchema | undefined,\n options: {\n typed?: boolean\n casing?: 'camelcase'\n override?: (data: FunctionParamsAST) => FunctionParamsAST\n } = {},\n) {\n return getASTParams(operationSchema, options).reduce((acc, curr) => {\n if (curr.name && curr.enabled) {\n let name = isValidVarName(curr.name) ? curr.name : camelCase(curr.name)\n\n if (options.casing === 'camelcase') {\n name = camelCase(name)\n }\n\n acc[name] = {\n default: curr.default,\n type: curr.type,\n optional: !curr.required,\n }\n }\n\n return acc\n }, {} as Params)\n}\n"],"mappings":";;;;;;;;AAKA,SAAgB,YAAY,WAAgC;AAC1D,QAAO;EACL,UAAU,gBAAgB,IAAI,gBAAgB,UAAU,gBAAgB;EACxE,UAAU,YAAY,IAAI,YAAY,UAAU,YAAY;EAC5D,UAAU,QAAQ,UAAU,IAAI,QAAQ,UAAU,KAAK,CAAC,IAAI;EAC5D,UAAU,cAAc,IAAI;EAC7B,CACE,OAAO,QAAQ,CACf,KAAK,SAAS,aAAa,KAAK,KAAK,CAAC,CACtC,OAAO,QAAQ;;;;;;;;;;ACJpB,SAAgB,aACd,iBACA,EACE,QAAQ,OACR,aAIE,EAAE,EACe;AACrB,KAAI,CAAC,mBAAmB,CAAC,gBAAgB,OAAO,cAAc,CAAC,gBAAgB,KAC7E,QAAO,EAAE;CAGX,MAAM,iBAAiB,MAAM,QAAQ,gBAAgB,OAAO,SAAS,GAAG,gBAAgB,OAAO,WAAW,EAAE;AAE5G,QAAO,OAAO,QAAQ,gBAAgB,OAAO,WAAW,CAAC,KAAK,CAAC,UAA2C;EACxG,MAAM,OAA0B;GAC9B;GACA,SAAS,CAAC,CAAC;GACX,UAAU,eAAe,SAAS,KAAK;GACvC,MAAM,QAAQ,GAAG,gBAAgB,KAAK,IAAI,KAAK,MAAM;GACtD;AAED,SAAO,WAAW,SAAS,KAAK,GAAG;GACnC;;AAGJ,SAAgB,cACd,iBACA,UAII,EAAE,EACN;AACA,QAAO,aAAa,iBAAiB,QAAQ,CAAC,QAAQ,KAAK,SAAS;AAClE,MAAI,KAAK,QAAQ,KAAK,SAAS;GAC7B,IAAI,OAAO,eAAe,KAAK,KAAK,GAAG,KAAK,OAAO,UAAU,KAAK,KAAK;AAEvE,OAAI,QAAQ,WAAW,YACrB,QAAO,UAAU,KAAK;AAGxB,OAAI,QAAQ;IACV,SAAS,KAAK;IACd,MAAM,KAAK;IACX,UAAU,CAAC,KAAK;IACjB;;AAGH,SAAO;IACN,EAAE,CAAW"}
|
|
1
|
+
{"version":3,"file":"utils.js","names":[],"sources":["../src/utils/getComments.ts","../src/utils/getParams.ts","../src/utils/getSchemas.ts"],"sourcesContent":["import transformers from '@kubb/core/transformers'\nimport { URLPath } from '@kubb/core/utils'\n\nimport type { Operation } from '@kubb/oas'\n\nexport function getComments(operation: Operation): string[] {\n return [\n operation.getDescription() && `@description ${operation.getDescription()}`,\n operation.getSummary() && `@summary ${operation.getSummary()}`,\n operation.path && `{@link ${new URLPath(operation.path).URL}}`,\n operation.isDeprecated() && '@deprecated',\n ]\n .filter(Boolean)\n .map((text) => transformers.trim(text))\n .filter(Boolean)\n}\n","import { camelCase, isValidVarName } from '@kubb/core/transformers'\nimport type { FunctionParamsAST } from '@kubb/core/utils'\nimport type { OasTypes } from '@kubb/oas'\nimport type { Params } from '@kubb/react-fabric/types'\nimport type { OperationSchema } from '../types.ts'\n/**\n *\n * @deprecated\n * TODO move to operationManager hook\n */\nexport function getASTParams(\n operationSchema: OperationSchema | undefined,\n {\n typed = false,\n override,\n }: {\n typed?: boolean\n override?: (data: FunctionParamsAST) => FunctionParamsAST\n } = {},\n): FunctionParamsAST[] {\n if (!operationSchema || !operationSchema.schema.properties || !operationSchema.name) {\n return []\n }\n\n const requiredFields = Array.isArray(operationSchema.schema.required) ? operationSchema.schema.required : []\n\n return Object.entries(operationSchema.schema.properties).map(([name]: [string, OasTypes.SchemaObject]) => {\n const data: FunctionParamsAST = {\n name,\n enabled: !!name,\n required: requiredFields.includes(name),\n type: typed ? `${operationSchema.name}[\"${name}\"]` : undefined,\n }\n\n return override ? override(data) : data\n })\n}\n\nexport function getPathParams(\n operationSchema: OperationSchema | undefined,\n options: {\n typed?: boolean\n casing?: 'camelcase'\n override?: (data: FunctionParamsAST) => FunctionParamsAST\n } = {},\n) {\n return getASTParams(operationSchema, options).reduce((acc, curr) => {\n if (curr.name && curr.enabled) {\n let name = isValidVarName(curr.name) ? curr.name : camelCase(curr.name)\n\n if (options.casing === 'camelcase') {\n name = camelCase(name)\n }\n\n acc[name] = {\n default: curr.default,\n type: curr.type,\n optional: !curr.required,\n }\n }\n\n return acc\n }, {} as Params)\n}\n","import type { contentType, Oas, OasTypes } from '@kubb/oas'\n\nexport type GetSchemasResult = {\n schemas: Record<string, OasTypes.SchemaObject>\n /**\n * Mapping from original component name to resolved name after collision handling\n * e.g., { 'Order': 'OrderSchema', 'variant': 'variant2' }\n */\n nameMapping: Map<string, string>\n}\n\ntype Mode = 'schemas' | 'responses' | 'requestBodies'\n\ntype GetSchemasProps = {\n oas: Oas\n contentType?: contentType\n includes?: Mode[]\n /**\n * Whether to resolve name collisions with suffixes.\n * If not provided, uses oas.options.collisionDetection\n * @default false (from oas.options or fallback)\n */\n collisionDetection?: boolean\n}\n\n/**\n * Collect schemas from OpenAPI components (schemas, responses, requestBodies)\n * and return them in dependency order along with name mapping for collision resolution.\n *\n * This function is a wrapper around the oas.getSchemas() method for backward compatibility.\n * New code should use oas.getSchemas() directly.\n *\n * @deprecated Use oas.getSchemas() instead\n */\nexport function getSchemas({ oas, contentType, includes = ['schemas', 'requestBodies', 'responses'], collisionDetection }: GetSchemasProps): GetSchemasResult {\n return oas.getSchemas({\n contentType,\n includes,\n collisionDetection,\n })\n}\n"],"mappings":";;;;;;;;AAKA,SAAgB,YAAY,WAAgC;AAC1D,QAAO;EACL,UAAU,gBAAgB,IAAI,gBAAgB,UAAU,gBAAgB;EACxE,UAAU,YAAY,IAAI,YAAY,UAAU,YAAY;EAC5D,UAAU,QAAQ,UAAU,IAAI,QAAQ,UAAU,KAAK,CAAC,IAAI;EAC5D,UAAU,cAAc,IAAI;EAC7B,CACE,OAAO,QAAQ,CACf,KAAK,SAAS,aAAa,KAAK,KAAK,CAAC,CACtC,OAAO,QAAQ;;;;;;;;;;ACJpB,SAAgB,aACd,iBACA,EACE,QAAQ,OACR,aAIE,EAAE,EACe;AACrB,KAAI,CAAC,mBAAmB,CAAC,gBAAgB,OAAO,cAAc,CAAC,gBAAgB,KAC7E,QAAO,EAAE;CAGX,MAAM,iBAAiB,MAAM,QAAQ,gBAAgB,OAAO,SAAS,GAAG,gBAAgB,OAAO,WAAW,EAAE;AAE5G,QAAO,OAAO,QAAQ,gBAAgB,OAAO,WAAW,CAAC,KAAK,CAAC,UAA2C;EACxG,MAAM,OAA0B;GAC9B;GACA,SAAS,CAAC,CAAC;GACX,UAAU,eAAe,SAAS,KAAK;GACvC,MAAM,QAAQ,GAAG,gBAAgB,KAAK,IAAI,KAAK,MAAM;GACtD;AAED,SAAO,WAAW,SAAS,KAAK,GAAG;GACnC;;AAGJ,SAAgB,cACd,iBACA,UAII,EAAE,EACN;AACA,QAAO,aAAa,iBAAiB,QAAQ,CAAC,QAAQ,KAAK,SAAS;AAClE,MAAI,KAAK,QAAQ,KAAK,SAAS;GAC7B,IAAI,OAAO,eAAe,KAAK,KAAK,GAAG,KAAK,OAAO,UAAU,KAAK,KAAK;AAEvE,OAAI,QAAQ,WAAW,YACrB,QAAO,UAAU,KAAK;AAGxB,OAAI,QAAQ;IACV,SAAS,KAAK;IACd,MAAM,KAAK;IACX,UAAU,CAAC,KAAK;IACjB;;AAGH,SAAO;IACN,EAAE,CAAW;;;;;;;;;;;;;;AC5BlB,SAAgB,WAAW,EAAE,KAAK,aAAa,WAAW;CAAC;CAAW;CAAiB;CAAY,EAAE,sBAAyD;AAC5J,QAAO,IAAI,WAAW;EACpB;EACA;EACA;EACD,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/plugin-oas",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.19.0",
|
|
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",
|
|
@@ -82,8 +82,8 @@
|
|
|
82
82
|
"@kubb/react-fabric": "0.12.4",
|
|
83
83
|
"p-limit": "^7.2.0",
|
|
84
84
|
"remeda": "^2.33.4",
|
|
85
|
-
"@kubb/core": "4.
|
|
86
|
-
"@kubb/oas": "4.
|
|
85
|
+
"@kubb/core": "4.19.0",
|
|
86
|
+
"@kubb/oas": "4.19.0"
|
|
87
87
|
},
|
|
88
88
|
"peerDependencies": {
|
|
89
89
|
"@kubb/react-fabric": "0.12.4"
|
package/src/SchemaGenerator.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { BaseGenerator, type FileMetaBase } from '@kubb/core'
|
|
|
3
3
|
import transformers, { pascalCase } from '@kubb/core/transformers'
|
|
4
4
|
import { type AsyncEventEmitter, getUniqueName } from '@kubb/core/utils'
|
|
5
5
|
import type { KubbFile } from '@kubb/fabric-core/types'
|
|
6
|
-
import type { contentType, Oas, OpenAPIV3, SchemaObject } from '@kubb/oas'
|
|
6
|
+
import type { contentType, Oas, OasTypes, OpenAPIV3, SchemaObject } from '@kubb/oas'
|
|
7
7
|
import { isDiscriminator, isNullable, isReference } from '@kubb/oas'
|
|
8
8
|
import type { Fabric } from '@kubb/react-fabric'
|
|
9
9
|
import pLimit from 'p-limit'
|
|
@@ -12,7 +12,6 @@ import type { Generator } from './generators/types.ts'
|
|
|
12
12
|
import { isKeyword, type Schema, type SchemaKeywordMapper, schemaKeywords } from './SchemaMapper.ts'
|
|
13
13
|
import type { OperationSchema, Override, Refs } from './types.ts'
|
|
14
14
|
import { getSchemaFactory } from './utils/getSchemaFactory.ts'
|
|
15
|
-
import { getSchemas } from './utils/getSchemas.ts'
|
|
16
15
|
import { buildSchema } from './utils.tsx'
|
|
17
16
|
|
|
18
17
|
export type GetSchemaGeneratorOptions<T extends SchemaGenerator<any, any, any>> = T extends SchemaGenerator<infer Options, any, any> ? Options : never
|
|
@@ -50,7 +49,7 @@ export type SchemaGeneratorOptions = {
|
|
|
50
49
|
*/
|
|
51
50
|
name?: (name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string
|
|
52
51
|
/**
|
|
53
|
-
* Receive schema and name(
|
|
52
|
+
* Receive schema and name(propertyName) and return FakerMeta array
|
|
54
53
|
* TODO TODO add docs
|
|
55
54
|
* @beta
|
|
56
55
|
*/
|
|
@@ -74,13 +73,31 @@ export class SchemaGenerator<
|
|
|
74
73
|
// Collect the types of all referenced schemas, so we can export them later
|
|
75
74
|
refs: Refs = {}
|
|
76
75
|
|
|
77
|
-
//
|
|
78
|
-
|
|
76
|
+
// Map from original component paths to resolved schema names (after collision resolution)
|
|
77
|
+
// e.g., { '#/components/schemas/Order': 'OrderSchema', '#/components/responses/Product': 'ProductResponse' }
|
|
78
|
+
#schemaNameMapping: Map<string, string> = new Map()
|
|
79
|
+
|
|
80
|
+
// Flag to track if nameMapping has been initialized
|
|
81
|
+
#nameMappingInitialized = false
|
|
79
82
|
|
|
80
83
|
// Cache for parsed schemas to avoid redundant parsing
|
|
81
84
|
// Using WeakMap for automatic garbage collection when schemas are no longer referenced
|
|
82
85
|
#parseCache: Map<string, Schema[]> = new Map()
|
|
83
86
|
|
|
87
|
+
/**
|
|
88
|
+
* Ensure the name mapping is initialized (lazy initialization)
|
|
89
|
+
*/
|
|
90
|
+
#ensureNameMapping() {
|
|
91
|
+
if (this.#nameMappingInitialized) {
|
|
92
|
+
return
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const { oas, contentType, include } = this.context
|
|
96
|
+
const { nameMapping } = oas.getSchemas({ contentType, includes: include })
|
|
97
|
+
this.#schemaNameMapping = nameMapping
|
|
98
|
+
this.#nameMappingInitialized = true
|
|
99
|
+
}
|
|
100
|
+
|
|
84
101
|
/**
|
|
85
102
|
* Creates a type node from a given schema.
|
|
86
103
|
* Delegates to getBaseTypeFromSchema internally and
|
|
@@ -333,7 +350,7 @@ export class SchemaGenerator<
|
|
|
333
350
|
const propertySchema = properties[propertyName] as SchemaObject
|
|
334
351
|
|
|
335
352
|
const isRequired = Array.isArray(required) ? required?.includes(propertyName) : !!required
|
|
336
|
-
const nullable = propertySchema
|
|
353
|
+
const nullable = isNullable(propertySchema)
|
|
337
354
|
|
|
338
355
|
validationFunctions.push(...this.parse({ schema: propertySchema, name: propertyName, parentName: name }))
|
|
339
356
|
|
|
@@ -453,15 +470,21 @@ export class SchemaGenerator<
|
|
|
453
470
|
]
|
|
454
471
|
}
|
|
455
472
|
|
|
456
|
-
|
|
473
|
+
// Ensure name mapping is initialized before resolving names
|
|
474
|
+
this.#ensureNameMapping()
|
|
475
|
+
|
|
476
|
+
const originalName = $ref.replace(/.+\//, '')
|
|
477
|
+
// Use the full $ref path to look up the collision-resolved name
|
|
478
|
+
const resolvedName = this.#schemaNameMapping.get($ref) || originalName
|
|
479
|
+
|
|
457
480
|
const propertyName = this.context.pluginManager.resolveName({
|
|
458
|
-
name:
|
|
481
|
+
name: resolvedName,
|
|
459
482
|
pluginKey: this.context.plugin.key,
|
|
460
483
|
type: 'function',
|
|
461
484
|
})
|
|
462
485
|
|
|
463
486
|
const fileName = this.context.pluginManager.resolveName({
|
|
464
|
-
name:
|
|
487
|
+
name: resolvedName,
|
|
465
488
|
pluginKey: this.context.plugin.key,
|
|
466
489
|
type: 'file',
|
|
467
490
|
})
|
|
@@ -473,7 +496,7 @@ export class SchemaGenerator<
|
|
|
473
496
|
|
|
474
497
|
this.refs[$ref] = {
|
|
475
498
|
propertyName,
|
|
476
|
-
originalName,
|
|
499
|
+
originalName: resolvedName,
|
|
477
500
|
path: file.path,
|
|
478
501
|
}
|
|
479
502
|
|
|
@@ -498,7 +521,7 @@ export class SchemaGenerator<
|
|
|
498
521
|
}
|
|
499
522
|
|
|
500
523
|
// If the discriminator property is an extension property (starts with x-),
|
|
501
|
-
//
|
|
524
|
+
// its metadata and not an actual schema property, so we can't add constraints for it.
|
|
502
525
|
// In this case, return the union as-is without adding discriminator constraints.
|
|
503
526
|
if (discriminator.propertyName.startsWith('x-')) {
|
|
504
527
|
return schema
|
|
@@ -698,11 +721,6 @@ export class SchemaGenerator<
|
|
|
698
721
|
if (schemaObject.type && Array.isArray(schemaObject.type)) {
|
|
699
722
|
// OPENAPI v3.1.0: https://www.openapis.org/blog/2021/02/16/migrating-from-openapi-3-0-to-3-1-0
|
|
700
723
|
const items = schemaObject.type.filter((value) => value !== 'null') as Array<OpenAPIV3.NonArraySchemaObjectType>
|
|
701
|
-
const hasNull = (schemaObject.type as string[]).includes('null')
|
|
702
|
-
|
|
703
|
-
if (hasNull && !nullable) {
|
|
704
|
-
baseItems.push({ keyword: schemaKeywords.nullable })
|
|
705
|
-
}
|
|
706
724
|
|
|
707
725
|
if (items.length > 1) {
|
|
708
726
|
const parsedItems = [
|
|
@@ -768,7 +786,7 @@ export class SchemaGenerator<
|
|
|
768
786
|
keyword: schemaKeywords.union,
|
|
769
787
|
args: (schemaObject.oneOf || schemaObject.anyOf)!
|
|
770
788
|
.map((item) => {
|
|
771
|
-
// first item, this
|
|
789
|
+
// first item, this is ref
|
|
772
790
|
return item && this.parse({ schema: item as SchemaObject, name, parentName })[0]
|
|
773
791
|
})
|
|
774
792
|
.filter(Boolean),
|
|
@@ -1036,7 +1054,7 @@ export class SchemaGenerator<
|
|
|
1036
1054
|
}
|
|
1037
1055
|
|
|
1038
1056
|
if (version === '3.1' && 'const' in schemaObject) {
|
|
1039
|
-
// const keyword takes
|
|
1057
|
+
// const keyword takes precedence over the actual type.
|
|
1040
1058
|
|
|
1041
1059
|
if (schemaObject['const'] === null) {
|
|
1042
1060
|
return [{ keyword: schemaKeywords.null }]
|
|
@@ -1193,7 +1211,7 @@ export class SchemaGenerator<
|
|
|
1193
1211
|
if (schemaObject.properties || schemaObject.additionalProperties || 'patternProperties' in schemaObject) {
|
|
1194
1212
|
if (isDiscriminator(schemaObject)) {
|
|
1195
1213
|
// override schema to set type to be based on discriminator mapping, use of enum to convert type string to type 'mapping1' | 'mapping2'
|
|
1196
|
-
const
|
|
1214
|
+
const schemaObjectOverridden = Object.keys(schemaObject.properties || {}).reduce((acc, propertyName) => {
|
|
1197
1215
|
if (acc.properties?.[propertyName] && propertyName === schemaObject.discriminator.propertyName) {
|
|
1198
1216
|
return {
|
|
1199
1217
|
...acc,
|
|
@@ -1210,7 +1228,7 @@ export class SchemaGenerator<
|
|
|
1210
1228
|
return acc
|
|
1211
1229
|
}, schemaObject || {}) as SchemaObject
|
|
1212
1230
|
|
|
1213
|
-
return [...this.#parseProperties(name,
|
|
1231
|
+
return [...this.#parseProperties(name, schemaObjectOverridden), ...baseItems]
|
|
1214
1232
|
}
|
|
1215
1233
|
|
|
1216
1234
|
return [...this.#parseProperties(name, schemaObject), ...baseItems]
|
|
@@ -1249,13 +1267,29 @@ export class SchemaGenerator<
|
|
|
1249
1267
|
|
|
1250
1268
|
async build(...generators: Array<Generator<TPluginOptions>>): Promise<Array<KubbFile.File<TFileMeta>>> {
|
|
1251
1269
|
const { oas, contentType, include } = this.context
|
|
1252
|
-
const schemas = getSchemas({ oas, contentType, includes: include })
|
|
1253
|
-
const schemaEntries = Object.entries(schemas)
|
|
1254
1270
|
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1271
|
+
// Initialize the name mapping if not already done
|
|
1272
|
+
if (!this.#nameMappingInitialized) {
|
|
1273
|
+
const { schemas, nameMapping } = oas.getSchemas({ contentType, includes: include })
|
|
1274
|
+
this.#schemaNameMapping = nameMapping
|
|
1275
|
+
this.#nameMappingInitialized = true
|
|
1276
|
+
const schemaEntries = Object.entries(schemas)
|
|
1277
|
+
|
|
1278
|
+
this.context.events?.emit('debug', {
|
|
1279
|
+
date: new Date(),
|
|
1280
|
+
logs: [`Building ${schemaEntries.length} schemas`, ` • Content Type: ${contentType || 'application/json'}`, ` • Generators: ${generators.length}`],
|
|
1281
|
+
})
|
|
1282
|
+
|
|
1283
|
+
// Continue with build using the schemas
|
|
1284
|
+
return this.#doBuild(schemas, generators)
|
|
1285
|
+
}
|
|
1286
|
+
// If already initialized, just get the schemas (without mapping)
|
|
1287
|
+
const { schemas } = oas.getSchemas({ contentType, includes: include })
|
|
1288
|
+
return this.#doBuild(schemas, generators)
|
|
1289
|
+
}
|
|
1290
|
+
|
|
1291
|
+
async #doBuild(schemas: Record<string, OasTypes.SchemaObject>, generators: Array<Generator<TPluginOptions>>): Promise<Array<KubbFile.File<TFileMeta>>> {
|
|
1292
|
+
const schemaEntries = Object.entries(schemas)
|
|
1259
1293
|
|
|
1260
1294
|
// Increased parallelism for better performance
|
|
1261
1295
|
// - generatorLimit increased from 1 to 3 to allow parallel generator processing
|
package/src/SchemaMapper.ts
CHANGED
|
@@ -61,8 +61,8 @@ export type SchemaKeywordMapper = {
|
|
|
61
61
|
*/
|
|
62
62
|
path: KubbFile.Path
|
|
63
63
|
/**
|
|
64
|
-
* When true `File.Import`
|
|
65
|
-
* When false a reference
|
|
64
|
+
* When true `File.Import` is used.
|
|
65
|
+
* When false a reference is used inside the current file.
|
|
66
66
|
*/
|
|
67
67
|
isImportable: boolean
|
|
68
68
|
}
|
|
@@ -168,7 +168,7 @@ export type SchemaTree = {
|
|
|
168
168
|
current: Schema
|
|
169
169
|
siblings: Schema[]
|
|
170
170
|
/**
|
|
171
|
-
* this
|
|
171
|
+
* this is equal to the key of a property(object)
|
|
172
172
|
*/
|
|
173
173
|
name?: string
|
|
174
174
|
}
|
|
@@ -60,7 +60,7 @@ type UseOperationManagerResult = {
|
|
|
60
60
|
}
|
|
61
61
|
|
|
62
62
|
/**
|
|
63
|
-
* `useOperationManager`
|
|
63
|
+
* `useOperationManager` returns helper functions to get the operation file and operation name.
|
|
64
64
|
*/
|
|
65
65
|
export function useOperationManager<TPluginOptions extends PluginFactoryOptions = PluginFactoryOptions>(
|
|
66
66
|
generator: Omit<OperationGenerator<TPluginOptions>, 'build'>,
|
|
@@ -31,7 +31,7 @@ type UseSchemaManagerResult = {
|
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
/**
|
|
34
|
-
* `useSchemaManager`
|
|
34
|
+
* `useSchemaManager` returns helper functions to get the schema file and schema name.
|
|
35
35
|
*/
|
|
36
36
|
export function useSchemaManager(): UseSchemaManagerResult {
|
|
37
37
|
const plugin = usePlugin()
|
package/src/plugin.ts
CHANGED
|
@@ -23,6 +23,7 @@ export const pluginOas = definePlugin<PluginOas>((options) => {
|
|
|
23
23
|
contentType,
|
|
24
24
|
oasClass,
|
|
25
25
|
discriminator = 'strict',
|
|
26
|
+
collisionDetection = false,
|
|
26
27
|
} = options
|
|
27
28
|
|
|
28
29
|
const getOas = async ({ validate, config, events }: { validate: boolean; config: Config; events: AsyncEventEmitter<KubbEvents> }): Promise<Oas> => {
|
|
@@ -32,11 +33,12 @@ export const pluginOas = definePlugin<PluginOas>((options) => {
|
|
|
32
33
|
oas.setOptions({
|
|
33
34
|
contentType,
|
|
34
35
|
discriminator,
|
|
36
|
+
collisionDetection,
|
|
35
37
|
})
|
|
36
38
|
|
|
37
39
|
try {
|
|
38
40
|
if (validate) {
|
|
39
|
-
await oas.
|
|
41
|
+
await oas.validate()
|
|
40
42
|
}
|
|
41
43
|
} catch (er) {
|
|
42
44
|
const caughtError = er as Error
|
package/src/types.ts
CHANGED
|
@@ -46,35 +46,55 @@ export type Options = {
|
|
|
46
46
|
/**
|
|
47
47
|
* Which server to use from the array of `servers.url[serverIndex]`
|
|
48
48
|
* @example
|
|
49
|
-
* - `0`
|
|
50
|
-
* - `1`
|
|
49
|
+
* - `0` returns `http://petstore.swagger.io/api`
|
|
50
|
+
* - `1` returns `http://localhost:3000`
|
|
51
51
|
*/
|
|
52
52
|
serverIndex?: number
|
|
53
53
|
/**
|
|
54
54
|
* Define which contentType should be used.
|
|
55
|
-
* By default, the first
|
|
55
|
+
* By default, uses the first valid JSON media type.
|
|
56
56
|
*/
|
|
57
57
|
contentType?: contentType
|
|
58
58
|
/**
|
|
59
59
|
* Defines how the discriminator value should be interpreted during processing.
|
|
60
|
-
*
|
|
60
|
+
* - 'strict' uses the oneOf schemas as defined, without modification.
|
|
61
|
+
* - 'inherit' replaces the oneOf schema with the schema referenced by discriminator.mapping[key].
|
|
61
62
|
* @default 'strict'
|
|
62
|
-
*
|
|
63
|
-
* @example
|
|
64
|
-
* - `inherit`: Replaces the `oneOf` schema with the schema referenced by `discriminator.mapping[key]`.
|
|
65
|
-
* - `strict`: Uses the `oneOf` schemas as defined, without modification.
|
|
66
|
-
*
|
|
67
63
|
* @see https://github.com/kubb-labs/kubb/issues/1736
|
|
68
64
|
*/
|
|
69
65
|
discriminator?: 'strict' | 'inherit'
|
|
70
66
|
/**
|
|
71
|
-
* Override some
|
|
67
|
+
* Override some behavior of the Oas class instance, see '@kubb/oas'
|
|
72
68
|
*/
|
|
73
69
|
oasClass?: typeof Oas
|
|
74
70
|
/**
|
|
75
71
|
* Define some generators next to the JSON generation
|
|
76
72
|
*/
|
|
77
73
|
generators?: Array<Generator<PluginOas>>
|
|
74
|
+
/**
|
|
75
|
+
* Resolve name collisions when schemas from different components share the same name (case-insensitive).
|
|
76
|
+
*
|
|
77
|
+
* When enabled, Kubb automatically detects and resolves collisions using intelligent suffixes:
|
|
78
|
+
* - Cross-component collisions: Adds semantic suffixes based on the component type (Schema/Response/Request)
|
|
79
|
+
* - Same-component collisions: Adds numeric suffixes (2, 3, ...) for case-insensitive duplicates
|
|
80
|
+
*
|
|
81
|
+
* When disabled (legacy behavior), collisions may result in duplicate files or overwrite issues.
|
|
82
|
+
*
|
|
83
|
+
* **Cross-component collision example:**
|
|
84
|
+
* If you have "Order" in both schemas and requestBodies:
|
|
85
|
+
* - With `collisionDetection: true`: Generates `OrderSchema.ts`, `OrderRequest.ts`
|
|
86
|
+
* - With `collisionDetection: false`: May generate duplicate `Order.ts` files
|
|
87
|
+
*
|
|
88
|
+
* **Same-component collision example:**
|
|
89
|
+
* If you have "Variant" and "variant" in schemas:
|
|
90
|
+
* - With `collisionDetection: true`: Generates `Variant.ts`, `Variant2.ts`
|
|
91
|
+
* - With `collisionDetection: false`: May overwrite or create duplicates
|
|
92
|
+
*
|
|
93
|
+
* @default false
|
|
94
|
+
* @see https://github.com/kubb-labs/kubb/issues/1999
|
|
95
|
+
* @note this will be the default in Kubb v5
|
|
96
|
+
*/
|
|
97
|
+
collisionDetection?: boolean
|
|
78
98
|
}
|
|
79
99
|
|
|
80
100
|
/**
|