@kubb/plugin-oas 5.0.0-alpha.30 → 5.0.0-alpha.31

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/utils.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","names":["#options","#transformParam","#eachParam"],"sources":["../../../internals/utils/src/reserved.ts","../../../internals/utils/src/urlPath.ts","../src/utils/getComments.ts","../src/utils/getImports.ts","../src/utils/getParams.ts","../src/utils/getSchemas.ts","../src/utils/paramsCasing.ts"],"sourcesContent":["/**\n * JavaScript and Java reserved words.\n * @link https://github.com/jonschlinkert/reserved/blob/master/index.js\n */\nconst reservedWords = new Set([\n 'abstract',\n 'arguments',\n 'boolean',\n 'break',\n 'byte',\n 'case',\n 'catch',\n 'char',\n 'class',\n 'const',\n 'continue',\n 'debugger',\n 'default',\n 'delete',\n 'do',\n 'double',\n 'else',\n 'enum',\n 'eval',\n 'export',\n 'extends',\n 'false',\n 'final',\n 'finally',\n 'float',\n 'for',\n 'function',\n 'goto',\n 'if',\n 'implements',\n 'import',\n 'in',\n 'instanceof',\n 'int',\n 'interface',\n 'let',\n 'long',\n 'native',\n 'new',\n 'null',\n 'package',\n 'private',\n 'protected',\n 'public',\n 'return',\n 'short',\n 'static',\n 'super',\n 'switch',\n 'synchronized',\n 'this',\n 'throw',\n 'throws',\n 'transient',\n 'true',\n 'try',\n 'typeof',\n 'var',\n 'void',\n 'volatile',\n 'while',\n 'with',\n 'yield',\n 'Array',\n 'Date',\n 'hasOwnProperty',\n 'Infinity',\n 'isFinite',\n 'isNaN',\n 'isPrototypeOf',\n 'length',\n 'Math',\n 'name',\n 'NaN',\n 'Number',\n 'Object',\n 'prototype',\n 'String',\n 'toString',\n 'undefined',\n 'valueOf',\n] as const)\n\n/**\n * Prefixes `word` with `_` when it is a reserved JavaScript/Java identifier or starts with a digit.\n *\n * @example\n * ```ts\n * transformReservedWord('class') // '_class'\n * transformReservedWord('42foo') // '_42foo'\n * transformReservedWord('status') // 'status'\n * ```\n */\nexport function transformReservedWord(word: string): string {\n const firstChar = word.charCodeAt(0)\n if (word && (reservedWords.has(word as 'valueOf') || (firstChar >= 48 && firstChar <= 57))) {\n return `_${word}`\n }\n return word\n}\n\n/**\n * Returns `true` when `name` is a syntactically valid JavaScript variable name.\n *\n * @example\n * ```ts\n * isValidVarName('status') // true\n * isValidVarName('class') // false (reserved word)\n * isValidVarName('42foo') // false (starts with digit)\n * ```\n */\nexport function isValidVarName(name: string): boolean {\n try {\n new Function(`var ${name}`)\n } catch {\n return false\n }\n return true\n}\n","import { camelCase } from './casing.ts'\nimport { isValidVarName } from './reserved.ts'\n\nexport type URLObject = {\n /**\n * The resolved URL string (Express-style or template literal, depending on context).\n */\n url: string\n /**\n * Extracted path parameters as a key-value map, or `undefined` when the path has none.\n */\n params?: Record<string, string>\n}\n\ntype ObjectOptions = {\n /**\n * Controls whether the `url` is rendered as an Express path or a template literal.\n * @default 'path'\n */\n type?: 'path' | 'template'\n /**\n * Optional transform applied to each extracted parameter name.\n */\n replacer?: (pathParam: string) => string\n /**\n * When `true`, the result is serialized to a string expression instead of a plain object.\n */\n stringify?: boolean\n}\n\n/**\n * Supported identifier casing strategies for path parameters.\n */\ntype PathCasing = 'camelcase'\n\ntype Options = {\n /**\n * Casing strategy applied to path parameter names.\n * @default undefined (original identifier preserved)\n */\n casing?: PathCasing\n}\n\n/**\n * Parses and transforms an OpenAPI/Swagger path string into various URL formats.\n *\n * @example\n * const p = new URLPath('/pet/{petId}')\n * p.URL // '/pet/:petId'\n * p.template // '`/pet/${petId}`'\n */\nexport class URLPath {\n /**\n * The raw OpenAPI/Swagger path string, e.g. `/pet/{petId}`.\n */\n path: string\n\n #options: Options\n\n constructor(path: string, options: Options = {}) {\n this.path = path\n this.#options = options\n }\n\n /** Converts the OpenAPI path to Express-style colon syntax, e.g. `/pet/{petId}` → `/pet/:petId`.\n *\n * @example\n * ```ts\n * new URLPath('/pet/{petId}').URL // '/pet/:petId'\n * ```\n */\n get URL(): string {\n return this.toURLPath()\n }\n\n /** Returns `true` when `path` is a fully-qualified URL (e.g. starts with `https://`).\n *\n * @example\n * ```ts\n * new URLPath('https://petstore.swagger.io/v2/pet').isURL // true\n * new URLPath('/pet/{petId}').isURL // false\n * ```\n */\n get isURL(): boolean {\n try {\n return !!new URL(this.path).href\n } catch {\n return false\n }\n }\n\n /**\n * Converts the OpenAPI path to a TypeScript template literal string.\n *\n * @example\n * new URLPath('/pet/{petId}').template // '`/pet/${petId}`'\n * new URLPath('/account/monetary-accountID').template // '`/account/${monetaryAccountId}`'\n */\n get template(): string {\n return this.toTemplateString()\n }\n\n /** Returns the path and its extracted params as a structured `URLObject`, or as a stringified expression when `stringify` is set.\n *\n * @example\n * ```ts\n * new URLPath('/pet/{petId}').object\n * // { url: '/pet/:petId', params: { petId: 'petId' } }\n * ```\n */\n get object(): URLObject | string {\n return this.toObject()\n }\n\n /** Returns a map of path parameter names, or `undefined` when the path has no parameters.\n *\n * @example\n * ```ts\n * new URLPath('/pet/{petId}').params // { petId: 'petId' }\n * new URLPath('/pet').params // undefined\n * ```\n */\n get params(): Record<string, string> | undefined {\n return this.getParams()\n }\n\n #transformParam(raw: string): string {\n const param = isValidVarName(raw) ? raw : camelCase(raw)\n return this.#options.casing === 'camelcase' ? camelCase(param) : param\n }\n\n /**\n * Iterates over every `{param}` token in `path`, calling `fn` with the raw token and transformed name.\n */\n #eachParam(fn: (raw: string, param: string) => void): void {\n for (const match of this.path.matchAll(/\\{([^}]+)\\}/g)) {\n const raw = match[1]!\n fn(raw, this.#transformParam(raw))\n }\n }\n\n toObject({ type = 'path', replacer, stringify }: ObjectOptions = {}): URLObject | string {\n const object = {\n url: type === 'path' ? this.toURLPath() : this.toTemplateString({ replacer }),\n params: this.getParams(),\n }\n\n if (stringify) {\n if (type === 'template') {\n return JSON.stringify(object).replaceAll(\"'\", '').replaceAll(`\"`, '')\n }\n\n if (object.params) {\n return `{ url: '${object.url}', params: ${JSON.stringify(object.params).replaceAll(\"'\", '').replaceAll(`\"`, '')} }`\n }\n\n return `{ url: '${object.url}' }`\n }\n\n return object\n }\n\n /**\n * Converts the OpenAPI path to a TypeScript template literal string.\n * An optional `replacer` can transform each extracted parameter name before interpolation.\n *\n * @example\n * new URLPath('/pet/{petId}').toTemplateString() // '`/pet/${petId}`'\n */\n toTemplateString({ prefix = '', replacer }: { prefix?: string; replacer?: (pathParam: string) => string } = {}): string {\n const parts = this.path.split(/\\{([^}]+)\\}/)\n const result = parts\n .map((part, i) => {\n if (i % 2 === 0) return part\n const param = this.#transformParam(part)\n return `\\${${replacer ? replacer(param) : param}}`\n })\n .join('')\n\n return `\\`${prefix}${result}\\``\n }\n\n /**\n * Extracts all `{param}` segments from the path and returns them as a key-value map.\n * An optional `replacer` transforms each parameter name in both key and value positions.\n * Returns `undefined` when no path parameters are found.\n *\n * @example\n * ```ts\n * new URLPath('/pet/{petId}/tag/{tagId}').getParams()\n * // { petId: 'petId', tagId: 'tagId' }\n * ```\n */\n getParams(replacer?: (pathParam: string) => string): Record<string, string> | undefined {\n const params: Record<string, string> = {}\n\n this.#eachParam((_raw, param) => {\n const key = replacer ? replacer(param) : param\n params[key] = key\n })\n\n return Object.keys(params).length > 0 ? params : undefined\n }\n\n /** Converts the OpenAPI path to Express-style colon syntax.\n *\n * @example\n * ```ts\n * new URLPath('/pet/{petId}').toURLPath() // '/pet/:petId'\n * ```\n */\n toURLPath(): string {\n return this.path.replace(/\\{([^}]+)\\}/g, ':$1')\n }\n}\n","import { URLPath } from '@internals/utils'\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((x): x is string => Boolean(x))\n .flatMap((text) => {\n return text.split(/\\r?\\n/).map((line) => line.trim())\n })\n .filter((x): x is string => Boolean(x))\n}\n","import type { FabricFile } from '@kubb/fabric-core/types'\nimport { SchemaGenerator } from '../SchemaGenerator.ts'\nimport type { Schema } from '../SchemaMapper'\nimport { schemaKeywords } from '../SchemaMapper'\n\n/**\n * Get imports from a schema tree by extracting all ref schemas that are importable\n */\nexport function getImports(tree: Array<Schema>): Array<FabricFile.Import> {\n const refs = SchemaGenerator.deepSearch(tree, schemaKeywords.ref)\n\n if (!refs) return []\n\n return refs\n .map((item) => {\n if (!item.args.path || !item.args.isImportable) {\n return undefined\n }\n\n return {\n name: [item.args.name],\n path: item.args.path,\n } satisfies FabricFile.Import\n })\n .filter((x): x is NonNullable<typeof x> => x !== undefined)\n}\n","import { camelCase, isValidVarName } from '@internals/utils'\nimport type { FunctionParamsAST } from '@kubb/core'\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 casing,\n override,\n }: {\n typed?: boolean\n casing?: 'camelcase'\n override?: (data: FunctionParamsAST) => FunctionParamsAST\n } = {},\n): FunctionParamsAST[] {\n if (!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 // Use camelCase name for indexed access if casing is enabled\n const accessName = casing === 'camelcase' ? camelCase(name) : name\n\n const data: FunctionParamsAST = {\n name,\n enabled: !!name,\n required: requiredFields.includes(name),\n type: typed ? `${operationSchema.name}[\"${accessName}\"]` : 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 = curr.name\n\n // Only transform to camelCase if explicitly requested\n if (options.casing === 'camelcase') {\n name = camelCase(name)\n } else if (!isValidVarName(name)) {\n // If not valid variable name and casing not set, still need to make it valid\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\n/**\n * Get a mapping of camelCase parameter names to their original names\n * Used for mapping function parameters to backend parameter names\n */\nexport function getParamsMapping(\n operationSchema: OperationSchema | undefined,\n options: {\n casing?: 'camelcase'\n } = {},\n): Record<string, string> | undefined {\n if (!operationSchema?.schema.properties) {\n return undefined\n }\n\n const allEntries: Array<[string, string]> = []\n let hasTransformation = false\n\n Object.entries(operationSchema.schema.properties).forEach(([originalName]) => {\n let transformedName = originalName\n\n // Only transform to camelCase if explicitly requested\n if (options.casing === 'camelcase') {\n transformedName = camelCase(originalName)\n } else if (!isValidVarName(originalName)) {\n // If not valid variable name and casing not set, still need to make it valid\n transformedName = camelCase(originalName)\n }\n\n allEntries.push([originalName, transformedName])\n\n if (transformedName !== originalName) {\n hasTransformation = true\n }\n })\n\n // When using explicit casing and there are transformations, include ALL params so that\n // mappedParams contains every parameter (not just the ones whose names changed).\n // This prevents params with already-camelCase names (e.g. 'page', 'search') from being\n // silently dropped when other params in the same schema do need transformation.\n if (options.casing === 'camelcase' && hasTransformation) {\n return Object.fromEntries(allEntries)\n }\n\n // When casing is not specified or no transformations are needed, only return changed entries\n const mapping: Record<string, string> = {}\n allEntries.forEach(([originalName, transformedName]) => {\n if (transformedName !== originalName) {\n mapping[originalName] = transformedName\n }\n })\n\n return Object.keys(mapping).length > 0 ? mapping : undefined\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","import { camelCase, isValidVarName } from '@internals/utils'\nimport type { SchemaObject } from '@kubb/oas'\n\n/**\n * Apply casing transformation to schema properties\n * Only transforms property names, not nested schemas\n */\nexport function applyParamsCasing(schema: SchemaObject, casing: 'camelcase' | undefined): SchemaObject {\n if (!casing || !schema.properties) {\n return schema\n }\n\n const transformedProperties: Record<string, any> = {}\n const transformedRequired: string[] = []\n\n // Transform property names\n Object.entries(schema.properties).forEach(([originalName, propertySchema]) => {\n let transformedName = originalName\n\n if (casing === 'camelcase') {\n transformedName = camelCase(originalName)\n } else if (!isValidVarName(originalName)) {\n // If not valid variable name, make it valid\n transformedName = camelCase(originalName)\n }\n\n transformedProperties[transformedName] = propertySchema\n })\n\n // Transform required field names\n if (Array.isArray(schema.required)) {\n schema.required.forEach((originalName) => {\n let transformedName = originalName\n\n if (casing === 'camelcase') {\n transformedName = camelCase(originalName)\n } else if (!isValidVarName(originalName)) {\n transformedName = camelCase(originalName)\n }\n\n transformedRequired.push(transformedName)\n })\n }\n\n // Return a new schema with transformed properties and required fields\n return {\n ...schema,\n properties: transformedProperties,\n ...(transformedRequired.length > 0 && { required: transformedRequired }),\n } as SchemaObject\n}\n\n/**\n * Check if this schema is a parameter schema (pathParams, queryParams, or headerParams)\n * Only these should be transformed, not response/data/body\n */\nexport function isParameterSchema(schemaName: string): boolean {\n const lowerName = schemaName.toLowerCase()\n return lowerName.includes('pathparams') || lowerName.includes('queryparams') || lowerName.includes('headerparams')\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAoHA,SAAgB,eAAe,MAAuB;AACpD,KAAI;AACF,MAAI,SAAS,OAAO,OAAO;SACrB;AACN,SAAO;;AAET,QAAO;;;;;;;;;;;;ACvET,IAAa,UAAb,MAAqB;;;;CAInB;CAEA;CAEA,YAAY,MAAc,UAAmB,EAAE,EAAE;AAC/C,OAAK,OAAO;AACZ,QAAA,UAAgB;;;;;;;;;CAUlB,IAAI,MAAc;AAChB,SAAO,KAAK,WAAW;;;;;;;;;;CAWzB,IAAI,QAAiB;AACnB,MAAI;AACF,UAAO,CAAC,CAAC,IAAI,IAAI,KAAK,KAAK,CAAC;UACtB;AACN,UAAO;;;;;;;;;;CAWX,IAAI,WAAmB;AACrB,SAAO,KAAK,kBAAkB;;;;;;;;;;CAWhC,IAAI,SAA6B;AAC/B,SAAO,KAAK,UAAU;;;;;;;;;;CAWxB,IAAI,SAA6C;AAC/C,SAAO,KAAK,WAAW;;CAGzB,gBAAgB,KAAqB;EACnC,MAAM,QAAQ,eAAe,IAAI,GAAG,MAAM,UAAU,IAAI;AACxD,SAAO,MAAA,QAAc,WAAW,cAAc,UAAU,MAAM,GAAG;;;;;CAMnE,WAAW,IAAgD;AACzD,OAAK,MAAM,SAAS,KAAK,KAAK,SAAS,eAAe,EAAE;GACtD,MAAM,MAAM,MAAM;AAClB,MAAG,KAAK,MAAA,eAAqB,IAAI,CAAC;;;CAItC,SAAS,EAAE,OAAO,QAAQ,UAAU,cAA6B,EAAE,EAAsB;EACvF,MAAM,SAAS;GACb,KAAK,SAAS,SAAS,KAAK,WAAW,GAAG,KAAK,iBAAiB,EAAE,UAAU,CAAC;GAC7E,QAAQ,KAAK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GACzC;AAGF,KAAI,MAAM,QAAQ,OAAO,SAAS,CAChC,QAAO,SAAS,SAAS,iBAAiB;EACxC,IAAI,kBAAkB;AAEtB,MAAI,WAAW,YACb,mBAAkB,UAAU,aAAa;WAChC,CAAC,eAAe,aAAa,CACtC,mBAAkB,UAAU,aAAa;AAG3C,sBAAoB,KAAK,gBAAgB;GACzC;AAIJ,QAAO;EACL,GAAG;EACH,YAAY;EACZ,GAAI,oBAAoB,SAAS,KAAK,EAAE,UAAU,qBAAqB;EACxE;;;;;;AAOH,SAAgB,kBAAkB,YAA6B;CAC7D,MAAM,YAAY,WAAW,aAAa;AAC1C,QAAO,UAAU,SAAS,aAAa,IAAI,UAAU,SAAS,cAAc,IAAI,UAAU,SAAS,eAAe"}
1
+ {"version":3,"file":"utils.js","names":["#options","#transformParam","#eachParam"],"sources":["../../../internals/utils/src/reserved.ts","../../../internals/utils/src/urlPath.ts","../src/utils/getComments.ts","../src/utils/getImports.ts","../src/utils/getParams.ts","../src/utils/getSchemas.ts","../src/utils/paramsCasing.ts"],"sourcesContent":["/**\n * JavaScript and Java reserved words.\n * @link https://github.com/jonschlinkert/reserved/blob/master/index.js\n */\nconst reservedWords = new Set([\n 'abstract',\n 'arguments',\n 'boolean',\n 'break',\n 'byte',\n 'case',\n 'catch',\n 'char',\n 'class',\n 'const',\n 'continue',\n 'debugger',\n 'default',\n 'delete',\n 'do',\n 'double',\n 'else',\n 'enum',\n 'eval',\n 'export',\n 'extends',\n 'false',\n 'final',\n 'finally',\n 'float',\n 'for',\n 'function',\n 'goto',\n 'if',\n 'implements',\n 'import',\n 'in',\n 'instanceof',\n 'int',\n 'interface',\n 'let',\n 'long',\n 'native',\n 'new',\n 'null',\n 'package',\n 'private',\n 'protected',\n 'public',\n 'return',\n 'short',\n 'static',\n 'super',\n 'switch',\n 'synchronized',\n 'this',\n 'throw',\n 'throws',\n 'transient',\n 'true',\n 'try',\n 'typeof',\n 'var',\n 'void',\n 'volatile',\n 'while',\n 'with',\n 'yield',\n 'Array',\n 'Date',\n 'hasOwnProperty',\n 'Infinity',\n 'isFinite',\n 'isNaN',\n 'isPrototypeOf',\n 'length',\n 'Math',\n 'name',\n 'NaN',\n 'Number',\n 'Object',\n 'prototype',\n 'String',\n 'toString',\n 'undefined',\n 'valueOf',\n] as const)\n\n/**\n * Prefixes `word` with `_` when it is a reserved JavaScript/Java identifier or starts with a digit.\n *\n * @example\n * ```ts\n * transformReservedWord('class') // '_class'\n * transformReservedWord('42foo') // '_42foo'\n * transformReservedWord('status') // 'status'\n * ```\n */\nexport function transformReservedWord(word: string): string {\n const firstChar = word.charCodeAt(0)\n if (word && (reservedWords.has(word as 'valueOf') || (firstChar >= 48 && firstChar <= 57))) {\n return `_${word}`\n }\n return word\n}\n\n/**\n * Returns `true` when `name` is a syntactically valid JavaScript variable name.\n *\n * @example\n * ```ts\n * isValidVarName('status') // true\n * isValidVarName('class') // false (reserved word)\n * isValidVarName('42foo') // false (starts with digit)\n * ```\n */\nexport function isValidVarName(name: string): boolean {\n try {\n new Function(`var ${name}`)\n } catch {\n return false\n }\n return true\n}\n","import { camelCase } from './casing.ts'\nimport { isValidVarName } from './reserved.ts'\n\nexport type URLObject = {\n /**\n * The resolved URL string (Express-style or template literal, depending on context).\n */\n url: string\n /**\n * Extracted path parameters as a key-value map, or `undefined` when the path has none.\n */\n params?: Record<string, string>\n}\n\ntype ObjectOptions = {\n /**\n * Controls whether the `url` is rendered as an Express path or a template literal.\n * @default 'path'\n */\n type?: 'path' | 'template'\n /**\n * Optional transform applied to each extracted parameter name.\n */\n replacer?: (pathParam: string) => string\n /**\n * When `true`, the result is serialized to a string expression instead of a plain object.\n */\n stringify?: boolean\n}\n\n/**\n * Supported identifier casing strategies for path parameters.\n */\ntype PathCasing = 'camelcase'\n\ntype Options = {\n /**\n * Casing strategy applied to path parameter names.\n * @default undefined (original identifier preserved)\n */\n casing?: PathCasing\n}\n\n/**\n * Parses and transforms an OpenAPI/Swagger path string into various URL formats.\n *\n * @example\n * const p = new URLPath('/pet/{petId}')\n * p.URL // '/pet/:petId'\n * p.template // '`/pet/${petId}`'\n */\nexport class URLPath {\n /**\n * The raw OpenAPI/Swagger path string, e.g. `/pet/{petId}`.\n */\n path: string\n\n #options: Options\n\n constructor(path: string, options: Options = {}) {\n this.path = path\n this.#options = options\n }\n\n /** Converts the OpenAPI path to Express-style colon syntax, e.g. `/pet/{petId}` → `/pet/:petId`.\n *\n * @example\n * ```ts\n * new URLPath('/pet/{petId}').URL // '/pet/:petId'\n * ```\n */\n get URL(): string {\n return this.toURLPath()\n }\n\n /** Returns `true` when `path` is a fully-qualified URL (e.g. starts with `https://`).\n *\n * @example\n * ```ts\n * new URLPath('https://petstore.swagger.io/v2/pet').isURL // true\n * new URLPath('/pet/{petId}').isURL // false\n * ```\n */\n get isURL(): boolean {\n try {\n return !!new URL(this.path).href\n } catch {\n return false\n }\n }\n\n /**\n * Converts the OpenAPI path to a TypeScript template literal string.\n *\n * @example\n * new URLPath('/pet/{petId}').template // '`/pet/${petId}`'\n * new URLPath('/account/monetary-accountID').template // '`/account/${monetaryAccountId}`'\n */\n get template(): string {\n return this.toTemplateString()\n }\n\n /** Returns the path and its extracted params as a structured `URLObject`, or as a stringified expression when `stringify` is set.\n *\n * @example\n * ```ts\n * new URLPath('/pet/{petId}').object\n * // { url: '/pet/:petId', params: { petId: 'petId' } }\n * ```\n */\n get object(): URLObject | string {\n return this.toObject()\n }\n\n /** Returns a map of path parameter names, or `undefined` when the path has no parameters.\n *\n * @example\n * ```ts\n * new URLPath('/pet/{petId}').params // { petId: 'petId' }\n * new URLPath('/pet').params // undefined\n * ```\n */\n get params(): Record<string, string> | undefined {\n return this.getParams()\n }\n\n #transformParam(raw: string): string {\n const param = isValidVarName(raw) ? raw : camelCase(raw)\n return this.#options.casing === 'camelcase' ? camelCase(param) : param\n }\n\n /**\n * Iterates over every `{param}` token in `path`, calling `fn` with the raw token and transformed name.\n */\n #eachParam(fn: (raw: string, param: string) => void): void {\n for (const match of this.path.matchAll(/\\{([^}]+)\\}/g)) {\n const raw = match[1]!\n fn(raw, this.#transformParam(raw))\n }\n }\n\n toObject({ type = 'path', replacer, stringify }: ObjectOptions = {}): URLObject | string {\n const object = {\n url: type === 'path' ? this.toURLPath() : this.toTemplateString({ replacer }),\n params: this.getParams(),\n }\n\n if (stringify) {\n if (type === 'template') {\n return JSON.stringify(object).replaceAll(\"'\", '').replaceAll(`\"`, '')\n }\n\n if (object.params) {\n return `{ url: '${object.url}', params: ${JSON.stringify(object.params).replaceAll(\"'\", '').replaceAll(`\"`, '')} }`\n }\n\n return `{ url: '${object.url}' }`\n }\n\n return object\n }\n\n /**\n * Converts the OpenAPI path to a TypeScript template literal string.\n * An optional `replacer` can transform each extracted parameter name before interpolation.\n *\n * @example\n * new URLPath('/pet/{petId}').toTemplateString() // '`/pet/${petId}`'\n */\n toTemplateString({ prefix = '', replacer }: { prefix?: string; replacer?: (pathParam: string) => string } = {}): string {\n const parts = this.path.split(/\\{([^}]+)\\}/)\n const result = parts\n .map((part, i) => {\n if (i % 2 === 0) return part\n const param = this.#transformParam(part)\n return `\\${${replacer ? replacer(param) : param}}`\n })\n .join('')\n\n return `\\`${prefix}${result}\\``\n }\n\n /**\n * Extracts all `{param}` segments from the path and returns them as a key-value map.\n * An optional `replacer` transforms each parameter name in both key and value positions.\n * Returns `undefined` when no path parameters are found.\n *\n * @example\n * ```ts\n * new URLPath('/pet/{petId}/tag/{tagId}').getParams()\n * // { petId: 'petId', tagId: 'tagId' }\n * ```\n */\n getParams(replacer?: (pathParam: string) => string): Record<string, string> | undefined {\n const params: Record<string, string> = {}\n\n this.#eachParam((_raw, param) => {\n const key = replacer ? replacer(param) : param\n params[key] = key\n })\n\n return Object.keys(params).length > 0 ? params : undefined\n }\n\n /** Converts the OpenAPI path to Express-style colon syntax.\n *\n * @example\n * ```ts\n * new URLPath('/pet/{petId}').toURLPath() // '/pet/:petId'\n * ```\n */\n toURLPath(): string {\n return this.path.replace(/\\{([^}]+)\\}/g, ':$1')\n }\n}\n","import { URLPath } from '@internals/utils'\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((x): x is string => Boolean(x))\n .flatMap((text) => {\n return text.split(/\\r?\\n/).map((line) => line.trim())\n })\n .filter((x): x is string => Boolean(x))\n}\n","import type { KubbFile } from '@kubb/core'\nimport { SchemaGenerator } from '../SchemaGenerator.ts'\nimport type { Schema } from '../SchemaMapper'\nimport { schemaKeywords } from '../SchemaMapper'\n\n/**\n * Get imports from a schema tree by extracting all ref schemas that are importable\n */\nexport function getImports(tree: Array<Schema>): Array<KubbFile.Import> {\n const refs = SchemaGenerator.deepSearch(tree, schemaKeywords.ref)\n\n if (!refs) return []\n\n return refs\n .map((item) => {\n if (!item.args.path || !item.args.isImportable) {\n return undefined\n }\n\n return {\n name: [item.args.name],\n path: item.args.path,\n } satisfies KubbFile.Import\n })\n .filter((x): x is NonNullable<typeof x> => x !== undefined)\n}\n","import { camelCase, isValidVarName } from '@internals/utils'\nimport type { FunctionParamsAST } from '@kubb/core'\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 casing,\n override,\n }: {\n typed?: boolean\n casing?: 'camelcase'\n override?: (data: FunctionParamsAST) => FunctionParamsAST\n } = {},\n): FunctionParamsAST[] {\n if (!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 // Use camelCase name for indexed access if casing is enabled\n const accessName = casing === 'camelcase' ? camelCase(name) : name\n\n const data: FunctionParamsAST = {\n name,\n enabled: !!name,\n required: requiredFields.includes(name),\n type: typed ? `${operationSchema.name}[\"${accessName}\"]` : 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 = curr.name\n\n // Only transform to camelCase if explicitly requested\n if (options.casing === 'camelcase') {\n name = camelCase(name)\n } else if (!isValidVarName(name)) {\n // If not valid variable name and casing not set, still need to make it valid\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\n/**\n * Get a mapping of camelCase parameter names to their original names\n * Used for mapping function parameters to backend parameter names\n */\nexport function getParamsMapping(\n operationSchema: OperationSchema | undefined,\n options: {\n casing?: 'camelcase'\n } = {},\n): Record<string, string> | undefined {\n if (!operationSchema?.schema.properties) {\n return undefined\n }\n\n const allEntries: Array<[string, string]> = []\n let hasTransformation = false\n\n Object.entries(operationSchema.schema.properties).forEach(([originalName]) => {\n let transformedName = originalName\n\n // Only transform to camelCase if explicitly requested\n if (options.casing === 'camelcase') {\n transformedName = camelCase(originalName)\n } else if (!isValidVarName(originalName)) {\n // If not valid variable name and casing not set, still need to make it valid\n transformedName = camelCase(originalName)\n }\n\n allEntries.push([originalName, transformedName])\n\n if (transformedName !== originalName) {\n hasTransformation = true\n }\n })\n\n // When using explicit casing and there are transformations, include ALL params so that\n // mappedParams contains every parameter (not just the ones whose names changed).\n // This prevents params with already-camelCase names (e.g. 'page', 'search') from being\n // silently dropped when other params in the same schema do need transformation.\n if (options.casing === 'camelcase' && hasTransformation) {\n return Object.fromEntries(allEntries)\n }\n\n // When casing is not specified or no transformations are needed, only return changed entries\n const mapping: Record<string, string> = {}\n allEntries.forEach(([originalName, transformedName]) => {\n if (transformedName !== originalName) {\n mapping[originalName] = transformedName\n }\n })\n\n return Object.keys(mapping).length > 0 ? mapping : undefined\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","import { camelCase, isValidVarName } from '@internals/utils'\nimport type { SchemaObject } from '@kubb/oas'\n\n/**\n * Apply casing transformation to schema properties\n * Only transforms property names, not nested schemas\n */\nexport function applyParamsCasing(schema: SchemaObject, casing: 'camelcase' | undefined): SchemaObject {\n if (!casing || !schema.properties) {\n return schema\n }\n\n const transformedProperties: Record<string, any> = {}\n const transformedRequired: string[] = []\n\n // Transform property names\n Object.entries(schema.properties).forEach(([originalName, propertySchema]) => {\n let transformedName = originalName\n\n if (casing === 'camelcase') {\n transformedName = camelCase(originalName)\n } else if (!isValidVarName(originalName)) {\n // If not valid variable name, make it valid\n transformedName = camelCase(originalName)\n }\n\n transformedProperties[transformedName] = propertySchema\n })\n\n // Transform required field names\n if (Array.isArray(schema.required)) {\n schema.required.forEach((originalName) => {\n let transformedName = originalName\n\n if (casing === 'camelcase') {\n transformedName = camelCase(originalName)\n } else if (!isValidVarName(originalName)) {\n transformedName = camelCase(originalName)\n }\n\n transformedRequired.push(transformedName)\n })\n }\n\n // Return a new schema with transformed properties and required fields\n return {\n ...schema,\n properties: transformedProperties,\n ...(transformedRequired.length > 0 && { required: transformedRequired }),\n } as SchemaObject\n}\n\n/**\n * Check if this schema is a parameter schema (pathParams, queryParams, or headerParams)\n * Only these should be transformed, not response/data/body\n */\nexport function isParameterSchema(schemaName: string): boolean {\n const lowerName = schemaName.toLowerCase()\n return lowerName.includes('pathparams') || lowerName.includes('queryparams') || lowerName.includes('headerparams')\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAoHA,SAAgB,eAAe,MAAuB;AACpD,KAAI;AACF,MAAI,SAAS,OAAO,OAAO;SACrB;AACN,SAAO;;AAET,QAAO;;;;;;;;;;;;ACvET,IAAa,UAAb,MAAqB;;;;CAInB;CAEA;CAEA,YAAY,MAAc,UAAmB,EAAE,EAAE;AAC/C,OAAK,OAAO;AACZ,QAAA,UAAgB;;;;;;;;;CAUlB,IAAI,MAAc;AAChB,SAAO,KAAK,WAAW;;;;;;;;;;CAWzB,IAAI,QAAiB;AACnB,MAAI;AACF,UAAO,CAAC,CAAC,IAAI,IAAI,KAAK,KAAK,CAAC;UACtB;AACN,UAAO;;;;;;;;;;CAWX,IAAI,WAAmB;AACrB,SAAO,KAAK,kBAAkB;;;;;;;;;;CAWhC,IAAI,SAA6B;AAC/B,SAAO,KAAK,UAAU;;;;;;;;;;CAWxB,IAAI,SAA6C;AAC/C,SAAO,KAAK,WAAW;;CAGzB,gBAAgB,KAAqB;EACnC,MAAM,QAAQ,eAAe,IAAI,GAAG,MAAM,UAAU,IAAI;AACxD,SAAO,MAAA,QAAc,WAAW,cAAc,UAAU,MAAM,GAAG;;;;;CAMnE,WAAW,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AI,CAAC,UAAU,CAAC,OAAO,WACrB,QAAO;CAGT,MAAM,wBAA6C,EAAE;CACrD,MAAM,sBAAgC,EAAE;AAGxC,QAAO,QAAQ,OAAO,WAAW,CAAC,SAAS,CAAC,cAAc,oBAAoB;EAC5E,IAAI,kBAAkB;AAEtB,MAAI,WAAW,YACb,mBAAkB,UAAU,aAAa;WAChC,CAAC,eAAe,aAAa,CAEtC,mBAAkB,UAAU,aAAa;AAG3C,wBAAsB,mBAAmB;GACzC;AAGF,KAAI,MAAM,QAAQ,OAAO,SAAS,CAChC,QAAO,SAAS,SAAS,iBAAiB;EACxC,IAAI,kBAAkB;AAEtB,MAAI,WAAW,YACb,mBAAkB,UAAU,aAAa;WAChC,CAAC,eAAe,aAAa,CACtC,mBAAkB,UAAU,aAAa;AAG3C,sBAAoB,KAAK,gBAAgB;GACzC;AAIJ,QAAO;EACL,GAAG;EACH,YAAY;EACZ,GAAI,oBAAoB,SAAS,KAAK,EAAE,UAAU,qBAAqB;EACxE;;;;;;AAOH,SAAgB,kBAAkB,YAA6B;CAC7D,MAAM,YAAY,WAAW,aAAa;AAC1C,QAAO,UAAU,SAAS,aAAa,IAAI,UAAU,SAAS,cAAc,IAAI,UAAU,SAAS,eAAe"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubb/plugin-oas",
3
- "version": "5.0.0-alpha.30",
3
+ "version": "5.0.0-alpha.31",
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",
@@ -84,8 +84,8 @@
84
84
  "@kubb/fabric-core": "0.15.1",
85
85
  "@kubb/react-fabric": "0.15.1",
86
86
  "remeda": "^2.33.7",
87
- "@kubb/core": "5.0.0-alpha.30",
88
- "@kubb/oas": "5.0.0-alpha.30"
87
+ "@kubb/core": "5.0.0-alpha.31",
88
+ "@kubb/oas": "5.0.0-alpha.31"
89
89
  },
90
90
  "peerDependencies": {
91
91
  "@kubb/fabric-core": "0.15.1",
@@ -1,7 +1,7 @@
1
1
  import type { AsyncEventEmitter } from '@internals/utils'
2
2
  import { pascalCase } from '@internals/utils'
3
- import type { FileMetaBase, KubbEvents, Plugin, PluginDriver, PluginFactoryOptions } from '@kubb/core'
4
- import type { FabricFile, Fabric as FabricType } from '@kubb/fabric-core/types'
3
+ import type { FileMetaBase, KubbEvents, KubbFile, Plugin, PluginDriver, PluginFactoryOptions } from '@kubb/core'
4
+ import type { Fabric as FabricType } from '@kubb/fabric-core/types'
5
5
  import type { contentType, HttpMethod, Oas, OasTypes, Operation, SchemaObject } from '@kubb/oas'
6
6
  import type { CoreGenerator } from './generators/createGenerator.ts'
7
7
  import type { ReactGenerator } from './generators/createReactGenerator.ts'
@@ -10,7 +10,7 @@ import type { Exclude, Include, OperationSchemas, Override } from './types.ts'
10
10
  import { withRequiredRequestBodySchema } from './utils/requestBody.ts'
11
11
  import { renderOperation, renderOperations } from './utils.tsx'
12
12
 
13
- export type OperationMethodResult<TFileMeta extends FileMetaBase> = Promise<FabricFile.File<TFileMeta> | Array<FabricFile.File<TFileMeta>> | null>
13
+ export type OperationMethodResult<TFileMeta extends FileMetaBase> = Promise<KubbFile.File<TFileMeta> | Array<KubbFile.File<TFileMeta>> | null>
14
14
 
15
15
  type Context<TOptions, TPluginOptions extends PluginFactoryOptions> = {
16
16
  fabric: FabricType
@@ -25,7 +25,7 @@ type Context<TOptions, TPluginOptions extends PluginFactoryOptions> = {
25
25
  * Current plugin
26
26
  */
27
27
  plugin: Plugin<TPluginOptions>
28
- mode: FabricFile.Mode
28
+ mode: KubbFile.Mode
29
29
  UNSTABLE_NAMING?: true
30
30
  }
31
31
 
@@ -205,7 +205,7 @@ export class OperationGenerator<TPluginOptions extends PluginFactoryOptions = Pl
205
205
  )
206
206
  }
207
207
 
208
- async build(...generators: Array<Generator<TPluginOptions>>): Promise<Array<FabricFile.File<TFileMeta>>> {
208
+ async build(...generators: Array<Generator<TPluginOptions>>): Promise<Array<KubbFile.File<TFileMeta>>> {
209
209
  const operations = await this.getOperations()
210
210
 
211
211
  this.context.events?.emit('debug', {
@@ -213,7 +213,7 @@ export class OperationGenerator<TPluginOptions extends PluginFactoryOptions = Pl
213
213
  logs: [`Building ${operations.length} operations`, ` • Generators: ${generators.length}`],
214
214
  })
215
215
 
216
- const results: Array<FabricFile.File<TFileMeta>> = []
216
+ const results: Array<KubbFile.File<TFileMeta>> = []
217
217
 
218
218
  for (const generator of generators) {
219
219
  if (!('type' in generator)) {
@@ -223,7 +223,7 @@ export class OperationGenerator<TPluginOptions extends PluginFactoryOptions = Pl
223
223
  // After the v2 guard above, all generators here are v1
224
224
  const v1Generator = generator as ReactGenerator<TPluginOptions> | CoreGenerator<TPluginOptions>
225
225
 
226
- const opResultsFlat: Array<FabricFile.File<TFileMeta>> = []
226
+ const opResultsFlat: Array<KubbFile.File<TFileMeta>> = []
227
227
 
228
228
  for (const { operation, method } of operations) {
229
229
  const options = this.getOptions(operation, method)
@@ -256,7 +256,7 @@ export class OperationGenerator<TPluginOptions extends PluginFactoryOptions = Pl
256
256
  },
257
257
  })
258
258
 
259
- opResultsFlat.push(...([result ?? []].flat() as Array<FabricFile.File<TFileMeta>>))
259
+ opResultsFlat.push(...([result ?? []].flat() as Array<KubbFile.File<TFileMeta>>))
260
260
  }
261
261
  }
262
262
 
@@ -282,7 +282,7 @@ export class OperationGenerator<TPluginOptions extends PluginFactoryOptions = Pl
282
282
  plugin: this.context.plugin,
283
283
  })
