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

Add option to create string enums based on JSON enums

Open cdietschrun opened this issue 6 years ago • 7 comments

Addresses #200 . Tests seem to do what I expect and the snapshot file generates what I want as well.

I'm hopeful this can be merged and released soon, or at least reviewed and I can reply to feedback ASAP.

Thanks!

cdietschrun avatar Oct 15 '19 20:10 cdietschrun

bump? Otherwise I may end up using a custom version of this package in our flows here internally at Microsoft until this gets reviewed/released

cdietschrun avatar Oct 17 '19 17:10 cdietschrun

I published and installed a dev version of this locally here and see

error TypeError: Cannot read property 'endsWith' of undefined
    at C:\Users\chdietsc\source\repos\mason-ui\node_modules\json-schema-to-typescript\dist\src\generator.js:144:25
    at generateRawType (C:\Users\chdietsc\source\repos\mason-ui\node_modules\json-schema-to-typescript\dist\src\generator.js:145:11)
    at generateType (C:\Users\chdietsc\source\repos\mason-ui\node_modules\json-schema-to-typescript\dist\src\generator.js:129:16)
    at C:\Users\chdietsc\source\repos\mason-ui\node_modules\json-schema-to-typescript\dist\src\generator.js:241:47
    at Array.map (<anonymous>)
    at generateInterface (C:\Users\chdietsc\source\repos\mason-ui\node_modules\json-schema-to-typescript\dist\src\generator.js:239:14)
    at generateStandaloneInterface (C:\Users\chdietsc\source\repos\mason-ui\node_modules\json-schema-to-typescript\dist\src\generator.js:278:11)
    at declareNamedInterfaces (C:\Users\chdietsc\source\repos\mason-ui\node_modules\json-schema-to-typescript\dist\src\generator.js:70:128)
    at C:\Users\chdietsc\source\repos\mason-ui\node_modules\json-schema-to-typescript\dist\src\generator.js:79:57
    at Array.map (<anonymous>)

which I'm trying to debug now, but am not an expert with npm/Node/console logging in this case (not seeing debugging messages I'd expect to see)

cdietschrun avatar Oct 17 '19 20:10 cdietschrun

Looks like that error was an interesting edge case and when removed from my schemas it passes. It's very likely that's a bad edge case/incorrect schema definition as it was old and barely used for us.

I'd go back and say that this PR is ready for review/merging when possible.

Sigh, nevermind. I guess I don't fully understand how this all gets generated together, as in my test case, my enums aren't being placed anywhere, only referenced by enum name in my output TS file, but they are there without my new flag. This is unfortunate for me as I'm nearing this great tool because I can't manage to make it work for what I need to do with it.

cdietschrun avatar Oct 17 '19 21:10 cdietschrun

@cdietschrun thank you so much for adding this! Do you need any help with the requested changes by @bcherny?

RXminuS avatar Feb 14 '20 16:02 RXminuS

I can probably pick this up, if you don't mind @bcherny

nabati avatar Apr 26 '21 09:04 nabati

I would love if this feature made it in!

erik-am avatar Aug 16 '21 14:08 erik-am

@cdietschrun @bcherny I'm going to pick this up over the weekend if there are no objections

ghost avatar Aug 17 '21 14:08 ghost

Any update on this PR? Worthless to mention the benefits of this

overbit avatar Nov 28 '22 14:11 overbit