@kubb/plugin-oas 0.0.0-canary-20251222142412 → 0.0.0-canary-20251222215628
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-DnqO8-jJ.cjs → SchemaGenerator-CzfhDNTC.cjs} +49 -50
- package/dist/SchemaGenerator-CzfhDNTC.cjs.map +1 -0
- package/dist/{SchemaGenerator-D6Ux5Gk1.js → SchemaGenerator-RhszLa_8.js} +49 -50
- package/dist/SchemaGenerator-RhszLa_8.js.map +1 -0
- package/dist/{SchemaMapper-9utcuebF.d.ts → SchemaMapper-BQqC-HKo.d.ts} +21 -23
- package/dist/{SchemaMapper-Bas8HSlb.d.cts → SchemaMapper-DHoFzVaG.d.cts} +21 -23
- package/dist/{createGenerator-xSurgvql.d.ts → createGenerator-BOeO1z4V.d.cts} +7 -7
- package/dist/{createGenerator-BcQ7-2GF.d.cts → createGenerator-BPhjS5cM.d.ts} +7 -7
- package/dist/generators.d.cts +2 -2
- package/dist/generators.d.ts +2 -2
- package/dist/getSchemas-DFlFfjx-.cjs.map +1 -1
- package/dist/getSchemas-DH7Mz7ud.js.map +1 -1
- package/dist/hooks.cjs +1 -1
- package/dist/hooks.d.cts +2 -2
- package/dist/hooks.d.ts +2 -2
- package/dist/hooks.js +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/mocks.d.cts +1 -1
- package/dist/mocks.d.ts +1 -1
- package/dist/utils.d.cts +7 -7
- package/dist/utils.d.ts +7 -7
- package/package.json +3 -3
- package/src/SchemaGenerator.ts +66 -44
- package/src/utils/getSchemaFactory.ts +14 -10
- package/dist/SchemaGenerator-D6Ux5Gk1.js.map +0 -1
- package/dist/SchemaGenerator-DnqO8-jJ.cjs.map +0 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { C as Plugin, D as AsyncEventEmitter, O as KubbEvents, S as Output, T as ResolveNameParams, _ as contentType, b as Config, d as HttpMethod, g as SchemaObject, h as Operation, i as SchemaKeywordMapper, k as BaseGenerator, t as Schema, u as Oas, v as FileMetaBase, w as PluginFactoryOptions, x as Group, y as PluginManager } from "./SchemaMapper-
|
|
2
|
-
import { KubbFile } from "@kubb/fabric-core/types";
|
|
1
|
+
import { C as Plugin, D as AsyncEventEmitter, O as KubbEvents, S as Output, T as ResolveNameParams, _ as contentType, b as Config, d as HttpMethod, g as SchemaObject, h as Operation, i as SchemaKeywordMapper, k as BaseGenerator, t as Schema, u as Oas, v as FileMetaBase, w as PluginFactoryOptions, x as Group, y as PluginManager } from "./SchemaMapper-BQqC-HKo.js";
|
|
3
2
|
import { Fabric } from "@kubb/react-fabric";
|
|
3
|
+
import { KubbFile } from "@kubb/fabric-core/types";
|
|
4
4
|
import { KubbNode } from "@kubb/react-fabric/types";
|
|
5
5
|
|
|
6
6
|
//#region ../core/src/utils/FunctionParams.d.ts
|
|
@@ -264,14 +264,14 @@ type SchemaGeneratorOptions = {
|
|
|
264
264
|
* TODO TODO add docs
|
|
265
265
|
* @beta
|
|
266
266
|
*/
|
|
267
|
-
schema?: (schemaProps: SchemaProps$1, defaultSchemas: Schema[]) => Schema
|
|
267
|
+
schema?: (schemaProps: SchemaProps$1, defaultSchemas: Schema[]) => Array<Schema> | undefined;
|
|
268
268
|
};
|
|
269
269
|
};
|
|
270
270
|
type SchemaGeneratorBuildOptions = Omit<OperationSchema, 'name' | 'schema'>;
|
|
271
271
|
type SchemaProps$1 = {
|
|
272
|
-
|
|
273
|
-
name
|
|
274
|
-
parentName
|
|
272
|
+
schema: SchemaObject | null;
|
|
273
|
+
name: string | null;
|
|
274
|
+
parentName: string | null;
|
|
275
275
|
};
|
|
276
276
|
declare class SchemaGenerator<TOptions extends SchemaGeneratorOptions = SchemaGeneratorOptions, TPluginOptions extends PluginFactoryOptions = PluginFactoryOptions, TFileMeta extends FileMetaBase = FileMetaBase> extends BaseGenerator<TOptions, Context<TOptions, TPluginOptions>> {
|
|
277
277
|
#private;
|
|
@@ -353,4 +353,4 @@ type CoreGenerator<TOptions extends PluginFactoryOptions> = {
|
|
|
353
353
|
declare function createGenerator<TOptions extends PluginFactoryOptions>(generator: UserGenerator<TOptions>): CoreGenerator<TOptions>;
|
|
354
354
|
//#endregion
|
|
355
355
|
export { Resolver as C, ResolvePathOptions as S, Options as _, createReactGenerator as a, Ref as b, SchemaGeneratorBuildOptions as c, OperationGenerator as d, OperationMethodResult as f, OperationSchemas as g, OperationSchema as h, ReactGenerator as i, SchemaGeneratorOptions as l, Include as m, createGenerator as n, GetSchemaGeneratorOptions as o, Exclude as p, Generator as r, SchemaGenerator as s, CoreGenerator as t, SchemaMethodResult as u, Override as v, FunctionParamsAST as w, Refs as x, PluginOas as y };
|
|
356
|
-
//# sourceMappingURL=createGenerator-
|
|
356
|
+
//# sourceMappingURL=createGenerator-BPhjS5cM.d.ts.map
|
package/dist/generators.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import "./SchemaMapper-
|
|
2
|
-
import { a as createReactGenerator, n as createGenerator, r as Generator, t as CoreGenerator, y as PluginOas } from "./createGenerator-
|
|
1
|
+
import "./SchemaMapper-DHoFzVaG.cjs";
|
|
2
|
+
import { a as createReactGenerator, n as createGenerator, r as Generator, t as CoreGenerator, y as PluginOas } from "./createGenerator-BOeO1z4V.cjs";
|
|
3
3
|
|
|
4
4
|
//#region src/generators/jsonGenerator.d.ts
|
|
5
5
|
declare const jsonGenerator: CoreGenerator<PluginOas>;
|
package/dist/generators.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import "./SchemaMapper-
|
|
2
|
-
import { a as createReactGenerator, n as createGenerator, r as Generator, t as CoreGenerator, y as PluginOas } from "./createGenerator-
|
|
1
|
+
import "./SchemaMapper-BQqC-HKo.js";
|
|
2
|
+
import { a as createReactGenerator, n as createGenerator, r as Generator, t as CoreGenerator, y as PluginOas } from "./createGenerator-BPhjS5cM.js";
|
|
3
3
|
|
|
4
4
|
//#region src/generators/jsonGenerator.d.ts
|
|
5
5
|
declare const jsonGenerator: CoreGenerator<PluginOas>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getSchemas-DFlFfjx-.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
|
|
1
|
+
{"version":3,"file":"getSchemas-DFlFfjx-.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:\n | ((TWithRef extends true ? OpenAPIV3.SchemaObject | OpenAPIV3.ReferenceObject : OpenAPIV3.SchemaObject) & {\n nullable?: boolean\n 'x-nullable'?: boolean\n })\n | null\n version: '3.0'\n }\n | {\n schemaObject:\n | ((TWithRef extends true ? OpenAPIV3_1.SchemaObject | OpenAPIV3_1.ReferenceObject : OpenAPIV3_1.SchemaObject) & {\n nullable?: boolean\n 'x-nullable'?: boolean\n })\n | null\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 | null) => SchemaResult<TWithRef> {\n return (schema: SchemaObject | null) => {\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 responseObject = response as OasTypes.ResponseObject\n if (responseObject.content && !schemas[name]) {\n const firstContentType = Object.keys(responseObject.content)[0] || 'application/json'\n schemas[name] = responseObject.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 requestObject = request as OasTypes.RequestBodyObject\n if (requestObject.content && !schemas[name]) {\n const firstContentType = Object.keys(requestObject.content)[0] || 'application/json'\n schemas[name] = requestObject.content?.[contentType || firstContentType]?.schema as OasTypes.SchemaObject\n }\n }\n }\n\n return sortSchemas(schemas)\n}\n"],"mappings":";;;;;;;;;;;AAiCA,SAAgB,iBAAmD,KAAmE;AACpI,SAAQ,WAAgC;EACtC,MAAM,+CAAgC,IAAI,IAAI,GAAG,QAAQ;AAEzD,SAAO;GACL,cAAc,IAAI,mBAAmB,OAAO;GAC5C;GACD;;;;;;;;;AC3BL,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,iBAAiB;AACvB,OAAI,eAAe,WAAW,CAAC,QAAQ,OAAO;IAC5C,MAAM,mBAAmB,OAAO,KAAK,eAAe,QAAQ,CAAC,MAAM;AACnE,YAAQ,QAAQ,eAAe,UAAU,eAAe,mBAAmB;;;;AAKjF,KAAI,SAAS,SAAS,gBAAgB,EAAE;EACtC,MAAM,gBAAgB,YAAY,iBAAiB,EAAE;AACrD,OAAK,MAAM,CAAC,MAAM,YAAY,OAAO,QAAQ,cAAc,EAAE;GAC3D,MAAM,gBAAgB;AACtB,OAAI,cAAc,WAAW,CAAC,QAAQ,OAAO;IAC3C,MAAM,mBAAmB,OAAO,KAAK,cAAc,QAAQ,CAAC,MAAM;AAClE,YAAQ,QAAQ,cAAc,UAAU,eAAe,mBAAmB;;;;AAKhF,QAAO,YAAY,QAAQ"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getSchemas-DH7Mz7ud.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
|
|
1
|
+
{"version":3,"file":"getSchemas-DH7Mz7ud.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:\n | ((TWithRef extends true ? OpenAPIV3.SchemaObject | OpenAPIV3.ReferenceObject : OpenAPIV3.SchemaObject) & {\n nullable?: boolean\n 'x-nullable'?: boolean\n })\n | null\n version: '3.0'\n }\n | {\n schemaObject:\n | ((TWithRef extends true ? OpenAPIV3_1.SchemaObject | OpenAPIV3_1.ReferenceObject : OpenAPIV3_1.SchemaObject) & {\n nullable?: boolean\n 'x-nullable'?: boolean\n })\n | null\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 | null) => SchemaResult<TWithRef> {\n return (schema: SchemaObject | null) => {\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 responseObject = response as OasTypes.ResponseObject\n if (responseObject.content && !schemas[name]) {\n const firstContentType = Object.keys(responseObject.content)[0] || 'application/json'\n schemas[name] = responseObject.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 requestObject = request as OasTypes.RequestBodyObject\n if (requestObject.content && !schemas[name]) {\n const firstContentType = Object.keys(requestObject.content)[0] || 'application/json'\n schemas[name] = requestObject.content?.[contentType || firstContentType]?.schema as OasTypes.SchemaObject\n }\n }\n }\n\n return sortSchemas(schemas)\n}\n"],"mappings":";;;;;;;;;;AAiCA,SAAgB,iBAAmD,KAAmE;AACpI,SAAQ,WAAgC;EACtC,MAAM,UAAU,sBAAsB,IAAI,IAAI,GAAG,QAAQ;AAEzD,SAAO;GACL,cAAc,IAAI,mBAAmB,OAAO;GAC5C;GACD;;;;;;;;;AC3BL,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,iBAAiB;AACvB,OAAI,eAAe,WAAW,CAAC,QAAQ,OAAO;IAC5C,MAAM,mBAAmB,OAAO,KAAK,eAAe,QAAQ,CAAC,MAAM;AACnE,YAAQ,QAAQ,eAAe,UAAU,eAAe,mBAAmB;;;;AAKjF,KAAI,SAAS,SAAS,gBAAgB,EAAE;EACtC,MAAM,gBAAgB,YAAY,iBAAiB,EAAE;AACrD,OAAK,MAAM,CAAC,MAAM,YAAY,OAAO,QAAQ,cAAc,EAAE;GAC3D,MAAM,gBAAgB;AACtB,OAAI,cAAc,WAAW,CAAC,QAAQ,OAAO;IAC3C,MAAM,mBAAmB,OAAO,KAAK,cAAc,QAAQ,CAAC,MAAM;AAClE,YAAQ,QAAQ,cAAc,UAAU,eAAe,mBAAmB;;;;AAKhF,QAAO,YAAY,QAAQ"}
|
package/dist/hooks.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const require_chunk = require('./chunk-CbDLau6x.cjs');
|
|
2
|
-
const require_SchemaGenerator = require('./SchemaGenerator-
|
|
2
|
+
const require_SchemaGenerator = require('./SchemaGenerator-CzfhDNTC.cjs');
|
|
3
3
|
const require_SchemaMapper = require('./SchemaMapper-BN2pgCUs.cjs');
|
|
4
4
|
let _kubb_react_fabric = require("@kubb/react-fabric");
|
|
5
5
|
let _kubb_core_hooks = require("@kubb/core/hooks");
|
package/dist/hooks.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { C as Plugin, T as ResolveNameParams, h as Operation, t as Schema, u as Oas, v as FileMetaBase, w as PluginFactoryOptions } from "./SchemaMapper-
|
|
2
|
-
import { d as OperationGenerator, g as OperationSchemas } from "./createGenerator-
|
|
1
|
+
import { C as Plugin, T as ResolveNameParams, h as Operation, t as Schema, u as Oas, v as FileMetaBase, w as PluginFactoryOptions } from "./SchemaMapper-DHoFzVaG.cjs";
|
|
2
|
+
import { d as OperationGenerator, g as OperationSchemas } from "./createGenerator-BOeO1z4V.cjs";
|
|
3
3
|
import { KubbFile } from "@kubb/fabric-core/types";
|
|
4
4
|
|
|
5
5
|
//#region src/hooks/useOas.d.ts
|
package/dist/hooks.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { C as Plugin, T as ResolveNameParams, h as Operation, t as Schema, u as Oas, v as FileMetaBase, w as PluginFactoryOptions } from "./SchemaMapper-
|
|
2
|
-
import { d as OperationGenerator, g as OperationSchemas } from "./createGenerator-
|
|
1
|
+
import { C as Plugin, T as ResolveNameParams, h as Operation, t as Schema, u as Oas, v as FileMetaBase, w as PluginFactoryOptions } from "./SchemaMapper-BQqC-HKo.js";
|
|
2
|
+
import { d as OperationGenerator, g as OperationSchemas } from "./createGenerator-BPhjS5cM.js";
|
|
3
3
|
import { KubbFile } from "@kubb/fabric-core/types";
|
|
4
4
|
|
|
5
5
|
//#region src/hooks/useOas.d.ts
|
package/dist/hooks.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as SchemaGenerator } from "./SchemaGenerator-
|
|
1
|
+
import { t as SchemaGenerator } from "./SchemaGenerator-RhszLa_8.js";
|
|
2
2
|
import { n as schemaKeywords } from "./SchemaMapper-eCHsqfmg.js";
|
|
3
3
|
import { useApp } from "@kubb/react-fabric";
|
|
4
4
|
import { usePlugin, usePluginManager } from "@kubb/core/hooks";
|
package/dist/index.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const require_chunk = require('./chunk-CbDLau6x.cjs');
|
|
2
2
|
const require_generators = require('./generators-CV6CkJ4H.cjs');
|
|
3
|
-
const require_SchemaGenerator = require('./SchemaGenerator-
|
|
3
|
+
const require_SchemaGenerator = require('./SchemaGenerator-CzfhDNTC.cjs');
|
|
4
4
|
const require_SchemaMapper = require('./SchemaMapper-BN2pgCUs.cjs');
|
|
5
5
|
let _kubb_core = require("@kubb/core");
|
|
6
6
|
let _kubb_core_transformers = require("@kubb/core/transformers");
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { C as Plugin, E as UserPluginWithLifeCycle, a as SchemaMapper, b as Config, c as schemaKeywords, g as SchemaObject, h as Operation, i as SchemaKeywordMapper, n as SchemaKeyword, o as SchemaTree, r as SchemaKeywordBase, s as isKeyword, t as Schema, w as PluginFactoryOptions } from "./SchemaMapper-
|
|
2
|
-
import { C as Resolver, S as ResolvePathOptions, _ as Options, a as createReactGenerator$1, b as Ref, c as SchemaGeneratorBuildOptions, d as OperationGenerator, f as OperationMethodResult, g as OperationSchemas, h as OperationSchema, i as ReactGenerator, l as SchemaGeneratorOptions, m as Include, n as createGenerator$1, o as GetSchemaGeneratorOptions, p as Exclude, r as Generator$1, s as SchemaGenerator, u as SchemaMethodResult, v as Override, x as Refs, y as PluginOas } from "./createGenerator-
|
|
1
|
+
import { C as Plugin, E as UserPluginWithLifeCycle, a as SchemaMapper, b as Config, c as schemaKeywords, g as SchemaObject, h as Operation, i as SchemaKeywordMapper, n as SchemaKeyword, o as SchemaTree, r as SchemaKeywordBase, s as isKeyword, t as Schema, w as PluginFactoryOptions } from "./SchemaMapper-DHoFzVaG.cjs";
|
|
2
|
+
import { C as Resolver, S as ResolvePathOptions, _ as Options, a as createReactGenerator$1, b as Ref, c as SchemaGeneratorBuildOptions, d as OperationGenerator, f as OperationMethodResult, g as OperationSchemas, h as OperationSchema, i as ReactGenerator, l as SchemaGeneratorOptions, m as Include, n as createGenerator$1, o as GetSchemaGeneratorOptions, p as Exclude, r as Generator$1, s as SchemaGenerator, u as SchemaMethodResult, v as Override, x as Refs, y as PluginOas } from "./createGenerator-BOeO1z4V.cjs";
|
|
3
3
|
import { Fabric } from "@kubb/react-fabric";
|
|
4
4
|
|
|
5
5
|
//#region src/createParser.d.ts
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { C as Plugin, E as UserPluginWithLifeCycle, a as SchemaMapper, b as Config, c as schemaKeywords, g as SchemaObject, h as Operation, i as SchemaKeywordMapper, n as SchemaKeyword, o as SchemaTree, r as SchemaKeywordBase, s as isKeyword, t as Schema, w as PluginFactoryOptions } from "./SchemaMapper-
|
|
2
|
-
import { C as Resolver, S as ResolvePathOptions, _ as Options, a as createReactGenerator$1, b as Ref, c as SchemaGeneratorBuildOptions, d as OperationGenerator, f as OperationMethodResult, g as OperationSchemas, h as OperationSchema, i as ReactGenerator, l as SchemaGeneratorOptions, m as Include, n as createGenerator$1, o as GetSchemaGeneratorOptions, p as Exclude, r as Generator$1, s as SchemaGenerator, u as SchemaMethodResult, v as Override, x as Refs, y as PluginOas } from "./createGenerator-
|
|
1
|
+
import { C as Plugin, E as UserPluginWithLifeCycle, a as SchemaMapper, b as Config, c as schemaKeywords, g as SchemaObject, h as Operation, i as SchemaKeywordMapper, n as SchemaKeyword, o as SchemaTree, r as SchemaKeywordBase, s as isKeyword, t as Schema, w as PluginFactoryOptions } from "./SchemaMapper-BQqC-HKo.js";
|
|
2
|
+
import { C as Resolver, S as ResolvePathOptions, _ as Options, a as createReactGenerator$1, b as Ref, c as SchemaGeneratorBuildOptions, d as OperationGenerator, f as OperationMethodResult, g as OperationSchemas, h as OperationSchema, i as ReactGenerator, l as SchemaGeneratorOptions, m as Include, n as createGenerator$1, o as GetSchemaGeneratorOptions, p as Exclude, r as Generator$1, s as SchemaGenerator, u as SchemaMethodResult, v as Override, x as Refs, y as PluginOas } from "./createGenerator-BPhjS5cM.js";
|
|
3
3
|
import { Fabric } from "@kubb/react-fabric";
|
|
4
4
|
|
|
5
5
|
//#region src/createParser.d.ts
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { n as createReactGenerator$1, r as createGenerator$1, t as jsonGenerator } from "./generators-Cw71XBIe.js";
|
|
2
|
-
import { a as pLimit, i as buildSchema, n as buildOperation, r as buildOperations, t as SchemaGenerator } from "./SchemaGenerator-
|
|
2
|
+
import { a as pLimit, i as buildSchema, n as buildOperation, r as buildOperations, t as SchemaGenerator } from "./SchemaGenerator-RhszLa_8.js";
|
|
3
3
|
import { n as schemaKeywords, t as isKeyword } from "./SchemaMapper-eCHsqfmg.js";
|
|
4
4
|
import { BaseGenerator, definePlugin, getMode } from "@kubb/core";
|
|
5
5
|
import transformers, { camelCase } from "@kubb/core/transformers";
|
package/dist/mocks.d.cts
CHANGED
package/dist/mocks.d.ts
CHANGED
package/dist/utils.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
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-
|
|
2
|
-
import { h as OperationSchema, w as FunctionParamsAST } from "./createGenerator-
|
|
1
|
+
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-DHoFzVaG.cjs";
|
|
2
|
+
import { h as OperationSchema, w as FunctionParamsAST } from "./createGenerator-BOeO1z4V.cjs";
|
|
3
3
|
import { Params } from "@kubb/react-fabric/types";
|
|
4
4
|
|
|
5
5
|
//#region src/utils/getBanner.d.ts
|
|
@@ -39,16 +39,16 @@ declare function getPathParams(operationSchema: OperationSchema | undefined, opt
|
|
|
39
39
|
* Make it possible to narrow down the schema based on a specific version(3 or 3.1)
|
|
40
40
|
*/
|
|
41
41
|
type SchemaResult<TWithRef extends boolean = false> = {
|
|
42
|
-
schemaObject
|
|
42
|
+
schemaObject: ((TWithRef extends true ? OpenAPIV3.SchemaObject | OpenAPIV3.ReferenceObject : OpenAPIV3.SchemaObject) & {
|
|
43
43
|
nullable?: boolean;
|
|
44
44
|
'x-nullable'?: boolean;
|
|
45
|
-
};
|
|
45
|
+
}) | null;
|
|
46
46
|
version: '3.0';
|
|
47
47
|
} | {
|
|
48
|
-
schemaObject
|
|
48
|
+
schemaObject: ((TWithRef extends true ? OpenAPIV3_1.SchemaObject | OpenAPIV3_1.ReferenceObject : OpenAPIV3_1.SchemaObject) & {
|
|
49
49
|
nullable?: boolean;
|
|
50
50
|
'x-nullable'?: boolean;
|
|
51
|
-
};
|
|
51
|
+
}) | null;
|
|
52
52
|
version: '3.1';
|
|
53
53
|
};
|
|
54
54
|
/**
|
|
@@ -58,7 +58,7 @@ type SchemaResult<TWithRef extends boolean = false> = {
|
|
|
58
58
|
*
|
|
59
59
|
* @returns A function that takes an optional schema and returns a versioned schema result.
|
|
60
60
|
*/
|
|
61
|
-
declare function getSchemaFactory<TWithRef extends boolean = false>(oas: Oas): (schema
|
|
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
64
|
type Mode = 'schemas' | 'responses' | 'requestBodies';
|
package/dist/utils.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
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-
|
|
2
|
-
import { h as OperationSchema, w as FunctionParamsAST } from "./createGenerator-
|
|
1
|
+
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-BQqC-HKo.js";
|
|
2
|
+
import { h as OperationSchema, w as FunctionParamsAST } from "./createGenerator-BPhjS5cM.js";
|
|
3
3
|
import { Params } from "@kubb/react-fabric/types";
|
|
4
4
|
|
|
5
5
|
//#region src/utils/getBanner.d.ts
|
|
@@ -39,16 +39,16 @@ declare function getPathParams(operationSchema: OperationSchema | undefined, opt
|
|
|
39
39
|
* Make it possible to narrow down the schema based on a specific version(3 or 3.1)
|
|
40
40
|
*/
|
|
41
41
|
type SchemaResult<TWithRef extends boolean = false> = {
|
|
42
|
-
schemaObject
|
|
42
|
+
schemaObject: ((TWithRef extends true ? OpenAPIV3.SchemaObject | OpenAPIV3.ReferenceObject : OpenAPIV3.SchemaObject) & {
|
|
43
43
|
nullable?: boolean;
|
|
44
44
|
'x-nullable'?: boolean;
|
|
45
|
-
};
|
|
45
|
+
}) | null;
|
|
46
46
|
version: '3.0';
|
|
47
47
|
} | {
|
|
48
|
-
schemaObject
|
|
48
|
+
schemaObject: ((TWithRef extends true ? OpenAPIV3_1.SchemaObject | OpenAPIV3_1.ReferenceObject : OpenAPIV3_1.SchemaObject) & {
|
|
49
49
|
nullable?: boolean;
|
|
50
50
|
'x-nullable'?: boolean;
|
|
51
|
-
};
|
|
51
|
+
}) | null;
|
|
52
52
|
version: '3.1';
|
|
53
53
|
};
|
|
54
54
|
/**
|
|
@@ -58,7 +58,7 @@ type SchemaResult<TWithRef extends boolean = false> = {
|
|
|
58
58
|
*
|
|
59
59
|
* @returns A function that takes an optional schema and returns a versioned schema result.
|
|
60
60
|
*/
|
|
61
|
-
declare function getSchemaFactory<TWithRef extends boolean = false>(oas: Oas): (schema
|
|
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
64
|
type Mode = 'schemas' | 'responses' | 'requestBodies';
|
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-20251222215628",
|
|
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.7.4",
|
|
83
83
|
"p-limit": "^7.2.0",
|
|
84
84
|
"remeda": "^2.32.0",
|
|
85
|
-
"@kubb/core": "0.0.0-canary-
|
|
86
|
-
"@kubb/oas": "0.0.0-canary-
|
|
85
|
+
"@kubb/core": "0.0.0-canary-20251222215628",
|
|
86
|
+
"@kubb/oas": "0.0.0-canary-20251222215628"
|
|
87
87
|
},
|
|
88
88
|
"peerDependencies": {
|
|
89
89
|
"@kubb/react-fabric": "0.7.4"
|
package/src/SchemaGenerator.ts
CHANGED
|
@@ -55,16 +55,16 @@ export type SchemaGeneratorOptions = {
|
|
|
55
55
|
* TODO TODO add docs
|
|
56
56
|
* @beta
|
|
57
57
|
*/
|
|
58
|
-
schema?: (schemaProps: SchemaProps, defaultSchemas: Schema[]) => Schema
|
|
58
|
+
schema?: (schemaProps: SchemaProps, defaultSchemas: Schema[]) => Array<Schema> | undefined
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
61
|
|
|
62
62
|
export type SchemaGeneratorBuildOptions = Omit<OperationSchema, 'name' | 'schema'>
|
|
63
63
|
|
|
64
64
|
type SchemaProps = {
|
|
65
|
-
|
|
66
|
-
name
|
|
67
|
-
parentName
|
|
65
|
+
schema: SchemaObject | null
|
|
66
|
+
name: string | null
|
|
67
|
+
parentName: string | null
|
|
68
68
|
}
|
|
69
69
|
|
|
70
70
|
export class SchemaGenerator<
|
|
@@ -84,7 +84,7 @@ export class SchemaGenerator<
|
|
|
84
84
|
* optionally adds a union with null.
|
|
85
85
|
*/
|
|
86
86
|
parse(props: SchemaProps): Schema[] {
|
|
87
|
-
const options = this.#getOptions(props)
|
|
87
|
+
const options = this.#getOptions(props.name)
|
|
88
88
|
|
|
89
89
|
const defaultSchemas = this.#parseSchemaObject(props)
|
|
90
90
|
const schemas = options.transformers?.schema?.(props, defaultSchemas) || defaultSchemas || []
|
|
@@ -108,6 +108,14 @@ export class SchemaGenerator<
|
|
|
108
108
|
Object.values(schema.args?.additionalProperties || {}).forEach((entrySchema) => {
|
|
109
109
|
foundItems.push(...SchemaGenerator.deepSearch<T>([entrySchema], keyword))
|
|
110
110
|
})
|
|
111
|
+
|
|
112
|
+
if (schema.args?.patternProperties) {
|
|
113
|
+
Object.values(schema.args.patternProperties).forEach((entrySchemas) => {
|
|
114
|
+
entrySchemas.forEach((entrySchema) => {
|
|
115
|
+
foundItems.push(...SchemaGenerator.deepSearch<T>([entrySchema], keyword))
|
|
116
|
+
})
|
|
117
|
+
})
|
|
118
|
+
}
|
|
111
119
|
}
|
|
112
120
|
|
|
113
121
|
if (isKeyword(schema, schemaKeywords.array)) {
|
|
@@ -234,7 +242,7 @@ export class SchemaGenerator<
|
|
|
234
242
|
})
|
|
235
243
|
}
|
|
236
244
|
|
|
237
|
-
#getOptions(
|
|
245
|
+
#getOptions(name: string | null): Partial<TOptions> {
|
|
238
246
|
const { override = [] } = this.context
|
|
239
247
|
|
|
240
248
|
return {
|
|
@@ -249,8 +257,8 @@ export class SchemaGenerator<
|
|
|
249
257
|
}
|
|
250
258
|
}
|
|
251
259
|
|
|
252
|
-
#getUnknownType(
|
|
253
|
-
const options = this.#getOptions(
|
|
260
|
+
#getUnknownType(name: string | null): string {
|
|
261
|
+
const options = this.#getOptions(name)
|
|
254
262
|
|
|
255
263
|
if (options.unknownType === 'any') {
|
|
256
264
|
return schemaKeywords.any
|
|
@@ -262,8 +270,8 @@ export class SchemaGenerator<
|
|
|
262
270
|
return schemaKeywords.unknown
|
|
263
271
|
}
|
|
264
272
|
|
|
265
|
-
#getEmptyType(
|
|
266
|
-
const options = this.#getOptions(
|
|
273
|
+
#getEmptyType(name: string | null): string {
|
|
274
|
+
const options = this.#getOptions(name)
|
|
267
275
|
|
|
268
276
|
if (options.emptySchemaType === 'any') {
|
|
269
277
|
return schemaKeywords.any
|
|
@@ -278,7 +286,7 @@ export class SchemaGenerator<
|
|
|
278
286
|
/**
|
|
279
287
|
* Recursively creates a type literal with the given props.
|
|
280
288
|
*/
|
|
281
|
-
#parseProperties(
|
|
289
|
+
#parseProperties(name: string | null, schemaObject: SchemaObject): Schema[] {
|
|
282
290
|
const properties = schemaObject?.properties || {}
|
|
283
291
|
const additionalProperties = schemaObject?.additionalProperties
|
|
284
292
|
const required = schemaObject?.required
|
|
@@ -292,7 +300,7 @@ export class SchemaGenerator<
|
|
|
292
300
|
const isRequired = Array.isArray(required) ? required?.includes(propertyName) : !!required
|
|
293
301
|
const nullable = propertySchema.nullable ?? propertySchema['x-nullable'] ?? false
|
|
294
302
|
|
|
295
|
-
validationFunctions.push(...this.parse({
|
|
303
|
+
validationFunctions.push(...this.parse({ schema: propertySchema, name: propertyName, parentName: name }))
|
|
296
304
|
|
|
297
305
|
validationFunctions.push({
|
|
298
306
|
keyword: schemaKeywords.name,
|
|
@@ -315,8 +323,8 @@ export class SchemaGenerator<
|
|
|
315
323
|
if (additionalProperties) {
|
|
316
324
|
additionalPropertiesSchemas =
|
|
317
325
|
additionalProperties === true || !Object.keys(additionalProperties).length
|
|
318
|
-
? [{ keyword: this.#getUnknownType(
|
|
319
|
-
: this.parse({
|
|
326
|
+
? [{ keyword: this.#getUnknownType(name) }]
|
|
327
|
+
: this.parse({ schema: additionalProperties as SchemaObject, name: null, parentName: name })
|
|
320
328
|
}
|
|
321
329
|
|
|
322
330
|
let patternPropertiesSchemas: Record<string, Schema[]> = {}
|
|
@@ -325,8 +333,8 @@ export class SchemaGenerator<
|
|
|
325
333
|
patternPropertiesSchemas = Object.entries(patternProperties).reduce((acc, [pattern, patternSchema]) => {
|
|
326
334
|
const schemas =
|
|
327
335
|
patternSchema === true || !Object.keys(patternSchema as object).length
|
|
328
|
-
? [{ keyword: this.#getUnknownType(
|
|
329
|
-
: this.parse({
|
|
336
|
+
? [{ keyword: this.#getUnknownType(name) }]
|
|
337
|
+
: this.parse({ schema: patternSchema, name: null, parentName: name })
|
|
330
338
|
|
|
331
339
|
return {
|
|
332
340
|
...acc,
|
|
@@ -359,7 +367,7 @@ export class SchemaGenerator<
|
|
|
359
367
|
/**
|
|
360
368
|
* Create a type alias for the schema referenced by the given ReferenceObject
|
|
361
369
|
*/
|
|
362
|
-
#getRefAlias(schemaObject: OpenAPIV3.ReferenceObject, name: string |
|
|
370
|
+
#getRefAlias(schemaObject: OpenAPIV3.ReferenceObject, name: string | null): Schema[] {
|
|
363
371
|
const { $ref } = schemaObject
|
|
364
372
|
const ref = this.refs[$ref]
|
|
365
373
|
|
|
@@ -437,7 +445,7 @@ export class SchemaGenerator<
|
|
|
437
445
|
return this.#getRefAlias(schemaObject, name)
|
|
438
446
|
}
|
|
439
447
|
|
|
440
|
-
#getParsedSchemaObject(schema
|
|
448
|
+
#getParsedSchemaObject(schema: SchemaObject | null) {
|
|
441
449
|
return getSchemaFactory(this.context.oas)(schema)
|
|
442
450
|
}
|
|
443
451
|
|
|
@@ -454,13 +462,33 @@ export class SchemaGenerator<
|
|
|
454
462
|
return schema
|
|
455
463
|
}
|
|
456
464
|
|
|
457
|
-
|
|
465
|
+
// If the discriminator property is an extension property (starts with x-),
|
|
466
|
+
// it's metadata and not an actual schema property, so we can't add constraints for it.
|
|
467
|
+
// In this case, return the union as-is without adding discriminator constraints.
|
|
468
|
+
if (discriminator.propertyName.startsWith('x-')) {
|
|
469
|
+
return schema
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
const objectPropertySchema = SchemaGenerator.find(this.parse({ schema: schemaObject, name: null, parentName: null }), schemaKeywords.object)
|
|
458
473
|
|
|
459
474
|
return {
|
|
460
475
|
...schema,
|
|
461
476
|
args: Object.entries(discriminator.mapping || {})
|
|
462
477
|
.map(([key, value]) => {
|
|
463
|
-
|
|
478
|
+
let arg: Schema | undefined
|
|
479
|
+
|
|
480
|
+
// Check if this is a synthetic ref for inline schemas (e.g., #kubb-inline-0)
|
|
481
|
+
if (value.startsWith('#kubb-inline-')) {
|
|
482
|
+
const index = Number.parseInt(value.replace('#kubb-inline-', ''), 10)
|
|
483
|
+
// Validate index is within bounds
|
|
484
|
+
if (!Number.isNaN(index) && index >= 0 && index < schema.args.length) {
|
|
485
|
+
arg = schema.args[index]
|
|
486
|
+
}
|
|
487
|
+
} else {
|
|
488
|
+
// Regular ref - find by $ref value
|
|
489
|
+
arg = schema.args.find((item) => isKeyword(item, schemaKeywords.ref) && item.args.$ref === value)
|
|
490
|
+
}
|
|
491
|
+
|
|
464
492
|
// Skip discriminator mappings that don't have a corresponding schema in the oneOf/anyOf
|
|
465
493
|
if (!arg) {
|
|
466
494
|
return undefined
|
|
@@ -504,7 +532,7 @@ export class SchemaGenerator<
|
|
|
504
532
|
* Without oneOf/anyOf, the discriminator is just for documentation/validation
|
|
505
533
|
* purposes and doesn't create a TypeScript union type that would be circular.
|
|
506
534
|
*/
|
|
507
|
-
#wouldCreateCircularReference(item: unknown, childSchemaName: string |
|
|
535
|
+
#wouldCreateCircularReference(item: unknown, childSchemaName: string | null): boolean {
|
|
508
536
|
if (!isReference(item) || !childSchemaName) {
|
|
509
537
|
return false
|
|
510
538
|
}
|
|
@@ -542,13 +570,13 @@ export class SchemaGenerator<
|
|
|
542
570
|
* This is the very core of the OpenAPI to TS conversion - it takes a
|
|
543
571
|
* schema and returns the appropriate type.
|
|
544
572
|
*/
|
|
545
|
-
#parseSchemaObject({
|
|
573
|
+
#parseSchemaObject({ schema: _schemaObject, name, parentName }: SchemaProps): Schema[] {
|
|
546
574
|
const normalizedSchema = this.context.oas.flattenSchema(_schemaObject)
|
|
547
575
|
|
|
548
576
|
const { schemaObject, version } = this.#getParsedSchemaObject(normalizedSchema)
|
|
549
577
|
|
|
550
|
-
const options = this.#getOptions(
|
|
551
|
-
const emptyType = this.#getEmptyType(
|
|
578
|
+
const options = this.#getOptions(name)
|
|
579
|
+
const emptyType = this.#getEmptyType(name)
|
|
552
580
|
|
|
553
581
|
if (!schemaObject) {
|
|
554
582
|
return [{ keyword: emptyType }]
|
|
@@ -649,7 +677,7 @@ export class SchemaGenerator<
|
|
|
649
677
|
.map(
|
|
650
678
|
(item) =>
|
|
651
679
|
this.parse({
|
|
652
|
-
|
|
680
|
+
schema: { ...schemaObject, type: item },
|
|
653
681
|
name,
|
|
654
682
|
parentName,
|
|
655
683
|
})[0],
|
|
@@ -706,7 +734,7 @@ export class SchemaGenerator<
|
|
|
706
734
|
args: (schemaObject.oneOf || schemaObject.anyOf)!
|
|
707
735
|
.map((item) => {
|
|
708
736
|
// first item, this will be ref
|
|
709
|
-
return item && this.parse({
|
|
737
|
+
return item && this.parse({ schema: item as SchemaObject, name, parentName })[0]
|
|
710
738
|
})
|
|
711
739
|
.filter(Boolean),
|
|
712
740
|
}
|
|
@@ -720,7 +748,7 @@ export class SchemaGenerator<
|
|
|
720
748
|
}
|
|
721
749
|
|
|
722
750
|
if (schemaWithoutOneOf.properties) {
|
|
723
|
-
const propertySchemas = this.parse({
|
|
751
|
+
const propertySchemas = this.parse({ schema: schemaWithoutOneOf, name, parentName })
|
|
724
752
|
|
|
725
753
|
union.args = [
|
|
726
754
|
...union.args.map((arg) => {
|
|
@@ -750,7 +778,7 @@ export class SchemaGenerator<
|
|
|
750
778
|
return []
|
|
751
779
|
}
|
|
752
780
|
|
|
753
|
-
return item ? this.parse({
|
|
781
|
+
return item ? this.parse({ schema: item, name, parentName }) : []
|
|
754
782
|
})
|
|
755
783
|
.filter(Boolean),
|
|
756
784
|
}
|
|
@@ -790,7 +818,7 @@ export class SchemaGenerator<
|
|
|
790
818
|
}
|
|
791
819
|
|
|
792
820
|
for (const item of parsedItems) {
|
|
793
|
-
const parsed = this.parse({
|
|
821
|
+
const parsed = this.parse({ schema: item, name, parentName })
|
|
794
822
|
|
|
795
823
|
if (Array.isArray(parsed)) {
|
|
796
824
|
and.args = and.args ? and.args.concat(parsed) : parsed
|
|
@@ -799,7 +827,7 @@ export class SchemaGenerator<
|
|
|
799
827
|
}
|
|
800
828
|
|
|
801
829
|
if (schemaWithoutAllOf.properties) {
|
|
802
|
-
and.args = [...(and.args || []), ...this.parse({
|
|
830
|
+
and.args = [...(and.args || []), ...this.parse({ schema: schemaWithoutAllOf, name, parentName })]
|
|
803
831
|
}
|
|
804
832
|
|
|
805
833
|
return SchemaGenerator.combineObjects([and, ...baseItems])
|
|
@@ -822,7 +850,7 @@ export class SchemaGenerator<
|
|
|
822
850
|
items: normalizedItems,
|
|
823
851
|
} as SchemaObject
|
|
824
852
|
|
|
825
|
-
return this.parse({
|
|
853
|
+
return this.parse({ schema: normalizedSchema, name, parentName })
|
|
826
854
|
}
|
|
827
855
|
|
|
828
856
|
if (options.enumSuffix === '') {
|
|
@@ -962,11 +990,11 @@ export class SchemaGenerator<
|
|
|
962
990
|
max,
|
|
963
991
|
items: prefixItems
|
|
964
992
|
.map((item) => {
|
|
965
|
-
return this.parse({
|
|
993
|
+
return this.parse({ schema: item, name, parentName })[0]
|
|
966
994
|
})
|
|
967
995
|
.filter(Boolean),
|
|
968
996
|
rest: this.parse({
|
|
969
|
-
|
|
997
|
+
schema: items,
|
|
970
998
|
name,
|
|
971
999
|
parentName,
|
|
972
1000
|
})[0],
|
|
@@ -1114,7 +1142,7 @@ export class SchemaGenerator<
|
|
|
1114
1142
|
if ('items' in schemaObject || schemaObject.type === ('array' as 'string')) {
|
|
1115
1143
|
const min = schemaObject.minimum ?? schemaObject.minLength ?? schemaObject.minItems ?? undefined
|
|
1116
1144
|
const max = schemaObject.maximum ?? schemaObject.maxLength ?? schemaObject.maxItems ?? undefined
|
|
1117
|
-
const items = this.parse({
|
|
1145
|
+
const items = this.parse({ schema: 'items' in schemaObject ? (schemaObject.items as SchemaObject) : [], name, parentName })
|
|
1118
1146
|
const unique = !!schemaObject.uniqueItems
|
|
1119
1147
|
|
|
1120
1148
|
return [
|
|
@@ -1151,16 +1179,10 @@ export class SchemaGenerator<
|
|
|
1151
1179
|
return acc
|
|
1152
1180
|
}, schemaObject || {}) as SchemaObject
|
|
1153
1181
|
|
|
1154
|
-
return [
|
|
1155
|
-
...this.#parseProperties({
|
|
1156
|
-
schemaObject: schemaObjectOverriden,
|
|
1157
|
-
name,
|
|
1158
|
-
}),
|
|
1159
|
-
...baseItems,
|
|
1160
|
-
]
|
|
1182
|
+
return [...this.#parseProperties(name, schemaObjectOverriden), ...baseItems]
|
|
1161
1183
|
}
|
|
1162
1184
|
|
|
1163
|
-
return [...this.#parseProperties(
|
|
1185
|
+
return [...this.#parseProperties(name, schemaObject), ...baseItems]
|
|
1164
1186
|
}
|
|
1165
1187
|
|
|
1166
1188
|
if (schemaObject.type) {
|
|
@@ -1211,8 +1233,8 @@ export class SchemaGenerator<
|
|
|
1211
1233
|
generatorLimit(async () => {
|
|
1212
1234
|
const schemaTasks = schemaEntries.map(([name, schemaObject]) =>
|
|
1213
1235
|
schemaLimit(async () => {
|
|
1214
|
-
const options = this.#getOptions(
|
|
1215
|
-
const tree = this.parse({ name,
|
|
1236
|
+
const options = this.#getOptions(name)
|
|
1237
|
+
const tree = this.parse({ schema: schemaObject, name, parentName: null })
|
|
1216
1238
|
|
|
1217
1239
|
if (generator.type === 'react') {
|
|
1218
1240
|
await buildSchema(
|