OpenAPITools / OpenAPITools/openapi-generator
[REQ][Typescript] Allow uniontypes for type-mappings
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Maybe this already is possible and I just don't know how to use it. Here's my problem / idea:
By default openapigen uses string for "type": "string", "format": "date-time" models, what is technically totally correct. I know I can change the type to e.g. date using --type-mappings=DateTime=Date but I'd rather use --type-mappings=DateTime="Date|String". In my opinion this is the technically nices solution since I can easyly say prop=newDate(prop) without needing to cast to any or create a new model.
The only issue is: when using --type-mappings=DateTime="Date|String" all my models get a import { Date|String } from './date|String'; that need to be removed later on. Am I just using it wrong? Or aren't union types supported yet?
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 at the TypeScript generator entry point for the --type-mappings option and reproduce the DateTime="Date|String" case. Trace how the mapping affects generated imports and models; it is done when union types are emitted as valid TypeScript without invalid imports such as Date|String.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100