r/elixir • u/Reckless_Dev1045 • 10d ago
Infusion - generates elixir SDKs from openapi specs, would love feedback
hey all, been working on this for a bit and finally put it on hex so figured i'd share.
it's called infusion. you give it an openapi spec and it writes a full elixir SDK for that API. structs for the schemas, a function per endpoint, retries, pagination, streaming, all that.
reason i started is pretty simple. most API companies generate their SDKs with stainless or fern or speakeasy now and none of them do elixir, so whenever a new API comes out we get nothing and end up writing http calls by hand. i tried the two elixir generators that already exist on openai's spec first and one crashed and the other turned union types into empty structs, so yeah.
using it looks like this:
{:infusion, "~> 0.2", only: :dev, runtime: false}
mix infusion.gen https://raw.githubusercontent.com/github/rest-api-description/main/descriptions/api.github.com/api.github.com.json --name GitHub

that gives you the whole github api (around 1300 endpoints) in like 16 seconds, and then you can just do
{:ok, repo} = GitHub.Repos.get("elixir-lang", "elixir")
and get a proper struct back. this is it hitting the real github api:

list endpoints also get an `_all` version that pages lazily, so you can just Enum over every repo in an org without thinking about pages:

streaming was honestly the most fun part. here it's reading wikimedia's live feed of wikipedia edits through a generated SDK:

so far i've tested it on openai, stripe, github, twilio and cloudflare's specs and they all compile with zero warnings (cloudflare's is huge, almost 3800 endpoints). github and wikimedia are tested against the real APIs, the rest only against stubs for now since i don't have keys for everything.
0.2 came out yesterday and the main thing is the names now match the official SDKs, so it's `OpenAI.Chat.Completions.create` like in their python one, not some weird generated name.
still rough in places. some nested objects come back as plain maps instead of structs, and there's no config file yet for renaming stuff. next thing i want to do is publish an actual SDK on hex, probably twilio since the current elixir client hasn't been updated in a while.
if you try it on a spec and it breaks please open an issue with the spec, that helps a ton. also curious which API you'd want an elixir SDK for first.
5
u/bitztream 10d ago
Hi! Any advantages over https://hex.pm/packages/oapi_generator ?
1
u/mlambie 10d ago
What’s going on with the timestamps in the wiki streaming screenshot? Field’s are mixed up.
2
u/rynam0 10d ago
Excellent idea. Thanks for posting.