-
-
Notifications
You must be signed in to change notification settings - Fork 89
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
feature: deduplicate schemas in generated OpenAPI #366
Comments
|
On further look, it seems like |
Let's say you have a Post entity that's returned from a bunch of endpoints. Repeating that entity in the OpenAPI schema at every endpoint will create a large .JSON file. It probably also makes it harder for downstream tooling to organize types (would end up with Post1 Post2 etc) - this is one advantage of schema-first codegen driven development right now, there is clean code available when you e.g. jump to definition which takes you to a nicely-named interface
Check out the OpenAPI specification's components: https://swagger.io/specification/#:~:text=Specification%20Extensions.-,Components%20Object,-Holds%20a%20set
Perhaps referential equality could be used to output refs. OR, change the library's API to allow specifying shared schemas.
EDIT: Referential equality probably wouldn't work; even if the Zod schema is referentially equal (which it may not be if the user defines it twice for some reason),
@anatine/zod-openapi
probably doesn't create referentially equal objects. The objects would have to be deduped by content (perhaps JSON.stringify if it can be trusted that the objects are stringifiable and deterministically ordered). This kind of magic seems like it'd be brittle.The text was updated successfully, but these errors were encountered: