Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
6 tasks done
flex-mookeun opened this issue Apr 12, 2025 · 1 comment

Comments

@flex-mookeun
Copy link

flex-mookeun commented Apr 12, 2025

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 #19715, and following fix #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

#19715

Suggest a fix

Not sure but changes regarding seenModelFilenames needs to be reverted just like #19913?

@ross-paypay
Copy link
Contributor

This also appears to be an issue in the Rust based clients

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants