json-schema-to-typescript
json-schema-to-typescript copied to clipboard
Enhance tsEnumNames
There are some points where tsEnumNames could be enhanced:
- JSON is ~~usually~~ often
snake_case. Allow ts_enum_names. - JSON Editor uses
enum_titlesfor a similar scenario. Allow both or adopt. - Space characters will lead to invalid TS. Sanitize or explain in docs.
@simonschllng PRs are welcome!
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.
@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.
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.