OpenAPITools / OpenAPITools/openapi-generator

[BUG] [typescript] schema names with different case generates broken model imports and exports

Open
#21,078 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Bug Report Checklist
  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

Hi, it seems there is case collision issue with schema names in typescript generator.
When schema names conflict due to case differences, the generated model file names are suffixed with index,
but the model import and export statements don’t reflect those file names, causing broken references.

I first encountered this with typescript-axios generator, but the issue is reproducible with typescript generator.

I think I found related change https://github.com/OpenAPITools/openapi-generator/pull/19715, and following fix https://github.com/OpenAPITools/openapi-generator/pull/19913 although it is not directly related to typescript.

openapi-generator version

v7.9.0 or higher

OpenAPI declaration file content or url
{
  "openapi": "3.0.1",
  "info": {},
  "paths": {},
  "components": {
    "schemas": {
      "Response": {
        "required": ["upper", "lower"],
        "type": "object",
        "properties": {
          "upper": {
            "$ref": "#/components/schemas/ModelA"
          },
          "lower": {
            "$ref": "#/components/schemas/Modela"
          }
        }
      },
      "ModelA": {
        "type": "string",
        "enum": ["A", "B"]
      },
      "Modela": {
        "type": "string",
        "enum": ["A", "B"]
      }
    }
  }
}

openapitools.json

{
  "generator-cli": {
    "version": "7.12.0",
    "generators": {
      "typescript": {
        "inputSpec": "./spec.json",
        "output": "./generated",
        "generatorName": "typescript-axios",
        "additionalProperties": {
          "withSeparateModelsAndApi": true,
          "apiPackage": "apis",
          "modelPackage": "models"
        }
      }
    }
  }
}

Generation Details

The schema Modela creates modela0.ts, but the model is not referenced with index-suffixed file name.

// response.ts
import type { ModelA } from './model-a';
import type { Modela } from './modela';

export interface Response {
    'upper': ModelA;
    'lower': Modela;
}
// index.ts
export * from './model-a';
export * from './modela';
export * from './response';

Steps to reproduce

java -jar "openapi-generator-cli.jar" generate --input-spec ./spec.json --output ./generated --generator-name typescript-axios --additional-properties withSeparateModelsAndApi=true,apiPackage=apis,modelPackage=models

Related issues/PRs

https://github.com/OpenAPITools/openapi-generator/pull/19715

Suggest a fix

Not sure but changes regarding seenModelFilenames needs to be reverted just like https://github.com/OpenAPITools/openapi-generator/pull/19913?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the supplied spec and openapitools.json with the typescript-axios generator, then inspect how the TypeScript generator tracks model filenames and emits imports and exports. The fix is done when case-colliding schemas such as ModelA and Modela generate references to their actual index-suffixed files and the generated output builds successfully.

Written by the indexing model from the issue text.

Assessment

Tech stack
openapi, typescript
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.