@kubb/plugin-ts 3.18.3 → 4.0.2

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 (48) hide show
  1. package/dist/{components-B-Jx1kI5.cjs → components-BlMLL1s7.cjs} +76 -373
  2. package/dist/components-BlMLL1s7.cjs.map +1 -0
  3. package/dist/{components-6F5RoYuJ.js → components-DaYIAKg5.js} +64 -367
  4. package/dist/components-DaYIAKg5.js.map +1 -0
  5. package/dist/components.cjs +1 -1
  6. package/dist/components.d.cts +1 -1
  7. package/dist/components.d.ts +1 -1
  8. package/dist/components.js +1 -1
  9. package/dist/generators.cjs +2 -2
  10. package/dist/generators.d.cts +1 -1
  11. package/dist/generators.d.ts +1 -1
  12. package/dist/generators.js +2 -2
  13. package/dist/index.cjs +2 -2
  14. package/dist/index.d.cts +1 -1
  15. package/dist/index.d.ts +1 -1
  16. package/dist/index.js +2 -2
  17. package/dist/{plugin-BXxI6FcR.cjs → plugin-CxUQoqgN.cjs} +36 -24
  18. package/dist/plugin-CxUQoqgN.cjs.map +1 -0
  19. package/dist/{plugin-CldbLff9.js → plugin-D1oIzd18.js} +14 -13
  20. package/dist/plugin-D1oIzd18.js.map +1 -0
  21. package/dist/{types-BWn5y2Wo.d.ts → types-BLgrg7-y.d.cts} +4 -3
  22. package/dist/{types-Bnh-xEll.d.cts → types-C7OjrC1J.d.ts} +4 -3
  23. package/package.json +8 -9
  24. package/src/components/Type.tsx +20 -8
  25. package/src/generators/__snapshots__/enumAllOf.ts +3 -3
  26. package/src/generators/__snapshots__/enumArray.ts +2 -2
  27. package/src/generators/__snapshots__/enumArray20.ts +3 -3
  28. package/src/generators/__snapshots__/enumInObject.ts +3 -3
  29. package/src/generators/__snapshots__/enumItems.ts +3 -3
  30. package/src/generators/__snapshots__/enumNames.ts +2 -2
  31. package/src/generators/__snapshots__/enumNamesConst.ts +2 -2
  32. package/src/generators/__snapshots__/enumNamesLiteral.ts +2 -2
  33. package/src/generators/__snapshots__/enumNamesPascalConst.ts +3 -3
  34. package/src/generators/__snapshots__/enumNamesType.ts +2 -2
  35. package/src/generators/__snapshots__/enumNullableMember.ts +3 -3
  36. package/src/generators/__snapshots__/enumNullableType.ts +3 -3
  37. package/src/generators/__snapshots__/enumString.ts +3 -3
  38. package/src/generators/__snapshots__/enumVarNamesType.ts +3 -3
  39. package/src/generators/__snapshots__/fooBase.ts +2 -2
  40. package/src/generators/__snapshots__/pascalEnum.ts +13 -0
  41. package/src/generators/typeGenerator.tsx +5 -1
  42. package/src/parser.ts +4 -3
  43. package/src/plugin.ts +5 -2
  44. package/src/types.ts +1 -2
  45. package/dist/components-6F5RoYuJ.js.map +0 -1
  46. package/dist/components-B-Jx1kI5.cjs.map +0 -1
  47. package/dist/plugin-BXxI6FcR.cjs.map +0 -1
  48. package/dist/plugin-CldbLff9.js.map +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin-CxUQoqgN.cjs","names":["properties: Record<string, ts.TypeNode>","factory","transformers","SchemaGenerator","options","type","Oas","File","Type","File","OasType","pluginOasName","path","FileManager","options","groupName: Group['name']","transformers","PluginManager","SchemaGenerator","OperationGenerator"],"sources":["../src/generators/typeGenerator.tsx","../src/generators/oasGenerator.tsx","../src/plugin.ts"],"sourcesContent":["import type { PluginManager } from '@kubb/core'\nimport transformers from '@kubb/core/transformers'\nimport { print } from '@kubb/parser-ts'\nimport * as factory from '@kubb/parser-ts/factory'\nimport { createReactGenerator, type OperationSchemas, type OperationSchema as OperationSchemaType, SchemaGenerator } from '@kubb/plugin-oas'\nimport { Oas } from '@kubb/plugin-oas/components'\nimport { useOas, useOperationManager, useSchemaManager } from '@kubb/plugin-oas/hooks'\nimport { getBanner, getFooter } from '@kubb/plugin-oas/utils'\nimport { File, useApp } from '@kubb/react'\nimport type ts from 'typescript'\nimport { Type } from '../components'\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 print([namespaceNode])\n}\n\nexport const typeGenerator = createReactGenerator<PluginTs>({\n name: 'typescript',\n Operation({ operation, options }) {\n const { mapper, enumType, syntaxType, optionalType } = options\n\n const { plugin, pluginManager, mode } = useApp<PluginTs>()\n const oas = useOas()\n const { getSchemas, getFile, getName, getGroup } = useOperationManager()\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 oas,\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: schemaObject, description, keysToOmit, ...options }: OperationSchemaType) => {\n const tree = schemaGenerator.parse({ schemaObject, name })\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 <Oas.Schema key={[name, schemaObject.$ref].join('-')} name={name} schemaObject={schemaObject} tree={tree}>\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={schemaObject}\n mapper={mapper}\n enumType={enumType}\n optionalType={optionalType}\n keysToOmit={keysToOmit}\n syntaxType={syntaxType}\n />\n </Oas.Schema>\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, options }) {\n const { mapper, enumType, syntaxType, optionalType } = options\n const {\n mode,\n plugin: {\n options: { output },\n },\n pluginManager,\n } = useApp<PluginTs>()\n const oas = useOas()\n\n const { getName, getImports, getFile } = useSchemaManager()\n const imports = getImports(schema.tree)\n\n if (enumType === 'asPascalConst') {\n console.warn(`enumType '${enumType}' is deprecated`)\n }\n\n let typedName = getName(schema.name, { type: 'type' })\n\n if (enumType === 'asConst') typedName = typedName += 'Key' // Suffix for avoiding collisions (https://github.com/kubb-labs/kubb/issues/1873)\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 { createReactGenerator } from '@kubb/plugin-oas'\nimport { useOas } from '@kubb/plugin-oas/hooks'\nimport { getBanner, getFooter } from '@kubb/plugin-oas/utils'\nimport { File, useApp } from '@kubb/react'\nimport { OasType } from '../components'\nimport type { PluginTs } from '../types.ts'\n\nexport const oasGenerator = createReactGenerator<PluginTs>({\n name: 'oas',\n Operations() {\n const {\n pluginManager,\n plugin: {\n options: { output },\n key: pluginKey,\n },\n } = useApp<PluginTs>()\n const oas = useOas()\n\n const file = pluginManager.getFile({ name: 'oas', extname: '.ts', pluginKey })\n\n return (\n <File\n baseName={file.baseName}\n path={file.path}\n meta={file.meta}\n banner={getBanner({ oas, output, config: pluginManager.config })}\n footer={getFooter({ oas, output })}\n >\n <File.Import name={['Infer']} path=\"@kubb/oas\" isTypeOnly />\n\n <OasType name={'oas'} typeName={'Oas'} api={oas.api} />\n </File>\n )\n },\n})\n","import path from 'node:path'\n\nimport { FileManager, type Group, PluginManager, createPlugin } from '@kubb/core'\nimport { camelCase, pascalCase } from '@kubb/core/transformers'\nimport { OperationGenerator, SchemaGenerator, pluginOasName } from '@kubb/plugin-oas'\n\nimport type { Plugin } from '@kubb/core'\nimport type { PluginOas as SwaggerPluginOptions } from '@kubb/plugin-oas'\nimport { oasGenerator, typeGenerator } from './generators'\nimport type { PluginTs } from './types.ts'\n\nexport const pluginTsName = 'plugin-ts' satisfies PluginTs['name']\n\nexport const pluginTs = createPlugin<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 oasType = false,\n mapper = {},\n generators = [typeGenerator, oasType === 'infer' ? oasGenerator : undefined].filter(Boolean),\n contentType,\n } = options\n\n return {\n name: pluginTsName,\n options: {\n output,\n transformers,\n dateType,\n optionalType,\n oasType,\n enumType,\n enumSuffix,\n unknownType,\n emptySchemaType,\n syntaxType,\n group,\n override,\n mapper,\n },\n context() {\n return {\n usedEnumNames: {} as Record<string, number>,\n }\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 ?? FileManager.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 buildStart() {\n const [swaggerPlugin]: [Plugin<SwaggerPluginOptions>] = PluginManager.getDependedPlugins<SwaggerPluginOptions>(this.plugins, [pluginOasName])\n\n const oas = await swaggerPlugin.context.getOas()\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = FileManager.getMode(path.resolve(root, output.path))\n\n const schemaGenerator = new SchemaGenerator(this.plugin.options, {\n oas,\n pluginManager: this.pluginManager,\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.addFile(...schemaFiles)\n\n const operationGenerator = new OperationGenerator(this.plugin.options, {\n oas,\n pluginManager: this.pluginManager,\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.addFile(...operationFiles)\n\n const barrelFiles = await this.fileManager.getBarrelFiles({\n type: output.barrelType ?? 'named',\n root,\n output,\n meta: {\n pluginKey: this.plugin.key,\n },\n logger: this.logger,\n })\n\n await this.addFile(...barrelFiles)\n },\n }\n})\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAcA,SAAS,oBAAoB,EAAE,MAAM,SAAS,iBAAoG;CAChJ,MAAMA,aAA0C,EAAE;AAElD,KAAI,QAAQ,SACV,YAAW,cAAcC,yBAAQ,uBAAuB,EACtD,OAAO,QAA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Type as Type$1 } from "./components-DaYIAKg5.js";
2
2
  import path from "node:path";
3
3
  import { FileManager, PluginManager, createPlugin } from "@kubb/core";
4
4
  import transformers, { camelCase, pascalCase } from "@kubb/core/transformers";
@@ -66,7 +66,7 @@ function printCombinedSchema({ name, schemas, pluginManager }) {
66
66
  name,
67
67
  type: factory.createTypeLiteralNode(Object.keys(properties).map((key) => {
68
68
  const type = properties[key];
69
- if (!type) return void 0;
69
+ if (!type) return;
70
70
  return factory.createPropertySignature({
71
71
  name: transformers.pascalCase(key),
72
72
  type
@@ -179,9 +179,11 @@ const typeGenerator = createReactGenerator({
179
179
  const { getName, getImports, getFile } = useSchemaManager();
180
180
  const imports = getImports(schema.tree);
181
181
  if (enumType === "asPascalConst") console.warn(`enumType '${enumType}' is deprecated`);
182
+ let typedName = getName(schema.name, { type: "type" });
183
+ if (enumType === "asConst") typedName = typedName += "Key";
182
184
  const type = {
183
185
  name: getName(schema.name, { type: "function" }),
184
- typedName: getName(schema.name, { type: "type" }),
186
+ typedName,
185
187
  file: getFile(schema.name)
186
188
  };
187
189
  return /* @__PURE__ */ jsxs(File, {
@@ -277,7 +279,6 @@ const pluginTs = createPlugin((options) => {
277
279
  oasType,
278
280
  enumType,
279
281
  enumSuffix,
280
- usedEnumNames: {},
281
282
  unknownType,
282
283
  emptySchemaType,
283
284
  syntaxType,
@@ -285,11 +286,13 @@ const pluginTs = createPlugin((options) => {
285
286
  override,
286
287
  mapper
287
288
  },
289
+ context() {
290
+ return { usedEnumNames: {} };
291
+ },
288
292
  pre: [pluginOasName],
289
293
  resolvePath(baseName, pathMode, options$1) {
290
294
  const root = path.resolve(this.config.root, this.config.output.path);
291
- const mode = pathMode ?? FileManager.getMode(path.resolve(root, output.path));
292
- if (mode === "single")
295
+ if ((pathMode ?? FileManager.getMode(path.resolve(root, output.path))) === "single")
293
296
  /**
294
297
  * when output is a file then we will always append to the same file(output file), see fileManager.addOrAppend
295
298
  * Other plugins then need to call addOrAppend instead of just add from the fileManager class
@@ -314,7 +317,7 @@ const pluginTs = createPlugin((options) => {
314
317
  const oas = await swaggerPlugin.context.getOas();
315
318
  const root = path.resolve(this.config.root, this.config.output.path);
316
319
  const mode = FileManager.getMode(path.resolve(root, output.path));
317
- const schemaGenerator = new SchemaGenerator(this.plugin.options, {
320
+ const schemaFiles = await new SchemaGenerator(this.plugin.options, {
318
321
  oas,
319
322
  pluginManager: this.pluginManager,
320
323
  plugin: this.plugin,
@@ -323,10 +326,9 @@ const pluginTs = createPlugin((options) => {
323
326
  override,
324
327
  mode,
325
328
  output: output.path
326
- });
327
- const schemaFiles = await schemaGenerator.build(...generators);
329
+ }).build(...generators);
328
330
  await this.addFile(...schemaFiles);
329
- const operationGenerator = new OperationGenerator(this.plugin.options, {
331
+ const operationFiles = await new OperationGenerator(this.plugin.options, {
330
332
  oas,
331
333
  pluginManager: this.pluginManager,
332
334
  plugin: this.plugin,
@@ -335,8 +337,7 @@ const pluginTs = createPlugin((options) => {
335
337
  include,
336
338
  override,
337
339
  mode
338
- });
339
- const operationFiles = await operationGenerator.build(...generators);
340
+ }).build(...generators);
340
341
  await this.addFile(...operationFiles);
341
342
  const barrelFiles = await this.fileManager.getBarrelFiles({
342
343
  type: output.barrelType ?? "named",
@@ -352,4 +353,4 @@ const pluginTs = createPlugin((options) => {
352
353
 
353
354
  //#endregion
354
355
  export { oasGenerator, pluginTs, pluginTsName, typeGenerator };
355
- //# sourceMappingURL=plugin-CldbLff9.js.map
356
+ //# sourceMappingURL=plugin-D1oIzd18.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin-D1oIzd18.js","names":["properties: Record<string, ts.TypeNode>","options","type","Type","options","groupName: Group['name']","transformers"],"sources":["../src/generators/typeGenerator.tsx","../src/generators/oasGenerator.tsx","../src/plugin.ts"],"sourcesContent":["import type { PluginManager } from '@kubb/core'\nimport transformers from '@kubb/core/transformers'\nimport { print } from '@kubb/parser-ts'\nimport * as factory from '@kubb/parser-ts/factory'\nimport { createReactGenerator, type OperationSchemas, type OperationSchema as OperationSchemaType, SchemaGenerator } from '@kubb/plugin-oas'\nimport { Oas } from '@kubb/plugin-oas/components'\nimport { useOas, useOperationManager, useSchemaManager } from '@kubb/plugin-oas/hooks'\nimport { getBanner, getFooter } from '@kubb/plugin-oas/utils'\nimport { File, useApp } from '@kubb/react'\nimport type ts from 'typescript'\nimport { Type } from '../components'\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 print([namespaceNode])\n}\n\nexport const typeGenerator = createReactGenerator<PluginTs>({\n name: 'typescript',\n Operation({ operation, options }) {\n const { mapper, enumType, syntaxType, optionalType } = options\n\n const { plugin, pluginManager, mode } = useApp<PluginTs>()\n const oas = useOas()\n const { getSchemas, getFile, getName, getGroup } = useOperationManager()\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 oas,\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: schemaObject, description, keysToOmit, ...options }: OperationSchemaType) => {\n const tree = schemaGenerator.parse({ schemaObject, name })\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 <Oas.Schema key={[name, schemaObject.$ref].join('-')} name={name} schemaObject={schemaObject} tree={tree}>\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={schemaObject}\n mapper={mapper}\n enumType={enumType}\n optionalType={optionalType}\n keysToOmit={keysToOmit}\n syntaxType={syntaxType}\n />\n </Oas.Schema>\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, options }) {\n const { mapper, enumType, syntaxType, optionalType } = options\n const {\n mode,\n plugin: {\n options: { output },\n },\n pluginManager,\n } = useApp<PluginTs>()\n const oas = useOas()\n\n const { getName, getImports, getFile } = useSchemaManager()\n const imports = getImports(schema.tree)\n\n if (enumType === 'asPascalConst') {\n console.warn(`enumType '${enumType}' is deprecated`)\n }\n\n let typedName = getName(schema.name, { type: 'type' })\n\n if (enumType === 'asConst') typedName = typedName += 'Key' // Suffix for avoiding collisions (https://github.com/kubb-labs/kubb/issues/1873)\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 { createReactGenerator } from '@kubb/plugin-oas'\nimport { useOas } from '@kubb/plugin-oas/hooks'\nimport { getBanner, getFooter } from '@kubb/plugin-oas/utils'\nimport { File, useApp } from '@kubb/react'\nimport { OasType } from '../components'\nimport type { PluginTs } from '../types.ts'\n\nexport const oasGenerator = createReactGenerator<PluginTs>({\n name: 'oas',\n Operations() {\n const {\n pluginManager,\n plugin: {\n options: { output },\n key: pluginKey,\n },\n } = useApp<PluginTs>()\n const oas = useOas()\n\n const file = pluginManager.getFile({ name: 'oas', extname: '.ts', pluginKey })\n\n return (\n <File\n baseName={file.baseName}\n path={file.path}\n meta={file.meta}\n banner={getBanner({ oas, output, config: pluginManager.config })}\n footer={getFooter({ oas, output })}\n >\n <File.Import name={['Infer']} path=\"@kubb/oas\" isTypeOnly />\n\n <OasType name={'oas'} typeName={'Oas'} api={oas.api} />\n </File>\n )\n },\n})\n","import path from 'node:path'\n\nimport { FileManager, type Group, PluginManager, createPlugin } from '@kubb/core'\nimport { camelCase, pascalCase } from '@kubb/core/transformers'\nimport { OperationGenerator, SchemaGenerator, pluginOasName } from '@kubb/plugin-oas'\n\nimport type { Plugin } from '@kubb/core'\nimport type { PluginOas as SwaggerPluginOptions } from '@kubb/plugin-oas'\nimport { oasGenerator, typeGenerator } from './generators'\nimport type { PluginTs } from './types.ts'\n\nexport const pluginTsName = 'plugin-ts' satisfies PluginTs['name']\n\nexport const pluginTs = createPlugin<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 oasType = false,\n mapper = {},\n generators = [typeGenerator, oasType === 'infer' ? oasGenerator : undefined].filter(Boolean),\n contentType,\n } = options\n\n return {\n name: pluginTsName,\n options: {\n output,\n transformers,\n dateType,\n optionalType,\n oasType,\n enumType,\n enumSuffix,\n unknownType,\n emptySchemaType,\n syntaxType,\n group,\n override,\n mapper,\n },\n context() {\n return {\n usedEnumNames: {} as Record<string, number>,\n }\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 ?? FileManager.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 buildStart() {\n const [swaggerPlugin]: [Plugin<SwaggerPluginOptions>] = PluginManager.getDependedPlugins<SwaggerPluginOptions>(this.plugins, [pluginOasName])\n\n const oas = await swaggerPlugin.context.getOas()\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = FileManager.getMode(path.resolve(root, output.path))\n\n const schemaGenerator = new SchemaGenerator(this.plugin.options, {\n oas,\n pluginManager: this.pluginManager,\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.addFile(...schemaFiles)\n\n const operationGenerator = new OperationGenerator(this.plugin.options, {\n oas,\n pluginManager: this.pluginManager,\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.addFile(...operationFiles)\n\n const barrelFiles = await this.fileManager.getBarrelFiles({\n type: output.barrelType ?? 'named',\n root,\n output,\n meta: {\n pluginKey: this.plugin.key,\n },\n logger: this.logger,\n })\n\n await this.addFile(...barrelFiles)\n },\n }\n})\n"],"mappings":";;;;;;;;;;;;;;AAcA,SAAS,oBAAoB,EAAE,MAAM,SAAS,iBAAoG;CAChJ,MAAMA,aAA0C,EAAE;AAElD,KAAI,QAAQ,SACV,YAAW,cAAc,QAAQ,uBAAuB,EACtD,OAAO,QAAQ,UAAU,KAAK,QAAQ;EACpC,MAAM,aAAa,cAAc,YAAY;GAC3C,MAAM,IAAI;GACV,WAAW,CAAC,aAAa;GACzB,MAAM;GACP,CAAC;AAEF,SAAO,QAAQ,wBAAwB,QAAQ,iBAAiB,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,aAAa,QAAQ,wBAAwB,QAAQ,iBAAiB,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,gBAAgB,QAAQ,wBAAwB,QAAQ,iBAAiB,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,iBAAiB,QAAQ,wBAAwB,QAAQ,iBAAiB,WAAW,EAAE,OAAU;;AAG9G,KAAI,QAAQ,cAAc;EACxB,MAAM,aAAa,cAAc,YAAY;GAC3C,MAAM,QAAQ,aAAa;GAC3B,WAAW,CAAC,aAAa;GACzB,MAAM;GACP,CAAC;AACF,a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AAC,CAE8C,MAAM,GAAG,WAAW;AACpE,SAAM,KAAK,QAAQ,GAAG,eAAe;GAErC,MAAM,cAAc,MAAM,KAAK,YAAY,eAAe;IACxD,MAAM,OAAO,cAAc;IAC3B;IACA;IACA,MAAM,EACJ,WAAW,KAAK,OAAO,KACxB;IACD,QAAQ,KAAK;IACd,CAAC;AAEF,SAAM,KAAK,QAAQ,GAAG,YAAY;;EAErC;EACD"}
@@ -1235,10 +1235,11 @@ type ResolvedOptions = {
1235
1235
  transformers: NonNullable<Options$1['transformers']>;
1236
1236
  oasType: NonNullable<Options$1['oasType']>;
1237
1237
  syntaxType: NonNullable<Options$1['syntaxType']>;
1238
- usedEnumNames: Record<string, number>;
1239
1238
  mapper: Record<string, any>;
1240
1239
  };
1241
- type PluginTs = PluginFactoryOptions<'plugin-ts', Options$1, ResolvedOptions, never, ResolvePathOptions>;
1240
+ type PluginTs = PluginFactoryOptions<'plugin-ts', Options$1, ResolvedOptions, {
1241
+ usedEnumNames: Record<string, number>;
1242
+ }, ResolvePathOptions>;
1242
1243
  //#endregion
1243
1244
  export { Generator, type OasTypes, Options$1 as Options, PluginTs, Schema, SchemaObject$1 as SchemaObject, UserPluginWithLifeCycle };
1244
- //# sourceMappingURL=types-BWn5y2Wo.d.ts.map
1245
+ //# sourceMappingURL=types-BLgrg7-y.d.cts.map
@@ -1235,10 +1235,11 @@ type ResolvedOptions = {
1235
1235
  transformers: NonNullable<Options$1['transformers']>;
1236
1236
  oasType: NonNullable<Options$1['oasType']>;
1237
1237
  syntaxType: NonNullable<Options$1['syntaxType']>;
1238
- usedEnumNames: Record<string, number>;
1239
1238
  mapper: Record<string, any>;
1240
1239
  };
1241
- type PluginTs = PluginFactoryOptions<'plugin-ts', Options$1, ResolvedOptions, never, ResolvePathOptions>;
1240
+ type PluginTs = PluginFactoryOptions<'plugin-ts', Options$1, ResolvedOptions, {
1241
+ usedEnumNames: Record<string, number>;
1242
+ }, ResolvePathOptions>;
1242
1243
  //#endregion
1243
1244
  export { Generator, type OasTypes, Options$1 as Options, PluginTs, Schema, SchemaObject$1 as SchemaObject, UserPluginWithLifeCycle };
1244
- //# sourceMappingURL=types-Bnh-xEll.d.cts.map
1245
+ //# sourceMappingURL=types-C7OjrC1J.d.ts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubb/plugin-ts",
3
- "version": "3.18.3",
3
+ "version": "4.0.2",
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",
@@ -57,22 +57,21 @@
57
57
  "!/**/__tests__/**"
58
58
  ],
59
59
  "dependencies": {
60
- "@kubb/core": "3.18.3",
61
- "@kubb/oas": "3.18.3",
62
- "@kubb/parser-ts": "3.18.3",
63
- "@kubb/plugin-oas": "3.18.3",
64
- "@kubb/react": "3.18.3"
60
+ "@kubb/core": "4.0.2",
61
+ "@kubb/oas": "4.0.2",
62
+ "@kubb/parser-ts": "4.0.2",
63
+ "@kubb/plugin-oas": "4.0.2",
64
+ "@kubb/react": "4.0.2"
65
65
  },
66
66
  "devDependencies": {
67
67
  "@types/react": "^18.3.24",
68
68
  "react": "^18.3.1",
69
69
  "tsdown": "^0.14.2",
70
70
  "typescript": "^5.9.2",
71
- "@kubb/config-ts": "3.18.3",
72
- "@kubb/plugin-oas": "3.18.3"
71
+ "@kubb/plugin-oas": "4.0.2"
73
72
  },
74
73
  "peerDependencies": {
75
- "@kubb/react": "^3.0.0"
74
+ "@kubb/react": "^4.0.0"
76
75
  },
77
76
  "engines": {
78
77
  "node": ">=20"
@@ -31,6 +31,7 @@ export function Type({ name, typedName, tree, keysToOmit, schema, optionalType,
31
31
  }
32
32
 
33
33
  const schemaFromTree = tree.find((item) => item.keyword === schemaKeywords.schema)
34
+ const enumSchemas = SchemaGenerator.deepSearch(tree, schemaKeywords.enum)
34
35
 
35
36
  let type =
36
37
  (tree
@@ -52,6 +53,23 @@ export function Type({ name, typedName, tree, keysToOmit, schema, optionalType,
52
53
  .filter(Boolean)
53
54
  .at(0) as ts.TypeNode) || typeKeywordMapper.undefined()
54
55
 
56
+ // Add a "Key" suffix to avoid collisions where necessary
57
+ if (enumType === 'asConst' && enumSchemas.length > 0) {
58
+ const isDirectEnum = schema.type === 'array' && schema.items !== undefined
59
+ const isEnumOnly = 'enum' in schema && schema.enum
60
+
61
+ if (isDirectEnum || isEnumOnly) {
62
+ const enumSchema = enumSchemas[0]!
63
+ const typeNameWithKey = `${enumSchema.args.typeName}Key`
64
+
65
+ type = factory.createTypeReferenceNode(typeNameWithKey)
66
+
67
+ if (schema.type === 'array') {
68
+ type = factory.createArrayTypeNode(type)
69
+ }
70
+ }
71
+ }
72
+
55
73
  if (schemaFromTree && isKeyword(schemaFromTree, schemaKeywords.schema)) {
56
74
  const isNullish = tree.some((item) => item.keyword === schemaKeywords.nullish)
57
75
  const isNullable = tree.some((item) => item.keyword === schemaKeywords.nullable)
@@ -102,11 +120,9 @@ export function Type({ name, typedName, tree, keysToOmit, schema, optionalType,
102
120
  }),
103
121
  )
104
122
 
105
- const enumSchemas = SchemaGenerator.deepSearch(tree, schemaKeywords.enum)
106
-
107
123
  const enums = [...new Set(enumSchemas)].map((enumSchema) => {
108
124
  const name = enumType === 'asPascalConst' ? transformers.pascalCase(enumSchema.args.name) : transformers.camelCase(enumSchema.args.name)
109
- const typeName = enumSchema.args.typeName
125
+ const typeName = enumType === 'asConst' ? `${enumSchema.args.typeName}Key` : enumSchema.args.typeName
110
126
 
111
127
  const [nameNode, typeNode] = factory.createEnumDeclaration({
112
128
  name,
@@ -146,11 +162,7 @@ export function Type({ name, typedName, tree, keysToOmit, schema, optionalType,
146
162
  }
147
163
  </Fragment>
148
164
  ))}
149
- {enums.every((item) => item.typeName !== name) && (
150
- <File.Source name={typedName} isTypeOnly isExportable isIndexable>
151
- {print(typeNodes)}
152
- </File.Source>
153
- )}
165
+ <File.Source name={name}>{print(typeNodes)}</File.Source>
154
166
  </Fragment>
155
167
  )
156
168
  }
@@ -3,13 +3,13 @@
3
3
  * Do not edit manually.
4
4
  */
5
5
 
6
- export const enumAllOfReasonEnum2 = {
6
+ export const enumAllOfReasonEnum = {
7
7
  created_at: 'created_at',
8
8
  description: 'description',
9
9
  } as const
10
10
 
11
- export type EnumAllOfReasonEnum2 = (typeof enumAllOfReasonEnum2)[keyof typeof enumAllOfReasonEnum2]
11
+ export type EnumAllOfReasonEnumKey = (typeof enumAllOfReasonEnum)[keyof typeof enumAllOfReasonEnum]
12
12
 
13
13
  export type enumAllOf = {
14
- reason?: EnumAllOfReasonEnum2
14
+ reason?: EnumAllOfReasonEnumKey
15
15
  }
@@ -3,6 +3,6 @@
3
3
  * Do not edit manually.
4
4
  */
5
5
 
6
- export type EnumArrayEnum2 = 'NW' | 'NE' | 'SW' | 'SE'
6
+ export type EnumArrayEnum = 'NW' | 'NE' | 'SW' | 'SE'
7
7
 
8
- export type enumArray = EnumArrayEnum2[]
8
+ export type enumArray = EnumArrayEnum[]
@@ -3,18 +3,18 @@
3
3
  * Do not edit manually.
4
4
  */
5
5
 
6
- export const enumArrayIdentifierEnum2 = {
6
+ export const enumArrayIdentifierEnum = {
7
7
  NW: 'NW',
8
8
  NE: 'NE',
9
9
  SW: 'SW',
10
10
  SE: 'SE',
11
11
  } as const
12
12
 
13
- export type EnumArrayIdentifierEnum2 = (typeof enumArrayIdentifierEnum2)[keyof typeof enumArrayIdentifierEnum2]
13
+ export type EnumArrayIdentifierEnumKey = (typeof enumArrayIdentifierEnum)[keyof typeof enumArrayIdentifierEnum]
14
14
 
15
15
  export type enumArray = {
16
16
  /**
17
17
  * @type array | undefined
18
18
  */
19
- identifier?: [number, string, EnumArrayIdentifierEnum2, ...unknown[]]
19
+ identifier?: [number, string, EnumArrayIdentifierEnumKey, ...unknown[]]
20
20
  }
@@ -3,16 +3,16 @@
3
3
  * Do not edit manually.
4
4
  */
5
5
 
6
- export const enumInObjectReasonEnum2 = {
6
+ export const enumInObjectReasonEnum = {
7
7
  created_at: 'created_at',
8
8
  description: 'description',
9
9
  } as const
10
10
 
11
- export type EnumInObjectReasonEnum2 = (typeof enumInObjectReasonEnum2)[keyof typeof enumInObjectReasonEnum2]
11
+ export type EnumInObjectReasonEnumKey = (typeof enumInObjectReasonEnum)[keyof typeof enumInObjectReasonEnum]
12
12
 
13
13
  export type enumInObject = {
14
14
  /**
15
15
  * @type string | undefined
16
16
  */
17
- reason?: EnumInObjectReasonEnum2
17
+ reason?: EnumInObjectReasonEnumKey
18
18
  }
@@ -3,11 +3,11 @@
3
3
  * Do not edit manually.
4
4
  */
5
5
 
6
- export const enumItemsEnum2 = {
6
+ export const enumItemsEnum = {
7
7
  created_at: 'created_at',
8
8
  description: 'description',
9
9
  } as const
10
10
 
11
- export type EnumItemsEnum2 = (typeof enumItemsEnum2)[keyof typeof enumItemsEnum2]
11
+ export type EnumItemsEnumKey = (typeof enumItemsEnum)[keyof typeof enumItemsEnum]
12
12
 
13
- export type enumItems = EnumItemsEnum2[]
13
+ export type enumItems = EnumItemsEnumKey[]
@@ -3,9 +3,9 @@
3
3
  * Do not edit manually.
4
4
  */
5
5
 
6
- export enum EnumNamesTypeEnum2 {
6
+ export enum EnumNamesTypeEnum {
7
7
  'Pending' = 0,
8
8
  'Received' = 1,
9
9
  }
10
10
 
11
- export type enumNamesType = EnumNamesTypeEnum2
11
+ export type enumNamesType = EnumNamesTypeEnum
@@ -3,9 +3,9 @@
3
3
  * Do not edit manually.
4
4
  */
5
5
 
6
- export const enum EnumNamesTypeEnum2 {
6
+ export const enum EnumNamesTypeEnum {
7
7
  'Pending' = 0,
8
8
  'Received' = 1,
9
9
  }
10
10
 
11
- export type enumNamesType = EnumNamesTypeEnum2
11
+ export type enumNamesType = EnumNamesTypeEnum
@@ -3,6 +3,6 @@
3
3
  * Do not edit manually.
4
4
  */
5
5
 
6
- export type EnumNamesTypeEnum2 = 0 | 1
6
+ export type EnumNamesTypeEnum = 0 | 1
7
7
 
8
- export type enumNamesType = EnumNamesTypeEnum2
8
+ export type enumNamesType = EnumNamesTypeEnum
@@ -3,11 +3,11 @@
3
3
  * Do not edit manually.
4
4
  */
5
5
 
6
- export const EnumNamesTypeEnum2 = {
6
+ export const EnumNamesTypeEnum = {
7
7
  Pending: 0,
8
8
  Received: 1,
9
9
  } as const
10
10
 
11
- type EnumNamesTypeEnum2 = (typeof EnumNamesTypeEnum2)[keyof typeof EnumNamesTypeEnum2]
11
+ type EnumNamesTypeEnum = (typeof EnumNamesTypeEnum)[keyof typeof EnumNamesTypeEnum]
12
12
 
13
- export type enumNamesType = EnumNamesTypeEnum2
13
+ export type enumNamesType = EnumNamesTypeEnum
@@ -8,6 +8,6 @@ export const enumNamesType = {
8
8
  Received: 1,
9
9
  } as const
10
10
 
11
- export type EnumNamesTypeEnum2 = (typeof enumNamesType)[keyof typeof enumNamesType]
11
+ export type EnumNamesTypeEnumKey = (typeof enumNamesType)[keyof typeof enumNamesType]
12
12
 
13
- export type enumNamesType = EnumNamesTypeEnum2
13
+ export type enumNamesType = EnumNamesTypeEnumKey
@@ -3,11 +3,11 @@
3
3
  * Do not edit manually.
4
4
  */
5
5
 
6
- export const enumNullableMemberEnum2 = {
6
+ export const enumNullableMemberEnum = {
7
7
  first: 'first',
8
8
  second: 'second',
9
9
  } as const
10
10
 
11
- export type EnumNullableMemberEnum2 = (typeof enumNullableMemberEnum2)[keyof typeof enumNullableMemberEnum2]
11
+ export type EnumNullableMemberEnumKey = (typeof enumNullableMemberEnum)[keyof typeof enumNullableMemberEnum]
12
12
 
13
- export type enumNullableMember = EnumNullableMemberEnum2 | null
13
+ export type enumNullableMember = EnumNullableMemberEnumKey | null
@@ -3,11 +3,11 @@
3
3
  * Do not edit manually.
4
4
  */
5
5
 
6
- export const enumNullableTypeEnum2 = {
6
+ export const enumNullableTypeEnum = {
7
7
  first: 'first',
8
8
  second: 'second',
9
9
  } as const
10
10
 
11
- export type EnumNullableTypeEnum2 = (typeof enumNullableTypeEnum2)[keyof typeof enumNullableTypeEnum2]
11
+ export type EnumNullableTypeEnumKey = (typeof enumNullableTypeEnum)[keyof typeof enumNullableTypeEnum]
12
12
 
13
- export type enumNullableType = EnumNullableTypeEnum2 | null
13
+ export type enumNullableType = EnumNullableTypeEnumKey | null
@@ -3,13 +3,13 @@
3
3
  * Do not edit manually.
4
4
  */
5
5
 
6
- export const enumStringEnum2 = {
6
+ export const enumStringEnum = {
7
7
  'created at': 'created at',
8
8
  description: 'description',
9
9
  'FILE.UPLOADED': 'FILE.UPLOADED',
10
10
  'FILE.DOWNLOADED': 'FILE.DOWNLOADED',
11
11
  } as const
12
12
 
13
- export type EnumStringEnum2 = (typeof enumStringEnum2)[keyof typeof enumStringEnum2]
13
+ export type EnumStringEnumKey = (typeof enumStringEnum)[keyof typeof enumStringEnum]
14
14
 
15
- export type enumString = EnumStringEnum2
15
+ export type enumString = EnumStringEnumKey
@@ -3,11 +3,11 @@
3
3
  * Do not edit manually.
4
4
  */
5
5
 
6
- export const enumVarNamesTypeEnum2 = {
6
+ export const enumVarNamesTypeEnum = {
7
7
  Pending: 0,
8
8
  Received: 1,
9
9
  } as const
10
10
 
11
- export type EnumVarNamesTypeEnum2 = (typeof enumVarNamesTypeEnum2)[keyof typeof enumVarNamesTypeEnum2]
11
+ export type EnumVarNamesTypeEnumKey = (typeof enumVarNamesTypeEnum)[keyof typeof enumVarNamesTypeEnum]
12
12
 
13
- export type enumVarNamesType = EnumVarNamesTypeEnum2
13
+ export type enumVarNamesType = EnumVarNamesTypeEnumKey
@@ -3,11 +3,11 @@
3
3
  * Do not edit manually.
4
4
  */
5
5
 
6
- export type FooBasetypeEnum2 = 'type-string' | 'type-number'
6
+ export type FooBasetypeEnum = 'type-string' | 'type-number'
7
7
 
8
8
  export type fooBase = {
9
9
  /**
10
10
  * @type string
11
11
  */
12
- $type: FooBasetypeEnum2
12
+ $type: FooBasetypeEnum
13
13
  }
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Generated by Kubb (https://kubb.dev/).
3
+ * Do not edit manually.
4
+ */
5
+
6
+ export const PASCALEnumsTypeEnum = {
7
+ first: 'first',
8
+ second: 'second',
9
+ } as const
10
+
11
+ export type PASCALEnumsTypeEnumKey = (typeof PASCALEnumsTypeEnum)[keyof typeof PASCALEnumsTypeEnum]
12
+
13
+ export type PASCALEnumsType = PASCALEnumsTypeEnumKey | null
@@ -195,9 +195,13 @@ export const typeGenerator = createReactGenerator<PluginTs>({
195
195
  console.warn(`enumType '${enumType}' is deprecated`)
196
196
  }
197
197
 
198
+ let typedName = getName(schema.name, { type: 'type' })
199
+
200
+ if (enumType === 'asConst') typedName = typedName += 'Key' // Suffix for avoiding collisions (https://github.com/kubb-labs/kubb/issues/1873)
201
+
198
202
  const type = {
199
203
  name: getName(schema.name, { type: 'function' }),
200
- typedName: getName(schema.name, { type: 'type' }),
204
+ typedName,
201
205
  file: getFile(schema.name),
202
206
  }
203
207
 
package/src/parser.ts CHANGED
@@ -190,7 +190,8 @@ export function parse({ current, siblings, name }: SchemaTree, options: ParserOp
190
190
  }
191
191
 
192
192
  if (isKeyword(current, schemaKeywords.enum)) {
193
- return typeKeywordMapper.enum(current.args.typeName)
193
+ // Adding suffix to enum (see https://github.com/kubb-labs/kubb/issues/1873)
194
+ return typeKeywordMapper.enum(options.enumType === 'asConst' ? `${current.args.typeName}Key` : current.args.typeName)
194
195
  }
195
196
 
196
197
  if (isKeyword(current, schemaKeywords.ref)) {
@@ -274,7 +275,7 @@ export function parse({ current, siblings, name }: SchemaTree, options: ParserOp
274
275
  }) as ts.TypeNode
275
276
  }
276
277
 
277
- const propertySignature = factory.createPropertySignature({
278
+ const propertyNode = factory.createPropertySignature({
278
279
  questionToken: isOptional || isNullish ? ['questionToken', 'questionTokenAndUndefined'].includes(options.optionalType as string) : false,
279
280
  name: mappedName,
280
281
  type,
@@ -282,7 +283,7 @@ export function parse({ current, siblings, name }: SchemaTree, options: ParserOp
282
283
  })
283
284
 
284
285
  return factory.appendJSDocToNode({
285
- node: propertySignature,
286
+ node: propertyNode,
286
287
  comments: [
287
288
  describeSchema ? `@description ${transformers.jsStringEscape(describeSchema.args)}` : undefined,
288
289
  deprecatedSchema ? '@deprecated' : undefined,
package/src/plugin.ts CHANGED
@@ -42,8 +42,6 @@ export const pluginTs = createPlugin<PluginTs>((options) => {
42
42
  oasType,
43
43
  enumType,
44
44
  enumSuffix,
45
- // keep the used enumnames between SchemaGenerator and OperationGenerator per plugin(pluginKey)
46
- usedEnumNames: {},
47
45
  unknownType,
48
46
  emptySchemaType,
49
47
  syntaxType,
@@ -51,6 +49,11 @@ export const pluginTs = createPlugin<PluginTs>((options) => {
51
49
  override,
52
50
  mapper,
53
51
  },
52
+ context() {
53
+ return {
54
+ usedEnumNames: {} as Record<string, number>,
55
+ }
56
+ },
54
57
  pre: [pluginOasName],
55
58
  resolvePath(baseName, pathMode, options) {
56
59
  const root = path.resolve(this.config.root, this.config.output.path)