@kubb/plugin-ts 4.13.0 → 4.14.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 (35) hide show
  1. package/dist/{components-Daoap7CS.js → components-HKIi69kI.js} +23 -39
  2. package/dist/components-HKIi69kI.js.map +1 -0
  3. package/dist/{components-DCfalUek.cjs → components-pzX1Kb4u.cjs} +19 -41
  4. package/dist/components-pzX1Kb4u.cjs.map +1 -0
  5. package/dist/components.cjs +1 -2
  6. package/dist/components.d.cts +2 -17
  7. package/dist/components.d.ts +2 -17
  8. package/dist/components.js +2 -2
  9. package/dist/generators.cjs +1 -1
  10. package/dist/generators.d.cts +1 -1
  11. package/dist/generators.d.ts +1 -1
  12. package/dist/generators.js +1 -1
  13. package/dist/index.cjs +1 -1
  14. package/dist/index.d.cts +1 -1
  15. package/dist/index.d.ts +1 -1
  16. package/dist/index.js +1 -1
  17. package/dist/{plugin-DTEjK1nR.js → plugin-BEfry-Dm.js} +6 -6
  18. package/dist/plugin-BEfry-Dm.js.map +1 -0
  19. package/dist/{plugin-N8vqlDtu.cjs → plugin-DljW3znk.cjs} +3 -3
  20. package/dist/plugin-DljW3znk.cjs.map +1 -0
  21. package/dist/{types-WHo75HZq.d.cts → types-C51mhXW0.d.cts} +9 -6
  22. package/dist/{types-De3dRAE2.d.ts → types-DcA3qMIF.d.ts} +9 -6
  23. package/package.json +7 -7
  24. package/src/components/Type.tsx +27 -22
  25. package/src/components/index.ts +0 -1
  26. package/src/factory.ts +7 -5
  27. package/src/generators/__snapshots__/enumNamesInlineLiteral.ts +6 -0
  28. package/src/generators/typeGenerator.tsx +2 -2
  29. package/src/parser.ts +21 -4
  30. package/src/types.ts +4 -2
  31. package/dist/components-DCfalUek.cjs.map +0 -1
  32. package/dist/components-Daoap7CS.js.map +0 -1
  33. package/dist/plugin-DTEjK1nR.js.map +0 -1
  34. package/dist/plugin-N8vqlDtu.cjs.map +0 -1
  35. package/src/components/OasType.tsx +0 -28
@@ -1,4 +1,4 @@
1
- import { n as PluginTs, r as ReactGenerator } from "./types-WHo75HZq.cjs";
1
+ import { n as PluginTs, r as ReactGenerator } from "./types-C51mhXW0.cjs";
2
2
 
3
3
  //#region src/generators/typeGenerator.d.ts
4
4
  declare const typeGenerator: ReactGenerator<PluginTs>;
@@ -1,4 +1,4 @@
1
- import { n as PluginTs, r as ReactGenerator } from "./types-De3dRAE2.js";
1
+ import { n as PluginTs, r as ReactGenerator } from "./types-DcA3qMIF.js";
2
2
 
3
3
  //#region src/generators/typeGenerator.d.ts
4
4
  declare const typeGenerator: ReactGenerator<PluginTs>;
@@ -1,3 +1,3 @@
1
- import { r as typeGenerator } from "./plugin-DTEjK1nR.js";
1
+ import { r as typeGenerator } from "./plugin-BEfry-Dm.js";
2
2
 
3
3
  export { typeGenerator };
package/dist/index.cjs CHANGED
@@ -1,4 +1,4 @@
1
- const require_plugin = require('./plugin-N8vqlDtu.cjs');
1
+ const require_plugin = require('./plugin-DljW3znk.cjs');
2
2
 
3
3
  exports.pluginTs = require_plugin.pluginTs;
4
4
  exports.pluginTsName = require_plugin.pluginTsName;
package/dist/index.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { a as UserPluginWithLifeCycle, n as PluginTs, t as Options } from "./types-WHo75HZq.cjs";
1
+ import { a as UserPluginWithLifeCycle, n as PluginTs, t as Options } from "./types-C51mhXW0.cjs";
2
2
 
3
3
  //#region src/plugin.d.ts
4
4
  declare const pluginTsName = "plugin-ts";
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { a as UserPluginWithLifeCycle, n as PluginTs, t as Options } from "./types-De3dRAE2.js";
1
+ import { a as UserPluginWithLifeCycle, n as PluginTs, t as Options } from "./types-DcA3qMIF.js";
2
2
 
3
3
  //#region src/plugin.d.ts
4
4
  declare const pluginTsName = "plugin-ts";
package/dist/index.js CHANGED
@@ -1,3 +1,3 @@
1
- import { n as pluginTsName, t as pluginTs } from "./plugin-DTEjK1nR.js";
1
+ import { n as pluginTsName, t as pluginTs } from "./plugin-BEfry-Dm.js";
2
2
 
3
3
  export { pluginTs, pluginTsName };
@@ -1,10 +1,10 @@
1
- import { a as createTypeLiteralNode, c as modifiers, i as createTypeAliasDeclaration, n as createIdentifier, o as createTypeReferenceNode, r as createPropertySignature, s as createUnionDeclaration, t as Type$1 } from "./components-Daoap7CS.js";
1
+ import { a as createTypeLiteralNode, c as modifiers, i as createTypeAliasDeclaration, n as createIdentifier, o as createTypeReferenceNode, r as createPropertySignature, s as createUnionDeclaration, t as Type } from "./components-HKIi69kI.js";
2
2
  import path from "node:path";
3
3
  import { definePlugin, getBarrelFiles, getMode } from "@kubb/core";
4
4
  import transformers, { camelCase, pascalCase } from "@kubb/core/transformers";
5
5
  import { OperationGenerator, SchemaGenerator, isKeyword, pluginOasName, schemaKeywords } from "@kubb/plugin-oas";
6
6
  import { useMode, usePluginManager } from "@kubb/core/hooks";
7
- import { print } from "@kubb/fabric-core/parsers/typescript";
7
+ import { safePrint } from "@kubb/fabric-core/parsers/typescript";
8
8
  import { createReactGenerator } from "@kubb/plugin-oas/generators";
9
9
  import { useOas, useOperationManager, useSchemaManager } from "@kubb/plugin-oas/hooks";
10
10
  import { getBanner, getFooter } from "@kubb/plugin-oas/utils";
@@ -62,7 +62,7 @@ function printCombinedSchema({ name, schemas, pluginManager }) {
62
62
  });
63
63
  return createTypeReferenceNode(createIdentifier(identifier), void 0);
64
64
  }) });
