ecyrbe / zodios

typescript http client and server with zod validation
https://www.zodios.org/
MIT License
1.71k stars 46 forks source link

[Feature Request] Generate schemas dynamically from request #558

Closed brettdh closed 7 months ago

brettdh commented 1 year ago

I have an API that adheres to the jsonapi.org spec, and I'm attempting to describe it with Zodios. One semantic detail that's proven hard to capture is sparse fieldsets, where the set of fields returned is controlled by a query parameter. Since response schemas are static in Zodios when defining an API, I end up having to mark all fields as .optional() if I want to exclude them from the fieldset in any request context.

I haven't thought this all the way through, but I wonder if there's a way to enable schema refinement based on the input parameters to a query. I'm very new to Typescript and Zod, so I thought I'd create this issue fairly open-ended and see if it sparks any ideas (or reveals any workarounds).

stale[bot] commented 12 months ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

brettdh commented 12 months ago

Still interested in feedback here.

stale[bot] commented 11 months ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

brettdh commented 11 months ago

Stiiiiill interested in feedback.

stale[bot] commented 10 months ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

brettdh commented 10 months ago

🏓

stale[bot] commented 9 months ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

brettdh commented 8 months ago

Last try. 🏓

Ackincolor commented 8 months ago

Maybe using a zodios plugin : here

In the response object, get requested fields, and return a object with filtered keys

stale[bot] commented 7 months ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.