json-schema-to-typescript icon indicating copy to clipboard operation
json-schema-to-typescript copied to clipboard

Enhance tsEnumNames

Open simonschllng opened this issue 9 years ago • 4 comments

There are some points where tsEnumNames could be enhanced:

  • JSON is ~~usually~~ often snake_case. Allow ts_enum_names.
  • JSON Editor uses enum_titles for a similar scenario. Allow both or adopt.
  • Space characters will lead to invalid TS. Sanitize or explain in docs.

simonschllng avatar Sep 09 '16 17:09 simonschllng

@simonschllng PRs are welcome!

bcherny avatar Sep 09 '16 17:09 bcherny

Another thing - would it be possible to refer to an existing TS enum member? For instance, if I have an enum defined:

MyEnum:
  type: string
  enum: [one, two, three]
  tsEnumValues: [One, Two, Three]

that produces

export const enum MyEnum {
  One = 'one',
  Two = 'two',
  Three = 'three',
}

Now, in another place, I'd like to define that a definition has a certain constant as a property. This is possible using something like:

property:
  type: string
  enum: [two]

and of course that produces 'two' in the output. However, it'd be great to have it output MyEnum.Two. Of course it's possible to write $ref: $/definitions/MyEnum, but that will just compile to MyEnum rather than a specific value.

oleg-codaio avatar May 04 '18 06:05 oleg-codaio

@vaskevich I'm not sure JSON-Schema supports that. If you can point to where in the spec it does support it, we can add support in JSTT as well.

bcherny avatar May 05 '18 17:05 bcherny

Well, I found my own thread here again. I was able to work around this by making use of tsType to override the type to be MyEnum.Two, for instance.

oleg-codaio avatar Apr 22 '21 02:04 oleg-codaio