Skip to content

[Bug]: x-modelgen-inferred-name extension ignored for inline enums in payloads preset #328

@jonaslagoni

Description

@jonaslagoni

Description

The payloads preset generates files named AnonymousSchema_X.ts for inline enum properties even when the x-modelgen-inferred-name extension is provided. The extension is present in the AsyncAPI document but is completely ignored by the generator.

This may be related to the previously closed #137, but that fix did not address the x-modelgen-inferred-name extension case.

Environment

  • CLI Version: 0.64.2 (latest)
  • Node Version: 22+
  • OS: Windows 11 (MINGW64)

Minimal Reproduction

codegen.ts

import { TheCodegenConfiguration } from '@the-codegen-project/cli'

const config: TheCodegenConfiguration = {
  inputType: 'asyncapi',
  inputPath: './input.asyncapi.json',
  language: 'typescript',
  generators: [
    {
      preset: 'payloads',
      outputPath: './output',
      serializationType: 'json',
      language: 'typescript',
      enum: 'enum',
    },
  ],
}

export default config

input.asyncapi.json

{
  "asyncapi": "3.0.0",
  "info": {
    "title": "Test x-modelgen-inferred-name",
    "version": "1.0.0"
  },
  "channels": {
    "test": {
      "messages": {
        "testMsg": {
          "payload": {
            "type": "object",
            "properties": {
              "status": {
                "x-modelgen-inferred-name": "Status",
                "type": "string",
                "enum": ["active", "inactive"]
              }
            }
          }
        }
      }
    }
  }
}

Command

pnpm codegen generate ./codegen.ts

Expected Output

  • File: Status.ts
  • Content:
enum Status {
  ACTIVE = "active",
  INACTIVE = "inactive",
}
export { Status };

Actual Output

  • File: AnonymousSchema_1StatusEnum.ts
  • Content:
enum AnonymousSchema_1StatusEnum {
  ACTIVE = "active",
  INACTIVE = "inactive",
}
export { AnonymousSchema_1StatusEnum };

Additional Context

The x-modelgen-inferred-name extension is documented in Modelina and should be respected when present. Looking at Modelina's JsonSchemaInputProcessor.ts, it explicitly checks for existing values:

} else if (
  name &&
  !(schema as any)[this.MODELGEN_INFFERED_NAME] &&
  schema.$ref === undefined
)

This suggests the extension should NOT be overwritten if already present. The issue seems to be in how the CLI processes/transforms schemas before passing them to Modelina - the extension may be stripped or not properly forwarded.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions