OpenAPITools / OpenAPITools/openapi-generator
[BUG][typescript] Models named after language-specific types generate incorrectly
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)?
- What's the version of OpenAPI Generator used?
- Have you search for related issues/PRs?
- What's the actual output vs expected output?
- [Optional] Bounty to sponsor the fix (example)
Description
If models in the spec are named as lower cased language-specific types, it bypasses sanity checks and produces undesirable result.
E.g. my model is named map. Then the generated interface is named Map, and the api file silently maps that to any
openapi-generator version
master
OpenAPI declaration file content or url
Command line used for generation
docker run --rm -v ${PWD}:/local openapitools/openapi-generator-cli generate \
-i /local/spec.yaml \
-g typescript-angular \
-o /local/generated
Steps to reproduce
- Run command above
- Check the generated
model/map.tsandapi/default.service.ts - Existing output:
// model/map.ts:
export interface Map { ... }
// api/default.service.ts
public mapGet(observe?: 'body', reportProgress?: boolean, options?: {httpHeaderAccept?: '*/*'}): Observable<any>;
- Expected output
// model/map.ts:
export interface ModelMap { ... }
// api/default.service.ts
public mapGet(observe?: 'body', reportProgress?: boolean, options?: {httpHeaderAccept?: '*/*'}): Observable<ModelMap>;
Related issues/PRs
It's somewhat similar to https://github.com/OpenAPITools/openapi-generator/issues/5104 .
Suggest a fix
Half of the problem (generating a correct model name) is addressed in https://github.com/OpenAPITools/openapi-generator/pull/5138
The proper result type in api file (instead of any) still needs a separate fix.
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
Run the documented Docker generation command with the linked language-specific.yml spec, then inspect generated model/map.ts and api/default.service.ts. Compare the model name and API return type with the expected ModelMap output, and verify the generated API no longer uses any for this model.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- angular, typescript
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100