284
284
 
285
- results.push(...opResultsFlat, ...((operationsResult ?? []) as unknown as Array<FabricFile.File<TFileMeta>>))
285
+ results.push(...opResultsFlat, ...((operationsResult ?? []) as unknown as Array<KubbFile.File<TFileMeta>>))
286
286
  }
287
287
 
288
288
  return results
@@ -1,7 +1,7 @@
1
1
  import type { AsyncEventEmitter } from '@internals/utils'
2
2
  import { getUniqueName, pascalCase, stringify } from '@internals/utils'
3
- import type { FileMetaBase, KubbEvents, Plugin, PluginDriver, PluginFactoryOptions, ResolveNameParams } from '@kubb/core'
4
- import type { FabricFile, Fabric as FabricType } from '@kubb/fabric-core/types'
3
+ import type { FileMetaBase, KubbEvents, KubbFile, Plugin, PluginDriver, PluginFactoryOptions, ResolveNameParams } from '@kubb/core'
4
+ import type { Fabric as FabricType } from '@kubb/fabric-core/types'
5
5
  import type { contentType, Oas, OasTypes, OpenAPIV3, SchemaObject } from '@kubb/oas'
6
6
  import { isDiscriminator, isNullable, isReference, KUBB_INLINE_REF_PREFIX } from '@kubb/oas'
