fastify-type-provider-json-schema-to-ts icon indicating copy to clipboard operation
fastify-type-provider-json-schema-to-ts copied to clipboard

Accept FromSchemaOptions in plugin definitions for references

Open bcomnes opened this issue 1 year ago • 1 comments

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 or next?

Checklist

bcomnes avatar Sep 16 '24 22:09 bcomnes

I'll update this for 4.0. Is this (or similar) something people would be willing to land?

bcomnes avatar Sep 30 '24 17:09 bcomnes

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.

mcollina avatar Oct 17 '24 16:10 mcollina

Yeah. Been playing with it inside of a fork. Will update

bcomnes avatar Oct 17 '24 16:10 bcomnes

This would be a nice addition, currently working it around by using .withTypeProvider, but it would be nice sugar to have it in the plugin definition instead.

mikaelkaron avatar Dec 17 '24 17:12 mikaelkaron

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.

bcomnes avatar Dec 17 '24 17:12 bcomnes

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 @bcomnes/fastify-type-provider-json-schema-to-ts if anyone wants to play with it in the meantime.

bcomnes avatar Dec 18 '24 23:12 bcomnes

I'll try the fork in my project and drop feedback here if anything breaks.

mikaelkaron avatar Dec 19 '24 07:12 mikaelkaron

Sorry @bcomnes, this'll need a rebase to resolve conflicts due to migrating this repo from standard to neostandard for linting. :)

Fdawgs avatar Dec 19 '24 10:12 Fdawgs

Ok @Fdawgs should be good to go. I also simplified the README.md to reduce redundancy in some of the examples. I also added some migration examples to the PR to link from the changelog.

bcomnes avatar Dec 19 '24 19:12 bcomnes

~~@bcomnes where was that fork published ?~~

Never mind. I installed it from bcomnes/fastify-type-provider-json-schema-to-ts#references-in-helpers.

Works great!!

mikaelkaron avatar Dec 22 '24 12:12 mikaelkaron