-
-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add ValidatorSchemaOptions and SerializerSchemaOptions #103
base: main
Are you sure you want to change the base?
Conversation
7b38ce9
to
3dc0e8a
Compare
I'll update this for 4.0. Is this (or similar) something people would be willing to land? |
3dc0e8a
to
8efd6bc
Compare
I'm ok to land this in v4. Can you update this? Sorry for the long wait, it ended up at the bottom of my long GH notification queue. |
Yeah. Been playing with it inside of a fork. Will update |
This would be a nice addition, currently working it around by using |
Sorry to be slow on this PR, if anyone wants to beat me to it, feel free. The main hangup I'm having here is figuring out an API that is acceptable. I think given the new changes in fastify type providers, the generic should accept two options objects, one for the serializer and one for the validator. In practice, I've found that I need to pass serialize options to one side and not the other. |
8efd6bc
to
91e9b5f
Compare
Ok, I refactored a bunch of discoveries I made while using this. I think this is ready to go but open to feedback and objections regarding the breaking change. cc @mcollina this is ready to go, @Fdawgs as the most active maintainer and also @kalvenschraut as the original contributor of these options. I'm quite happy with how this turned out, especially when used with the async plugin provider. Very clean! Published my fork at |
BREAKING CHANGE: Use named type arguments and also pass ValidatorSchemaOptions and SerializerSchemaOptions to their respective type provider.
91e9b5f
to
72a5cfa
Compare
I'll try the fork in my project and drop feedback here if anything breaks. |
Original Messsage
I would like to propose that the Plugin definition of this type provider support accepting
FromSchemaOptions
somewhere in the generics argument, so that I can pass in schema references on routes that have external references.Is that something you are open to? Feedback welcome. I will add test shortly. I just wanted to open up for some feedback in terms of implementation.
Also, do you want me to target
latest
ornext
?This patch introduces two new options for the JsonSchemaToTsProvider:
ValidatorSchemaOptions
SerializerSchemaOptions
These are both
FromSchemaOptions
from thejson-schema-to-ts
package.Most importantly, they let you customize the
references
allowing for named schema references, and secondlydeserialize
which lets you customize how things are serialized and deserialized from a type perspective. See the updated examples of when this is useful.They can be passed to the type provider and the plugin providers.
Secondly, since you don't always need to set these, and there are 2 more options, all meta type arguments have been shifted to named arguments instead of unnamed positionals.
I'm happy to undo this second part, but in my experience named arguments for a complex options object like this tends to be more clear and less verbose and more explicit when you want to skip arguments you don't want to set.
I also updated the readme and tests.
BREAKING CHANGE: This is a significant breaking change that requires consumers to update any code that uses type options anywhere.
Checklist
npm run test
andnpm run benchmark
and the Code of conduct