React API hooks generator

Aug 2021

A utility to generate JS functions and React Query hooks for API comunication.

The apps which we were building in Soincon were using the same pattern - a client in React queries an API generated from Java Spring. There was always the same code which was necessary to write. I saw that we have a nice Open API specification about our endpoints and thought that it would be nice programatically generate a functions which would query those endpoints. It could also suggest the necessary parameters which every endpoint expects and most importantly generates types of the DTOs for Typescript. We were also using react-query and I thought that it would be nice to generate also a hook for every endpoint.

After writing a proof of concept I've found out that somebody made a similar library. I've decided to fork it (because of some internal needs) and implement the missing parts.

Now every new project uses this generator and it saves hours and hours of coding and it reduces possible errors which might be introduced if the code would be written manually.

Tha plan is to implement a plugin system to the forked library so it will be abstract enough so everybody could use it. The specific needs would move go to a custom plugins.

Repo: https://github.com/soincon/swagger-to-react-query