7
7
  import { isDeepEqual, isNumber, uniqueWith } from 'remeda'
@@ -15,7 +15,7 @@ import { renderSchema } from './utils.tsx'
15
15
 
16
16
  export type GetSchemaGeneratorOptions<T extends SchemaGenerator<any, any, any>> = T extends SchemaGenerator<infer Options, any, any> ? Options : never
17
17
 
18
- export type SchemaMethodResult<TFileMeta extends FileMetaBase> = Promise<FabricFile.File<TFileMeta> | Array<FabricFile.File<TFileMeta>> | null>
18
+ export type SchemaMethodResult<TFileMeta extends FileMetaBase> = Promise<KubbFile.File<TFileMeta> | Array<KubbFile.File<TFileMeta>> | null>
19
19
 
20
20
  type Context<TOptions, TPluginOptions extends PluginFactoryOptions> = {
21
21
  fabric: FabricType
@@ -26,7 +26,7 @@ type Context<TOptions, TPluginOptions extends PluginFactoryOptions> = {
26
26
  * Current plugin
27
27
  */
28
28
  plugin: Plugin<TPluginOptions>
29
- mode: FabricFile.Mode
29
+ mode: KubbFile.Mode
30
30
  include?: Array<'schemas' | 'responses' | 'requestBodies'>
31
31
  override: Array<Override<TOptions>> | undefined
32
32
  contentType?: contentType
@@ -1331,7 +1331,7 @@ export class SchemaGenerator<
1331
1331
  return [{ keyword: emptyType }, ...baseItems]
1332
1332
  }
1333
1333
 
1334
- async build(...generators: Array<Generator<TPluginOptions>>): Promise<Array<FabricFile.File<TFileMeta>>> {
1334
+ async build(...generators: Array<Generator<TPluginOptions>>): Promise<Array<KubbFile.File<TFileMeta>>> {
1335
1335
  const { oas, contentType, include } = this.context
1336
1336
 
1337
1337
  // Initialize the name mapping if not already done
@@ -1354,10 +1354,10 @@ export class SchemaGenerator<
1354
1354
  return this.#doBuild(schemas, generators)
1355
1355
  }
1356
1356
 
1357
- async #doBuild(schemas: Record<string, OasTypes.SchemaObject>, generators: Array<Generator<TPluginOptions>>): Promise<Array<FabricFile.File<TFileMeta>>> {
1357
+ async #doBuild(schemas: Record<string, OasTypes.SchemaObject>, generators: Array<Generator<TPluginOptions>>): Promise<Array<KubbFile.File<TFileMeta>>> {
1358
1358
  const schemaEntries = Object.entries(schemas)
1359
1359
 
1360
- const results: Array<FabricFile.File<TFileMeta>> = []
1360
+ const results: Array<KubbFile.File<TFileMeta>> = []
1361
1361
 
1362
1362
  for (const generator of generators) {
1363
1363
  if (!('type' in generator)) {
@@ -1411,7 +1411,7 @@ export class SchemaGenerator<
1411
1411
  },
1412
1412
  })
1413
1413
 
1414
- results.push(...([result ?? []].flat() as Array<FabricFile.File<TFileMeta>>))
1414
+ results.push(...([result ?? []].flat() as Array<KubbFile.File<TFileMeta>>))
1415
1415
  }
