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
  • #3451
Closed
Open
Issue created Jul 24, 2019 by Administrator@rootContributor

[REQ][typescript-*] String Enums

Created by: eseliger

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

Since TS version 2.4 string enums are supported, which are the preferred way of defining enums that can have string values (over the legacy object-type-dualism). https://www.typescriptlang.org/docs/handbook/enums.html#string-enums

Describe the solution you'd like

I implemented it already on a branch for internal use at my company, which is using an additional property called "stringEnums" for now. No breaking change since it needs to be enabled, off by default

Describe alternatives you've considered

Other solutions that would be possible are:

  • Default to string enums, which would be incompatible with TS<2.4 and be a breaking change
  • Add a proprietary flag to the openapi spec. I think this is not really desirable because most problems that are solved this way are rather specific to the operation, whereas this is more of a global flag IMO.

Comparison of outputs

before:

export interface User {
    title: User.TitleEnum
    name: string
}
export namespace User {
	export type TitleEnum = 'Mr' | 'Mrs' | 'Ms'
	export const TitleEnum = {
	    Mr: 'Mr' as Title,
	    Mrs: 'Mrs' as Title,
	    Ms: 'Ms' as Title,
	}
}

with string enums enabled:

export interface User {
    title: UserTitle
    name: string
}
export enum UserTitle {
    Mr = 'Mr',
    Mrs = 'Mrs',
    Ms = 'Ms',
}
Assignee
Assign to
Time tracking