@kubb/plugin-oas 4.18.5 → 4.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{SchemaGenerator-DExEah4y.js → SchemaGenerator-D8GP-AGi.js} +45 -17
- package/dist/SchemaGenerator-D8GP-AGi.js.map +1 -0
- package/dist/{SchemaGenerator-B18-jWu7.cjs → SchemaGenerator-DO3rrt_U.cjs} +46 -18
- package/dist/SchemaGenerator-DO3rrt_U.cjs.map +1 -0
- package/dist/{SchemaMapper-oZdVAbXF.d.ts → SchemaMapper-DI2vHHE0.d.ts} +24 -7
- package/dist/{SchemaMapper-BWZ2ZjPQ.d.cts → SchemaMapper-DmB5NyNo.d.cts} +24 -7
- package/dist/{createGenerator-RL6jHKJ-.d.cts → createGenerator-BF26dp_h.d.cts} +26 -2
- package/dist/{createGenerator-Bq76G0TY.d.ts → createGenerator-DhGg_jH6.d.ts} +26 -2
- package/dist/generators.d.cts +2 -2
- package/dist/generators.d.ts +2 -2
- package/dist/getSchemaFactory-CBp1me72.cjs +29 -0
- package/dist/getSchemaFactory-CBp1me72.cjs.map +1 -0
- package/dist/getSchemaFactory-DsoVRgxV.js +24 -0
- package/dist/getSchemaFactory-DsoVRgxV.js.map +1 -0
- package/dist/hooks.cjs +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 +4 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +4 -3
- package/dist/index.js.map +1 -1
- package/dist/mocks.d.cts +1 -1
- package/dist/mocks.d.ts +1 -1
- package/dist/utils.cjs +26 -3
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.d.cts +25 -5
- package/dist/utils.d.ts +25 -5
- package/dist/utils.js +24 -1
- package/dist/utils.js.map +1 -1
- package/package.json +3 -3
- package/src/SchemaGenerator.ts +53 -14
- package/src/plugin.ts +2 -0
- package/src/types.ts +24 -0
- package/src/utils/getSchemas.ts +27 -105
- package/dist/SchemaGenerator-B18-jWu7.cjs.map +0 -1
- package/dist/SchemaGenerator-DExEah4y.js.map +0 -1
- package/dist/getSchemas-BUXPwm-5.js +0 -101
- package/dist/getSchemas-BUXPwm-5.js.map +0 -1
- package/dist/getSchemas-D3YweIFO.cjs +0 -112
- package/dist/getSchemas-D3YweIFO.cjs.map +0 -1
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["path","#isExcluded","#isIncluded","validate","oas","options","_createGenerator","_createReactGenerator"],"sources":["../src/createParser.ts","../src/OperationGenerator.ts","../src/plugin.ts","../src/index.ts"],"sourcesContent":["import { SchemaGenerator } from './SchemaGenerator.ts'\nimport type { Schema, SchemaKeywordMapper, SchemaMapper, SchemaTree } from './SchemaMapper.ts'\nimport { schemaKeywords } from './SchemaMapper.ts'\n\n/**\n * Helper type to create a SchemaTree with a specific current schema type\n */\ntype SchemaTreeWithKeyword<K extends keyof SchemaKeywordMapper> = Omit<SchemaTree, 'current'> & {\n current: SchemaKeywordMapper[K]\n}\n\n/**\n * Handler context with parse method available via `this`\n */\nexport type HandlerContext<TOutput, TOptions> = {\n parse: (tree: SchemaTree, options: TOptions) => TOutput | null | undefined\n}\n\n/**\n * Handler function type for custom keyword processing\n * Handlers can access the parse function via `this.parse`\n * The tree.current is typed based on the keyword K\n */\nexport type KeywordHandler<TOutput, TOptions, K extends keyof SchemaKeywordMapper = keyof SchemaKeywordMapper> = (\n this: HandlerContext<TOutput, TOptions>,\n tree: SchemaTreeWithKeyword<K>,\n options: TOptions,\n) => TOutput | null | undefined\n\n/**\n * Configuration for createParser\n */\nexport type CreateParserConfig<TOutput, TOptions> = {\n /**\n * The keyword mapper that maps schema keywords to output generators\n */\n mapper: SchemaMapper<TOutput>\n\n /**\n * Custom handlers for specific schema keywords\n * These provide the implementation for complex types that need special processing\n *\n * Use function syntax (not arrow functions) to enable use of `this` keyword:\n * ```typescript\n * handlers: {\n * enum(tree, options, parse) {\n * // Implementation\n * }\n * }\n * ```\n *\n * Common keywords that typically need handlers:\n * - union: Combine multiple schemas into a union\n * - and: Combine multiple schemas into an intersection\n * - array: Handle array types with items\n * - object: Handle object types with properties\n * - enum: Handle enum types\n * - tuple: Handle tuple types\n * - const: Handle literal/const types\n * - ref: Handle references to other schemas\n * - string/number/integer: Handle primitives with constraints (min/max)\n * - matches: Handle regex patterns\n * - default/describe/optional/nullable: Handle modifiers\n */\n handlers: Partial<{\n [K in keyof SchemaKeywordMapper]: KeywordHandler<TOutput, TOptions, K>\n }>\n}\n\n/**\n * Creates a parser function that converts schema trees to output using the provided mapper and handlers\n *\n * This function provides a framework for building parsers by:\n * 1. Checking for custom handlers for each keyword\n * 2. Falling back to the mapper for simple keywords\n * 3. Providing utilities for common operations (finding siblings, etc.)\n *\n * The generated parser is recursive and can handle nested schemas.\n *\n * **Type Safety**: Each handler receives a `tree` parameter where `tree.current` is automatically\n * typed as the specific schema keyword type (e.g., `SchemaKeywordMapper['ref']` for the `ref` handler).\n * This means you can access `tree.current.args` with full type safety without needing `isKeyword` checks,\n * though such checks can still be used as runtime guards if desired.\n *\n * @template TOutput - The output type (e.g., string for Zod/Faker, ts.TypeNode for TypeScript)\n * @template TOptions - The parser options type\n * @param config - Configuration object containing mapper and handlers\n * @returns A parse function that converts SchemaTree to TOutput\n *\n * @example\n * ```ts\n * // Create a simple string-based parser\n * const parse = createParser({\n * mapper: zodKeywordMapper,\n * handlers: {\n * // tree.current is typed as SchemaKeywordMapper['union']\n * union(tree, options) {\n * const items = tree.current.args // args is correctly typed as Schema[]\n * .map(it => this.parse({ ...tree, current: it }, options))\n * .filter(Boolean)\n * return `z.union([${items.join(', ')}])`\n * },\n * // tree.current is typed as SchemaKeywordMapper['string']\n * string(tree, options) {\n * const minSchema = findSchemaKeyword(tree.siblings, 'min')\n * const maxSchema = findSchemaKeyword(tree.siblings, 'max')\n * return zodKeywordMapper.string(false, minSchema?.args, maxSchema?.args)\n * },\n * // tree.current is typed as SchemaKeywordMapper['ref']\n * ref(tree, options) {\n * // No need for isKeyword check - tree.current.args is already properly typed\n * return `Ref: ${tree.current.args.name}`\n * }\n * }\n * })\n * ```\n */\nexport function createParser<TOutput, TOptions extends Record<string, any>>(\n config: CreateParserConfig<TOutput, TOptions>,\n): (tree: SchemaTree, options: TOptions) => TOutput | null | undefined {\n const { mapper, handlers } = config\n\n function parse(tree: SchemaTree, options: TOptions): TOutput | null | undefined {\n const { current } = tree\n\n // Check if there's a custom handler for this keyword\n const handler = handlers[current.keyword as keyof SchemaKeywordMapper]\n if (handler) {\n // Create context object with parse method accessible via `this`\n const context: HandlerContext<TOutput, TOptions> = { parse }\n // We need to cast tree here because TypeScript can't statically verify\n // that the handler type matches the current keyword at runtime\n return handler.call(context, tree as any, options)\n }\n\n // Fall back to simple mapper lookup\n const value = mapper[current.keyword as keyof typeof mapper]\n\n if (!value) {\n return undefined\n }\n\n // For simple keywords without args, call the mapper directly\n if (current.keyword in mapper) {\n return value()\n }\n\n return undefined\n }\n\n return parse\n}\n\n/**\n * Helper to find a schema keyword in siblings\n * Useful in handlers when you need to find related schemas (e.g., min/max for string)\n *\n * @example\n * ```ts\n * const minSchema = findSchemaKeyword(tree.siblings, 'min')\n * const maxSchema = findSchemaKeyword(tree.siblings, 'max')\n * return zodKeywordMapper.string(false, minSchema?.args, maxSchema?.args)\n * ```\n */\nexport function findSchemaKeyword<K extends keyof SchemaKeywordMapper>(siblings: Schema[], keyword: K): SchemaKeywordMapper[K] | undefined {\n return SchemaGenerator.find(siblings, schemaKeywords[keyword]) as SchemaKeywordMapper[K] | undefined\n}\n","import type { KubbEvents, Plugin, PluginFactoryOptions, PluginManager } from '@kubb/core'\nimport { BaseGenerator, type FileMetaBase } from '@kubb/core'\nimport transformers from '@kubb/core/transformers'\nimport type { AsyncEventEmitter } from '@kubb/core/utils'\nimport type { KubbFile } from '@kubb/fabric-core/types'\nimport type { contentType, HttpMethod, Oas, OasTypes, Operation, SchemaObject } from '@kubb/oas'\nimport type { Fabric } from '@kubb/react-fabric'\nimport pLimit from 'p-limit'\nimport type { Generator } from './generators/types.ts'\nimport type { Exclude, Include, OperationSchemas, Override } from './types.ts'\nimport { buildOperation, buildOperations } from './utils.tsx'\n\nexport type OperationMethodResult<TFileMeta extends FileMetaBase> = Promise<KubbFile.File<TFileMeta> | Array<KubbFile.File<TFileMeta>> | null>\n\ntype Context<TOptions, TPluginOptions extends PluginFactoryOptions> = {\n fabric: Fabric\n oas: Oas\n exclude: Array<Exclude> | undefined\n include: Array<Include> | undefined\n override: Array<Override<TOptions>> | undefined\n contentType: contentType | undefined\n pluginManager: PluginManager\n events?: AsyncEventEmitter<KubbEvents>\n /**\n * Current plugin\n */\n plugin: Plugin<TPluginOptions>\n mode: KubbFile.Mode\n UNSTABLE_NAMING?: true\n}\n\nexport class OperationGenerator<\n TPluginOptions extends PluginFactoryOptions = PluginFactoryOptions,\n TFileMeta extends FileMetaBase = FileMetaBase,\n> extends BaseGenerator<TPluginOptions['resolvedOptions'], Context<TPluginOptions['resolvedOptions'], TPluginOptions>> {\n getOptions(operation: Operation, method: HttpMethod): Partial<TPluginOptions['resolvedOptions']> {\n const { override = [] } = this.context\n const operationId = operation.getOperationId({ friendlyCase: true })\n const contentType = operation.getContentType()\n\n return (\n override.find(({ pattern, type }) => {\n switch (type) {\n case 'tag':\n return operation.getTags().some((tag) => tag.name.match(pattern))\n case 'operationId':\n return !!operationId.match(pattern)\n case 'path':\n return !!operation.path.match(pattern)\n case 'method':\n return !!method.match(pattern)\n case 'contentType':\n return !!contentType.match(pattern)\n default:\n return false\n }\n })?.options || {}\n )\n }\n\n #isExcluded(operation: Operation, method: HttpMethod): boolean {\n const { exclude = [] } = this.context\n const operationId = operation.getOperationId({ friendlyCase: true })\n const contentType = operation.getContentType()\n\n return exclude.some(({ pattern, type }) => {\n switch (type) {\n case 'tag':\n return operation.getTags().some((tag) => tag.name.match(pattern))\n case 'operationId':\n return !!operationId.match(pattern)\n case 'path':\n return !!operation.path.match(pattern)\n case 'method':\n return !!method.match(pattern)\n case 'contentType':\n return !!contentType.match(pattern)\n default:\n return false\n }\n })\n }\n\n #isIncluded(operation: Operation, method: HttpMethod): boolean {\n const { include = [] } = this.context\n const operationId = operation.getOperationId({ friendlyCase: true })\n const contentType = operation.getContentType()\n\n return include.some(({ pattern, type }) => {\n switch (type) {\n case 'tag':\n return operation.getTags().some((tag) => tag.name.match(pattern))\n case 'operationId':\n return !!operationId.match(pattern)\n case 'path':\n return !!operation.path.match(pattern)\n case 'method':\n return !!method.match(pattern)\n case 'contentType':\n return !!contentType.match(pattern)\n default:\n return false\n }\n })\n }\n\n getSchemas(\n operation: Operation,\n {\n resolveName = (name) => name,\n }: {\n resolveName?: (name: string) => string\n } = {},\n ): OperationSchemas {\n const operationId = operation.getOperationId({ friendlyCase: true })\n const operationName = transformers.pascalCase(operationId)\n\n const resolveKeys = (schema?: SchemaObject) => (schema?.properties ? Object.keys(schema.properties) : undefined)\n\n const pathParamsSchema = this.context.oas.getParametersSchema(operation, 'path')\n const queryParamsSchema = this.context.oas.getParametersSchema(operation, 'query')\n const headerParamsSchema = this.context.oas.getParametersSchema(operation, 'header')\n const requestSchema = this.context.oas.getRequestSchema(operation)\n const statusCodes = operation.getResponseStatusCodes().map((statusCode) => {\n const name = statusCode === 'default' ? 'error' : statusCode\n const schema = this.context.oas.getResponseSchema(operation, statusCode)\n const keys = resolveKeys(schema)\n\n return {\n name: this.context.UNSTABLE_NAMING\n ? resolveName(transformers.pascalCase(`${operationId} status ${name}`))\n : resolveName(transformers.pascalCase(`${operationId} ${name}`)),\n description: (operation.getResponseByStatusCode(statusCode) as OasTypes.ResponseObject)?.description,\n schema,\n operation,\n operationName,\n statusCode: name === 'error' ? undefined : Number(statusCode),\n keys,\n keysToOmit: keys?.filter((key) => (schema?.properties?.[key] as OasTypes.SchemaObject)?.writeOnly),\n }\n })\n\n const successful = statusCodes.filter((item) => item.statusCode?.toString().startsWith('2'))\n const errors = statusCodes.filter((item) => item.statusCode?.toString().startsWith('4') || item.statusCode?.toString().startsWith('5'))\n\n return {\n pathParams: pathParamsSchema\n ? {\n name: resolveName(transformers.pascalCase(`${operationId} PathParams`)),\n operation,\n operationName,\n schema: pathParamsSchema,\n keys: resolveKeys(pathParamsSchema),\n }\n : undefined,\n queryParams: queryParamsSchema\n ? {\n name: resolveName(transformers.pascalCase(`${operationId} QueryParams`)),\n operation,\n operationName,\n schema: queryParamsSchema,\n keys: resolveKeys(queryParamsSchema) || [],\n }\n : undefined,\n headerParams: headerParamsSchema\n ? {\n name: resolveName(transformers.pascalCase(`${operationId} HeaderParams`)),\n operation,\n operationName,\n schema: headerParamsSchema,\n keys: resolveKeys(headerParamsSchema),\n }\n : undefined,\n request: requestSchema\n ? {\n name: this.context.UNSTABLE_NAMING\n ? resolveName(transformers.pascalCase(`${operationId} RequestData`))\n : resolveName(transformers.pascalCase(`${operationId} ${operation.method === 'get' ? 'queryRequest' : 'mutationRequest'}`)),\n description: (operation.schema.requestBody as OasTypes.RequestBodyObject)?.description,\n operation,\n operationName,\n schema: requestSchema,\n keys: resolveKeys(requestSchema),\n keysToOmit: resolveKeys(requestSchema)?.filter((key) => (requestSchema.properties?.[key] as OasTypes.SchemaObject)?.readOnly),\n }\n : undefined,\n response: {\n name: this.context.UNSTABLE_NAMING\n ? resolveName(transformers.pascalCase(`${operationId} ResponseData`))\n : resolveName(transformers.pascalCase(`${operationId} ${operation.method === 'get' ? 'queryResponse' : 'mutationResponse'}`)),\n operation,\n operationName,\n schema: {\n oneOf: successful.map((item) => ({ ...item.schema, $ref: item.name })) || undefined,\n } as SchemaObject,\n },\n responses: successful,\n errors,\n statusCodes,\n }\n }\n\n async getOperations(): Promise<Array<{ path: string; method: HttpMethod; operation: Operation }>> {\n const { oas } = this.context\n\n const paths = oas.getPaths()\n\n return Object.entries(paths).flatMap(([path, methods]) =>\n Object.entries(methods)\n .map((values) => {\n const [method, operation] = values as [HttpMethod, Operation]\n if (this.#isExcluded(operation, method)) {\n return null\n }\n\n if (this.context.include && !this.#isIncluded(operation, method)) {\n return null\n }\n\n return operation ? { path, method: method as HttpMethod, operation } : null\n })\n .filter(Boolean),\n )\n }\n\n async build(...generators: Array<Generator<TPluginOptions>>): Promise<Array<KubbFile.File<TFileMeta>>> {\n const operations = await this.getOperations()\n\n // Increased parallelism for better performance\n // - generatorLimit increased from 1 to 3 to allow parallel generator processing\n // - operationLimit increased from 10 to 30 to process more operations concurrently\n const generatorLimit = pLimit(3)\n const operationLimit = pLimit(30)\n\n this.context.events?.emit('debug', {\n date: new Date(),\n logs: [`Building ${operations.length} operations`, ` • Generators: ${generators.length}`],\n })\n\n const writeTasks = generators.map((generator) =>\n generatorLimit(async () => {\n const operationTasks = operations.map(({ operation, method }) =>\n operationLimit(async () => {\n const options = this.getOptions(operation, method)\n\n if (generator.type === 'react') {\n await buildOperation(operation, {\n config: this.context.pluginManager.config,\n fabric: this.context.fabric,\n Component: generator.Operation,\n generator: this,\n plugin: {\n ...this.context.plugin,\n options: {\n ...this.options,\n ...options,\n },\n },\n })\n\n return []\n }\n\n const result = await generator.operation?.({\n generator: this,\n config: this.context.pluginManager.config,\n operation,\n plugin: {\n ...this.context.plugin,\n options: {\n ...this.options,\n ...options,\n },\n },\n })\n\n return result ?? []\n }),\n )\n\n const operationResults = await Promise.all(operationTasks)\n const opResultsFlat = operationResults.flat()\n\n if (generator.type === 'react') {\n await buildOperations(\n operations.map((op) => op.operation),\n {\n fabric: this.context.fabric,\n config: this.context.pluginManager.config,\n Component: generator.Operations,\n generator: this,\n plugin: this.context.plugin,\n },\n )\n\n return []\n }\n\n const operationsResult = await generator.operations?.({\n generator: this,\n config: this.context.pluginManager.config,\n operations: operations.map((op) => op.operation),\n plugin: this.context.plugin,\n })\n\n return [...opResultsFlat, ...(operationsResult ?? [])] as unknown as KubbFile.File<TFileMeta>\n }),\n )\n\n const nestedResults = await Promise.all(writeTasks)\n\n return nestedResults.flat()\n }\n}\n","import path from 'node:path'\nimport { type Config, definePlugin, type Group, getMode, type KubbEvents } from '@kubb/core'\nimport { camelCase } from '@kubb/core/transformers'\nimport type { AsyncEventEmitter } from '@kubb/core/utils'\nimport type { Oas } from '@kubb/oas'\nimport { parseFromConfig } from '@kubb/oas'\nimport { jsonGenerator } from './generators'\nimport { OperationGenerator } from './OperationGenerator.ts'\nimport { SchemaGenerator } from './SchemaGenerator.ts'\nimport type { PluginOas } from './types.ts'\n\nexport const pluginOasName = 'plugin-oas' satisfies PluginOas['name']\n\nexport const pluginOas = definePlugin<PluginOas>((options) => {\n const {\n output = {\n path: 'schemas',\n },\n group,\n validate = true,\n generators = [jsonGenerator],\n serverIndex,\n contentType,\n oasClass,\n discriminator = 'strict',\n } = options\n\n const getOas = async ({ validate, config, events }: { validate: boolean; config: Config; events: AsyncEventEmitter<KubbEvents> }): Promise<Oas> => {\n // needs to be in a different variable or the catch here will not work(return of a promise instead)\n const oas = await parseFromConfig(config, oasClass)\n\n oas.setOptions({\n contentType,\n discriminator,\n })\n\n try {\n if (validate) {\n await oas.validate()\n }\n } catch (er) {\n const caughtError = er as Error\n const errorTimestamp = new Date()\n const error = new Error('OAS Validation failed', {\n cause: caughtError,\n })\n\n events.emit('info', caughtError.message)\n events.emit('debug', {\n date: errorTimestamp,\n logs: [`✗ ${error.message}`, caughtError.message],\n })\n }\n\n return oas\n }\n\n return {\n name: pluginOasName,\n options: {\n output,\n validate,\n discriminator,\n ...options,\n },\n inject() {\n const config = this.config\n const events = this.events\n\n let oas: Oas\n\n return {\n async getOas({ validate = false } = {}) {\n if (!oas) {\n oas = await getOas({ config, events, validate })\n }\n\n return oas\n },\n async getBaseURL() {\n const oas = await getOas({ config, events, validate: false })\n if (serverIndex !== undefined) {\n return oas.api.servers?.at(serverIndex)?.url\n }\n\n return undefined\n },\n }\n },\n resolvePath(baseName, pathMode, options) {\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = pathMode ?? getMode(path.resolve(root, output.path))\n\n if (mode === 'single') {\n /**\n * when output is a file then we will always append to the same file(output file), see fileManager.addOrAppend\n * Other plugins then need to call addOrAppend instead of just add from the fileManager class\n */\n return path.resolve(root, output.path)\n }\n\n if (group && (options?.group?.path || options?.group?.tag)) {\n const groupName: Group['name'] = group?.name\n ? group.name\n : (ctx) => {\n if (group?.type === 'path') {\n return `${ctx.group.split('/')[1]}`\n }\n return `${camelCase(ctx.group)}Controller`\n }\n\n return path.resolve(\n root,\n output.path,\n groupName({\n group: group.type === 'path' ? options.group.path! : options.group.tag!,\n }),\n baseName,\n )\n }\n\n return path.resolve(root, output.path, baseName)\n },\n async install() {\n const oas = await this.getOas({ validate })\n\n if (!output) {\n return\n }\n\n await oas.dereference()\n\n const schemaGenerator = new SchemaGenerator(\n {\n unknownType: 'unknown',\n emptySchemaType: 'unknown',\n dateType: 'date',\n transformers: {},\n ...this.plugin.options,\n },\n {\n fabric: this.fabric,\n oas,\n pluginManager: this.pluginManager,\n events: this.events,\n plugin: this.plugin,\n contentType,\n include: undefined,\n override: undefined,\n mode: 'split',\n output: output.path,\n },\n )\n\n const schemaFiles = await schemaGenerator.build(...generators)\n await this.upsertFile(...schemaFiles)\n\n const operationGenerator = new OperationGenerator(this.plugin.options, {\n fabric: this.fabric,\n oas,\n pluginManager: this.pluginManager,\n events: this.events,\n plugin: this.plugin,\n contentType,\n exclude: undefined,\n include: undefined,\n override: undefined,\n mode: 'split',\n })\n\n const operationFiles = await operationGenerator.build(...generators)\n\n await this.upsertFile(...operationFiles)\n },\n }\n})\n","import type { PluginFactoryOptions } from '@kubb/core'\nimport { createGenerator as _createGenerator } from './generators/createGenerator.ts'\nimport { createReactGenerator as _createReactGenerator } from './generators/createReactGenerator.ts'\nimport type { Generator as _Generator } from './generators/types.ts'\n\nexport type { CreateParserConfig, KeywordHandler } from './createParser.ts'\nexport { createParser, findSchemaKeyword } from './createParser.ts'\nexport type { OperationMethodResult } from './OperationGenerator.ts'\nexport { OperationGenerator } from './OperationGenerator.ts'\nexport { pluginOas, pluginOasName } from './plugin.ts'\nexport type {\n GetSchemaGeneratorOptions,\n SchemaGeneratorBuildOptions,\n SchemaGeneratorOptions,\n SchemaMethodResult,\n} from './SchemaGenerator.ts'\nexport { SchemaGenerator } from './SchemaGenerator.ts'\nexport type {\n Schema,\n SchemaKeyword,\n SchemaKeywordBase,\n SchemaKeywordMapper,\n SchemaMapper,\n SchemaTree,\n} from './SchemaMapper.ts'\nexport { isKeyword, schemaKeywords } from './SchemaMapper.ts'\nexport type * from './types.ts'\nexport { buildOperation, buildOperations, buildSchema } from './utils.tsx'\n\n/**\n * @deprecated use `import { createGenerator } from '@kubb/plugin-oas/generators'`\n */\nexport const createGenerator = _createGenerator\n\n/**\n * @deprecated use `import { createReactGenerator } from '@kubb/plugin-oas/generators'`\n */\nexport const createReactGenerator = _createReactGenerator\n\n/**\n * @deprecated use `import { Generator } from '@kubb/plugin-oas/generators'`\n */\nexport type Generator<TOptions extends PluginFactoryOptions> = _Generator<TOptions>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqHA,SAAgB,aACd,QACqE;CACrE,MAAM,EAAE,QAAQ,aAAa;CAE7B,SAAS,MAAM,MAAkB,SAA+C;EAC9E,MAAM,EAAE,YAAY;EAGpB,MAAM,UAAU,SAAS,QAAQ;AACjC,MAAI,SAAS;GAEX,MAAM,UAA6C,EAAE,OAAO;AAG5D,UAAO,QAAQ,KAAK,SAAS,MAAa,QAAQ;;EAIpD,MAAM,QAAQ,OAAO,QAAQ;AAE7B,MAAI,CAAC,MACH;AAIF,MAAI,QAAQ,WAAW,OACrB,QAAO,OAAO;;AAMlB,QAAO;;;;;;;;;;;;;AAcT,SAAgB,kBAAuD,UAAoB,SAAgD;AACzI,QAAO,gBAAgB,KAAK,UAAU,eAAe,SAAS;;;;;ACtIhE,IAAa,qBAAb,cAGU,cAA6G;CACrH,WAAW,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,MAAM,KACpE,CAAC,EACF,SACD;;AAGH,UAAO,KAAK,QAAQ,MAAM,OAAO,MAAM,SAAS;;EAElD,MAAM,UAAU;GACd,MAAM,MAAM,MAAM,KAAK,OAAO,EAAE,UAAU,CAAC;AAE3C,OAAI,CAAC,OACH;AAGF,SAAM,IAAI,aAAa;GAwBvB,MAAM,cAAc,MAtBI,IAAI,gBAC1B;IACE,aAAa;IACb,iBAAiB;IACjB,UAAU;IACV,cAAc,EAAE;IAChB,GAAG,KAAK,OAAO;IAChB,EACD;IACE,QAAQ,KAAK;IACb;IACA,eAAe,KAAK;IACpB,QAAQ,KAAK;IACb,QAAQ,KAAK;IACb;IACA,SAAS;IACT,UAAU;IACV,MAAM;IACN,QAAQ,OAAO;IAChB,CACF,CAEyC,MAAM,GAAG,WAAW;AAC9D,SAAM,KAAK,WAAW,GAAG,YAAY;GAerC,MAAM,iBAAiB,MAbI,IAAI,mBAAmB,KAAK,OAAO,SAAS;IACrE,QAAQ,KAAK;IACb;IACA,eAAe,KAAK;IACpB,QAAQ,KAAK;IACb,QAAQ,KAAK;IACb;IACA,SAAS;IACT,SAAS;IACT,UAAU;IACV,MAAM;IACP,CAAC,CAE8C,MAAM,GAAG,WAAW;AAEpE,SAAM,KAAK,WAAW,GAAG,eAAe;;EAE3C;EACD;;;;;;;AC/IF,MAAa,kBAAkBC;;;;AAK/B,MAAa,uBAAuBC"}
|
|
1
|
+
{"version":3,"file":"index.js","names":["path","#isExcluded","#isIncluded","validate","oas","options","_createGenerator","_createReactGenerator"],"sources":["../src/createParser.ts","../src/OperationGenerator.ts","../src/plugin.ts","../src/index.ts"],"sourcesContent":["import { SchemaGenerator } from './SchemaGenerator.ts'\nimport type { Schema, SchemaKeywordMapper, SchemaMapper, SchemaTree } from './SchemaMapper.ts'\nimport { schemaKeywords } from './SchemaMapper.ts'\n\n/**\n * Helper type to create a SchemaTree with a specific current schema type\n */\ntype SchemaTreeWithKeyword<K extends keyof SchemaKeywordMapper> = Omit<SchemaTree, 'current'> & {\n current: SchemaKeywordMapper[K]\n}\n\n/**\n * Handler context with parse method available via `this`\n */\nexport type HandlerContext<TOutput, TOptions> = {\n parse: (tree: SchemaTree, options: TOptions) => TOutput | null | undefined\n}\n\n/**\n * Handler function type for custom keyword processing\n * Handlers can access the parse function via `this.parse`\n * The tree.current is typed based on the keyword K\n */\nexport type KeywordHandler<TOutput, TOptions, K extends keyof SchemaKeywordMapper = keyof SchemaKeywordMapper> = (\n this: HandlerContext<TOutput, TOptions>,\n tree: SchemaTreeWithKeyword<K>,\n options: TOptions,\n) => TOutput | null | undefined\n\n/**\n * Configuration for createParser\n */\nexport type CreateParserConfig<TOutput, TOptions> = {\n /**\n * The keyword mapper that maps schema keywords to output generators\n */\n mapper: SchemaMapper<TOutput>\n\n /**\n * Custom handlers for specific schema keywords\n * These provide the implementation for complex types that need special processing\n *\n * Use function syntax (not arrow functions) to enable use of `this` keyword:\n * ```typescript\n * handlers: {\n * enum(tree, options, parse) {\n * // Implementation\n * }\n * }\n * ```\n *\n * Common keywords that typically need handlers:\n * - union: Combine multiple schemas into a union\n * - and: Combine multiple schemas into an intersection\n * - array: Handle array types with items\n * - object: Handle object types with properties\n * - enum: Handle enum types\n * - tuple: Handle tuple types\n * - const: Handle literal/const types\n * - ref: Handle references to other schemas\n * - string/number/integer: Handle primitives with constraints (min/max)\n * - matches: Handle regex patterns\n * - default/describe/optional/nullable: Handle modifiers\n */\n handlers: Partial<{\n [K in keyof SchemaKeywordMapper]: KeywordHandler<TOutput, TOptions, K>\n }>\n}\n\n/**\n * Creates a parser function that converts schema trees to output using the provided mapper and handlers\n *\n * This function provides a framework for building parsers by:\n * 1. Checking for custom handlers for each keyword\n * 2. Falling back to the mapper for simple keywords\n * 3. Providing utilities for common operations (finding siblings, etc.)\n *\n * The generated parser is recursive and can handle nested schemas.\n *\n * **Type Safety**: Each handler receives a `tree` parameter where `tree.current` is automatically\n * typed as the specific schema keyword type (e.g., `SchemaKeywordMapper['ref']` for the `ref` handler).\n * This means you can access `tree.current.args` with full type safety without needing `isKeyword` checks,\n * though such checks can still be used as runtime guards if desired.\n *\n * @template TOutput - The output type (e.g., string for Zod/Faker, ts.TypeNode for TypeScript)\n * @template TOptions - The parser options type\n * @param config - Configuration object containing mapper and handlers\n * @returns A parse function that converts SchemaTree to TOutput\n *\n * @example\n * ```ts\n * // Create a simple string-based parser\n * const parse = createParser({\n * mapper: zodKeywordMapper,\n * handlers: {\n * // tree.current is typed as SchemaKeywordMapper['union']\n * union(tree, options) {\n * const items = tree.current.args // args is correctly typed as Schema[]\n * .map(it => this.parse({ ...tree, current: it }, options))\n * .filter(Boolean)\n * return `z.union([${items.join(', ')}])`\n * },\n * // tree.current is typed as SchemaKeywordMapper['string']\n * string(tree, options) {\n * const minSchema = findSchemaKeyword(tree.siblings, 'min')\n * const maxSchema = findSchemaKeyword(tree.siblings, 'max')\n * return zodKeywordMapper.string(false, minSchema?.args, maxSchema?.args)\n * },\n * // tree.current is typed as SchemaKeywordMapper['ref']\n * ref(tree, options) {\n * // No need for isKeyword check - tree.current.args is already properly typed\n * return `Ref: ${tree.current.args.name}`\n * }\n * }\n * })\n * ```\n */\nexport function createParser<TOutput, TOptions extends Record<string, any>>(\n config: CreateParserConfig<TOutput, TOptions>,\n): (tree: SchemaTree, options: TOptions) => TOutput | null | undefined {\n const { mapper, handlers } = config\n\n function parse(tree: SchemaTree, options: TOptions): TOutput | null | undefined {\n const { current } = tree\n\n // Check if there's a custom handler for this keyword\n const handler = handlers[current.keyword as keyof SchemaKeywordMapper]\n if (handler) {\n // Create context object with parse method accessible via `this`\n const context: HandlerContext<TOutput, TOptions> = { parse }\n // We need to cast tree here because TypeScript can't statically verify\n // that the handler type matches the current keyword at runtime\n return handler.call(context, tree as any, options)\n }\n\n // Fall back to simple mapper lookup\n const value = mapper[current.keyword as keyof typeof mapper]\n\n if (!value) {\n return undefined\n }\n\n // For simple keywords without args, call the mapper directly\n if (current.keyword in mapper) {\n return value()\n }\n\n return undefined\n }\n\n return parse\n}\n\n/**\n * Helper to find a schema keyword in siblings\n * Useful in handlers when you need to find related schemas (e.g., min/max for string)\n *\n * @example\n * ```ts\n * const minSchema = findSchemaKeyword(tree.siblings, 'min')\n * const maxSchema = findSchemaKeyword(tree.siblings, 'max')\n * return zodKeywordMapper.string(false, minSchema?.args, maxSchema?.args)\n * ```\n */\nexport function findSchemaKeyword<K extends keyof SchemaKeywordMapper>(siblings: Schema[], keyword: K): SchemaKeywordMapper[K] | undefined {\n return SchemaGenerator.find(siblings, schemaKeywords[keyword]) as SchemaKeywordMapper[K] | undefined\n}\n","import type { KubbEvents, Plugin, PluginFactoryOptions, PluginManager } from '@kubb/core'\nimport { BaseGenerator, type FileMetaBase } from '@kubb/core'\nimport transformers from '@kubb/core/transformers'\nimport type { AsyncEventEmitter } from '@kubb/core/utils'\nimport type { KubbFile } from '@kubb/fabric-core/types'\nimport type { contentType, HttpMethod, Oas, OasTypes, Operation, SchemaObject } from '@kubb/oas'\nimport type { Fabric } from '@kubb/react-fabric'\nimport pLimit from 'p-limit'\nimport type { Generator } from './generators/types.ts'\nimport type { Exclude, Include, OperationSchemas, Override } from './types.ts'\nimport { buildOperation, buildOperations } from './utils.tsx'\n\nexport type OperationMethodResult<TFileMeta extends FileMetaBase> = Promise<KubbFile.File<TFileMeta> | Array<KubbFile.File<TFileMeta>> | null>\n\ntype Context<TOptions, TPluginOptions extends PluginFactoryOptions> = {\n fabric: Fabric\n oas: Oas\n exclude: Array<Exclude> | undefined\n include: Array<Include> | undefined\n override: Array<Override<TOptions>> | undefined\n contentType: contentType | undefined\n pluginManager: PluginManager\n events?: AsyncEventEmitter<KubbEvents>\n /**\n * Current plugin\n */\n plugin: Plugin<TPluginOptions>\n mode: KubbFile.Mode\n UNSTABLE_NAMING?: true\n}\n\nexport class OperationGenerator<\n TPluginOptions extends PluginFactoryOptions = PluginFactoryOptions,\n TFileMeta extends FileMetaBase = FileMetaBase,\n> extends BaseGenerator<TPluginOptions['resolvedOptions'], Context<TPluginOptions['resolvedOptions'], TPluginOptions>> {\n getOptions(operation: Operation, method: HttpMethod): Partial<TPluginOptions['resolvedOptions']> {\n const { override = [] } = this.context\n const operationId = operation.getOperationId({ friendlyCase: true })\n const contentType = operation.getContentType()\n\n return (\n override.find(({ pattern, type }) => {\n switch (type) {\n case 'tag':\n return operation.getTags().some((tag) => tag.name.match(pattern))\n case 'operationId':\n return !!operationId.match(pattern)\n case 'path':\n return !!operation.path.match(pattern)\n case 'method':\n return !!method.match(pattern)\n case 'contentType':\n return !!contentType.match(pattern)\n default:\n return false\n }\n })?.options || {}\n )\n }\n\n #isExcluded(operation: Operation, method: HttpMethod): boolean {\n const { exclude = [] } = this.context\n const operationId = operation.getOperationId({ friendlyCase: true })\n const contentType = operation.getContentType()\n\n return exclude.some(({ pattern, type }) => {\n switch (type) {\n case 'tag':\n return operation.getTags().some((tag) => tag.name.match(pattern))\n case 'operationId':\n return !!operationId.match(pattern)\n case 'path':\n return !!operation.path.match(pattern)\n case 'method':\n return !!method.match(pattern)\n case 'contentType':\n return !!contentType.match(pattern)\n default:\n return false\n }\n })\n }\n\n #isIncluded(operation: Operation, method: HttpMethod): boolean {\n const { include = [] } = this.context\n const operationId = operation.getOperationId({ friendlyCase: true })\n const contentType = operation.getContentType()\n\n return include.some(({ pattern, type }) => {\n switch (type) {\n case 'tag':\n return operation.getTags().some((tag) => tag.name.match(pattern))\n case 'operationId':\n return !!operationId.match(pattern)\n case 'path':\n return !!operation.path.match(pattern)\n case 'method':\n return !!method.match(pattern)\n case 'contentType':\n return !!contentType.match(pattern)\n default:\n return false\n }\n })\n }\n\n getSchemas(\n operation: Operation,\n {\n resolveName = (name) => name,\n }: {\n resolveName?: (name: string) => string\n } = {},\n ): OperationSchemas {\n const operationId = operation.getOperationId({ friendlyCase: true })\n const operationName = transformers.pascalCase(operationId)\n\n const resolveKeys = (schema?: SchemaObject) => (schema?.properties ? Object.keys(schema.properties) : undefined)\n\n const pathParamsSchema = this.context.oas.getParametersSchema(operation, 'path')\n const queryParamsSchema = this.context.oas.getParametersSchema(operation, 'query')\n const headerParamsSchema = this.context.oas.getParametersSchema(operation, 'header')\n const requestSchema = this.context.oas.getRequestSchema(operation)\n const statusCodes = operation.getResponseStatusCodes().map((statusCode) => {\n const name = statusCode === 'default' ? 'error' : statusCode\n const schema = this.context.oas.getResponseSchema(operation, statusCode)\n const keys = resolveKeys(schema)\n\n return {\n name: this.context.UNSTABLE_NAMING\n ? resolveName(transformers.pascalCase(`${operationId} status ${name}`))\n : resolveName(transformers.pascalCase(`${operationId} ${name}`)),\n description: (operation.getResponseByStatusCode(statusCode) as OasTypes.ResponseObject)?.description,\n schema,\n operation,\n operationName,\n statusCode: name === 'error' ? undefined : Number(statusCode),\n keys,\n keysToOmit: keys?.filter((key) => (schema?.properties?.[key] as OasTypes.SchemaObject)?.writeOnly),\n }\n })\n\n const successful = statusCodes.filter((item) => item.statusCode?.toString().startsWith('2'))\n const errors = statusCodes.filter((item) => item.statusCode?.toString().startsWith('4') || item.statusCode?.toString().startsWith('5'))\n\n return {\n pathParams: pathParamsSchema\n ? {\n name: resolveName(transformers.pascalCase(`${operationId} PathParams`)),\n operation,\n operationName,\n schema: pathParamsSchema,\n keys: resolveKeys(pathParamsSchema),\n }\n : undefined,\n queryParams: queryParamsSchema\n ? {\n name: resolveName(transformers.pascalCase(`${operationId} QueryParams`)),\n operation,\n operationName,\n schema: queryParamsSchema,\n keys: resolveKeys(queryParamsSchema) || [],\n }\n : undefined,\n headerParams: headerParamsSchema\n ? {\n name: resolveName(transformers.pascalCase(`${operationId} HeaderParams`)),\n operation,\n operationName,\n schema: headerParamsSchema,\n keys: resolveKeys(headerParamsSchema),\n }\n : undefined,\n request: requestSchema\n ? {\n name: this.context.UNSTABLE_NAMING\n ? resolveName(transformers.pascalCase(`${operationId} RequestData`))\n : resolveName(transformers.pascalCase(`${operationId} ${operation.method === 'get' ? 'queryRequest' : 'mutationRequest'}`)),\n description: (operation.schema.requestBody as OasTypes.RequestBodyObject)?.description,\n operation,\n operationName,\n schema: requestSchema,\n keys: resolveKeys(requestSchema),\n keysToOmit: resolveKeys(requestSchema)?.filter((key) => (requestSchema.properties?.[key] as OasTypes.SchemaObject)?.readOnly),\n }\n : undefined,\n response: {\n name: this.context.UNSTABLE_NAMING\n ? resolveName(transformers.pascalCase(`${operationId} ResponseData`))\n : resolveName(transformers.pascalCase(`${operationId} ${operation.method === 'get' ? 'queryResponse' : 'mutationResponse'}`)),\n operation,\n operationName,\n schema: {\n oneOf: successful.map((item) => ({ ...item.schema, $ref: item.name })) || undefined,\n } as SchemaObject,\n },\n responses: successful,\n errors,\n statusCodes,\n }\n }\n\n async getOperations(): Promise<Array<{ path: string; method: HttpMethod; operation: Operation }>> {\n const { oas } = this.context\n\n const paths = oas.getPaths()\n\n return Object.entries(paths).flatMap(([path, methods]) =>\n Object.entries(methods)\n .map((values) => {\n const [method, operation] = values as [HttpMethod, Operation]\n if (this.#isExcluded(operation, method)) {\n return null\n }\n\n if (this.context.include && !this.#isIncluded(operation, method)) {\n return null\n }\n\n return operation ? { path, method: method as HttpMethod, operation } : null\n })\n .filter(Boolean),\n )\n }\n\n async build(...generators: Array<Generator<TPluginOptions>>): Promise<Array<KubbFile.File<TFileMeta>>> {\n const operations = await this.getOperations()\n\n // Increased parallelism for better performance\n // - generatorLimit increased from 1 to 3 to allow parallel generator processing\n // - operationLimit increased from 10 to 30 to process more operations concurrently\n const generatorLimit = pLimit(3)\n const operationLimit = pLimit(30)\n\n this.context.events?.emit('debug', {\n date: new Date(),\n logs: [`Building ${operations.length} operations`, ` • Generators: ${generators.length}`],\n })\n\n const writeTasks = generators.map((generator) =>\n generatorLimit(async () => {\n const operationTasks = operations.map(({ operation, method }) =>\n operationLimit(async () => {\n const options = this.getOptions(operation, method)\n\n if (generator.type === 'react') {\n await buildOperation(operation, {\n config: this.context.pluginManager.config,\n fabric: this.context.fabric,\n Component: generator.Operation,\n generator: this,\n plugin: {\n ...this.context.plugin,\n options: {\n ...this.options,\n ...options,\n },\n },\n })\n\n return []\n }\n\n const result = await generator.operation?.({\n generator: this,\n config: this.context.pluginManager.config,\n operation,\n plugin: {\n ...this.context.plugin,\n options: {\n ...this.options,\n ...options,\n },\n },\n })\n\n return result ?? []\n }),\n )\n\n const operationResults = await Promise.all(operationTasks)\n const opResultsFlat = operationResults.flat()\n\n if (generator.type === 'react') {\n await buildOperations(\n operations.map((op) => op.operation),\n {\n fabric: this.context.fabric,\n config: this.context.pluginManager.config,\n Component: generator.Operations,\n generator: this,\n plugin: this.context.plugin,\n },\n )\n\n return []\n }\n\n const operationsResult = await generator.operations?.({\n generator: this,\n config: this.context.pluginManager.config,\n operations: operations.map((op) => op.operation),\n plugin: this.context.plugin,\n })\n\n return [...opResultsFlat, ...(operationsResult ?? [])] as unknown as KubbFile.File<TFileMeta>\n }),\n )\n\n const nestedResults = await Promise.all(writeTasks)\n\n return nestedResults.flat()\n }\n}\n","import path from 'node:path'\nimport { type Config, definePlugin, type Group, getMode, type KubbEvents } from '@kubb/core'\nimport { camelCase } from '@kubb/core/transformers'\nimport type { AsyncEventEmitter } from '@kubb/core/utils'\nimport type { Oas } from '@kubb/oas'\nimport { parseFromConfig } from '@kubb/oas'\nimport { jsonGenerator } from './generators'\nimport { OperationGenerator } from './OperationGenerator.ts'\nimport { SchemaGenerator } from './SchemaGenerator.ts'\nimport type { PluginOas } from './types.ts'\n\nexport const pluginOasName = 'plugin-oas' satisfies PluginOas['name']\n\nexport const pluginOas = definePlugin<PluginOas>((options) => {\n const {\n output = {\n path: 'schemas',\n },\n group,\n validate = true,\n generators = [jsonGenerator],\n serverIndex,\n contentType,\n oasClass,\n discriminator = 'strict',\n collisionDetection = false,\n } = options\n\n const getOas = async ({ validate, config, events }: { validate: boolean; config: Config; events: AsyncEventEmitter<KubbEvents> }): Promise<Oas> => {\n // needs to be in a different variable or the catch here will not work(return of a promise instead)\n const oas = await parseFromConfig(config, oasClass)\n\n oas.setOptions({\n contentType,\n discriminator,\n collisionDetection,\n })\n\n try {\n if (validate) {\n await oas.validate()\n }\n } catch (er) {\n const caughtError = er as Error\n const errorTimestamp = new Date()\n const error = new Error('OAS Validation failed', {\n cause: caughtError,\n })\n\n events.emit('info', caughtError.message)\n events.emit('debug', {\n date: errorTimestamp,\n logs: [`✗ ${error.message}`, caughtError.message],\n })\n }\n\n return oas\n }\n\n return {\n name: pluginOasName,\n options: {\n output,\n validate,\n discriminator,\n ...options,\n },\n inject() {\n const config = this.config\n const events = this.events\n\n let oas: Oas\n\n return {\n async getOas({ validate = false } = {}) {\n if (!oas) {\n oas = await getOas({ config, events, validate })\n }\n\n return oas\n },\n async getBaseURL() {\n const oas = await getOas({ config, events, validate: false })\n if (serverIndex !== undefined) {\n return oas.api.servers?.at(serverIndex)?.url\n }\n\n return undefined\n },\n }\n },\n resolvePath(baseName, pathMode, options) {\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = pathMode ?? getMode(path.resolve(root, output.path))\n\n if (mode === 'single') {\n /**\n * when output is a file then we will always append to the same file(output file), see fileManager.addOrAppend\n * Other plugins then need to call addOrAppend instead of just add from the fileManager class\n */\n return path.resolve(root, output.path)\n }\n\n if (group && (options?.group?.path || options?.group?.tag)) {\n const groupName: Group['name'] = group?.name\n ? group.name\n : (ctx) => {\n if (group?.type === 'path') {\n return `${ctx.group.split('/')[1]}`\n }\n return `${camelCase(ctx.group)}Controller`\n }\n\n return path.resolve(\n root,\n output.path,\n groupName({\n group: group.type === 'path' ? options.group.path! : options.group.tag!,\n }),\n baseName,\n )\n }\n\n return path.resolve(root, output.path, baseName)\n },\n async install() {\n const oas = await this.getOas({ validate })\n\n if (!output) {\n return\n }\n\n await oas.dereference()\n\n const schemaGenerator = new SchemaGenerator(\n {\n unknownType: 'unknown',\n emptySchemaType: 'unknown',\n dateType: 'date',\n transformers: {},\n ...this.plugin.options,\n },\n {\n fabric: this.fabric,\n oas,\n pluginManager: this.pluginManager,\n events: this.events,\n plugin: this.plugin,\n contentType,\n include: undefined,\n override: undefined,\n mode: 'split',\n output: output.path,\n },\n )\n\n const schemaFiles = await schemaGenerator.build(...generators)\n await this.upsertFile(...schemaFiles)\n\n const operationGenerator = new OperationGenerator(this.plugin.options, {\n fabric: this.fabric,\n oas,\n pluginManager: this.pluginManager,\n events: this.events,\n plugin: this.plugin,\n contentType,\n exclude: undefined,\n include: undefined,\n override: undefined,\n mode: 'split',\n })\n\n const operationFiles = await operationGenerator.build(...generators)\n\n await this.upsertFile(...operationFiles)\n },\n }\n})\n","import type { PluginFactoryOptions } from '@kubb/core'\nimport { createGenerator as _createGenerator } from './generators/createGenerator.ts'\nimport { createReactGenerator as _createReactGenerator } from './generators/createReactGenerator.ts'\nimport type { Generator as _Generator } from './generators/types.ts'\n\nexport type { CreateParserConfig, KeywordHandler } from './createParser.ts'\nexport { createParser, findSchemaKeyword } from './createParser.ts'\nexport type { OperationMethodResult } from './OperationGenerator.ts'\nexport { OperationGenerator } from './OperationGenerator.ts'\nexport { pluginOas, pluginOasName } from './plugin.ts'\nexport type {\n GetSchemaGeneratorOptions,\n SchemaGeneratorBuildOptions,\n SchemaGeneratorOptions,\n SchemaMethodResult,\n} from './SchemaGenerator.ts'\nexport { SchemaGenerator } from './SchemaGenerator.ts'\nexport type {\n Schema,\n SchemaKeyword,\n SchemaKeywordBase,\n SchemaKeywordMapper,\n SchemaMapper,\n SchemaTree,\n} from './SchemaMapper.ts'\nexport { isKeyword, schemaKeywords } from './SchemaMapper.ts'\nexport type * from './types.ts'\nexport { buildOperation, buildOperations, buildSchema } from './utils.tsx'\n\n/**\n * @deprecated use `import { createGenerator } from '@kubb/plugin-oas/generators'`\n */\nexport const createGenerator = _createGenerator\n\n/**\n * @deprecated use `import { createReactGenerator } from '@kubb/plugin-oas/generators'`\n */\nexport const createReactGenerator = _createReactGenerator\n\n/**\n * @deprecated use `import { Generator } from '@kubb/plugin-oas/generators'`\n */\nexport type Generator<TOptions extends PluginFactoryOptions> = _Generator<TOptions>\n"],"mappings":";;;;;;;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AAQ,KAAK;IACb,QAAQ,KAAK;IACb;IACA,SAAS;IACT,SAAS;IACT,UAAU;IACV,MAAM;IACP,CAAC,CAE8C,MAAM,GAAG,WAAW;AAEpE,SAAM,KAAK,WAAW,GAAG,eAAe;;EAE3C;EACD;;;;;;;ACjJF,MAAa,kBAAkBC;;;;AAK/B,MAAa,uBAAuBC"}
|
package/dist/mocks.d.cts
CHANGED
package/dist/mocks.d.ts
CHANGED
package/dist/utils.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const require_chunk = require('./chunk-C1_xRkKa.cjs');
|
|
2
|
-
const
|
|
2
|
+
const require_getSchemaFactory = require('./getSchemaFactory-CBp1me72.cjs');
|
|
3
3
|
const require_getFooter = require('./getFooter-BvLkEWpc.cjs');
|
|
4
4
|
let _kubb_core_transformers = require("@kubb/core/transformers");
|
|
5
5
|
_kubb_core_transformers = require_chunk.__toESM(_kubb_core_transformers);
|
|
@@ -51,13 +51,36 @@ function getPathParams(operationSchema, options = {}) {
|
|
|
51
51
|
}, {});
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
+
//#endregion
|
|
55
|
+
//#region src/utils/getSchemas.ts
|
|
56
|
+
/**
|
|
57
|
+
* Collect schemas from OpenAPI components (schemas, responses, requestBodies)
|
|
58
|
+
* and return them in dependency order along with name mapping for collision resolution.
|
|
59
|
+
*
|
|
60
|
+
* This function is a wrapper around the oas.getSchemas() method for backward compatibility.
|
|
61
|
+
* New code should use oas.getSchemas() directly.
|
|
62
|
+
*
|
|
63
|
+
* @deprecated Use oas.getSchemas() instead
|
|
64
|
+
*/
|
|
65
|
+
function getSchemas({ oas, contentType, includes = [
|
|
66
|
+
"schemas",
|
|
67
|
+
"requestBodies",
|
|
68
|
+
"responses"
|
|
69
|
+
], collisionDetection }) {
|
|
70
|
+
return oas.getSchemas({
|
|
71
|
+
contentType,
|
|
72
|
+
includes,
|
|
73
|
+
collisionDetection
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
|
|
54
77
|
//#endregion
|
|
55
78
|
exports.getBanner = require_getFooter.getBanner;
|
|
56
79
|
exports.getComments = getComments;
|
|
57
80
|
exports.getFooter = require_getFooter.getFooter;
|
|
58
81
|
exports.getPathParams = getPathParams;
|
|
59
|
-
exports.getSchemaFactory =
|
|
60
|
-
exports.getSchemas =
|
|
82
|
+
exports.getSchemaFactory = require_getSchemaFactory.getSchemaFactory;
|
|
83
|
+
exports.getSchemas = getSchemas;
|
|
61
84
|
Object.defineProperty(exports, 'isOptional', {
|
|
62
85
|
enumerable: true,
|
|
63
86
|
get: function () {
|
package/dist/utils.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.cjs","names":["URLPath","transformers"],"sources":["../src/utils/getComments.ts","../src/utils/getParams.ts"],"sourcesContent":["import transformers from '@kubb/core/transformers'\nimport { URLPath } from '@kubb/core/utils'\n\nimport type { Operation } from '@kubb/oas'\n\nexport function getComments(operation: Operation): string[] {\n return [\n operation.getDescription() && `@description ${operation.getDescription()}`,\n operation.getSummary() && `@summary ${operation.getSummary()}`,\n operation.path && `{@link ${new URLPath(operation.path).URL}}`,\n operation.isDeprecated() && '@deprecated',\n ]\n .filter(Boolean)\n .map((text) => transformers.trim(text))\n .filter(Boolean)\n}\n","import { camelCase, isValidVarName } from '@kubb/core/transformers'\nimport type { FunctionParamsAST } from '@kubb/core/utils'\nimport type { OasTypes } from '@kubb/oas'\nimport type { Params } from '@kubb/react-fabric/types'\nimport type { OperationSchema } from '../types.ts'\n/**\n *\n * @deprecated\n * TODO move to operationManager hook\n */\nexport function getASTParams(\n operationSchema: OperationSchema | undefined,\n {\n typed = false,\n override,\n }: {\n typed?: boolean\n override?: (data: FunctionParamsAST) => FunctionParamsAST\n } = {},\n): FunctionParamsAST[] {\n if (!operationSchema || !operationSchema.schema.properties || !operationSchema.name) {\n return []\n }\n\n const requiredFields = Array.isArray(operationSchema.schema.required) ? operationSchema.schema.required : []\n\n return Object.entries(operationSchema.schema.properties).map(([name]: [string, OasTypes.SchemaObject]) => {\n const data: FunctionParamsAST = {\n name,\n enabled: !!name,\n required: requiredFields.includes(name),\n type: typed ? `${operationSchema.name}[\"${name}\"]` : undefined,\n }\n\n return override ? override(data) : data\n })\n}\n\nexport function getPathParams(\n operationSchema: OperationSchema | undefined,\n options: {\n typed?: boolean\n casing?: 'camelcase'\n override?: (data: FunctionParamsAST) => FunctionParamsAST\n } = {},\n) {\n return getASTParams(operationSchema, options).reduce((acc, curr) => {\n if (curr.name && curr.enabled) {\n let name = isValidVarName(curr.name) ? curr.name : camelCase(curr.name)\n\n if (options.casing === 'camelcase') {\n name = camelCase(name)\n }\n\n acc[name] = {\n default: curr.default,\n type: curr.type,\n optional: !curr.required,\n }\n }\n\n return acc\n }, {} as Params)\n}\n"],"mappings":";;;;;;;;;AAKA,SAAgB,YAAY,WAAgC;AAC1D,QAAO;EACL,UAAU,gBAAgB,IAAI,gBAAgB,UAAU,gBAAgB;EACxE,UAAU,YAAY,IAAI,YAAY,UAAU,YAAY;EAC5D,UAAU,QAAQ,UAAU,IAAIA,yBAAQ,UAAU,KAAK,CAAC,IAAI;EAC5D,UAAU,cAAc,IAAI;EAC7B,CACE,OAAO,QAAQ,CACf,KAAK,SAASC,gCAAa,KAAK,KAAK,CAAC,CACtC,OAAO,QAAQ;;;;;;;;;;ACJpB,SAAgB,aACd,iBACA,EACE,QAAQ,OACR,aAIE,EAAE,EACe;AACrB,KAAI,CAAC,mBAAmB,CAAC,gBAAgB,OAAO,cAAc,CAAC,gBAAgB,KAC7E,QAAO,EAAE;CAGX,MAAM,iBAAiB,MAAM,QAAQ,gBAAgB,OAAO,SAAS,GAAG,gBAAgB,OAAO,WAAW,EAAE;AAE5G,QAAO,OAAO,QAAQ,gBAAgB,OAAO,WAAW,CAAC,KAAK,CAAC,UAA2C;EACxG,MAAM,OAA0B;GAC9B;GACA,SAAS,CAAC,CAAC;GACX,UAAU,eAAe,SAAS,KAAK;GACvC,MAAM,QAAQ,GAAG,gBAAgB,KAAK,IAAI,KAAK,MAAM;GACtD;AAED,SAAO,WAAW,SAAS,KAAK,GAAG;GACnC;;AAGJ,SAAgB,cACd,iBACA,UAII,EAAE,EACN;AACA,QAAO,aAAa,iBAAiB,QAAQ,CAAC,QAAQ,KAAK,SAAS;AAClE,MAAI,KAAK,QAAQ,KAAK,SAAS;GAC7B,IAAI,mDAAsB,KAAK,KAAK,GAAG,KAAK,8CAAiB,KAAK,KAAK;AAEvE,OAAI,QAAQ,WAAW,YACrB,+CAAiB,KAAK;AAGxB,OAAI,QAAQ;IACV,SAAS,KAAK;IACd,MAAM,KAAK;IACX,UAAU,CAAC,KAAK;IACjB;;AAGH,SAAO;IACN,EAAE,CAAW"}
|
|
1
|
+
{"version":3,"file":"utils.cjs","names":["URLPath","transformers"],"sources":["../src/utils/getComments.ts","../src/utils/getParams.ts","../src/utils/getSchemas.ts"],"sourcesContent":["import transformers from '@kubb/core/transformers'\nimport { URLPath } from '@kubb/core/utils'\n\nimport type { Operation } from '@kubb/oas'\n\nexport function getComments(operation: Operation): string[] {\n return [\n operation.getDescription() && `@description ${operation.getDescription()}`,\n operation.getSummary() && `@summary ${operation.getSummary()}`,\n operation.path && `{@link ${new URLPath(operation.path).URL}}`,\n operation.isDeprecated() && '@deprecated',\n ]\n .filter(Boolean)\n .map((text) => transformers.trim(text))\n .filter(Boolean)\n}\n","import { camelCase, isValidVarName } from '@kubb/core/transformers'\nimport type { FunctionParamsAST } from '@kubb/core/utils'\nimport type { OasTypes } from '@kubb/oas'\nimport type { Params } from '@kubb/react-fabric/types'\nimport type { OperationSchema } from '../types.ts'\n/**\n *\n * @deprecated\n * TODO move to operationManager hook\n */\nexport function getASTParams(\n operationSchema: OperationSchema | undefined,\n {\n typed = false,\n override,\n }: {\n typed?: boolean\n override?: (data: FunctionParamsAST) => FunctionParamsAST\n } = {},\n): FunctionParamsAST[] {\n if (!operationSchema || !operationSchema.schema.properties || !operationSchema.name) {\n return []\n }\n\n const requiredFields = Array.isArray(operationSchema.schema.required) ? operationSchema.schema.required : []\n\n return Object.entries(operationSchema.schema.properties).map(([name]: [string, OasTypes.SchemaObject]) => {\n const data: FunctionParamsAST = {\n name,\n enabled: !!name,\n required: requiredFields.includes(name),\n type: typed ? `${operationSchema.name}[\"${name}\"]` : undefined,\n }\n\n return override ? override(data) : data\n })\n}\n\nexport function getPathParams(\n operationSchema: OperationSchema | undefined,\n options: {\n typed?: boolean\n casing?: 'camelcase'\n override?: (data: FunctionParamsAST) => FunctionParamsAST\n } = {},\n) {\n return getASTParams(operationSchema, options).reduce((acc, curr) => {\n if (curr.name && curr.enabled) {\n let name = isValidVarName(curr.name) ? curr.name : camelCase(curr.name)\n\n if (options.casing === 'camelcase') {\n name = camelCase(name)\n }\n\n acc[name] = {\n default: curr.default,\n type: curr.type,\n optional: !curr.required,\n }\n }\n\n return acc\n }, {} as Params)\n}\n","import type { contentType, Oas, OasTypes } from '@kubb/oas'\n\nexport type GetSchemasResult = {\n schemas: Record<string, OasTypes.SchemaObject>\n /**\n * Mapping from original component name to resolved name after collision handling\n * e.g., { 'Order': 'OrderSchema', 'variant': 'variant2' }\n */\n nameMapping: Map<string, string>\n}\n\ntype Mode = 'schemas' | 'responses' | 'requestBodies'\n\ntype GetSchemasProps = {\n oas: Oas\n contentType?: contentType\n includes?: Mode[]\n /**\n * Whether to resolve name collisions with suffixes.\n * If not provided, uses oas.options.collisionDetection\n * @default false (from oas.options or fallback)\n */\n collisionDetection?: boolean\n}\n\n/**\n * Collect schemas from OpenAPI components (schemas, responses, requestBodies)\n * and return them in dependency order along with name mapping for collision resolution.\n *\n * This function is a wrapper around the oas.getSchemas() method for backward compatibility.\n * New code should use oas.getSchemas() directly.\n *\n * @deprecated Use oas.getSchemas() instead\n */\nexport function getSchemas({ oas, contentType, includes = ['schemas', 'requestBodies', 'responses'], collisionDetection }: GetSchemasProps): GetSchemasResult {\n return oas.getSchemas({\n contentType,\n includes,\n collisionDetection,\n })\n}\n"],"mapp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aAAa,WAAW;CAAC;CAAW;CAAiB;CAAY,EAAE,sBAAyD;AAC5J,QAAO,IAAI,WAAW;EACpB;EACA;EACA;EACD,CAAC"}
|
package/dist/utils.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { A as __name, S as Output, _ as contentType, b as Config, f as OasTypes, g as SchemaObject, h as Operation, l as isOptional, m as OpenAPIV3_1, p as OpenAPIV3, u as Oas } from "./SchemaMapper-
|
|
2
|
-
import { h as OperationSchema, w as FunctionParamsAST } from "./createGenerator-
|
|
1
|
+
import { A as __name, S as Output, _ as contentType, b as Config, f as OasTypes, g as SchemaObject, h as Operation, l as isOptional, m as OpenAPIV3_1, p as OpenAPIV3, u as Oas } from "./SchemaMapper-DmB5NyNo.cjs";
|
|
2
|
+
import { h as OperationSchema, w as FunctionParamsAST } from "./createGenerator-BF26dp_h.cjs";
|
|
3
3
|
import { Params } from "@kubb/react-fabric/types";
|
|
4
4
|
|
|
5
5
|
//#region src/utils/getBanner.d.ts
|
|
@@ -61,21 +61,41 @@ type SchemaResult<TWithRef extends boolean = false> = {
|
|
|
61
61
|
declare function getSchemaFactory<TWithRef extends boolean = false>(oas: Oas): (schema: SchemaObject | null) => SchemaResult<TWithRef>;
|
|
62
62
|
//#endregion
|
|
63
63
|
//#region src/utils/getSchemas.d.ts
|
|
64
|
+
type GetSchemasResult = {
|
|
65
|
+
schemas: Record<string, OasTypes.SchemaObject>;
|
|
66
|
+
/**
|
|
67
|
+
* Mapping from original component name to resolved name after collision handling
|
|
68
|
+
* e.g., { 'Order': 'OrderSchema', 'variant': 'variant2' }
|
|
69
|
+
*/
|
|
70
|
+
nameMapping: Map<string, string>;
|
|
71
|
+
};
|
|
64
72
|
type Mode = 'schemas' | 'responses' | 'requestBodies';
|
|
65
73
|
type GetSchemasProps = {
|
|
66
74
|
oas: Oas;
|
|
67
75
|
contentType?: contentType;
|
|
68
76
|
includes?: Mode[];
|
|
77
|
+
/**
|
|
78
|
+
* Whether to resolve name collisions with suffixes.
|
|
79
|
+
* If not provided, uses oas.options.collisionDetection
|
|
80
|
+
* @default false (from oas.options or fallback)
|
|
81
|
+
*/
|
|
82
|
+
collisionDetection?: boolean;
|
|
69
83
|
};
|
|
70
84
|
/**
|
|
71
85
|
* Collect schemas from OpenAPI components (schemas, responses, requestBodies)
|
|
72
|
-
* and return them in dependency order.
|
|
86
|
+
* and return them in dependency order along with name mapping for collision resolution.
|
|
87
|
+
*
|
|
88
|
+
* This function is a wrapper around the oas.getSchemas() method for backward compatibility.
|
|
89
|
+
* New code should use oas.getSchemas() directly.
|
|
90
|
+
*
|
|
91
|
+
* @deprecated Use oas.getSchemas() instead
|
|
73
92
|
*/
|
|
74
93
|
declare function getSchemas({
|
|
75
94
|
oas,
|
|
76
95
|
contentType,
|
|
77
|
-
includes
|
|
78
|
-
|
|
96
|
+
includes,
|
|
97
|
+
collisionDetection
|
|
98
|
+
}: GetSchemasProps): GetSchemasResult;
|
|
79
99
|
//#endregion
|
|
80
100
|
export { getBanner, getComments, getFooter, getPathParams, getSchemaFactory, getSchemas, isOptional };
|
|
81
101
|
//# sourceMappingURL=utils.d.cts.map
|
package/dist/utils.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { t as __name } from "./chunk-iVr_oF3V.js";
|
|
2
|
-
import { S as Output, _ as contentType, b as Config, f as OasTypes, g as SchemaObject, h as Operation, l as isOptional, m as OpenAPIV3_1, p as OpenAPIV3, u as Oas } from "./SchemaMapper-
|
|
3
|
-
import { h as OperationSchema, w as FunctionParamsAST } from "./createGenerator-
|
|
2
|
+
import { S as Output, _ as contentType, b as Config, f as OasTypes, g as SchemaObject, h as Operation, l as isOptional, m as OpenAPIV3_1, p as OpenAPIV3, u as Oas } from "./SchemaMapper-DI2vHHE0.js";
|
|
3
|
+
import { h as OperationSchema, w as FunctionParamsAST } from "./createGenerator-DhGg_jH6.js";
|
|
4
4
|
import { Params } from "@kubb/react-fabric/types";
|
|
5
5
|
|
|
6
6
|
//#region src/utils/getBanner.d.ts
|
|
@@ -62,21 +62,41 @@ type SchemaResult<TWithRef extends boolean = false> = {
|
|
|
62
62
|
declare function getSchemaFactory<TWithRef extends boolean = false>(oas: Oas): (schema: SchemaObject | null) => SchemaResult<TWithRef>;
|
|
63
63
|
//#endregion
|
|
64
64
|
//#region src/utils/getSchemas.d.ts
|
|
65
|
+
type GetSchemasResult = {
|
|
66
|
+
schemas: Record<string, OasTypes.SchemaObject>;
|
|
67
|
+
/**
|
|
68
|
+
* Mapping from original component name to resolved name after collision handling
|
|
69
|
+
* e.g., { 'Order': 'OrderSchema', 'variant': 'variant2' }
|
|
70
|
+
*/
|
|
71
|
+
nameMapping: Map<string, string>;
|
|
72
|
+
};
|
|
65
73
|
type Mode = 'schemas' | 'responses' | 'requestBodies';
|
|
66
74
|
type GetSchemasProps = {
|
|
67
75
|
oas: Oas;
|
|
68
76
|
contentType?: contentType;
|
|
69
77
|
includes?: Mode[];
|
|
78
|
+
/**
|
|
79
|
+
* Whether to resolve name collisions with suffixes.
|
|
80
|
+
* If not provided, uses oas.options.collisionDetection
|
|
81
|
+
* @default false (from oas.options or fallback)
|
|
82
|
+
*/
|
|
83
|
+
collisionDetection?: boolean;
|
|
70
84
|
};
|
|
71
85
|
/**
|
|
72
86
|
* Collect schemas from OpenAPI components (schemas, responses, requestBodies)
|
|
73
|
-
* and return them in dependency order.
|
|
87
|
+
* and return them in dependency order along with name mapping for collision resolution.
|
|
88
|
+
*
|
|
89
|
+
* This function is a wrapper around the oas.getSchemas() method for backward compatibility.
|
|
90
|
+
* New code should use oas.getSchemas() directly.
|
|
91
|
+
*
|
|
92
|
+
* @deprecated Use oas.getSchemas() instead
|
|
74
93
|
*/
|
|
75
94
|
declare function getSchemas({
|
|
76
95
|
oas,
|
|
77
96
|
contentType,
|
|
78
|
-
includes
|
|
79
|
-
|
|
97
|
+
includes,
|
|
98
|
+
collisionDetection
|
|
99
|
+
}: GetSchemasProps): GetSchemasResult;
|
|
80
100
|
//#endregion
|
|
81
101
|
export { getBanner, getComments, getFooter, getPathParams, getSchemaFactory, getSchemas, isOptional };
|
|
82
102
|
//# sourceMappingURL=utils.d.ts.map
|
package/dist/utils.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t as __name } from "./chunk-iVr_oF3V.js";
|
|
2
|
-
import {
|
|
2
|
+
import { t as getSchemaFactory } from "./getSchemaFactory-DsoVRgxV.js";
|
|
3
3
|
import { n as getBanner, t as getFooter } from "./getFooter-PYWvz29J.js";
|
|
4
4
|
import transformers, { camelCase, isValidVarName } from "@kubb/core/transformers";
|
|
5
5
|
import { URLPath } from "@kubb/core/utils";
|
|
@@ -50,6 +50,29 @@ function getPathParams(operationSchema, options = {}) {
|
|
|
50
50
|
}, {});
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
+
//#endregion
|
|
54
|
+
//#region src/utils/getSchemas.ts
|
|
55
|
+
/**
|
|
56
|
+
* Collect schemas from OpenAPI components (schemas, responses, requestBodies)
|
|
57
|
+
* and return them in dependency order along with name mapping for collision resolution.
|
|
58
|
+
*
|
|
59
|
+
* This function is a wrapper around the oas.getSchemas() method for backward compatibility.
|
|
60
|
+
* New code should use oas.getSchemas() directly.
|
|
61
|
+
*
|
|
62
|
+
* @deprecated Use oas.getSchemas() instead
|
|
63
|
+
*/
|
|
64
|
+
function getSchemas({ oas, contentType, includes = [
|
|
65
|
+
"schemas",
|
|
66
|
+
"requestBodies",
|
|
67
|
+
"responses"
|
|
68
|
+
], collisionDetection }) {
|
|
69
|
+
return oas.getSchemas({
|
|
70
|
+
contentType,
|
|
71
|
+
includes,
|
|
72
|
+
collisionDetection
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
|
|
53
76
|
//#endregion
|
|
54
77
|
export { getBanner, getComments, getFooter, getPathParams, getSchemaFactory, getSchemas, isOptional };
|
|
55
78
|
//# sourceMappingURL=utils.js.map
|
package/dist/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","names":[],"sources":["../src/utils/getComments.ts","../src/utils/getParams.ts"],"sourcesContent":["import transformers from '@kubb/core/transformers'\nimport { URLPath } from '@kubb/core/utils'\n\nimport type { Operation } from '@kubb/oas'\n\nexport function getComments(operation: Operation): string[] {\n return [\n operation.getDescription() && `@description ${operation.getDescription()}`,\n operation.getSummary() && `@summary ${operation.getSummary()}`,\n operation.path && `{@link ${new URLPath(operation.path).URL}}`,\n operation.isDeprecated() && '@deprecated',\n ]\n .filter(Boolean)\n .map((text) => transformers.trim(text))\n .filter(Boolean)\n}\n","import { camelCase, isValidVarName } from '@kubb/core/transformers'\nimport type { FunctionParamsAST } from '@kubb/core/utils'\nimport type { OasTypes } from '@kubb/oas'\nimport type { Params } from '@kubb/react-fabric/types'\nimport type { OperationSchema } from '../types.ts'\n/**\n *\n * @deprecated\n * TODO move to operationManager hook\n */\nexport function getASTParams(\n operationSchema: OperationSchema | undefined,\n {\n typed = false,\n override,\n }: {\n typed?: boolean\n override?: (data: FunctionParamsAST) => FunctionParamsAST\n } = {},\n): FunctionParamsAST[] {\n if (!operationSchema || !operationSchema.schema.properties || !operationSchema.name) {\n return []\n }\n\n const requiredFields = Array.isArray(operationSchema.schema.required) ? operationSchema.schema.required : []\n\n return Object.entries(operationSchema.schema.properties).map(([name]: [string, OasTypes.SchemaObject]) => {\n const data: FunctionParamsAST = {\n name,\n enabled: !!name,\n required: requiredFields.includes(name),\n type: typed ? `${operationSchema.name}[\"${name}\"]` : undefined,\n }\n\n return override ? override(data) : data\n })\n}\n\nexport function getPathParams(\n operationSchema: OperationSchema | undefined,\n options: {\n typed?: boolean\n casing?: 'camelcase'\n override?: (data: FunctionParamsAST) => FunctionParamsAST\n } = {},\n) {\n return getASTParams(operationSchema, options).reduce((acc, curr) => {\n if (curr.name && curr.enabled) {\n let name = isValidVarName(curr.name) ? curr.name : camelCase(curr.name)\n\n if (options.casing === 'camelcase') {\n name = camelCase(name)\n }\n\n acc[name] = {\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;AAGH,SAAO;IACN,EAAE,CAAW"}
|
|
1
|
+
{"version":3,"file":"utils.js","names":[],"sources":["../src/utils/getComments.ts","../src/utils/getParams.ts","../src/utils/getSchemas.ts"],"sourcesContent":["import transformers from '@kubb/core/transformers'\nimport { URLPath } from '@kubb/core/utils'\n\nimport type { Operation } from '@kubb/oas'\n\nexport function getComments(operation: Operation): string[] {\n return [\n operation.getDescription() && `@description ${operation.getDescription()}`,\n operation.getSummary() && `@summary ${operation.getSummary()}`,\n operation.path && `{@link ${new URLPath(operation.path).URL}}`,\n operation.isDeprecated() && '@deprecated',\n ]\n .filter(Boolean)\n .map((text) => transformers.trim(text))\n .filter(Boolean)\n}\n","import { camelCase, isValidVarName } from '@kubb/core/transformers'\nimport type { FunctionParamsAST } from '@kubb/core/utils'\nimport type { OasTypes } from '@kubb/oas'\nimport type { Params } from '@kubb/react-fabric/types'\nimport type { OperationSchema } from '../types.ts'\n/**\n *\n * @deprecated\n * TODO move to operationManager hook\n */\nexport function getASTParams(\n operationSchema: OperationSchema | undefined,\n {\n typed = false,\n override,\n }: {\n typed?: boolean\n override?: (data: FunctionParamsAST) => FunctionParamsAST\n } = {},\n): FunctionParamsAST[] {\n if (!operationSchema || !operationSchema.schema.properties || !operationSchema.name) {\n return []\n }\n\n const requiredFields = Array.isArray(operationSchema.schema.required) ? operationSchema.schema.required : []\n\n return Object.entries(operationSchema.schema.properties).map(([name]: [string, OasTypes.SchemaObject]) => {\n const data: FunctionParamsAST = {\n name,\n enabled: !!name,\n required: requiredFields.includes(name),\n type: typed ? `${operationSchema.name}[\"${name}\"]` : undefined,\n }\n\n return override ? override(data) : data\n })\n}\n\nexport function getPathParams(\n operationSchema: OperationSchema | undefined,\n options: {\n typed?: boolean\n casing?: 'camelcase'\n override?: (data: FunctionParamsAST) => FunctionParamsAST\n } = {},\n) {\n return getASTParams(operationSchema, options).reduce((acc, curr) => {\n if (curr.name && curr.enabled) {\n let name = isValidVarName(curr.name) ? curr.name : camelCase(curr.name)\n\n if (options.casing === 'camelcase') {\n name = camelCase(name)\n }\n\n acc[name] = {\n default: curr.default,\n type: curr.type,\n optional: !curr.required,\n }\n }\n\n return acc\n }, {} as Params)\n}\n","import type { contentType, Oas, OasTypes } from '@kubb/oas'\n\nexport type GetSchemasResult = {\n schemas: Record<string, OasTypes.SchemaObject>\n /**\n * Mapping from original component name to resolved name after collision handling\n * e.g., { 'Order': 'OrderSchema', 'variant': 'variant2' }\n */\n nameMapping: Map<string, string>\n}\n\ntype Mode = 'schemas' | 'responses' | 'requestBodies'\n\ntype GetSchemasProps = {\n oas: Oas\n contentType?: contentType\n includes?: Mode[]\n /**\n * Whether to resolve name collisions with suffixes.\n * If not provided, uses oas.options.collisionDetection\n * @default false (from oas.options or fallback)\n */\n collisionDetection?: boolean\n}\n\n/**\n * Collect schemas from OpenAPI components (schemas, responses, requestBodies)\n * and return them in dependency order along with name mapping for collision resolution.\n *\n * This function is a wrapper around the oas.getSchemas() method for backward compatibility.\n * New code should use oas.getSchemas() directly.\n *\n * @deprecated Use oas.getSchemas() instead\n */\nexport function getSchemas({ oas, contentType, includes = ['schemas', 'requestBodies', 'responses'], collisionDetection }: GetSchemasProps): GetSchemasResult {\n return oas.getSchemas({\n contentType,\n includes,\n collisionDetection,\n })\n}\n"],"mappings":";;;;;;;;AAKA,SAAgB,YAAY,WAAgC;AAC1D,QAAO;EACL,UAAU,gBAAgB,IAAI,gBAAgB,UAAU,gBAAgB;EACxE,UAAU,YAAY,IAAI,YAAY,UAAU,YAAY;EAC5D,UAAU,QAAQ,UAAU,IAAI,QAAQ,UAAU,KAAK,CAAC,IAAI;EAC5D,UAAU,cAAc,IAAI;EAC7B,CACE,OAAO,QAAQ,CACf,KAAK,SAAS,aAAa,KAAK,KAAK,CAAC,CACtC,OAAO,QAAQ;;;;;;;;;;ACJpB,SAAgB,aACd,iBACA,EACE,QAAQ,OACR,aAIE,EAAE,EACe;AACrB,KAAI,CAAC,mBAAmB,CAAC,gBAAgB,OAAO,cAAc,CAAC,gBAAgB,KAC7E,QAAO,EAAE;CAGX,MAAM,iBAAiB,MAAM,QAAQ,gBAAgB,OAAO,SAAS,GAAG,gBAAgB,OAAO,WAAW,EAAE;AAE5G,QAAO,OAAO,QAAQ,gBAAgB,OAAO,WAAW,CAAC,KAAK,CAAC,UAA2C;EACxG,MAAM,OAA0B;GAC9B;GACA,SAAS,CAAC,CAAC;GACX,UAAU,eAAe,SAAS,KAAK;GACvC,MAAM,QAAQ,GAAG,gBAAgB,KAAK,IAAI,KAAK,MAAM;GACtD;AAED,SAAO,WAAW,SAAS,KAAK,GAAG;GACnC;;AAGJ,SAAgB,cACd,iBACA,UAII,EAAE,EACN;AACA,QAAO,aAAa,iBAAiB,QAAQ,CAAC,QAAQ,KAAK,SAAS;AAClE,MAAI,KAAK,QAAQ,KAAK,SAAS;GAC7B,IAAI,OAAO,eAAe,KAAK,KAAK,GAAG,KAAK,OAAO,UAAU,KAAK,KAAK;AAEvE,OAAI,QAAQ,WAAW,YACrB,QAAO,UAAU,KAAK;AAGxB,OAAI,QAAQ;IACV,SAAS,KAAK;IACd,MAAM,KAAK;IACX,UAAU,CAAC,KAAK;IACjB;;AAGH,SAAO;IACN,EAAE,CAAW;;;;;;;;;;;;;;AC5BlB,SAAgB,WAAW,EAAE,KAAK,aAAa,WAAW;CAAC;CAAW;CAAiB;CAAY,EAAE,sBAAyD;AAC5J,QAAO,IAAI,WAAW;EACpB;EACA;EACA;EACD,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/plugin-oas",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.19.0",
|
|
4
4
|
"description": "OpenAPI Specification (OAS) plugin for Kubb, providing core functionality for parsing and processing OpenAPI/Swagger schemas for code generation.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"openapi",
|
|
@@ -82,8 +82,8 @@
|
|
|
82
82
|
"@kubb/react-fabric": "0.12.4",
|
|
83
83
|
"p-limit": "^7.2.0",
|
|
84
84
|
"remeda": "^2.33.4",
|
|
85
|
-
"@kubb/core": "4.
|
|
86
|
-
"@kubb/oas": "4.
|
|
85
|
+
"@kubb/core": "4.19.0",
|
|
86
|
+
"@kubb/oas": "4.19.0"
|
|
87
87
|
},
|
|
88
88
|
"peerDependencies": {
|
|
89
89
|
"@kubb/react-fabric": "0.12.4"
|
package/src/SchemaGenerator.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { BaseGenerator, type FileMetaBase } from '@kubb/core'
|
|
|
3
3
|
import transformers, { pascalCase } from '@kubb/core/transformers'
|
|
4
4
|
import { type AsyncEventEmitter, getUniqueName } from '@kubb/core/utils'
|
|
5
5
|
import type { KubbFile } from '@kubb/fabric-core/types'
|
|
6
|
-
import type { contentType, Oas, OpenAPIV3, SchemaObject } from '@kubb/oas'
|
|
6
|
+
import type { contentType, Oas, OasTypes, OpenAPIV3, SchemaObject } from '@kubb/oas'
|
|
7
7
|
import { isDiscriminator, isNullable, isReference } from '@kubb/oas'
|
|
8
8
|
import type { Fabric } from '@kubb/react-fabric'
|
|
9
9
|
import pLimit from 'p-limit'
|
|
@@ -12,7 +12,6 @@ import type { Generator } from './generators/types.ts'
|
|
|
12
12
|
import { isKeyword, type Schema, type SchemaKeywordMapper, schemaKeywords } from './SchemaMapper.ts'
|
|
13
13
|
import type { OperationSchema, Override, Refs } from './types.ts'
|
|
14
14
|
import { getSchemaFactory } from './utils/getSchemaFactory.ts'
|
|
15
|
-
import { getSchemas } from './utils/getSchemas.ts'
|
|
16
15
|
import { buildSchema } from './utils.tsx'
|
|
17
16
|
|
|
18
17
|
export type GetSchemaGeneratorOptions<T extends SchemaGenerator<any, any, any>> = T extends SchemaGenerator<infer Options, any, any> ? Options : never
|
|
@@ -74,13 +73,31 @@ export class SchemaGenerator<
|
|
|
74
73
|
// Collect the types of all referenced schemas, so we can export them later
|
|
75
74
|
refs: Refs = {}
|
|
76
75
|
|
|
77
|
-
//
|
|
78
|
-
|
|
76
|
+
// Map from original component paths to resolved schema names (after collision resolution)
|
|
77
|
+
// e.g., { '#/components/schemas/Order': 'OrderSchema', '#/components/responses/Product': 'ProductResponse' }
|
|
78
|
+
#schemaNameMapping: Map<string, string> = new Map()
|
|
79
|
+
|
|
80
|
+
// Flag to track if nameMapping has been initialized
|
|
81
|
+
#nameMappingInitialized = false
|
|
79
82
|
|
|
80
83
|
// Cache for parsed schemas to avoid redundant parsing
|
|
81
84
|
// Using WeakMap for automatic garbage collection when schemas are no longer referenced
|
|
82
85
|
#parseCache: Map<string, Schema[]> = new Map()
|
|
83
86
|
|
|
87
|
+
/**
|
|
88
|
+
* Ensure the name mapping is initialized (lazy initialization)
|
|
89
|
+
*/
|
|
90
|
+
#ensureNameMapping() {
|
|
91
|
+
if (this.#nameMappingInitialized) {
|
|
92
|
+
return
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const { oas, contentType, include } = this.context
|
|
96
|
+
const { nameMapping } = oas.getSchemas({ contentType, includes: include })
|
|
97
|
+
this.#schemaNameMapping = nameMapping
|
|
98
|
+
this.#nameMappingInitialized = true
|
|
99
|
+
}
|
|
100
|
+
|
|
84
101
|
/**
|
|
85
102
|
* Creates a type node from a given schema.
|
|
86
103
|
* Delegates to getBaseTypeFromSchema internally and
|
|
@@ -453,15 +470,21 @@ export class SchemaGenerator<
|
|
|
453
470
|
]
|
|
454
471
|
}
|
|
455
472
|
|
|
456
|
-
|
|
473
|
+
// Ensure name mapping is initialized before resolving names
|
|
474
|
+
this.#ensureNameMapping()
|
|
475
|
+
|
|
476
|
+
const originalName = $ref.replace(/.+\//, '')
|
|
477
|
+
// Use the full $ref path to look up the collision-resolved name
|
|
478
|
+
const resolvedName = this.#schemaNameMapping.get($ref) || originalName
|
|
479
|
+
|
|
457
480
|
const propertyName = this.context.pluginManager.resolveName({
|
|
458
|
-
name:
|
|
481
|
+
name: resolvedName,
|
|
459
482
|
pluginKey: this.context.plugin.key,
|
|
460
483
|
type: 'function',
|
|
461
484
|
})
|
|
462
485
|
|
|
463
486
|
const fileName = this.context.pluginManager.resolveName({
|
|
464
|
-
name:
|
|
487
|
+
name: resolvedName,
|
|
465
488
|
pluginKey: this.context.plugin.key,
|
|
466
489
|
type: 'file',
|
|
467
490
|
})
|
|
@@ -473,7 +496,7 @@ export class SchemaGenerator<
|
|
|
473
496
|
|
|
474
497
|
this.refs[$ref] = {
|
|
475
498
|
propertyName,
|
|
476
|
-
originalName,
|
|
499
|
+
originalName: resolvedName,
|
|
477
500
|
path: file.path,
|
|
478
501
|
}
|
|
479
502
|
|
|
@@ -1244,13 +1267,29 @@ export class SchemaGenerator<
|
|
|
1244
1267
|
|
|
1245
1268
|
async build(...generators: Array<Generator<TPluginOptions>>): Promise<Array<KubbFile.File<TFileMeta>>> {
|
|
1246
1269
|
const { oas, contentType, include } = this.context
|
|
1247
|
-
const schemas = getSchemas({ oas, contentType, includes: include })
|
|
1248
|
-
const schemaEntries = Object.entries(schemas)
|
|
1249
1270
|
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1271
|
+
// Initialize the name mapping if not already done
|
|
1272
|
+
if (!this.#nameMappingInitialized) {
|
|
1273
|
+
const { schemas, nameMapping } = oas.getSchemas({ contentType, includes: include })
|
|
1274
|
+
this.#schemaNameMapping = nameMapping
|
|
1275
|
+
this.#nameMappingInitialized = true
|
|
1276
|
+
const schemaEntries = Object.entries(schemas)
|
|
1277
|
+
|
|
1278
|
+
this.context.events?.emit('debug', {
|
|
1279
|
+
date: new Date(),
|
|
1280
|
+
logs: [`Building ${schemaEntries.length} schemas`, ` • Content Type: ${contentType || 'application/json'}`, ` • Generators: ${generators.length}`],
|
|
1281
|
+
})
|
|
1282
|
+
|
|
1283
|
+
// Continue with build using the schemas
|
|
1284
|
+
return this.#doBuild(schemas, generators)
|
|
1285
|
+
}
|
|
1286
|
+
// If already initialized, just get the schemas (without mapping)
|
|
1287
|
+
const { schemas } = oas.getSchemas({ contentType, includes: include })
|
|
1288
|
+
return this.#doBuild(schemas, generators)
|
|
1289
|
+
}
|
|
1290
|
+
|
|
1291
|
+
async #doBuild(schemas: Record<string, OasTypes.SchemaObject>, generators: Array<Generator<TPluginOptions>>): Promise<Array<KubbFile.File<TFileMeta>>> {
|
|
1292
|
+
const schemaEntries = Object.entries(schemas)
|
|
1254
1293
|
|
|
1255
1294
|
// Increased parallelism for better performance
|
|
1256
1295
|
// - generatorLimit increased from 1 to 3 to allow parallel generator processing
|
package/src/plugin.ts
CHANGED
|
@@ -23,6 +23,7 @@ export const pluginOas = definePlugin<PluginOas>((options) => {
|
|
|
23
23
|
contentType,
|
|
24
24
|
oasClass,
|
|
25
25
|
discriminator = 'strict',
|
|
26
|
+
collisionDetection = false,
|
|
26
27
|
} = options
|
|
27
28
|
|
|
28
29
|
const getOas = async ({ validate, config, events }: { validate: boolean; config: Config; events: AsyncEventEmitter<KubbEvents> }): Promise<Oas> => {
|
|
@@ -32,6 +33,7 @@ export const pluginOas = definePlugin<PluginOas>((options) => {
|
|
|
32
33
|
oas.setOptions({
|
|
33
34
|
contentType,
|
|
34
35
|
discriminator,
|
|
36
|
+
collisionDetection,
|
|
35
37
|
})
|
|
36
38
|
|
|
37
39
|
try {
|
package/src/types.ts
CHANGED
|
@@ -71,6 +71,30 @@ export type Options = {
|
|
|
71
71
|
* Define some generators next to the JSON generation
|
|
72
72
|
*/
|
|
73
73
|
generators?: Array<Generator<PluginOas>>
|
|
74
|
+
/**
|
|
75
|
+
* Resolve name collisions when schemas from different components share the same name (case-insensitive).
|
|
76
|
+
*
|
|
77
|
+
* When enabled, Kubb automatically detects and resolves collisions using intelligent suffixes:
|
|
78
|
+
* - Cross-component collisions: Adds semantic suffixes based on the component type (Schema/Response/Request)
|
|
79
|
+
* - Same-component collisions: Adds numeric suffixes (2, 3, ...) for case-insensitive duplicates
|
|
80
|
+
*
|
|
81
|
+
* When disabled (legacy behavior), collisions may result in duplicate files or overwrite issues.
|
|
82
|
+
*
|
|
83
|
+
* **Cross-component collision example:**
|
|
84
|
+
* If you have "Order" in both schemas and requestBodies:
|
|
85
|
+
* - With `collisionDetection: true`: Generates `OrderSchema.ts`, `OrderRequest.ts`
|
|
86
|
+
* - With `collisionDetection: false`: May generate duplicate `Order.ts` files
|
|
87
|
+
*
|
|
88
|
+
* **Same-component collision example:**
|
|
89
|
+
* If you have "Variant" and "variant" in schemas:
|
|
90
|
+
* - With `collisionDetection: true`: Generates `Variant.ts`, `Variant2.ts`
|
|
91
|
+
* - With `collisionDetection: false`: May overwrite or create duplicates
|
|
92
|
+
*
|
|
93
|
+
* @default false
|
|
94
|
+
* @see https://github.com/kubb-labs/kubb/issues/1999
|
|
95
|
+
* @note this will be the default in Kubb v5
|
|
96
|
+
*/
|
|
97
|
+
collisionDetection?: boolean
|
|
74
98
|
}
|
|
75
99
|
|
|
76
100
|
/**
|