API client (lib/api/)
The Dart API client at lib/api/ is generated, not hand-written. It is produced
by openapi-generator (dart-dio generator) from
SchulyBackend's OpenAPI 3.0 spec, served
at /openapi/v1.json. The app depends on it as a local package via a path: reference
in pubspec.yaml (schuly_api).
Regenerating
The backend must be running and reachable at http://localhost:5033. Then:
bun run apigen # regenerate from http://localhost:5033/openapi/v1.json
bun run apigen:local # same target, explicit local alias
apigen chains three steps:
- Generate —
openapi-generator-cli generate -g dart-dioagainst the live spec (http://localhost:5033/openapi/v1.json), output intolib/api(pubName=schuly_api,pubLibrary=schuly_api). - Patch (
apigen:patch) — rewriteslib/api/pubspec.yaml's SDK constraint. The generator resets it to'>=2.18.0 <4.0.0', which breaks the build due to a part-file language-version mismatch. The patch replaces it with^3.10.0. Implemented as abun -eone-liner so it runs identically on any shell. - Build (
apigen:build) —cd lib/api && dart pub get && dart run build_runner build --delete-conflicting-outputsto produce the.g.dartserialization code.
Notes
openapi.jsonis gitignored — always regenerate from the running backend rather than committing a local copy of the spec.lib/api/**is excluded fromflutter analyze(seeanalysis_options.yaml), so generator output never trips lint checks.- The generated
.g.dartfiles are produced bybuild_runner; if they go stale, re-runbun run apigen(or just theapigen:buildstep) to refresh them.
Related
- Development setup — installing deps, running the app.