OpenAPITools / OpenAPITools/openapi-generator
[BUG] Duplicate model files generated using typescript-angular for schema objects with the same name/different casing
Nobody has claimed this yet.
- 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
Given schema definitions that use the same name with different casing (e.g. MySchema and mySchema) the generated model for typescript does not differentiate and only my-schema.ts is generated.
We also noticed that using fileNaming=camelCase (the default value) results in mySchema.ts and mYSchema.ts both containing the same contents even though you'd expect different based on the schema example below. The generated interface is MySchema in both files which is also problematic.
openapi-generator version
6.4.0 and same result with 7.8.0
OpenAPI declaration file content or url
openapi: 3.0.1
info:
title: OpenAPI definition
version: v0
paths:
/fake/endpoint:
get:
responses:
"200":
content:
application/json:
schema:
type: object
description: OK
components:
schemas:
MySchema:
type: object
properties:
prop1:
type: string
mySchema:
type: object
properties:
prop2:
type: string
MYSchema:
type: object
properties:
prop3:
type: string
Generation Details
Generated content:
issue-repro-api/src/genfiles
└── openapi
├── README.md
├── api
│ └── api.ts
├── api.module.ts
├── configuration.ts
├── encoder.ts
├── git_push.sh
├── index.ts
├── model
│ ├── models.ts
│ └── my-schema.ts
├── param.ts
└── variables.ts
model.ts content
export * from './my-schema';
export * from './my-schema';
my-schema.ts content
export interface MySchema {
prop2?: string;
}
Generator output indicates it is overriting my-schema.ts is being written 2 times but I would have expected 3 times. given the example above.
...
[main] INFO o.o.codegen.TemplateManager - writing file issue-repro-api/src/genfiles/openapi/model/./my-schema.ts
[main] INFO o.o.codegen.TemplateManager - writing file issue-repro-api/src/genfiles/openapi/model/./my-schema.ts
Steps to reproduce
openapi-generator-cli generate \
-i openapi.yml \
-g typescript-angular \
-o src/genfiles/openapi \
--additional-properties \
providedIn=none,\
ngVersion=13.3.9,\
supportsES6=true,\
withInterfaces=true,\
fileNaming=kebab-case,\
enumPropertyNaming=UPPERCASE,\
removeEnumValuePrefix=false,\
apiModulePrefix=IssueRepro,\
useSingleRequestParameter=true,\
stringEnums=true
Related issues/PRs
Didn't find any.
Suggest a fix
Might require multiple fixes related to a case-sensitive mode for all code generation, to avoid converting specs to kebab and camel cases when that can cause issues like these.
Ideally the example spec would result in MySchema.ts, mySchema.ts and MYSchema.ts each with an interface that has case sensitive names.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running the provided OpenAPI declaration with the typescript-angular generator command and compare the generated model files and exports. Trace the naming and file-writing behavior shown in the generation output, then verify that MySchema, mySchema, and MYSchema produce distinct files, interfaces, and exports without overwriting.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- angular, openapi, typescript
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100