r/dartlang • • Oct 24 '26

Package SwaggerUI/OpenAPI specs generation for dart backends.

Switching to other languages in order to write backend applications because there's a clear lack availability of the tools around that in dart ecosystem.

One such problem I kept hitting: there is no standard package like (swag for go) to generate OpenAPI specs and Swagger UI for Dart backends. Thinking about solving this problem I started working on Axle(v0.2 out now).

The core idea is small. Almost everything lives in one package, axle_core: the annotations, the OpenAPI 3.1 document model, and a tiny serving contract called AxleDocs. No framework imports, no runtime dependencies. A CLI reads your annotated Dart source with package:analyzer and emits the spec, so no build_runner and no runtime registry. Then thin adapters translate AxleDocs into framework responses. I published adapters for Serverpod 4, Shelf, and Relic, but they are intentionally boring on purpose, anyone can write one for another framework without touching core or the CLI.

It gives you openapi.json, openapi.yaml, Swagger UI assets, and an AOT-safe const string. It handles security schemes, response headers, cookies, multiple media types, multipart uploads, parameter constraints, and oneOf schemas. If a route references a security scheme that doesn't exist, generation fails instead of emitting a broken contract.

Docs are at https://axle.infms.dev if you want the full picture. There is also an agent skill that walks through setup end to end:

npx skills add infm5/axle --skill axle-openapi-setup

If you've felt the same backend-in-Dart pain, I'd genuinely like to hear what would make this useful to you. Advice, criticism, all welcome.

9 Upvotes

4 comments sorted by

1

u/AhmedZNOUDA Oct 24 '26

The "generation fails instead of emitting a broken contract" stance is the right one, which is why I'd push it a bit further in one place. The docs say global json_serializable rename rules aren't supported. So a DTO with u/JsonSerializable(fieldRename: FieldRename.snake), or field_rename set in build.yaml, gets a spec that says createdAt while the server sends created_at, and nothing complains. Since you already resolve the class with the analyzer, failing with exit 65 when you see that would match the rest of the tool.

The other drift spot is the path itself. '/todos/:id' in u/ApiRoute and the router registration are two strings someone has to keep in sync, and with shelf_router it's written as <id>, so they don't even look alike. A small test that walks the paths in axleOpenApiJson and checks each one reaches a real handler (anything but a 404) would catch a renamed route in CI, and it fits the contract diff item on your roadmap.

1

u/Infamous-404 Oct 24 '26

Realised this and already working on the fix. If you find anything else that is also broken do let me know.

1

u/mateusfccp Oct 25 '26

I hope you succeed. OpenAPI generation on Dart today is terrible. Many packages, no one is great, most are maintained like crap.

2

u/Infamous-404 Oct 25 '26

Thanks for the kind words, do give it a try and let me know your opinions