1416
1416
  }
1417
1417
  }
@@ -1,4 +1,4 @@
1
- import type { FabricFile } from '@kubb/fabric-core/types'
1
+ import type { KubbFile } from '@kubb/core'
2
2
  import type { SchemaObject } from '@kubb/oas'
3
3
 
4
4
  export type SchemaKeywordMapper = {
@@ -59,7 +59,7 @@ export type SchemaKeywordMapper = {
59
59
  /**
60
60
  * Full qualified path.
61
61
  */
62
- path: FabricFile.Path
62
+ path: KubbFile.Path
63
63
  /**
64
64
  * When true `File.Import` is used.
65
65
  * When false a reference is used inside the current file.
@@ -1,21 +1,20 @@
1
- import type { PluginFactoryOptions } from '@kubb/core'
2
- import type { FabricFile } from '@kubb/fabric-core/types'
1
+ import type { KubbFile, PluginFactoryOptions } from '@kubb/core'
3
2
  import type { OperationProps, OperationsProps, SchemaProps } from './types.ts'
4
3
 
5
4
  type UserGenerator<TOptions extends PluginFactoryOptions> = {
6
5
  name: string
7
- operations?: (props: OperationsProps<TOptions>) => Promise<FabricFile.File[]>
8
- operation?: (props: OperationProps<TOptions>) => Promise<FabricFile.File[]>
9
- schema?: (props: SchemaProps<TOptions>) => Promise<FabricFile.File[]>
6
+ operations?: (props: OperationsProps<TOptions>) => Promise<KubbFile.File[]>
7
+ operation?: (props: OperationProps<TOptions>) => Promise<KubbFile.File[]>
8
+ schema?: (props: SchemaProps<TOptions>) => Promise<KubbFile.File[]>
10
9
  }
11
10
 
12
11
  export type CoreGenerator<TOptions extends PluginFactoryOptions> = {
13
12
  name: string
14
13
  type: 'core'
15
14
  version: '1'
16
- operations: (props: OperationsProps<TOptions>) => Promise<FabricFile.File[]>
17
- operation: (props: OperationProps<TOptions>) => Promise<FabricFile.File[]>
18
- schema: (props: SchemaProps<TOptions>) => Promise<FabricFile.File[]>
15
+ operations: (props: OperationsProps<TOptions>) => Promise<KubbFile.File[]>
16
+ operation: (props: OperationProps<TOptions>) => Promise<KubbFile.File[]>
17
+ schema: (props: SchemaProps<TOptions>) => Promise<KubbFile.File[]>
19
18
  }
20
19
 
21
20
  export function createGenerator<TOptions extends PluginFactoryOptions>(generator: UserGenerator<TOptions>): CoreGenerator<TOptions> {
@@ -1,6 +1,5 @@
1
- import type { FileMetaBase, PluginFactoryOptions, ResolveNameParams } from '@kubb/core'
1
+ import type { FileMetaBase, KubbFile, PluginFactoryOptions, ResolveNameParams } from '@kubb/core'
2
2
  import { useDriver, usePlugin } from '@kubb/core/hooks'
3
- import type { FabricFile } from '@kubb/fabric-core/types'
4
3
  import type { Operation, Operation as OperationType } from '@kubb/oas'
5
4
  import type { OperationGenerator } from '../OperationGenerator.ts'
6
5
  import type { OperationSchemas } from '../types.ts'
@@ -41,13 +40,13 @@ type UseOperationManagerResult = {
41
40
  prefix?: string
42
41
  suffix?: string
43
42
  pluginName?: string
44
- extname?: FabricFile.Extname
43
+ extname?: KubbFile.Extname
45
44
  group?: {
46
45
  tag?: string
47
46
  path?: string
48
47
  }
49
48
  },
50
- ) => FabricFile.File<FileMeta>
49
+ ) => KubbFile.File<FileMeta>
51
50
  groupSchemasByName: (
52
51
  operation: OperationType,
53
52
  params: {
@@ -1,6 +1,5 @@
1
- import type { FileMetaBase, ResolveNameParams } from '@kubb/core'
1
+ import type { FileMetaBase, KubbFile, ResolveNameParams } from '@kubb/core'
2
2
  import { useDriver, usePlugin } from '@kubb/core/hooks'
3
- import type { FabricFile } from '@kubb/fabric-core/types'
4
3
 
5
4
  type FileMeta = FileMetaBase & {
6
5
  pluginName: string
@@ -17,14 +16,14 @@ type UseSchemaManagerResult = {
17
16
  name: string,
18
17
  params?: {
19
18
  pluginName?: string
20
- mode?: FabricFile.Mode
21
- extname?: FabricFile.Extname
19
+ mode?: KubbFile.Mode
20
+ extname?: KubbFile.Extname
22
21
  group?: {
23
22
  tag?: string
24
23
  path?: string
25
24
  }
26
25
  },
27
- ) => FabricFile.File<FileMeta>
26
+ ) => KubbFile.File<FileMeta>
28
27
  }
29
28
 
30
29
  /**
package/src/types.ts CHANGED
@@ -1,5 +1,4 @@
1
- import type { Output, PluginFactoryOptions, ResolveNameParams, UserGroup } from '@kubb/core'
2
- import type { FabricFile } from '@kubb/fabric-core/types'
1
+ import type { KubbFile, Output, PluginFactoryOptions, ResolveNameParams, UserGroup } from '@kubb/core'
3
2
 
4
3
  import type { contentType, HttpMethod, Oas, Operation, SchemaObject } from '@kubb/oas'
5
4
  import type { Generator } from './generators/types.ts'
@@ -145,7 +144,7 @@ export type Options = {
145
144
  export type Ref = {
146
145
  propertyName: string
147
146
  originalName: string
148
- path: FabricFile.Path
147
+ path: KubbFile.Path
149
148
  pluginName?: string
150
149
  }
151
150
  export type Refs = Record<string, Ref>
@@ -155,8 +154,8 @@ export type Resolver = {
155
154
  * Original name or name resolved by `resolveName({ name: operation?.getOperationId() as string, pluginName })`
156
155
  */
157
156
  name: string
158
- baseName: FabricFile.BaseName
159
- path: FabricFile.Path
157
+ baseName: KubbFile.BaseName
158
+ path: KubbFile.Path
160
159
  }
161
160
 
162
161
  export type OperationSchema = {
@@ -1,4 +1,4 @@
1
- import type { FabricFile } from '@kubb/fabric-core/types'
1
+ import type { KubbFile } from '@kubb/core'
2
2
  import { SchemaGenerator } from '../SchemaGenerator.ts'
3
3
  import type { Schema } from '../SchemaMapper'
4
4
  import { schemaKeywords } from '../SchemaMapper'
@@ -6,7 +6,7 @@ import { schemaKeywords } from '../SchemaMapper'
6
6
  /**
7
7
  * Get imports from a schema tree by extracting all ref schemas that are importable
8
8
  */
9
- export function getImports(tree: Array<Schema>): Array<FabricFile.Import> {
9
+ export function getImports(tree: Array<Schema>): Array<KubbFile.Import> {
10
10
  const refs = SchemaGenerator.deepSearch(tree, schemaKeywords.ref)
11
11
 
12
12
  if (!refs) return []
@@ -20,7 +20,7 @@ export function getImports(tree: Array<Schema>): Array<FabricFile.Import> {
20
20
  return {
21
21
  name: [item.args.name],
22
22
  path: item.args.path,
23
- } satisfies FabricFile.Import
23
+ } satisfies KubbFile.Import
24
24
  })
25
25
  .filter((x): x is NonNullable<typeof x> => x !== undefined)
26
26
  }