News for hackers. Stuff that matters.
Re:Show HN: Instant API – Build type-safe web APIs with Java... by ushakov on Thursday October 26, 2023 @06:05AM (#38023690)
…or just use Zod?
Re:Show HN: Instant API – Build type-safe web APIs with Java... by Ciantic on Thursday October 26, 2023 @07:25AM (#38024136)
And if you like Zod, you might as well use this: https://github.com/asteasolutions/zod-to-openapi

It converts Zod types to OpenAPI specification.

Re:Show HN: Instant API – Build type-safe web APIs with Java... by vmfunction on Thursday October 26, 2023 @07:39AM (#38024247)
Or json schema, this https://www.npmjs.com/package/zod-to-json-schema

Json schema is more universal, and it can be used in .NET, Java, etc.

Re:Show HN: Instant API – Build type-safe web APIs with Java... by 9dev on Thursday October 26, 2023 @10:49AM (#38026333)
Yeah, that’s what I was thinking of. There are a few alternatives though, so I referred to existing tooling in general.
Re:Show HN: Instant API – Build type-safe web APIs with Java... by madeofpalk on Thursday October 26, 2023 @11:52AM (#38027300)
I don't like writing type definitions with zod's DSL.

I want to write definitions in the "first party syntax" - which both JSDoc and Typescript types are - and have everything else generated out from that.

Re:Show HN: Instant API – Build type-safe web APIs with Java... by purplerabbit on Thursday October 26, 2023 @02:36PM (#38029880)
I like the sentiment, but you’ve gotta admit that being able to skip the “generation” step has its benefits
Re:Show HN: Instant API – Build type-safe web APIs with Java... by madeofpalk on Friday October 27, 2023 @06:25AM (#38036768)
The only way to can skip that generation is if the zod type is your primary schema, which is only possible if your API is in javascript.
Re:Show HN: Instant API – Build type-safe web APIs with Java... by yencabulator on Thursday October 26, 2023 @04:46PM (#38031485)
Everybody seems to want that, except for the people who work on Typescript, who argue it'd be the wrong tool.

Typescript's types simply aren't able to provide input validation, both because they don't exist at runtime and for lack of power ("number must be 0..10").

At least with Zod, you also get Typescript types, from the same schema.

Re:Show HN: Instant API – Build type-safe web APIs with Java... by madeofpalk on Friday October 27, 2023 @06:14AM (#38036691)
My problem is how you declare the schema. I think the Typescript's teams stance is valid (though, I would love for them to sponsor/release an additional project for more runtime validation using typescript).

I don't want to declare my schema with zod's DSL. I'll either use an openapi spec from elsewhere and generate artefacts from that, or declare them with Typescript and... generate validation from them.