Ask HN: What are the best API generators you know?

7 points by whiskey14 ↗ HN
Supabase seems really close to what I'm enivisioning but it's not quite there.

Ideally I want something where: - I can drop in simple db schema outlining relationships - Generates models in a backend (flask, django or anything else) - Has UUID in postgres by default - Can create endpoints by specifying from open API schema

Anyone know of anything close to this?

10 comments

[ 0.24 ms ] story [ 34.9 ms ] thread
Swagger Codegen is more barebones but supports a lot of languages.
Hasura for GraphQL, Postgrest for REST
Don't love Python but absolutely Django
Django Rest framework and django admin are a god sent for getting a quick mvp app up and managing the data.
I always write my own code generators. It’s fun, it doesn’t take that much work, and the results are exactly what I want and need. I have developed business applications where 80% of the code was auto generated. All I had to write was the core business logic and a bit of special case UI code. Code generation is a real super power.
This sounds really interesting. Do you have any examples on GitHub that you could share?
Unfortunately not. It is all proprietary. However the key idea is simple enough: specify your domain model using JSON or your own parsed language (what I do). Read the specification and generate C++/C#/Java/Typescript/… code. That’s it.

There are many examples out there you can look at. Google buffers for example. The generator I implemented at work started out doing something like Google buffers 5 years before Google buffers became a thing. But it has then been expanded massively by colleagues to do so much more. It has saved man years of programming work and has removed a lot of the boring repetitive work. I think that is why it was become so popular among colleagues. It is the first thing they install when starting a new project.

I'm conflicted about this. I've worked with code generators built by coworkers with a great many years of experience. There are two key parts of the learning curve when approaching this situation. First, learning to use the code generator for simple tasks as intended. Second, extending or modifying it as needed to deal with bugs or unanticipated use cases.

It can take a couple of years to get to that point, and it's difficult because a bespoke code generator won't have the resources that an open source, widely adopted library will.

Also, you'll be responsible for building whatever connectors you need, as opposed to more popular libraries making plugins or expanding their capabilities.

That said, when done right, they can be extremely powerful and well suited to their particular use cases.

I introduced a code generator at work and it was quickly adapted and modified/upgraded by colleagues. It started out as a simple protocol generator (think Google buffers but 5 years before Google buffers became a thing) and was then expanded over the years by a number of people to handle a lot more (databases, model specifications etc.) generating C++, CMake, Typescript, Java, and C# code. There is no open source generator out there that can handle all the things this tool does. It has now become the first thing people install when starting new projects. I think the key to its success is that the code generator itself is really simple. So you can figure out how to improve it in no time. Also, the generated code is super pretty. It even includes comments explaining what the generated code does. This was a design choice by me to ensure that people trusted the generated code. Without it I don’t think the generator would have been successful. If people can’t understand the generated code then they don’t trust it and is less likely to use the generator.