OpenAPITools / OpenAPITools/openapi-generator

[typescript-angular] Support custom types (serialization/deserialization/imports) (momentjs)

Open
#1,875 10 comments 13 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Client: TypeScript Enhancement: Feature
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Hi,

I would like to be able to support custom types. This would mean:

  • Parameters in services are serialized from the custom type
  • Members of models are serialized/deserialized on receive/send.
  • Imports for the custom types are included where required.

My concrete case is that I want to use momentjs for date/time types in models and as parameters.

What I tried to do was:

  • Use a typemapping from Date to Moment; This works but only for Models (See #926)
  • Add an import mapping for Moment; This did not work.

But even then there seems to be no support for any kind pluggable serialization/deserialization. Maybe this could be achieved using custom providers? Maybe this is something to consider for #802.

I can imagine this is quite a common use case but could not find much about how to handle this.

My question is basically how would I achieve having working generated code where every date formatted string is replaced with a Moment type (Other than just writing my own templates).

Thanks

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 with the typescript-angular generator and review the existing typemapping and import-mapping behavior described in the issue. Compare that with the custom providers and template-based approaches mentioned, then define how generated model members and service parameters should serialize, deserialize, and import custom types. Done means a custom type such as Moment works consistently in generated code without maintaining custom templates.

Written by the indexing model from the issue text.

Assessment

Tech stack
angular, typescript
Domain
api, tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.