Skip to main content
Apivalk doesn’t ship a CLI binary — the generators are plain PHP. The pattern is: boot the same 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 both public/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

Make it executable and run it:

3. Regenerate docblocks

The DocBlockGenerator 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.
What you get:
  • For every non-resource request class: a rewritten docblock with @method annotations and shape classes in …/Request/Shape/.
  • For every AbstractResource subclass touched by a resource controller: @property annotations on the resource so $animal->name, $animal->status autocomplete.
  • For every AbstractListResourceController: a generated (or updated) *ListRequest class with @method sorting() / filtering() / paginator() tied to typed shape interfaces.
Run both scripts together as a single build step:

4. Wiring into CI

Two things you want to guard against:
  1. 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.
  2. Stale docblocks. Same pattern — git diff --quiet after regeneration.
Sketch:

5. Serving the spec to Swagger UI

The generator emits a plain JSON string; serve it from wherever. A one-endpoint controller works fine:
Or regenerate on-the-fly in a non-production environment:
The runtime cost is one pass over every route and its request/response documentation — fine for dev, measurably expensive once you’re over a few hundred routes. Cache the output to disk in anything resembling production.
  • 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.