Closed pdfowler closed 11 months ago
@xddq I'm new to the project (obviously) and wanted to share what I have done to handle a number of edge cases that I encountered while running our models through it. LMK what you think and how you'd like to proceed. Seriously appreciate your efforts here!
@pdfowler Hey!
Thanks for the effort! Glad that you want to contribute your work back into the project!
pipe the json-schema into ts2typebox
I assume you mean schema2typebox :p
You bring up a valid point with enums being somewhat controversial in "modern typescript". I rarely see or use them as well, and rather default to unions. I would say we could default to implement enums as unions. This will make the codegen easier to reason about and the generated code more "typescript like". I would advocate against adding additional knobs and toggles for generating enums. We can think about adding them in case people raise issues with valid/valueable arguments for them.
Interesting. We should add support for these! I didn't know you could use these in JSON schemas and therefore they were not be implemented. If I am seeing it correctly, it is not defined in the draft-06 which I did use as baseline. However, it is specified in draft-07.
If you want me to help you implement these features, please provide additional information, probably best via seperate issues. There is an issue template, but the info basically boils down to:
Again, thanks for your post! Open to thoughts and suggestions : ]
I think we're well aligned on all points. Let me finish my current push and then I'll get into the details here.
@pdfowler hey!
Just checking by since it has been two weeks now. What is your plan or your next steps here? It's okay if you don't have the time or simply don't want to continue. I just want to know what's up.
Creating issues as described in the previous post would still help me tremendously in fixing them, if you got time for that!
This has been part of a much bigger push and I've been down in the weeds getting all of our service types migrated to a new typed client. I'm coming up for air now and will take a pass at breaking things up this week and next.
I'll be starting with the union types, and moving ahead from there
@pdfowler Alright, awesome!
I will probably add support for typebox 0.30 as well as clean up the code base (a little bit) in the next weeks. But it should not get into the way :]
Closing in favor of other (discrete) PRs
Summary
I'm in the process of migrating our mongoose schemas to TypeBox as a part of our recent upgrade to Feathers v5. Our data model contains over 100 mongoose schemas with a large variety in usage including child schemas, discriminated types, enums, and much more. This PR is the end result of my local updates to the library to get our schemas generated
Process
I wrote a crude ts script to either take a service name, or map over all service directories. For each service it does the following:
ts2typeboxschema2typebox
services/${serviceName}/schema.ts
Changes
type: ['string', 'null']
)TODO