@kubb/plugin-oas 4.10.1 → 4.11.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.
Files changed (37) hide show
  1. package/dist/{SchemaGenerator-C2Rqz6y8.cjs → SchemaGenerator-BEyE5yFD.cjs} +6 -6
  2. package/dist/{SchemaGenerator-C2Rqz6y8.cjs.map → SchemaGenerator-BEyE5yFD.cjs.map} +1 -1
  3. package/dist/{SchemaGenerator-g4VcV8ci.js → SchemaGenerator-Bzj3I5Yv.js} +6 -6
  4. package/dist/{SchemaGenerator-g4VcV8ci.js.map → SchemaGenerator-Bzj3I5Yv.js.map} +1 -1
  5. package/dist/{SchemaMapper-BUV8vhg0.cjs → SchemaMapper-BN2pgCUs.cjs} +1 -1
  6. package/dist/{SchemaMapper-BUV8vhg0.cjs.map → SchemaMapper-BN2pgCUs.cjs.map} +1 -1
  7. package/dist/{SchemaMapper-GAIl5QsJ.js → SchemaMapper-eCHsqfmg.js} +1 -1
  8. package/dist/{SchemaMapper-GAIl5QsJ.js.map → SchemaMapper-eCHsqfmg.js.map} +1 -1
  9. package/dist/{generators--9_lTBjl.cjs → generators--YV0NNUJ.cjs} +2 -2
  10. package/dist/{generators--9_lTBjl.cjs.map → generators--YV0NNUJ.cjs.map} +1 -1
  11. package/dist/{generators-BoBhVZzp.js → generators-Cw71XBIe.js} +2 -2
  12. package/dist/{generators-BoBhVZzp.js.map → generators-Cw71XBIe.js.map} +1 -1
  13. package/dist/generators.cjs +1 -1
  14. package/dist/generators.js +1 -1
  15. package/dist/{getFooter-fhkUhUdk.js → getFooter-C2vyr3vj.js} +2 -2
  16. package/dist/{getFooter-fhkUhUdk.js.map → getFooter-C2vyr3vj.js.map} +1 -1
  17. package/dist/{getFooter-BWck5e2D.cjs → getFooter-D-b_lr3d.cjs} +2 -2
  18. package/dist/{getFooter-BWck5e2D.cjs.map → getFooter-D-b_lr3d.cjs.map} +1 -1
  19. package/dist/{getSchemas-BTCpbjet.cjs → getSchemas-DdrlFGPi.cjs} +1 -1
  20. package/dist/{getSchemas-BTCpbjet.cjs.map → getSchemas-DdrlFGPi.cjs.map} +1 -1
  21. package/dist/{getSchemas-CyMcV4aw.js → getSchemas-XWPSn2uf.js} +1 -1
  22. package/dist/{getSchemas-CyMcV4aw.js.map → getSchemas-XWPSn2uf.js.map} +1 -1
  23. package/dist/hooks.cjs +2 -2
  24. package/dist/hooks.js +2 -2
  25. package/dist/index.cjs +74 -4
  26. package/dist/index.cjs.map +1 -1
  27. package/dist/index.d.cts +99 -1
  28. package/dist/index.d.ts +99 -1
  29. package/dist/index.js +73 -5
  30. package/dist/index.js.map +1 -1
  31. package/dist/mocks.cjs +1 -1
  32. package/dist/mocks.js +1 -1
  33. package/dist/utils.cjs +3 -3
  34. package/dist/utils.js +3 -3
  35. package/package.json +3 -3
  36. package/src/createParser.ts +141 -0
  37. package/src/index.ts +2 -0
package/dist/index.js CHANGED
@@ -1,11 +1,79 @@
1
- import { n as createReactGenerator$1, r as createGenerator$1, t as jsonGenerator } from "./generators-BoBhVZzp.js";
2
- import { a as pLimit, i as buildSchema, n as buildOperation, r as buildOperations, t as SchemaGenerator } from "./SchemaGenerator-g4VcV8ci.js";
3
- import { n as schemaKeywords, t as isKeyword } from "./SchemaMapper-GAIl5QsJ.js";
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-Bzj3I5Yv.js";
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";
6
- import path from "node:path";
7
6
  import { parseFromConfig } from "@kubb/oas";
