@kubb/plugin-oas 0.0.0-canary-20251222142412 → 0.0.0-canary-20251222160843
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-DTyNa5fQ.cjs} +44 -50
- package/dist/SchemaGenerator-DTyNa5fQ.cjs.map +1 -0
- package/dist/{SchemaGenerator-D6Ux5Gk1.js → SchemaGenerator-DZHRBTyZ.js} +44 -50
- package/dist/SchemaGenerator-DZHRBTyZ.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 +58 -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-DTyNa5fQ.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-DZHRBTyZ.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-DTyNa5fQ.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-DZHRBTyZ.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-20251222160843",
|
|
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-20251222160843",
|
|
86
|
+
"@kubb/oas": "0.0.0-canary-20251222160843"
|
|
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 || []
|
|
@@ -234,7 +234,7 @@ export class SchemaGenerator<
|
|
|
234
234
|
})
|
|
235
235
|
}
|
|
236
236
|
|
|
237
|
-
#getOptions(
|
|
237
|
+
#getOptions(name: string | null): Partial<TOptions> {
|
|
238
238
|
const { override = [] } = this.context
|
|
239
239
|
|
|
240
240
|
return {
|
|
@@ -249,8 +249,8 @@ export class SchemaGenerator<
|
|
|
249
249
|
}
|
|
250
250
|
}
|
|
251
251
|
|
|
252
|
-
#getUnknownType(
|
|
253
|
-
const options = this.#getOptions(
|
|
252
|
+
#getUnknownType(name: string | null): string {
|
|
253
|
+
const options = this.#getOptions(name)
|
|
254
254
|
|
|
255
255
|
if (options.unknownType === 'any') {
|
|
256
256
|
return schemaKeywords.any
|
|
@@ -262,8 +262,8 @@ export class SchemaGenerator<
|
|
|
262
262
|
return schemaKeywords.unknown
|
|
263
263
|
}
|
|
264
264
|
|
|
265
|
-
#getEmptyType(
|
|
266
|
-
const options = this.#getOptions(
|
|
265
|
+
#getEmptyType(name: string | null): string {
|
|
266
|
+
const options = this.#getOptions(name)
|
|
267
267
|
|
|
268
268
|
if (options.emptySchemaType === 'any') {
|
|
269
269
|
return schemaKeywords.any
|
|
@@ -278,7 +278,7 @@ export class SchemaGenerator<
|
|
|
278
278
|
/**
|
|
279
279
|
* Recursively creates a type literal with the given props.
|
|
280
280
|
*/
|
|
281
|
-
#parseProperties(
|
|
281
|
+
#parseProperties(name: string | null, schemaObject: SchemaObject): Schema[] {
|
|
282
282
|
const properties = schemaObject?.properties || {}
|
|
283
283
|
const additionalProperties = schemaObject?.additionalProperties
|
|
284
284
|
const required = schemaObject?.required
|
|
@@ -292,7 +292,7 @@ export class SchemaGenerator<
|
|
|
292
292
|
const isRequired = Array.isArray(required) ? required?.includes(propertyName) : !!required
|
|
293
293
|
const nullable = propertySchema.nullable ?? propertySchema['x-nullable'] ?? false
|
|
294
294
|
|
|
295
|
-
validationFunctions.push(...this.parse({
|
|
295
|
+
validationFunctions.push(...this.parse({ schema: propertySchema, name: propertyName, parentName: name }))
|
|
296
296
|
|
|
297
297
|
validationFunctions.push({
|
|
298
298
|
keyword: schemaKeywords.name,
|
|
@@ -315,8 +315,8 @@ export class SchemaGenerator<
|
|
|
315
315
|
if (additionalProperties) {
|
|
316
316
|
additionalPropertiesSchemas =
|
|
317
317
|
additionalProperties === true || !Object.keys(additionalProperties).length
|
|
318
|
-
? [{ keyword: this.#getUnknownType(
|
|
319
|
-
: this.parse({
|
|
318
|
+
? [{ keyword: this.#getUnknownType(name) }]
|
|
319
|
+
: this.parse({ schema: additionalProperties as SchemaObject, name: null, parentName: name })
|
|
320
320
|
}
|
|
321
321
|
|
|
322
322
|
let patternPropertiesSchemas: Record<string, Schema[]> = {}
|
|
@@ -325,8 +325,8 @@ export class SchemaGenerator<
|
|
|
325
325
|
patternPropertiesSchemas = Object.entries(patternProperties).reduce((acc, [pattern, patternSchema]) => {
|
|
326
326
|
const schemas =
|
|
327
327
|
patternSchema === true || !Object.keys(patternSchema as object).length
|
|
328
|
-
? [{ keyword: this.#getUnknownType(
|
|
329
|
-
: this.parse({
|
|
328
|
+
? [{ keyword: this.#getUnknownType(name) }]
|
|
329
|
+
: this.parse({ schema: patternSchema, name: null, parentName: name })
|
|
330
330
|
|
|
331
331
|
return {
|
|
332
332
|
...acc,
|
|
@@ -359,7 +359,7 @@ export class SchemaGenerator<
|
|
|
359
359
|
/**
|
|
360
360
|
* Create a type alias for the schema referenced by the given ReferenceObject
|
|
361
361
|
*/
|
|
362
|
-
#getRefAlias(schemaObject: OpenAPIV3.ReferenceObject, name: string |
|
|
362
|
+
#getRefAlias(schemaObject: OpenAPIV3.ReferenceObject, name: string | null): Schema[] {
|
|
363
363
|
const { $ref } = schemaObject
|
|
364
364
|
const ref = this.refs[$ref]
|
|
365
365
|
|
|
@@ -437,7 +437,7 @@ export class SchemaGenerator<
|
|
|
437
437
|
return this.#getRefAlias(schemaObject, name)
|
|
438
438
|
}
|
|
439
439
|
|
|
440
|
-
#getParsedSchemaObject(schema
|
|
440
|
+
#getParsedSchemaObject(schema: SchemaObject | null) {
|
|
441
441
|
return getSchemaFactory(this.context.oas)(schema)
|
|
442
442
|
}
|
|
443
443
|
|
|
@@ -454,13 +454,33 @@ export class SchemaGenerator<
|
|
|
454
454
|
return schema
|
|
455
455
|
}
|
|
456
456
|
|
|
457
|
-
|
|
457
|
+
// If the discriminator property is an extension property (starts with x-),
|
|
458
|
+
// it's metadata and not an actual schema property, so we can't add constraints for it.
|
|
459
|
+
// In this case, return the union as-is without adding discriminator constraints.
|
|
460
|
+
if (discriminator.propertyName.startsWith('x-')) {
|
|
461
|
+
return schema
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
const objectPropertySchema = SchemaGenerator.find(this.parse({ schema: schemaObject, name: null, parentName: null }), schemaKeywords.object)
|
|
458
465
|
|
|
459
466
|
return {
|
|
460
467
|
...schema,
|
|
461
468
|
args: Object.entries(discriminator.mapping || {})
|
|
462
469
|
.map(([key, value]) => {
|
|
463
|
-
|
|
470
|
+
let arg: Schema | undefined
|
|
471
|
+
|
|
472
|
+
// Check if this is a synthetic ref for inline schemas (e.g., #kubb-inline-0)
|
|
473
|
+
if (value.startsWith('#kubb-inline-')) {
|
|
474
|
+
const index = Number.parseInt(value.replace('#kubb-inline-', ''), 10)
|
|
475
|
+
// Validate index is within bounds
|
|
476
|
+
if (!Number.isNaN(index) && index >= 0 && index < schema.args.length) {
|
|
477
|
+
arg = schema.args[index]
|
|
478
|
+
}
|
|
479
|
+
} else {
|
|
480
|
+
// Regular ref - find by $ref value
|
|
481
|
+
arg = schema.args.find((item) => isKeyword(item, schemaKeywords.ref) && item.args.$ref === value)
|
|
482
|
+
}
|
|
483
|
+
|
|
464
484
|
// Skip discriminator mappings that don't have a corresponding schema in the oneOf/anyOf
|
|
465
485
|
if (!arg) {
|
|
466
486
|
return undefined
|
|
@@ -504,7 +524,7 @@ export class SchemaGenerator<
|
|
|
504
524
|
* Without oneOf/anyOf, the discriminator is just for documentation/validation
|
|
505
525
|
* purposes and doesn't create a TypeScript union type that would be circular.
|
|
506
526
|
*/
|
|
507
|
-
#wouldCreateCircularReference(item: unknown, childSchemaName: string |
|
|
527
|
+
#wouldCreateCircularReference(item: unknown, childSchemaName: string | null): boolean {
|
|
508
528
|
if (!isReference(item) || !childSchemaName) {
|
|
509
529
|
return false
|
|
510
530
|
}
|
|
@@ -542,13 +562,13 @@ export class SchemaGenerator<
|
|
|
542
562
|
* This is the very core of the OpenAPI to TS conversion - it takes a
|
|
543
563
|
* schema and returns the appropriate type.
|
|
544
564
|
*/
|
|
545
|
-
#parseSchemaObject({
|
|
565
|
+
#parseSchemaObject({ schema: _schemaObject, name, parentName }: SchemaProps): Schema[] {
|
|
546
566
|
const normalizedSchema = this.context.oas.flattenSchema(_schemaObject)
|
|
547
567
|
|
|
548
568
|
const { schemaObject, version } = this.#getParsedSchemaObject(normalizedSchema)
|
|
549
569
|
|
|
550
|
-
const options = this.#getOptions(
|
|
551
|
-
const emptyType = this.#getEmptyType(
|
|
570
|
+
const options = this.#getOptions(name)
|
|
571
|
+
const emptyType = this.#getEmptyType(name)
|
|
552
572
|
|
|
553
573
|
if (!schemaObject) {
|
|
554
574
|
return [{ keyword: emptyType }]
|
|
@@ -649,7 +669,7 @@ export class SchemaGenerator<
|
|
|
649
669
|
.map(
|
|
650
670
|
(item) =>
|
|
651
671
|
this.parse({
|
|
652
|
-
|
|
672
|
+
schema: { ...schemaObject, type: item },
|
|
653
673
|
name,
|
|
654
674
|
parentName,
|
|
655
675
|
})[0],
|
|
@@ -706,7 +726,7 @@ export class SchemaGenerator<
|
|
|
706
726
|
args: (schemaObject.oneOf || schemaObject.anyOf)!
|
|
707
727
|
.map((item) => {
|
|
708
728
|
// first item, this will be ref
|
|
709
|
-
return item && this.parse({
|
|
729
|
+
return item && this.parse({ schema: item as SchemaObject, name, parentName })[0]
|
|
710
730
|
})
|
|
711
731
|
.filter(Boolean),
|
|
712
732
|
}
|
|
@@ -720,7 +740,7 @@ export class SchemaGenerator<
|
|
|
720
740
|
}
|
|
721
741
|
|
|
722
742
|
if (schemaWithoutOneOf.properties) {
|
|
723
|
-
const propertySchemas = this.parse({
|
|
743
|
+
const propertySchemas = this.parse({ schema: schemaWithoutOneOf, name, parentName })
|
|
724
744
|
|
|
725
745
|
union.args = [
|
|
726
746
|
...union.args.map((arg) => {
|
|
@@ -750,7 +770,7 @@ export class SchemaGenerator<
|
|
|
750
770
|
return []
|
|
751
771
|
}
|
|
752
772
|
|
|
753
|
-
return item ? this.parse({
|
|
773
|
+
return item ? this.parse({ schema: item, name, parentName }) : []
|
|
754
774
|
})
|
|
755
775
|
.filter(Boolean),
|
|
756
776
|
}
|
|
@@ -790,7 +810,7 @@ export class SchemaGenerator<
|
|
|
790
810
|
}
|
|
791
811
|
|
|
792
812
|
for (const item of parsedItems) {
|
|
793
|
-
const parsed = this.parse({
|
|
813
|
+
const parsed = this.parse({ schema: item, name, parentName })
|
|
794
814
|
|
|
795
815
|
if (Array.isArray(parsed)) {
|
|
796
816
|
and.args = and.args ? and.args.concat(parsed) : parsed
|
|
@@ -799,7 +819,7 @@ export class SchemaGenerator<
|
|
|
799
819
|
}
|
|
800
820
|
|
|
801
821
|
if (schemaWithoutAllOf.properties) {
|
|
802
|
-
and.args = [...(and.args || []), ...this.parse({
|
|
822
|
+
and.args = [...(and.args || []), ...this.parse({ schema: schemaWithoutAllOf, name, parentName })]
|
|
803
823
|
}
|
|
804
824
|
|
|
805
825
|
return SchemaGenerator.combineObjects([and, ...baseItems])
|
|
@@ -822,7 +842,7 @@ export class SchemaGenerator<
|
|
|
822
842
|
items: normalizedItems,
|
|
823
843
|
} as SchemaObject
|
|
824
844
|
|
|
825
|
-
return this.parse({
|
|
845
|
+
return this.parse({ schema: normalizedSchema, name, parentName })
|
|
826
846
|
}
|
|
827
847
|
|
|
828
848
|
if (options.enumSuffix === '') {
|
|
@@ -962,11 +982,11 @@ export class SchemaGenerator<
|
|
|
962
982
|
max,
|
|
963
983
|
items: prefixItems
|
|
964
984
|
.map((item) => {
|
|
965
|
-
return this.parse({
|
|
985
|
+
return this.parse({ schema: item, name, parentName })[0]
|
|
966
986
|
})
|
|
967
987
|
.filter(Boolean),
|
|
968
988
|
rest: this.parse({
|
|
969
|
-
|
|
989
|
+
schema: items,
|
|
970
990
|
name,
|
|
971
991
|
parentName,
|
|
972
992
|
})[0],
|
|
@@ -1114,7 +1134,7 @@ export class SchemaGenerator<
|
|
|
1114
1134
|
if ('items' in schemaObject || schemaObject.type === ('array' as 'string')) {
|
|
1115
1135
|
const min = schemaObject.minimum ?? schemaObject.minLength ?? schemaObject.minItems ?? undefined
|
|
1116
1136
|
const max = schemaObject.maximum ?? schemaObject.maxLength ?? schemaObject.maxItems ?? undefined
|
|
1117
|
-
const items = this.parse({
|
|
1137
|
+
const items = this.parse({ schema: 'items' in schemaObject ? (schemaObject.items as SchemaObject) : [], name, parentName })
|
|
1118
1138
|
const unique = !!schemaObject.uniqueItems
|
|
1119
1139
|
|
|
1120
1140
|
return [
|
|
@@ -1151,16 +1171,10 @@ export class SchemaGenerator<
|
|
|
1151
1171
|
return acc
|
|
1152
1172
|
}, schemaObject || {}) as SchemaObject
|
|
1153
1173
|
|
|
1154
|
-
return [
|
|
1155
|
-
...this.#parseProperties({
|
|
1156
|
-
schemaObject: schemaObjectOverriden,
|
|
1157
|
-
name,
|
|
1158
|
-
}),
|
|
1159
|
-
...baseItems,
|
|
1160
|
-
]
|
|
1174
|
+
return [...this.#parseProperties(name, schemaObjectOverriden), ...baseItems]
|
|
1161
1175
|
}
|
|
1162
1176
|
|
|
1163
|
-
return [...this.#parseProperties(
|
|
1177
|
+
return [...this.#parseProperties(name, schemaObject), ...baseItems]
|
|
1164
1178
|
}
|
|
1165
1179
|
|
|
1166
1180
|
if (schemaObject.type) {
|
|
@@ -1211,8 +1225,8 @@ export class SchemaGenerator<
|
|
|
1211
1225
|
generatorLimit(async () => {
|
|
1212
1226
|
const schemaTasks = schemaEntries.map(([name, schemaObject]) =>
|
|
1213
1227
|
schemaLimit(async () => {
|
|
1214
|
-
const options = this.#getOptions(
|
|
1215
|
-
const tree = this.parse({ name,
|
|
1228
|
+
const options = this.#getOptions(name)
|
|
1229
|
+
const tree = this.parse({ schema: schemaObject, name, parentName: null })
|
|
1216
1230
|
|
|
1217
1231
|
if (generator.type === 'react') {
|
|
1218
1232
|
await buildSchema(
|