Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

But that’s the whole point of something like this. You do it once and dynamically generate everything else downstream. So change it once in the zod schema and it propagates with type checking through your entire app.

The zod schema becomes the source of truth.



Does it? I don't use Zod on my JVM backend. How would I?

In addition to using OpenAPI, I generate TS interfaces from my data classes in a Gradle task.


One way might be to convert the Zod schema to a JSON schema and then to Java? I found a library to do that. [1] But I don’t know how lossy that would be. A purpose-built converter might do better.

[1] https://jsontypedef.com/docs/java-codegen/


Looks like there are libraries for generating zod schemas from OpenAPI definitions and others.

https://zod.dev/ecosystem?id=x-to-zod


Does zod really support that? What if the code base start out with a go backend and a TS/JS component is only added later? It would be nice if the source of truth was a bit more language agnostic.


Better to use something like OpenApi and generate your zod schema using it.


And thus is born the 15th IDL for cross language API calls...


Does it?

Most Go, Java, and Python APIs are practically all Swagger based.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: