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

Add `x-enum-varnames` support

Open amh4r opened this issue 4 years ago • 8 comments

Currently, json-schema-to-typescript uses a custom tsEnumNames extension for naming enum members. However, this extension is specific only to this library. Other major OpenAPI generators (1, 2) have adopted x-enum-varnames for the same purpose, so this PR brings json-schema-to-typescript in line with them.

This PR addresses feature request #200.

amh4r avatar Sep 06 '21 21:09 amh4r

@bcherny Would I add the following rule:

rules.set('Convert tsEnumNames -> x-enum-varnames', schema => {
  if (schema.tsEnumNames) {
    schema['x-enum-varnames'] = schema.tsEnumNames
    delete schema.tsEnumNames
  }
})

And then be able to always reference ['x-enum-varnames'], even when the spec actually uses .tsEnumNames?

amh4r avatar Sep 12 '21 21:09 amh4r

Yup, exactly. Don't forget to validate when you do that too, to make sure the schema doesn't already have conflicting x-enum-varnames and tsEnumNames defined.

bcherny avatar Sep 12 '21 21:09 bcherny

Is there a way to log a deprecation warning so that consumers know tsEnumNames may eventually be removed?

amh4r avatar Sep 13 '21 01:09 amh4r

@bcherny are you OK with the way I'm handling the existence of both x-enum-varnames and tsEnumNames? I figured throwing an error would be fine

amh4r avatar Sep 25 '21 16:09 amh4r

Hi, is there any chance it'll get merged soon?

galah92 avatar May 11 '22 08:05 galah92

@galah92 I have a couple open questions for @bcherny. I can pick this back up when he answers

amh4r avatar May 22 '22 13:05 amh4r

@galah92 I have a couple open questions for @bcherny. I can pick this back up when he answers

Sorry I missed this! The status was Changes Requested, so I missed your comments.

bcherny avatar May 23 '22 00:05 bcherny

No worries, @bcherny!

I started taking a look at this PR again and I'm having a hard time understanding my changes 😅. I think it'd take some effort to ramp myself back up, unfortunately. If this is something you could bang out quickly, then that's probably best. But if that's not the case then I can try to work on this again

amh4r avatar May 23 '22 00:05 amh4r