Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #10943
Closed
Open
Issue created Nov 23, 2021 by Administrator@rootContributor

[REQ] [typescript-axios] Object value enums

Created by: jmroon

Is your feature request related to a problem? Please describe.

While the typescript interfaces generated for the model can be fully compatible with client side models, this is not the case with enums as different string enums cannot be compatible on the client side. Typescript enums are problematic, and the typescript community has a better solution.

Implemented this would allow the client side models and server side models to be entirely decoupled, as enums are the only thing standing in the way of that at the moment.

I realize that many people likely use the server models directly, but a flexible approach would be preferable.

Describe the solution you'd like

The typescript-angular generator actually already implements this by default (stringEnums = false). It creates an object value enum as such:

export interface Model {
  type: Model.TypeEnum;
}
export namespace Model{
  export type TypeEnum = 'ONE' | 'TWO' | 'THREE';
  export const TypeEnum = {
    ONE: 'ONE' as TypeEnum,
    ONE: 'TWO' as TypeEnum,
    ONE: 'THREE' as TypeEnum,
  } as const;
}

Alternative Solutions

It would be even greater if this could be extended to all typescript generators, but I'm not sure if their functionality is centralized in any way.

I did take a quick look at the source, but my Java-fu is weak and I can't find the obvious place to implement the change.

Assignee
Assign to
Time tracking