65
- return print(createTypeAliasDeclaration({
65
+ return safePrint(createTypeAliasDeclaration({
66
66
  name,
67
67
  type: createTypeLiteralNode(Object.keys(properties).map((key) => {
68
68
  const type = properties[key];
@@ -131,7 +131,7 @@ const typeGenerator = createReactGenerator({
131
131
  imp.name,
132
132
  imp.path,
133
133
  imp.isTypeOnly
134
- ].join("-"))), /* @__PURE__ */ jsx(Type$1, {
134
+ ].join("-"))), /* @__PURE__ */ jsx(Type, {
135
135
  name: type$1.name,
136
136
  typedName: type$1.typedName,
137
137
  description,
@@ -207,7 +207,7 @@ const typeGenerator = createReactGenerator({
207
207
  schema.name,
208
208
  imp.path,
209
209
  imp.isTypeOnly
210
- ].join("-"))), /* @__PURE__ */ jsx(Type$1, {
210
+ ].join("-"))), /* @__PURE__ */ jsx(Type, {
211
211
  name: type.name,
212
212
  typedName: type.typedName,
213
213
  description: schema.value.description,
@@ -313,4 +313,4 @@ const pluginTs = definePlugin((options) => {
313
313
 
314
314
  //#endregion
315
315
  export { pluginTsName as n, typeGenerator as r, pluginTs as t };
316
- //# sourceMappingURL=plugin-DTEjK1nR.js.map
316
+ //# sourceMappingURL=plugin-BEfry-Dm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin-BEfry-Dm.js","names":["properties: Record<string, ts.TypeNode>","factory.createUnionDeclaration","factory.createTypeReferenceNode","factory.createIdentifier","factory.createTypeAliasDeclaration","factory.createTypeLiteralNode","factory.createPropertySignature","options","type","options","groupName: Group['name']","transformers"],"sources":["../src/generators/typeGenerator.tsx","../src/plugin.ts"],"sourcesContent":["import type { PluginManager } from '@kubb/core'\nimport { useMode, usePluginManager } from '@kubb/core/hooks'\nimport transformers from '@kubb/core/transformers'\nimport { safePrint } from '@kubb/fabric-core/parsers/typescript'\nimport { isKeyword, type OperationSchemas, type OperationSchema as OperationSchemaType, SchemaGenerator, schemaKeywords } from '@kubb/plugin-oas'\nimport { createReactGenerator } from '@kubb/plugin-oas/generators'\nimport { useOas, useOperationManager, useSchemaManager } from '@kubb/plugin-oas/hooks'\nimport { getBanner, getFooter } from '@kubb/plugin-oas/utils'\nimport { File } from '@kubb/react-fabric'\nimport type ts from 'typescript'\nimport { Type } from '../components'\nimport * as factory from '../factory.ts'\nimport { pluginTsName } from '../plugin.ts'\nimport type { PluginTs } from '../types'\n\nfunction printCombinedSchema({ name, schemas, pluginManager }: { name: string; schemas: OperationSchemas; pluginManager: PluginManager }): string {\n const properties: Record<string, ts.TypeNode> = {}\n\n if (schemas.response) {\n properties['response'] = factory.createUnionDeclaration({\n nodes: schemas.responses.map((res) => {\n const identifier = pluginManager.resolveName({\n name: res.name,\n pluginKey: [pluginTsName],\n type: 'function',\n })\n\n return factory.createTypeReferenceNode(factory.createIdentifier(identifier), undefined)\n }),\n })!\n }\n\n if (schemas.request) {\n const identifier = pluginManager.resolveName({\n name: schemas.request.name,\n pluginKey: [pluginTsName],\n type: 'function',\n })\n properties['request'] = factory.createTypeReferenceNode(factory.createIdentifier(identifier), undefined)\n }\n\n if (schemas.pathParams) {\n const identifier = pluginManager.resolveName({\n name: schemas.pathParams.name,\n pluginKey: [pluginTsName],\n type: 'function',\n })\n properties['pathParams'] = factory.createTypeReferenceNode(factory.createIdentifier(identifier), undefined)\n }\n\n if (schemas.queryParams) {\n const identifier = pluginManager.resolveName({\n name: schemas.queryParams.name,\n pluginKey: [pluginTsName],\n type: 'function',\n })\n properties['queryParams'] = factory.createTypeReferenceNode(factory.createIdentifier(identifier), undefined)\n }\n\n if (schemas.headerParams) {\n const identifier = pluginManager.resolveName({\n name: schemas.headerParams.name,\n pluginKey: [pluginTsName],\n type: 'function',\n })\n properties['headerParams'] = factory.createTypeReferenceNode(factory.createIdentifier(identifier), undefined)\n }\n\n if (schemas.errors) {\n properties['errors'] = factory.createUnionDeclaration({\n nodes: schemas.errors.map((error) => {\n const identifier = pluginManager.resolveName({\n name: error.name,\n pluginKey: [pluginTsName],\n type: 'function',\n })\n\n return factory.createTypeReferenceNode(factory.createIdentifier(identifier), undefined)\n }),\n })!\n }\n\n const namespaceNode = factory.createTypeAliasDeclaration({\n name,\n type: factory.createTypeLiteralNode(\n Object.keys(properties)\n .map((key) => {\n const type = properties[key]\n if (!type) {\n return undefined\n }\n\n return factory.createPropertySignature({\n name: transformers.pascalCase(key),\n type,\n })\n })\n .filter(Boolean),\n ),\n modifiers: [factory.modifiers.export],\n })\n\n return safePrint(namespaceNode)\n}\n\nexport const typeGenerator = createReactGenerator<PluginTs>({\n name: 'typescript',\n Operation({ operation, generator, plugin }) {\n const {\n options,\n options: { mapper, enumType, syntaxType, optionalType },\n } = plugin\n\n const mode = useMode()\n const pluginManager = usePluginManager()\n\n const oas = useOas()\n const { getSchemas, getFile, getName, getGroup } = useOperationManager(generator)\n const schemaManager = useSchemaManager()\n\n const file = getFile(operation)\n const schemas = getSchemas(operation)\n const type = getName(operation, { type: 'function', pluginKey: [pluginTsName] })\n const combinedSchemaName = operation.method === 'get' ? `${type}Query` : `${type}Mutation`\n const schemaGenerator = new SchemaGenerator(options, {\n fabric: generator.context.fabric,\n oas,\n events: generator.context.events,\n plugin,\n pluginManager,\n mode,\n override: options.override,\n })\n\n const operationSchemas = [schemas.pathParams, schemas.queryParams, schemas.headerParams, schemas.statusCodes, schemas.request, schemas.response]\n .flat()\n .filter(Boolean)\n\n const mapOperationSchema = ({ name, schema, description, keysToOmit, ...options }: OperationSchemaType) => {\n const tree = schemaGenerator.parse({ schema, name, parentName: null })\n const imports = schemaManager.getImports(tree)\n const group = options.operation ? getGroup(options.operation) : undefined\n\n const type = {\n name: schemaManager.getName(name, { type: 'type' }),\n typedName: schemaManager.getName(name, { type: 'type' }),\n file: schemaManager.getFile(options.operationName || name, { group }),\n }\n\n return (\n <>\n {mode === 'split' &&\n imports.map((imp) => (\n <File.Import key={[name, imp.name, imp.path, imp.isTypeOnly].join('-')} root={file.path} path={imp.path} name={imp.name} isTypeOnly />\n ))}\n <Type\n name={type.name}\n typedName={type.typedName}\n description={description}\n tree={tree}\n schema={schema}\n mapper={mapper}\n enumType={enumType}\n optionalType={optionalType}\n keysToOmit={keysToOmit}\n syntaxType={syntaxType}\n />\n </>\n )\n }\n\n return (\n <File\n baseName={file.baseName}\n path={file.path}\n meta={file.meta}\n banner={getBanner({ oas, output: plugin.options.output, config: pluginManager.config })}\n footer={getFooter({ oas, output: plugin.options.output })}\n >\n {operationSchemas.map(mapOperationSchema)}\n\n <File.Source name={combinedSchemaName} isExportable isIndexable isTypeOnly>\n {printCombinedSchema({ name: combinedSchemaName, schemas, pluginManager })}\n </File.Source>\n </File>\n )\n },\n Schema({ schema, plugin }) {\n const {\n options: { mapper, enumType, syntaxType, optionalType, output },\n } = plugin\n const mode = useMode()\n\n const oas = useOas()\n const pluginManager = usePluginManager()\n\n const { getName, getImports, getFile } = useSchemaManager()\n const imports = getImports(schema.tree)\n const schemaFromTree = schema.tree.find((item) => item.keyword === schemaKeywords.schema)\n\n let typedName = getName(schema.name, { type: 'type' })\n\n if (enumType === 'asConst' && schemaFromTree && isKeyword(schemaFromTree, schemaKeywords.enum)) {\n typedName = typedName += 'Key' //Suffix for avoiding collisions (https://github.com/kubb-labs/kubb/issues/1873)\n }\n\n const type = {\n name: getName(schema.name, { type: 'function' }),\n typedName,\n file: getFile(schema.name),\n }\n\n return (\n <File\n baseName={type.file.baseName}\n path={type.file.path}\n meta={type.file.meta}\n banner={getBanner({ oas, output, config: pluginManager.config })}\n footer={getFooter({ oas, output })}\n >\n {mode === 'split' &&\n imports.map((imp) => (\n <File.Import key={[schema.name, imp.path, imp.isTypeOnly].join('-')} root={type.file.path} path={imp.path} name={imp.name} isTypeOnly />\n ))}\n <Type\n name={type.name}\n typedName={type.typedName}\n description={schema.value.description}\n tree={schema.tree}\n schema={schema.value}\n mapper={mapper}\n enumType={enumType}\n optionalType={optionalType}\n syntaxType={syntaxType}\n />\n </File>\n )\n },\n})\n","import path from 'node:path'\nimport { definePlugin, type Group, getBarrelFiles, getMode } from '@kubb/core'\nimport { camelCase, pascalCase } from '@kubb/core/transformers'\nimport { OperationGenerator, pluginOasName, SchemaGenerator } from '@kubb/plugin-oas'\nimport { typeGenerator } from './generators'\nimport type { PluginTs } from './types.ts'\n\nexport const pluginTsName = 'plugin-ts' satisfies PluginTs['name']\n\nexport const pluginTs = definePlugin<PluginTs>((options) => {\n const {\n output = { path: 'types', barrelType: 'named' },\n group,\n exclude = [],\n include,\n override = [],\n enumType = 'asConst',\n enumSuffix = 'enum',\n dateType = 'string',\n unknownType = 'any',\n optionalType = 'questionToken',\n emptySchemaType = unknownType,\n syntaxType = 'type',\n transformers = {},\n mapper = {},\n generators = [typeGenerator].filter(Boolean),\n contentType,\n } = options\n\n const usedEnumNames = {}\n\n return {\n name: pluginTsName,\n options: {\n output,\n transformers,\n dateType,\n optionalType,\n enumType,\n enumSuffix,\n unknownType,\n emptySchemaType,\n syntaxType,\n group,\n override,\n mapper,\n usedEnumNames,\n },\n pre: [pluginOasName],\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 resolveName(name, type) {\n const resolvedName = pascalCase(name, { isFile: type === 'file' })\n\n if (type) {\n return transformers?.name?.(resolvedName, type) || resolvedName\n }\n\n return resolvedName\n },\n async install() {\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = getMode(path.resolve(root, output.path))\n const oas = await this.getOas()\n\n const schemaGenerator = new SchemaGenerator(this.plugin.options, {\n fabric: this.fabric,\n oas,\n pluginManager: this.pluginManager,\n events: this.events,\n plugin: this.plugin,\n contentType,\n include: undefined,\n override,\n mode,\n output: output.path,\n })\n\n const schemaFiles = await schemaGenerator.build(...generators)\n await this.upsertFile(...schemaFiles)\n\n const operationGenerator = new OperationGenerator(this.plugin.options, {\n fabric: this.fabric,\n oas,\n pluginManager: this.pluginManager,\n events: this.events,\n plugin: this.plugin,\n contentType,\n exclude,\n include,\n override,\n mode,\n })\n\n const operationFiles = await operationGenerator.build(...generators)\n await this.upsertFile(...operationFiles)\n\n const barrelFiles = await getBarrelFiles(this.fabric.files, {\n type: output.barrelType ?? 'named',\n root,\n output,\n meta: {\n pluginKey: this.plugin.key,\n },\n })\n\n await this.upsertFile(...barrelFiles)\n },\n }\n})\n"],"mappings":";;;;;;;;;;;;;;AAeA,SAAS,oBAAoB,EAAE,MAAM,SAAS,iBAAoG;CAChJ,MAAMA,aAA0C,EAAE;AAElD,KAAI,QAAQ,SACV,YAAW,cAAcC,uBAA+B,EACtD,OAAO,QAAQ,UAAU,KAAK,QAAQ;EACpC,MAAM,aAAa,cAAc,YAAY;GAC3C,MAAM,IAAI;GACV,WAAW,CAAC,aAAa;GACzB,MAAM;GACP,CAAC;AAEF,SAAOC,wBAAgCC,iBAAyB,WAAW,EAAE,OAAU;GACvF,EACH,CAAC;AAGJ,KAAI,QAAQ,SAAS;EACnB,MAAM,aAAa,cAAc,YAAY;GAC3C,MAAM,QAAQ,QAAQ;GACtB,WAAW,CAAC,aAAa;GACzB,MAAM;GACP,CAAC;AACF,aAAW,aAAaD,wBAAgCC,iBAAyB,WAAW,EAAE,OAAU;;AAG1G,KAAI,QAAQ,YAAY;EACtB,MAAM,aAAa,cAAc,YAAY;GAC3C,MAAM,QAAQ,WAAW;GACzB,WAAW,CAAC,aAAa;GACzB,MAAM;GACP,CAAC;AACF,aAAW,gBAAgBD,wBAAgCC,iBAAyB,WAAW,EAAE,OAAU;;AAG7G,KAAI,QAAQ,aAAa;EACvB,MAAM,aAAa,cAAc,YAAY;GAC3C,MAAM,QAAQ,YAAY;GAC1B,WAAW,CAAC,aAAa;GACzB,MAAM;GACP,CAAC;AACF,aAAW,iBAAiBD,wBAAgCC,iBAAyB,WAAW,EAAE,OAAU;;AAG9G,KAAI,QAAQ,cAAc;EACxB,MAAM,aAAa,cAAc,YAAY;GAC3C,MAAM,QAAQ,aAAa;GAC3B,WAAW,CAAC,aAAa;GACzB,MAAM;GACP,CAAC;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KAAK,OAAO,MAAM,KAAK,OAAO,OAAO,KAAK;GACpE,MAAM,OAAO,QAAQ,KAAK,QAAQ,MAAM,OAAO,KAAK,CAAC;GACrD,MAAM,MAAM,MAAM,KAAK,QAAQ;GAe/B,MAAM,cAAc,MAbI,IAAI,gBAAgB,KAAK,OAAO,SAAS;IAC/D,QAAQ,KAAK;IACb;IACA,eAAe,KAAK;IACpB,QAAQ,KAAK;IACb,QAAQ,KAAK;IACb;IACA,SAAS;IACT;IACA;IACA,QAAQ,OAAO;IAChB,CAAC,CAEwC,MAAM,GAAG,WAAW;AAC9D,SAAM,KAAK,WAAW,GAAG,YAAY;GAerC,MAAM,iBAAiB,MAbI,IAAI,mBAAmB,KAAK,OAAO,SAAS;IACrE,QAAQ,KAAK;IACb;IACA,eAAe,KAAK;IACpB,QAAQ,KAAK;IACb,QAAQ,KAAK;IACb;IACA;IACA;IACA;IACA;IACD,CAAC,CAE8C,MAAM,GAAG,WAAW;AACpE,SAAM,KAAK,WAAW,GAAG,eAAe;GAExC,MAAM,cAAc,MAAM,eAAe,KAAK,OAAO,OAAO;IAC1D,MAAM,OAAO,cAAc;IAC3B;IACA;IACA,MAAM,EACJ,WAAW,KAAK,OAAO,KACxB;IACF,CAAC;AAEF,SAAM,KAAK,WAAW,GAAG,YAAY;;EAExC;EACD"}
@@ -1,4 +1,4 @@
1
- const require_components = require('./components-DCfalUek.cjs');
1
+ const require_components = require('./components-pzX1Kb4u.cjs');
2
2
  let node_path = require("node:path");
3
3
  node_path = require_components.__toESM(node_path);
4
4
  let _kubb_core = require("@kubb/core");
@@ -64,7 +64,7 @@ function printCombinedSchema({ name, schemas, pluginManager }) {
64
64
  });
65
65
  return require_components.createTypeReferenceNode(require_components.createIdentifier(identifier), void 0);
66
66
  }) });
67
- return (0, _kubb_fabric_core_parsers_typescript.print)(require_components.createTypeAliasDeclaration({
67
+ return (0, _kubb_fabric_core_parsers_typescript.safePrint)(require_components.createTypeAliasDeclaration({
68
68
  name,
69
69
  type: require_components.createTypeLiteralNode(Object.keys(properties).map((key) => {
70
70
  const type = properties[key];
@@ -332,4 +332,4 @@ Object.defineProperty(exports, 'typeGenerator', {
332
332
  return typeGenerator;
333
333
  }
334
334
  });
335
- //# sourceMappingURL=plugin-N8vqlDtu.cjs.map
335
+ //# sourceMappingURL=plugin-DljW3znk.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin-DljW3znk.cjs","names":["properties: Record<string, ts.TypeNode>","transformers","SchemaGenerator","options","type","File","Type","schemaKeywords","pluginOasName","path","options","groupName: Group['name']","transformers","SchemaGenerator","OperationGenerator"],"sources":["../src/generators/typeGenerator.tsx","../src/plugin.ts"],"sourcesContent":["import type { PluginManager } from '@kubb/core'\nimport { useMode, usePluginManager } from '@kubb/core/hooks'\nimport transformers from '@kubb/core/transformers'\nimport { safePrint } from '@kubb/fabric-core/parsers/typescript'\nimport { isKeyword, type OperationSchemas, type OperationSchema as OperationSchemaType, SchemaGenerator, schemaKeywords } from '@kubb/plugin-oas'\nimport { createReactGenerator } from '@kubb/plugin-oas/generators'\nimport { useOas, useOperationManager, useSchemaManager } from '@kubb/plugin-oas/hooks'\nimport { getBanner, getFooter } from '@kubb/plugin-oas/utils'\nimport { File } from '@kubb/react-fabric'\nimport type ts from 'typescript'\nimport { Type } from '../components'\nimport * as factory from '../factory.ts'\nimport { pluginTsName } from '../plugin.ts'\nimport type { PluginTs } from '../types'\n\nfunction printCombinedSchema({ name, schemas, pluginManager }: { name: string; schemas: OperationSchemas; pluginManager: PluginManager }): string {\n const properties: Record<string, ts.TypeNode> = {}\n\n if (schemas.response) {\n properties['response'] = factory.createUnionDeclaration({\n nodes: schemas.responses.map((res) => {\n const identifier = pluginManager.resolveName({\n name: res.name,\n pluginKey: [pluginTsName],\n type: 'function',\n })\n\n return factory.createTypeReferenceNode(factory.createIdentifier(identifier), undefined)\n }),\n })!\n }\n\n if (schemas.request) {\n const identifier = pluginManager.resolveName({\n name: schemas.request.name,\n pluginKey: [pluginTsName],\n type: 'function',\n })\n properties['request'] = factory.createTypeReferenceNode(factory.createIdentifier(identifier), undefined)\n }\n\n if (schemas.pathParams) {\n const identifier = pluginManager.resolveName({\n name: schemas.pathParams.name,\n pluginKey: [pluginTsName],\n type: 'function',\n })\n properties['pathParams'] = factory.createTypeReferenceNode(factory.createIdentifier(identifier), undefined)\n }\n\n if (schemas.queryParams) {\n const identifier = pluginManager.resolveName({\n name: schemas.queryParams.name,\n pluginKey: [pluginTsName],\n type: 'function',\n })\n properties['queryParams'] = factory.createTypeReferenceNode(factory.createIdentifier(identifier), undefined)\n }\n\n if (schemas.headerParams) {\n const identifier = pluginManager.resolveName({\n name: schemas.headerParams.name,\n pluginKey: [pluginTsName],\n type: 'function',\n })\n properties['headerParams'] = factory.createTypeReferenceNode(factory.createIdentifier(identifier), undefined)\n }\n\n if (schemas.errors) {\n properties['errors'] = factory.createUnionDeclaration({\n nodes: schemas.errors.map((error) => {\n const identifier = pluginManager.resolveName({\n name: error.name,\n pluginKey: [pluginTsName],\n type: 'function',\n })\n\n return factory.createTypeReferenceNode(factory.createIdentifier(identifier), undefined)\n }),\n })!\n }\n\n const namespaceNode = factory.createTypeAliasDeclaration({\n name,\n type: factory.createTypeLiteralNode(\n Object.keys(properties)\n .map((key) => {\n const type = properties[key]\n if (!type) {\n return undefined\n }\n\n return factory.createPropertySignature({\n name: transformers.pascalCase(key),\n type,\n })\n })\n .filter(Boolean),\n ),\n modifiers: [factory.modifiers.export],\n })\n\n return safePrint(namespaceNode)\n}\n\nexport const typeGenerator = createReactGenerator<PluginTs>({\n name: 'typescript',\n Operation({ operation, generator, plugin }) {\n const {\n options,\n options: { mapper, enumType, syntaxType, optionalType },\n } = plugin\n\n const mode = useMode()\n const pluginManager = usePluginManager()\n\n const oas = useOas()\n const { getSchemas, getFile, getName, getGroup } = useOperationManager(generator)\n const schemaManager = useSchemaManager()\n\n const file = getFile(operation)\n const schemas = getSchemas(operation)\n const type = getName(operation, { type: 'function', pluginKey: [pluginTsName] })\n const combinedSchemaName = operation.method === 'get' ? `${type}Query` : `${type}Mutation`\n const schemaGenerator = new SchemaGenerator(options, {\n fabric: generator.context.fabric,\n oas,\n events: generator.context.events,\n plugin,\n pluginManager,\n mode,\n override: options.override,\n })\n\n const operationSchemas = [schemas.pathParams, schemas.queryParams, schemas.headerParams, schemas.statusCodes, schemas.request, schemas.response]\n .flat()\n .filter(Boolean)\n\n const mapOperationSchema = ({ name, schema, description, keysToOmit, ...options }: OperationSchemaType) => {\n const tree = schemaGenerator.parse({ schema, name, parentName: null })\n const imports = schemaManager.getImports(tree)\n const group = options.operation ? getGroup(options.operation) : undefined\n\n const type = {\n name: schemaManager.getName(name, { type: 'type' }),\n typedName: schemaManager.getName(name, { type: 'type' }),\n file: schemaManager.getFile(options.operationName || name, { group }),\n }\n\n return (\n <>\n {mode === 'split' &&\n imports.map((imp) => (\n <File.Import key={[name, imp.name, imp.path, imp.isTypeOnly].join('-')} root={file.path} path={imp.path} name={imp.name} isTypeOnly />\n ))}\n <Type\n name={type.name}\n typedName={type.typedName}\n description={description}\n tree={tree}\n schema={schema}\n mapper={mapper}\n enumType={enumType}\n optionalType={optionalType}\n keysToOmit={keysToOmit}\n syntaxType={syntaxType}\n />\n </>\n )\n }\n\n return (\n <File\n baseName={file.baseName}\n path={file.path}\n meta={file.meta}\n banner={getBanner({ oas, output: plugin.options.output, config: pluginManager.config })}\n footer={getFooter({ oas, output: plugin.options.output })}\n >\n {operationSchemas.map(mapOperationSchema)}\n\n <File.Source name={combinedSchemaName} isExportable isIndexable isTypeOnly>\n {printCombinedSchema({ name: combinedSchemaName, schemas, pluginManager })}\n </File.Source>\n </File>\n )\n },\n Schema({ schema, plugin }) {\n const {\n options: { mapper, enumType, syntaxType, optionalType, output },\n } = plugin\n const mode = useMode()\n\n const oas = useOas()\n const pluginManager = usePluginManager()\n\n const { getName, getImports, getFile } = useSchemaManager()\n const imports = getImports(schema.tree)\n const schemaFromTree = schema.tree.find((item) => item.keyword === schemaKeywords.schema)\n\n let typedName = getName(schema.name, { type: 'type' })\n\n if (enumType === 'asConst' && schemaFromTree && isKeyword(schemaFromTree, schemaKeywords.enum)) {\n typedName = typedName += 'Key' //Suffix for avoiding collisions (https://github.com/kubb-labs/kubb/issues/1873)\n }\n\n const type = {\n name: getName(schema.name, { type: 'function' }),\n typedName,\n file: getFile(schema.name),\n }\n\n return (\n <File\n baseName={type.file.baseName}\n path={type.file.path}\n meta={type.file.meta}\n banner={getBanner({ oas, output, config: pluginManager.config })}\n footer={getFooter({ oas, output })}\n >\n {mode === 'split' &&\n imports.map((imp) => (\n <File.Import key={[schema.name, imp.path, imp.isTypeOnly].join('-')} root={type.file.path} path={imp.path} name={imp.name} isTypeOnly />\n ))}\n <Type\n name={type.name}\n typedName={type.typedName}\n description={schema.value.description}\n tree={schema.tree}\n schema={schema.value}\n mapper={mapper}\n enumType={enumType}\n optionalType={optionalType}\n syntaxType={syntaxType}\n />\n </File>\n )\n },\n})\n","import path from 'node:path'\nimport { definePlugin, type Group, getBarrelFiles, getMode } from '@kubb/core'\nimport { camelCase, pascalCase } from '@kubb/core/transformers'\nimport { OperationGenerator, pluginOasName, SchemaGenerator } from '@kubb/plugin-oas'\nimport { typeGenerator } from './generators'\nimport type { PluginTs } from './types.ts'\n\nexport const pluginTsName = 'plugin-ts' satisfies PluginTs['name']\n\nexport const pluginTs = definePlugin<PluginTs>((options) => {\n const {\n output = { path: 'types', barrelType: 'named' },\n group,\n exclude = [],\n include,\n override = [],\n enumType = 'asConst',\n enumSuffix = 'enum',\n dateType = 'string',\n unknownType = 'any',\n optionalType = 'questionToken',\n emptySchemaType = unknownType,\n syntaxType = 'type',\n transformers = {},\n mapper = {},\n generators = [typeGenerator].filter(Boolean),\n contentType,\n } = options\n\n const usedEnumNames = {}\n\n return {\n name: pluginTsName,\n options: {\n output,\n transformers,\n dateType,\n optionalType,\n enumType,\n enumSuffix,\n unknownType,\n emptySchemaType,\n syntaxType,\n group,\n override,\n mapper,\n usedEnumNames,\n },\n pre: [pluginOasName],\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 resolveName(name, type) {\n const resolvedName = pascalCase(name, { isFile: type === 'file' })\n\n if (type) {\n return transformers?.name?.(resolvedName, type) || resolvedName\n }\n\n return resolvedName\n },\n async install() {\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = getMode(path.resolve(root, output.path))\n const oas = await this.getOas()\n\n const schemaGenerator = new SchemaGenerator(this.plugin.options, {\n fabric: this.fabric,\n oas,\n pluginManager: this.pluginManager,\n events: this.events,\n plugin: this.plugin,\n contentType,\n include: undefined,\n override,\n mode,\n output: output.path,\n })\n\n const schemaFiles = await schemaGenerator.build(...generators)\n await this.upsertFile(...schemaFiles)\n\n const operationGenerator = new OperationGenerator(this.plugin.options, {\n fabric: this.fabric,\n oas,\n pluginManager: this.pluginManager,\n events: this.events,\n plugin: this.plugin,\n contentType,\n exclude,\n include,\n override,\n mode,\n })\n\n const operationFiles = await operationGenerator.build(...generators)\n await this.upsertFile(...operationFiles)\n\n const barrelFiles = await getBarrelFiles(this.fabric.files, {\n type: output.barrelType ?? 'named',\n root,\n output,\n meta: {\n pluginKey: this.plugin.key,\n },\n })\n\n await this.upsertFile(...barrelFiles)\n },\n }\n})\n"],"mappings":";;;;;;;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K,OAAO,SAAS;IACrE,QAAQ,KAAK;IACb;IACA,eAAe,KAAK;IACpB,QAAQ,KAAK;IACb,QAAQ,KAAK;IACb;IACA;IACA;IACA;IACA;IACD,CAAC,CAE8C,MAAM,GAAG,WAAW;AACpE,SAAM,KAAK,WAAW,GAAG,eAAe;GAExC,MAAM,cAAc,qCAAqB,KAAK,OAAO,OAAO;IAC1D,MAAM,OAAO,cAAc;IAC3B;IACA;IACA,MAAM,EACJ,WAAW,KAAK,OAAO,KACxB;IACF,CAAC;AAEF,SAAM,KAAK,WAAW,GAAG,YAAY;;EAExC;EACD"}
@@ -1,7 +1,6 @@
1
1
  import * as oas_normalize_lib_types0 from "oas-normalize/lib/types";
2
2
  import BaseOas from "oas";
3
3
  import { Operation } from "oas/operation";
4
- import * as OasTypes from "oas/types";
5
4
  import { DiscriminatorObject, HttpMethods, OASDocument, SchemaObject } from "oas/types";
6
5
  import { KubbFile } from "@kubb/fabric-core/types";
7
6
  import { Fabric } from "@kubb/react-fabric";
@@ -183,6 +182,8 @@ interface KubbEvents {
183
182
  id?: string;
184
183
  command: string;
185
184
  args?: readonly string[];
185
+ success: boolean;
186
+ error: Error | null;
186
187
  }];
187
188
  /**
188
189
  * Emitted when a new version of Kubb is available.
@@ -1081,7 +1082,7 @@ type SchemaGeneratorOptions = {
1081
1082
  dateType: false | 'string' | 'stringOffset' | 'stringLocal' | 'date';
1082
1083
  unknownType: 'any' | 'unknown' | 'void';
1083
1084
  emptySchemaType: 'any' | 'unknown' | 'void';
1084
- enumType?: 'enum' | 'asConst' | 'asPascalConst' | 'constEnum' | 'literal';
1085
+ enumType?: 'enum' | 'asConst' | 'asPascalConst' | 'constEnum' | 'literal' | 'inlineLiteral';
1085
1086
  enumSuffix?: string;
1086
1087
  usedEnumNames?: Record<string, number>;
1087
1088
  mapper?: Record<string, string>;
@@ -1191,15 +1192,17 @@ type Options = {
1191
1192
  */
1192
1193
  override?: Array<Override<ResolvedOptions>>;
1193
1194
  /**
1194
- * Choose to use `enum`, `asConst`, `asPascalConst`, `constEnum`, or `literal` for enums.
1195
+ * Choose to use `enum`, `asConst`, `asPascalConst`, `constEnum`, `literal`, or `inlineLiteral` for enums.
1195
1196
  * - `enum`: TypeScript enum
1196
1197
  * - `asConst`: const with camelCase name (e.g., `petType`)
1197
1198
  * - `asPascalConst`: const with PascalCase name (e.g., `PetType`)
1198
1199
  * - `constEnum`: const enum
1199
1200
  * - `literal`: literal union type
1201
+ * - `inlineLiteral`: inline enum values directly into the type (default in v5)
1200
1202
  * @default 'asConst'
1203
+ * @note In Kubb v5, `inlineLiteral` will become the default.
1201
1204
  */
1202
- enumType?: 'enum' | 'asConst' | 'asPascalConst' | 'constEnum' | 'literal';
1205
+ enumType?: 'enum' | 'asConst' | 'asPascalConst' | 'constEnum' | 'literal' | 'inlineLiteral';
1203
1206
  /**
1204
1207
  * Switch between type or interface for creating TypeScript types
1205
1208
  * @default 'type'
@@ -1271,5 +1274,5 @@ type ResolvedOptions = {
1271
1274
  };
1272
1275
  type PluginTs = PluginFactoryOptions<'plugin-ts', Options, ResolvedOptions, never, ResolvePathOptions>;
1273
1276
  //#endregion
1274
- export { UserPluginWithLifeCycle as a, Schema as i, PluginTs as n, OasTypes as o, ReactGenerator as r, SchemaObject$1 as s, Options as t };
1275
- //# sourceMappingURL=types-WHo75HZq.d.cts.map
1277
+ export { UserPluginWithLifeCycle as a, Schema as i, PluginTs as n, SchemaObject$1 as o, ReactGenerator as r, Options as t };
1278
+ //# sourceMappingURL=types-C51mhXW0.d.cts.map
@@ -3,7 +3,6 @@ import ts from "typescript";
3
3
  import * as oas_normalize_lib_types0 from "oas-normalize/lib/types";
4
4
  import BaseOas from "oas";
5
5
  import { Operation } from "oas/operation";
6
- import * as OasTypes from "oas/types";
7
6
  import { DiscriminatorObject, HttpMethods, OASDocument, SchemaObject } from "oas/types";
8
7
  import { KubbFile } from "@kubb/fabric-core/types";
9
8
  import { KubbNode } from "@kubb/react-fabric/types";
@@ -183,6 +182,8 @@ interface KubbEvents {
183
182
  id?: string;
184
183
  command: string;
185
184
  args?: readonly string[];
185
+ success: boolean;
186
+ error: Error | null;
186
187
  }];
187
188
  /**
188
189
  * Emitted when a new version of Kubb is available.
@@ -1081,7 +1082,7 @@ type SchemaGeneratorOptions = {
1081
1082
  dateType: false | 'string' | 'stringOffset' | 'stringLocal' | 'date';
1082
1083
  unknownType: 'any' | 'unknown' | 'void';
1083
1084
  emptySchemaType: 'any' | 'unknown' | 'void';
1084
- enumType?: 'enum' | 'asConst' | 'asPascalConst' | 'constEnum' | 'literal';
1085
+ enumType?: 'enum' | 'asConst' | 'asPascalConst' | 'constEnum' | 'literal' | 'inlineLiteral';
1085
1086
  enumSuffix?: string;
1086
1087
  usedEnumNames?: Record<string, number>;
1087
1088
  mapper?: Record<string, string>;
@@ -1191,15 +1192,17 @@ type Options = {
1191
1192
  */
1192
1193
  override?: Array<Override<ResolvedOptions>>;
1193
1194
  /**
1194
- * Choose to use `enum`, `asConst`, `asPascalConst`, `constEnum`, or `literal` for enums.
1195
+ * Choose to use `enum`, `asConst`, `asPascalConst`, `constEnum`, `literal`, or `inlineLiteral` for enums.
1195
1196
  * - `enum`: TypeScript enum
1196
1197
  * - `asConst`: const with camelCase name (e.g., `petType`)
1197
1198
  * - `asPascalConst`: const with PascalCase name (e.g., `PetType`)
1198
1199
  * - `constEnum`: const enum
1199
1200
  * - `literal`: literal union type
1201
+ * - `inlineLiteral`: inline enum values directly into the type (default in v5)
1200
1202
  * @default 'asConst'
1203
+ * @note In Kubb v5, `inlineLiteral` will become the default.
1201
1204
  */
1202
- enumType?: 'enum' | 'asConst' | 'asPascalConst' | 'constEnum' | 'literal';
1205
+ enumType?: 'enum' | 'asConst' | 'asPascalConst' | 'constEnum' | 'literal' | 'inlineLiteral';
1203
1206
  /**
1204
1207
  * Switch between type or interface for creating TypeScript types
1205
1208
  * @default 'type'
@@ -1271,5 +1274,5 @@ type ResolvedOptions = {
1271
1274
  };
1272
1275
  type PluginTs = PluginFactoryOptions<'plugin-ts', Options, ResolvedOptions, never, ResolvePathOptions>;
1273
1276
  //#endregion
1274
- export { UserPluginWithLifeCycle as a, Schema as i, PluginTs as n, OasTypes as o, ReactGenerator as r, SchemaObject$1 as s, Options as t };
1275
- //# sourceMappingURL=types-De3dRAE2.d.ts.map
1277
+ export { UserPluginWithLifeCycle as a, Schema as i, PluginTs as n, SchemaObject$1 as o, ReactGenerator as r, Options as t };
1278
+ //# sourceMappingURL=types-DcA3qMIF.d.ts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubb/plugin-ts",
3
- "version": "4.13.0",
3
+ "version": "4.14.0",
4
4
  "description": "TypeScript code generation plugin for Kubb, transforming OpenAPI schemas into TypeScript interfaces, types, and utility functions.",
5
5
  "keywords": [
6
6
  "typescript",
@@ -64,17 +64,17 @@
64
64
  }
65
65
  ],
66
66
  "dependencies": {
67
- "@kubb/fabric-core": "0.9.0",
68
- "@kubb/react-fabric": "0.9.0",
67
+ "@kubb/fabric-core": "0.9.2",
68
+ "@kubb/react-fabric": "0.9.2",
69
69
  "natural-orderby": "^5.0.0",
70
70
  "remeda": "^2.33.1",
71
71
  "typescript": "5.9.3",
72
- "@kubb/core": "4.13.0",
73
- "@kubb/oas": "4.13.0",
74
- "@kubb/plugin-oas": "4.13.0"
72
+ "@kubb/core": "4.14.0",
73
+ "@kubb/oas": "4.14.0",
74
+ "@kubb/plugin-oas": "4.14.0"
75
75
  },
76
76
  "peerDependencies": {
77
- "@kubb/react-fabric": "0.9.0",
77
+ "@kubb/react-fabric": "0.9.2",
78
78
  "typescript": ">=5.9.0"
79
79
  },
80
80
  "engines": {
@@ -1,5 +1,5 @@
1
1
  import transformers from '@kubb/core/transformers'
2
- import { print } from '@kubb/fabric-core/parsers/typescript'
2
+ import { safePrint } from '@kubb/fabric-core/parsers/typescript'
3
3
  import type { SchemaObject } from '@kubb/oas'
4
4
  import { isKeyword, type Schema, SchemaGenerator, schemaKeywords } from '@kubb/plugin-oas'
5
5
  import { File } from '@kubb/react-fabric'
@@ -135,30 +135,35 @@ export function Type({ name, typedName, tree, keysToOmit, schema, optionalType,
135
135
  }
136
136
  })
137
137
 
138
+ // Skip enum exports when using inlineLiteral
139
+ const shouldExportEnums = enumType !== 'inlineLiteral'
140
+ const shouldExportType = enumType === 'inlineLiteral' || enums.every((item) => item.typeName !== name)
141
+
138
142
  return (
139
143
  <>
140
- {enums.map(({ name, nameNode, typeName, typeNode }) => (
141
- <>
142
- {nameNode && (
143
- <File.Source name={name} isExportable isIndexable>
144
- {print(nameNode)}
145
- </File.Source>
146
- )}
147
- {
148
- <File.Source
149
- name={typeName}
150
- isIndexable
151
- isExportable={['enum', 'asConst', 'constEnum', 'literal', undefined].includes(enumType)}
152
- isTypeOnly={['asConst', 'literal', undefined].includes(enumType)}
153
- >
154
- {print(typeNode)}
155
- </File.Source>
156
- }
157
- </>
158
- ))}
159
- {enums.every((item) => item.typeName !== name) && (
144
+ {shouldExportEnums &&
145
+ enums.map(({ name, nameNode, typeName, typeNode }) => (
146
+ <>
147
+ {nameNode && (
148
+ <File.Source name={name} isExportable isIndexable>
149
+ {safePrint(nameNode)}
150
+ </File.Source>
151
+ )}
152
+ {
153
+ <File.Source
154
+ name={typeName}
155
+ isIndexable
156
+ isExportable={['enum', 'asConst', 'constEnum', 'literal', undefined].includes(enumType)}
157
+ isTypeOnly={['asConst', 'literal', undefined].includes(enumType)}
158
+ >
159
+ {safePrint(typeNode)}
160
+ </File.Source>
161
+ }
162
+ </>
163
+ ))}
164
+ {shouldExportType && (
160
165
  <File.Source name={typedName} isTypeOnly isExportable isIndexable>
161
- {print(...typeNodes)}
166
+ {safePrint(...typeNodes)}
162
167
  </File.Source>
163
168
  )}
164
169
  </>
@@ -1,2 +1 @@
1
- export { OasType } from './OasType.tsx'
2
1
  export { Type } from './Type.tsx'
package/src/factory.ts CHANGED
@@ -28,7 +28,8 @@ function isValidIdentifier(str: string): boolean {
28
28
 
29
29
  function propertyName(name: string | ts.PropertyName): ts.PropertyName {
30
30
  if (typeof name === 'string') {
31
- return isValidIdentifier(name) ? factory.createIdentifier(name) : factory.createStringLiteral(name)
31
+ const isValid = isValidIdentifier(name)
32
+ return isValid ? factory.createIdentifier(name) : factory.createStringLiteral(name)
32
33
  }
33
34
  return name
34
35
  }
@@ -191,8 +192,9 @@ export function appendJSDocToNode<TNode extends ts.Node>({ node, comments }: { n
191
192
  return `${acc}\n * ${comment.replaceAll('*/', '*\\/')}`
192
193
  }, '*')
193
194
 
194
- // node: {...node}, with that ts.addSyntheticLeadingComment is appending
195
- return ts.addSyntheticLeadingComment({ ...node }, ts.SyntaxKind.MultiLineCommentTrivia, `${text || '*'}\n`, true)
195
+ // Use the node directly instead of spreading to avoid creating Unknown nodes
196
+ // TypeScript's addSyntheticLeadingComment accepts the node as-is
197
+ return ts.addSyntheticLeadingComment(node, ts.SyntaxKind.MultiLineCommentTrivia, `${text || '*'}\n`, true)
196
198
  }
197
199
 
198
200
  export function createIndexSignature(
@@ -406,7 +408,7 @@ export function createEnumDeclaration({
406
408
  * - `literal`: literal union type
407
409
  * @default `'enum'`
408
410
  */
409
- type?: 'enum' | 'asConst' | 'asPascalConst' | 'constEnum' | 'literal'
411
+ type?: 'enum' | 'asConst' | 'asPascalConst' | 'constEnum' | 'literal' | 'inlineLiteral'
410
412
  /**
411
413
  * Enum name in camelCase.
412
414
  */
@@ -417,7 +419,7 @@ export function createEnumDeclaration({
417
419
  typeName: string
418
420
  enums: [key: string | number, value: string | number | boolean][]
419
421
  }): [name: ts.Node | undefined, type: ts.Node] {
420
- if (type === 'literal') {
422
+ if (type === 'literal' || type === 'inlineLiteral') {
421
423
  return [
422
424
  undefined,
423
425
  factory.createTypeAliasDeclaration(
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Generated by Kubb (https://kubb.dev/).
3
+ * Do not edit manually.
4
+ */
5
+
6
+ export type enumNamesType = 0 | 1
@@ -1,7 +1,7 @@
1
1
  import type { PluginManager } from '@kubb/core'
2
2
  import { useMode, usePluginManager } from '@kubb/core/hooks'
3
3
  import transformers from '@kubb/core/transformers'
4
- import { print } from '@kubb/fabric-core/parsers/typescript'
4
+ import { safePrint } from '@kubb/fabric-core/parsers/typescript'
5
5
  import { isKeyword, type OperationSchemas, type OperationSchema as OperationSchemaType, SchemaGenerator, schemaKeywords } from '@kubb/plugin-oas'
6
6
  import { createReactGenerator } from '@kubb/plugin-oas/generators'
7
7
  import { useOas, useOperationManager, useSchemaManager } from '@kubb/plugin-oas/hooks'
@@ -100,7 +100,7 @@ function printCombinedSchema({ name, schemas, pluginManager }: { name: string; s
100
100
  modifiers: [factory.modifiers.export],
101
101
  })
102
102
 
103
- return print(namespaceNode)
103
+ return safePrint(namespaceNode)
104
104
  }
105
105
 
106
106
  export const typeGenerator = createReactGenerator<PluginTs>({
package/src/parser.ts CHANGED
@@ -143,15 +143,17 @@ type ParserOptions = {
143
143
  */
144
144
  optionalType: 'questionToken' | 'undefined' | 'questionTokenAndUndefined'
145
145
  /**
146
- * Choose to use `enum`, `asConst`, `asPascalConst`, `constEnum`, or `literal` for enums.
146
+ * Choose to use `enum`, `asConst`, `asPascalConst`, `constEnum`, `literal`, or `inlineLiteral` for enums.
147
147
  * - `enum`: TypeScript enum
148
148
  * - `asConst`: const with camelCase name (e.g., `petType`)
149
149
  * - `asPascalConst`: const with PascalCase name (e.g., `PetType`)
150
150
  * - `constEnum`: const enum
151
151
  * - `literal`: literal union type
152
+ * - `inlineLiteral`: inline enum values directly into the type (default in v5)
152
153
  * @default `'asConst'`
154
+ * @note In Kubb v5, `inlineLiteral` will become the default.
153
155
  */
154
- enumType: 'enum' | 'asConst' | 'asPascalConst' | 'constEnum' | 'literal'
156
+ enumType: 'enum' | 'asConst' | 'asPascalConst' | 'constEnum' | 'literal' | 'inlineLiteral'
155
157
  mapper?: Record<string, ts.PropertySignature>
156
158
  }
157
159
 
@@ -197,6 +199,20 @@ export const parse = createParser<ts.Node | null, ParserOptions>({
197
199
  const { current } = tree
198
200
  if (!isKeyword(current, schemaKeywords.enum)) return undefined
199
201
 
202
+ // If enumType is 'inlineLiteral', generate the literal union inline instead of a type reference
203
+ if (options.enumType === 'inlineLiteral') {
204
+ const enumValues = current.args.items
205
+ .map((item) => item.value)
206
+ .filter((value): value is string | number | boolean => value !== undefined && value !== null)
207
+ .map((value) => {
208
+ const format = typeof value === 'number' ? 'number' : typeof value === 'boolean' ? 'boolean' : 'string'
209
+ return typeKeywordMapper.const(value, format)
210
+ })
211
+ .filter(Boolean) as ts.TypeNode[]
212
+
213
+ return typeKeywordMapper.union(enumValues)
214
+ }
215
+
200
216
  // Adding suffix to enum (see https://github.com/kubb-labs/kubb/issues/1873)
201
217
  return typeKeywordMapper.enum(options.enumType === 'asConst' ? `${current.args.typeName}Key` : current.args.typeName)
202
218
  },
@@ -244,8 +260,9 @@ export const parse = createParser<ts.Node | null, ParserOptions>({
244
260
  const mappedName = nameSchema?.args || name
245
261
 
246
262
  // custom mapper(pluginOptions)
247
- if (options.mapper?.[mappedName]) {
248
- return options.mapper?.[mappedName]
263
+ // Use Object.hasOwn to avoid matching inherited properties like 'toString', 'valueOf', etc.
264
+ if (options.mapper && Object.hasOwn(options.mapper, mappedName)) {
265
+ return options.mapper[mappedName]
249
266
  }
250
267
 
251
268
  const isNullish = schemas.some((schema) => schema.keyword === schemaKeywords.nullish)
package/src/types.ts CHANGED
@@ -32,15 +32,17 @@ export type Options = {
32
32
  */
33
33
  override?: Array<Override<ResolvedOptions>>
34
34
  /**
35
- * Choose to use `enum`, `asConst`, `asPascalConst`, `constEnum`, or `literal` for enums.
35
+ * Choose to use `enum`, `asConst`, `asPascalConst`, `constEnum`, `literal`, or `inlineLiteral` for enums.
36
36
  * - `enum`: TypeScript enum
37
37
  * - `asConst`: const with camelCase name (e.g., `petType`)
38
38
  * - `asPascalConst`: const with PascalCase name (e.g., `PetType`)
39
39
  * - `constEnum`: const enum
40
40
  * - `literal`: literal union type
41
+ * - `inlineLiteral`: inline enum values directly into the type (default in v5)
41
42
  * @default 'asConst'
43
+ * @note In Kubb v5, `inlineLiteral` will become the default.
42
44
  */
43
- enumType?: 'enum' | 'asConst' | 'asPascalConst' | 'constEnum' | 'literal'
45
+ enumType?: 'enum' | 'asConst' | 'asPascalConst' | 'constEnum' | 'literal' | 'inlineLiteral'
44
46
  /**
45
47
  * Switch between type or interface for creating TypeScript types
46
48
  * @default 'type'