News for hackers. Stuff that matters.
Re:OpenAPI Generator allows generation of API client librari... by igor47 on Sunday October 16, 2022 @01:09AM (#33221188)
I'm also curious about the reverse direction -- can I generate an openAPI spec from my typescript Api? I'd rather write code than schemas.
Re:OpenAPI Generator allows generation of API client librari... by jayp on Sunday October 16, 2022 @01:53AM (#33221365)
This is the best project I’ve found to that for that - https://github.com/lukeautry/tsoa. Uses decorators mainly.

If there are other such projects, please share.

Re:OpenAPI Generator allows generation of API client librari... by aserafini on Sunday October 16, 2022 @02:01AM (#33221395)
This is exactly how FastAPI/Pydantic in the Python ecosystem works (and also in Django-ninja for Django).

You compose types representing your request and response shape. Those types validate the API request and it’s response, and also generate the OpenAPI.

Even slight drift between API spec, docs and actual behaviour is impossible in this setup, I couldn’t go back to working any other way!

Re:OpenAPI Generator allows generation of API client librari... by twelve40 on Sunday October 16, 2022 @02:12AM (#33221441)
can only speak for python on the backend, but have been using auto-generated schema from Django, and an auto-generated typescript client for it on the front end for years now.
Re:OpenAPI Generator allows generation of API client librari... by remoquete on Sunday October 16, 2022 @02:28AM (#33221518)
Sure, though that goes against the API first design principles that OpenAPI seeks to enable. It also results in poorly documented, often garbled OpenAPI specs. Code-generated specs simply cease to be effective as contracts.

https://swagger.io/resources/articles/adopting-an-api-first-...

Re:OpenAPI Generator allows generation of API client librari... by rattray on Sunday October 16, 2022 @09:07PM (#33228789)
This is something we hope to build relatively soon at Stainless, inspired by Stripe's in-house Ruby API DSL. I think what you're asking for is the right approach.