OpenAPITools / OpenAPITools/openapi-generator

[REQ][Typescript] Allow uniontypes for type-mappings

Open
#13,712 13 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Enhancement: Feature
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

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 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.