7
+ import path from "node:path";
8
+
9
+ //#region src/createParser.ts
10
+ /**
11
+ * Creates a parser function that converts schema trees to output using the provided mapper and handlers
12
+ *
13
+ * This function provides a framework for building parsers by:
14
+ * 1. Checking for custom handlers for each keyword
15
+ * 2. Falling back to the mapper for simple keywords
16
+ * 3. Providing utilities for common operations (finding siblings, etc.)
17
+ *
18
+ * The generated parser is recursive and can handle nested schemas.
19
+ *
20
+ * @template TOutput - The output type (e.g., string for Zod/Faker, ts.TypeNode for TypeScript)
21
+ * @template TOptions - The parser options type
22
+ * @param config - Configuration object containing mapper and handlers
23
+ * @returns A parse function that converts SchemaTree to TOutput
24
+ *
25
+ * @example
26
+ * ```ts
27
+ * // Create a simple string-based parser
28
+ * const parse = createParser({
29
+ * mapper: zodKeywordMapper,
30
+ * handlers: {
31
+ * union(tree, options) {
32
+ * const items = tree.current.args
33
+ * .map(it => this.parse({ ...tree, current: it }, options))
34
+ * .filter(Boolean)
35
+ * return `z.union([${items.join(', ')}])`
36
+ * },
37
+ * string(tree, options) {
38
+ * const minSchema = findSchemaKeyword(tree.siblings, 'min')
39
+ * const maxSchema = findSchemaKeyword(tree.siblings, 'max')
40
+ * return zodKeywordMapper.string(false, minSchema?.args, maxSchema?.args)
41
+ * }
42
+ * }
43
+ * })
44
+ * ```
45
+ */
46
+ function createParser(config) {
47
+ const { mapper, handlers } = config;
48
+ function parse(tree, options) {
49
+ const { current } = tree;
50
+ const handler = handlers[current.keyword];
51
+ if (handler) {
52
+ const context = { parse };
53
+ return handler.call(context, tree, options);
54
+ }
55
+ const value = mapper[current.keyword];
56
+ if (!value) return;
57
+ if (current.keyword in mapper) return value();
58
+ }
59
+ return parse;
60
+ }
61
+ /**
62
+ * Helper to find a schema keyword in siblings
63
+ * Useful in handlers when you need to find related schemas (e.g., min/max for string)
64
+ *
65
+ * @example
66
+ * ```ts
67
+ * const minSchema = findSchemaKeyword(tree.siblings, 'min')
68
+ * const maxSchema = findSchemaKeyword(tree.siblings, 'max')
69
+ * return zodKeywordMapper.string(false, minSchema?.args, maxSchema?.args)
70
+ * ```
71
+ */
72
+ function findSchemaKeyword(siblings, keyword) {
73
+ return SchemaGenerator.find(siblings, schemaKeywords[keyword]);
74
+ }
8
75
 
76
+ //#endregion
9
77
  //#region src/OperationGenerator.ts
