#Automated Typescript client codegen with OpenAPI?

1 messages · Page 1 of 1 (latest)

rugged mica
#

I use the Remix backend as a thin backend-for-frontend, while the "heavy lifting" (data access, business logic, etc...) I prefer to do in a .net core WebAPI project.

The WebAPI project generates an OpenAPI spec, which currently I am converting to a Typescript Client using a desktop tool, NSwag Studio. It isn't perfect, e.g. I need to manually change window to global every time I regenerate the client as it wasn't designed with polyfilled server-side fetch in mind.

My question: Is there a pain free way to implement automated client code generation into my Remix project? Not necessarily using NSwag as I'm sure there are superior Typescript client generators available. Ideally, I can just edit endpoints in my WebAPI project and have Remix (Vite???) rebuild the client code on the fly. Thanks

valid zodiac
pseudo lance
#

I use that as well. However, I have to stick with version 6, because the authors decided that with version 7 it will only generate the types for consumers of the API. I use it to validate that my APIs are producing the documented data format. This mostly comes into play when some fields are marked as readonly or writeonly. https://github.com/openapi-ts/openapi-typescript/issues/604

GitHub

See https://swagger.io/docs/specification/data-models/data-types/#readonly-writeonly These modifiers are on specific properties and allow for a single definition to be used in both read & write...

rugged mica
#

Ah, interesting @pseudo lance . I am in fact using read-only on my ID fields in an attempt to avoid defining multiple models in my webapi (write + read + database entities + mapping code... 💀) so thanks for the heads up that there are potential issues to look out for.
Edit: I've looked into this a bit more and it shouldn't be a problem for me as I'm only using the typescript models in client code 🤞

paper crypt
#

@rugged mica I went down the OpenAPI route with a .NET backend for awhile, but doing a REST API even with OpenAPI help is not very efficient [development time wise] for what is basically RPC. I recently switched to gRPC and that is well supported in .NET and for the typescript side I use bufbuild. The Protobuf services and messages are fairly easy to define and both client side and server side code is generated.

rugged mica
#

Thanks @paper crypt I really should look into that too. I'm primarily looking for a frictionless developer experience.

soft canopy