Apivalk instance your app uses, then call the generator. That way routes, middleware, and auth are always in sync with production.
1. Extract bootstrapping
You want a single factory that bothpublic/index.php and your generator script can call. If you already have one per Configure Apivalk → extending your configuration, skip this step.
2. The generator script
3. Regenerate docblocks
TheDocBlockGenerator walks your controllers and rewrites request classes (and resource classes) with @property / @method annotations plus typed Shape/ classes. Running it is identical in spirit: boot Apivalk, point at your controller directory, run.
Because DocBlockGenerator uses its own ClassLocator, you can invoke it without a full bootstrap — but running it after you’ve loaded the router guarantees you’re operating against the exact same tree the framework saw.
- For every non-resource request class: a rewritten docblock with
@methodannotations and shape classes in…/Request/Shape/. - For every
AbstractResourcesubclass touched by a resource controller:@propertyannotations on the resource so$animal->name,$animal->statusautocomplete. - For every
AbstractListResourceController: a generated (or updated)*ListRequestclass with@method sorting()/filtering()/paginator()tied to typed shape interfaces.
4. Wiring into CI
Two things you want to guard against:- Stale
openapi.json. If the file is committed, fail CI when regenerating produces a diff. If it isn’t committed, publish it as a build artifact. - Stale docblocks. Same pattern —
git diff --quietafter regeneration.
5. Serving the spec to Swagger UI
The generator emits a plain JSON string; serve it from wherever. A one-endpoint controller works fine:Related
- OpenAPI Generator — constructor arguments and object model in detail.
- DocBlock Generator — what the generator rewrites and which shapes it emits.
- Resource CRUD how-to — the docblock generator is especially valuable for resources, where the request shapes don’t exist as hand-written classes.