10
78
  var OperationGenerator = class extends BaseGenerator {
11
79
  #getOptions(operation, method) {
@@ -305,5 +373,5 @@ const createGenerator = createGenerator$1;
305
373
  const createReactGenerator = createReactGenerator$1;
306
374
 
307
375
  //#endregion
308
- export { OperationGenerator, SchemaGenerator, buildOperation, buildOperations, buildSchema, createGenerator, createReactGenerator, isKeyword, pluginOas, pluginOasName, schemaKeywords };
376
+ export { OperationGenerator, SchemaGenerator, buildOperation, buildOperations, buildSchema, createGenerator, createParser, createReactGenerator, findSchemaKeyword, isKeyword, pluginOas, pluginOasName, schemaKeywords };
309
377
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["path","#isExcluded","#isIncluded","#getOptions","oas: Oas","oas","options","groupName: Group['name']","_createGenerator","_createReactGenerator"],"sources":["../src/OperationGenerator.ts","../src/plugin.ts","../src/index.ts"],"sourcesContent":["import type { Plugin, PluginFactoryOptions, PluginManager } from '@kubb/core'\nimport { BaseGenerator, type FileMetaBase } from '@kubb/core'\nimport transformers from '@kubb/core/transformers'\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 /**\n * Current plugin\n */\n plugin: Plugin<TPluginOptions>\n mode: KubbFile.Mode\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 method = operation.method\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: 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: resolveName(transformers.pascalCase(`${operationId} ${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: resolveName(transformers.pascalCase(`${operationId} ${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 const generatorLimit = pLimit(1)\n const operationLimit = pLimit(10)\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 } from '@kubb/core'\nimport { camelCase } from '@kubb/core/transformers'\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 ({ config }: { config: Config }): 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.valdiate()\n }\n } catch (e) {\n const error = e as Error\n\n console.warn(error?.message)\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 let oas: Oas\n\n return {\n async getOas() {\n if (!oas) {\n oas = await getOas({ config })\n }\n\n return oas\n },\n async getBaseURL() {\n const oas = await getOas({ config })\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 if (!output) {\n return\n }\n\n const oas = await this.getOas()\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 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 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 { 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":";;;;;;;;;AA4BA,IAAa,qBAAb,cAGU,cAA6G;CACrH,YAAY,WAAsB,QAAgE;EAChG,MAAM,EAAE,WAAW,EAAE,KAAK,KAAK;EAC/B,MAAM,cAAc,UAAU,eAAe,EAAE,cAAc,MAAM,CAAC;EACpE,MAAM,cAAc,UAAU,gBAAgB;AAE9C,SACE,SAAS,MAAM,EAAE,SAAS,WAAW;AACnC,WAAQ,MAAR;IACE,KAAK,MACH,QAAO,UAAU,SAAS,CAAC,MAAM,QAAQ,IAAI,KAAK,MAAM,QAAQ,CAAC;IACnE,KAAK,cACH,QAAO,CAAC,CAAC,YAAY,MAAM,QAAQ;IACrC,KAAK,OACH,QAAO,CAAC,CAAC,UAAU,KAAK,MAAM,QAAQ;IACxC,KAAK,SACH,QAAO,CAAC,CAAC,OAAO,MAAM,QAAQ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O,GAAG,UAAU,IAAI,MAAM,CAAC;;AAGrC,WAAO,KAAK,QACV,MACA,OAAO,MACP,UAAU,EACR,OAAO,MAAM,SAAS,SAASD,UAAQ,MAAM,OAAQA,UAAQ,MAAM,KACpE,CAAC,EACF,SACD;;AAGH,UAAO,KAAK,QAAQ,MAAM,OAAO,MAAM,SAAS;;EAElD,MAAM,UAAU;AACd,OAAI,CAAC,OACH;GAGF,MAAM,MAAM,MAAM,KAAK,QAAQ;AAC/B,SAAM,IAAI,aAAa;GAuBvB,MAAM,cAAc,MArBI,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;IACA,SAAS;IACT,UAAU;IACV,MAAM;IACN,QAAQ,OAAO;IAChB,CACF,CAEyC,MAAM,GAAG,WAAW;AAC9D,SAAM,KAAK,WAAW,GAAG,YAAY;GAcrC,MAAM,iBAAiB,MAZI,IAAI,mBAAmB,KAAK,OAAO,SAAS;IACrE,QAAQ,KAAK;IACb;IACA,eAAe,KAAK;IACpB,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;;;;;;;ACnIF,MAAa,kBAAkBE;;;;AAK/B,MAAa,uBAAuBC"}
1
+ {"version":3,"file":"index.js","names":["context: HandlerContext<TOutput, TOptions>","path","#isExcluded","#isIncluded","#getOptions","oas: Oas","oas","options","groupName: Group['name']","_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 * 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 */\nexport type KeywordHandler<TOutput, TOptions> = (this: HandlerContext<TOutput, TOptions>, tree: SchemaTree, options: TOptions) => 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>\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 * @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 * union(tree, options) {\n * const items = tree.current.args\n * .map(it => this.parse({ ...tree, current: it }, options))\n * .filter(Boolean)\n * return `z.union([${items.join(', ')}])`\n * },\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 * }\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 return handler.call(context, tree, 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 { Plugin, PluginFactoryOptions, PluginManager } from '@kubb/core'\nimport { BaseGenerator, type FileMetaBase } from '@kubb/core'\nimport transformers from '@kubb/core/transformers'\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 /**\n * Current plugin\n */\n plugin: Plugin<TPluginOptions>\n mode: KubbFile.Mode\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 method = operation.method\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: 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: resolveName(transformers.pascalCase(`${operationId} ${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: resolveName(transformers.pascalCase(`${operationId} ${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 const generatorLimit = pLimit(1)\n const operationLimit = pLimit(10)\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 } from '@kubb/core'\nimport { camelCase } from '@kubb/core/transformers'\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 ({ config }: { config: Config }): 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.valdiate()\n }\n } catch (e) {\n const error = e as Error\n\n console.warn(error?.message)\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 let oas: Oas\n\n return {\n async getOas() {\n if (!oas) {\n oas = await getOas({ config })\n }\n\n return oas\n },\n async getBaseURL() {\n const oas = await getOas({ config })\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 if (!output) {\n return\n }\n\n const oas = await this.getOas()\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 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 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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,UAAU;AACd,OAAI,CAAC,OACH;GAGF,MAAM,MAAM,MAAM,KAAK,QAAQ;AAC/B,SAAM,IAAI,aAAa;GAuBvB,MAAM,cAAc,MArBI,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;IACA,SAAS;IACT,UAAU;IACV,MAAM;IACN,QAAQ,OAAO;IAChB,CACF,CAEyC,MAAM,GAAG,WAAW;AAC9D,SAAM,KAAK,WAAW,GAAG,YAAY;GAcrC,MAAM,iBAAiB,MAZI,IAAI,mBAAmB,KAAK,OAAO,SAAS;IACrE,QAAQ,KAAK;IACb;IACA,eAAe,KAAK;IACpB,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;;;;;;;ACjIF,MAAa,kBAAkBE;;;;AAK/B,MAAa,uBAAuBC"}
package/dist/mocks.cjs CHANGED
@@ -1,4 +1,4 @@
1
- const require_SchemaMapper = require('./SchemaMapper-BUV8vhg0.cjs');
1
+ const require_SchemaMapper = require('./SchemaMapper-BN2pgCUs.cjs');
2
2
 
3
3
  //#region src/mocks/schemas.ts
4
4
  const basic = [
package/dist/mocks.js CHANGED
@@ -1,4 +1,4 @@
1
- import { n as schemaKeywords } from "./SchemaMapper-GAIl5QsJ.js";
1
+ import { n as schemaKeywords } from "./SchemaMapper-eCHsqfmg.js";
2
2
 
3
3
  //#region src/mocks/schemas.ts
4
4
  const basic = [
package/dist/utils.cjs CHANGED
@@ -1,10 +1,10 @@
1
1
  const require_chunk = require('./chunk-CbDLau6x.cjs');
2
- const require_getFooter = require('./getFooter-BWck5e2D.cjs');
3
- const require_getSchemas = require('./getSchemas-BTCpbjet.cjs');
2
+ const require_getSchemas = require('./getSchemas-DdrlFGPi.cjs');
3
+ const require_getFooter = require('./getFooter-D-b_lr3d.cjs');
4
4
  let __kubb_core_transformers = require("@kubb/core/transformers");
5
5
  __kubb_core_transformers = require_chunk.__toESM(__kubb_core_transformers);
6
- let __kubb_oas = require("@kubb/oas");
7
6
  let __kubb_core_utils = require("@kubb/core/utils");
7
+ let __kubb_oas = require("@kubb/oas");
8
8
 
9
9
  //#region src/utils/getComments.ts
10
10
  function getComments(operation) {
package/dist/utils.js CHANGED
@@ -1,8 +1,8 @@
1
- import { n as getBanner, t as getFooter } from "./getFooter-fhkUhUdk.js";
2
- import { n as getSchemaFactory, t as getSchemas } from "./getSchemas-CyMcV4aw.js";
1
+ import { n as getSchemaFactory, t as getSchemas } from "./getSchemas-XWPSn2uf.js";
2
+ import { n as getBanner, t as getFooter } from "./getFooter-C2vyr3vj.js";
3
3
  import transformers, { camelCase, isValidVarName } from "@kubb/core/transformers";
4
- import { isOptional, isParameterObject } from "@kubb/oas";
5
4
  import { URLPath } from "@kubb/core/utils";
5
+ import { isOptional, isParameterObject } from "@kubb/oas";
6
6
 
7
7
  //#region src/utils/getComments.ts
8
8
  function getComments(operation) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubb/plugin-oas",
3
- "version": "4.10.1",
3
+ "version": "4.11.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",
@@ -83,8 +83,8 @@
83
83
  "@stoplight/yaml": "^4.3.0",
84
84
  "p-limit": "^7.2.0",
85
85
  "remeda": "^2.32.0",
86
- "@kubb/core": "4.10.1",
87
- "@kubb/oas": "4.10.1"
86
+ "@kubb/core": "4.11.0",
87
+ "@kubb/oas": "4.11.0"
88
88
  },
89
89
  "peerDependencies": {
90
90
  "@kubb/react-fabric": "0.5.4"
@@ -0,0 +1,141 @@
1
+ import { SchemaGenerator } from './SchemaGenerator.ts'
2
+ import type { Schema, SchemaKeywordMapper, SchemaMapper, SchemaTree } from './SchemaMapper.ts'
3
+ import { schemaKeywords } from './SchemaMapper.ts'
4
+
5
+ /**
6
+ * Handler context with parse method available via `this`
7
+ */
8
+ export type HandlerContext<TOutput, TOptions> = {
9
+ parse: (tree: SchemaTree, options: TOptions) => TOutput | null | undefined
10
+ }
11
+
12
+ /**
13
+ * Handler function type for custom keyword processing
14
+ * Handlers can access the parse function via `this.parse`
15
+ */
16
+ export type KeywordHandler<TOutput, TOptions> = (this: HandlerContext<TOutput, TOptions>, tree: SchemaTree, options: TOptions) => TOutput | null | undefined
17
+
18
+ /**
19
+ * Configuration for createParser
20
+ */
21
+ export type CreateParserConfig<TOutput, TOptions> = {
22
+ /**
23
+ * The keyword mapper that maps schema keywords to output generators
24
+ */
25
+ mapper: SchemaMapper<TOutput>
26
+
27
+ /**
28
+ * Custom handlers for specific schema keywords
29
+ * These provide the implementation for complex types that need special processing
30
+ *
31
+ * Use function syntax (not arrow functions) to enable use of `this` keyword:
32
+ * ```typescript
33
+ * handlers: {
34
+ * enum(tree, options, parse) {
35
+ * // Implementation
36
+ * }
37
+ * }
38
+ * ```
39
+ *
40
+ * Common keywords that typically need handlers:
41
+ * - union: Combine multiple schemas into a union
42
+ * - and: Combine multiple schemas into an intersection
43
+ * - array: Handle array types with items
44
+ * - object: Handle object types with properties
45
+ * - enum: Handle enum types
46
+ * - tuple: Handle tuple types
47
+ * - const: Handle literal/const types
48
+ * - ref: Handle references to other schemas
49
+ * - string/number/integer: Handle primitives with constraints (min/max)
50
+ * - matches: Handle regex patterns
51
+ * - default/describe/optional/nullable: Handle modifiers
52
+ */
53
+ handlers: Partial<{
54
+ [K in keyof SchemaKeywordMapper]: KeywordHandler<TOutput, TOptions>
55
+ }>
56
+ }
57
+
58
+ /**
59
+ * Creates a parser function that converts schema trees to output using the provided mapper and handlers
60
+ *
61
+ * This function provides a framework for building parsers by:
62
+ * 1. Checking for custom handlers for each keyword
63
+ * 2. Falling back to the mapper for simple keywords
64
+ * 3. Providing utilities for common operations (finding siblings, etc.)
65
+ *
66
+ * The generated parser is recursive and can handle nested schemas.
67
+ *
68
+ * @template TOutput - The output type (e.g., string for Zod/Faker, ts.TypeNode for TypeScript)
69
+ * @template TOptions - The parser options type
70
+ * @param config - Configuration object containing mapper and handlers
71
+ * @returns A parse function that converts SchemaTree to TOutput
72
+ *
73
+ * @example
74
+ * ```ts
75
+ * // Create a simple string-based parser
76
+ * const parse = createParser({
77
+ * mapper: zodKeywordMapper,
78
+ * handlers: {
79
+ * union(tree, options) {
80
+ * const items = tree.current.args
81
+ * .map(it => this.parse({ ...tree, current: it }, options))
82
+ * .filter(Boolean)
83
+ * return `z.union([${items.join(', ')}])`
84
+ * },
85
+ * string(tree, options) {
86
+ * const minSchema = findSchemaKeyword(tree.siblings, 'min')
87
+ * const maxSchema = findSchemaKeyword(tree.siblings, 'max')
88
+ * return zodKeywordMapper.string(false, minSchema?.args, maxSchema?.args)
89
+ * }
90
+ * }
91
+ * })
92
+ * ```
93
+ */
94
+ export function createParser<TOutput, TOptions extends Record<string, any>>(
95
+ config: CreateParserConfig<TOutput, TOptions>,
96
+ ): (tree: SchemaTree, options: TOptions) => TOutput | null | undefined {
97
+ const { mapper, handlers } = config
98
+
99
+ function parse(tree: SchemaTree, options: TOptions): TOutput | null | undefined {
100
+ const { current } = tree
101
+
102
+ // Check if there's a custom handler for this keyword
103
+ const handler = handlers[current.keyword as keyof SchemaKeywordMapper]
104
+ if (handler) {
105
+ // Create context object with parse method accessible via `this`
106
+ const context: HandlerContext<TOutput, TOptions> = { parse }
107
+ return handler.call(context, tree, options)
108
+ }
109
+
110
+ // Fall back to simple mapper lookup
111
+ const value = mapper[current.keyword as keyof typeof mapper]
112
+
113
+ if (!value) {
114
+ return undefined
115
+ }
116
+
117
+ // For simple keywords without args, call the mapper directly
118
+ if (current.keyword in mapper) {
119
+ return value()
120
+ }
121
+
122
+ return undefined
123
+ }
124
+
125
+ return parse
126
+ }
127
+
128
+ /**
129
+ * Helper to find a schema keyword in siblings
130
+ * Useful in handlers when you need to find related schemas (e.g., min/max for string)
131
+ *
132
+ * @example
133
+ * ```ts
134
+ * const minSchema = findSchemaKeyword(tree.siblings, 'min')
135
+ * const maxSchema = findSchemaKeyword(tree.siblings, 'max')
136
+ * return zodKeywordMapper.string(false, minSchema?.args, maxSchema?.args)
137
+ * ```
138
+ */
139
+ export function findSchemaKeyword<K extends keyof SchemaKeywordMapper>(siblings: Schema[], keyword: K): SchemaKeywordMapper[K] | undefined {
140
+ return SchemaGenerator.find(siblings, schemaKeywords[keyword]) as SchemaKeywordMapper[K] | undefined
141
+ }
package/src/index.ts CHANGED
@@ -3,6 +3,8 @@ import { createGenerator as _createGenerator } from './generators/createGenerato
3
3
  import { createReactGenerator as _createReactGenerator } from './generators/createReactGenerator.ts'
4
4
  import type { Generator as _Generator } from './generators/types.ts'
5
5
 
6
+ export type { CreateParserConfig, KeywordHandler } from './createParser.ts'
7
+ export { createParser, findSchemaKeyword } from './createParser.ts'
6
8
  export type { OperationMethodResult } from './OperationGenerator.ts'
7
9
  export { OperationGenerator } from './OperationGenerator.ts'
8
10
  export { pluginOas, pluginOasName } from './plugin.ts'