Workflow

Diagnostics

Read what the generator did not understand, route by route, and inspect the operation it built for one route.

The generator never stops on code it does not understand: it leaves the part out and records a diagnostic. Reading them is how you find what to fix: a missing return type, a resource that fails on its sample, a rule nobody maps.

Levels

LevelMeaningShown
infosomething was left out or guessed, the document is still right (an unknown rule, an untyped JsonResponse)with -v
warningthe document is incomplete or was changed (a resource that failed, a renamed operation id)by default
errorthe document cannot be written (a feature its version cannot write, an invalid document)always, even with -q

A document with an error is not written, and openapi:generate exits with 1. With --strict, a warning fails the document too.

Reading the output

Diagnostics are grouped by route, those of the document as a whole first. Each line gives the level, the stage (discovery, operation, request, response, sampling, pass, writing, validation) and the message:

$ php artisan openapi:generate

  v1 .................................................................. FAILED
  Document
    error writing: [unsupported] /tags/1/parent: parent needs 3.2.0
  GET /api/teams/{team}/users
    warning pass: operationId GET:users.index already used, renamed GET:users.index_2

Here, a #[Tag(parent: …)] cannot be written in a 3.1 strict document (write 3.2, set vendor_extensions: redoc, or strict: false), and two operations had the same id.

Terminal
php artisan openapi:generate -v     # infos too
php artisan openapi:generate -q     # errors only

Inspecting one route

openapi:inspect shows the operation the generator built for one route, after every pass, and every diagnostic about it, whatever the verbosity:

$ php artisan openapi:inspect books.store

  POST /api/books ............................................................
  Operation id .............................................. POST:books.store
  Summary ........................................................ Add a book.
  Description ......................................... The price is in euros.
  Tags .................................................................. Book
  Security .......................................... sanctum | session + xsrf
  Body (required) ........................................... application/json
  201 Created: application/json ..............................................
  401 Unauthenticated: application/json ......................................
  422 Validation failed: application/json ....................................

The route is its name (books.store), its URI (api/books/{book}, every method), or its method and URI ("GET api/books"). --document= chooses the document, the first one by default.

A route that is not in the document is reported:

$ php artisan openapi:inspect api/internal/stats

   ERROR  api/internal/stats is not in the document v1.

It is filtered by routes.include or routes.exclude, marked #[Exclude], or is a redirect, a view or an internal route; see Routes & operations.

Common diagnostics

MessageFix
no response extractor for …the return type is not one the generator reads: type the return differently, or declare #[Response]
JsonResponse without #[Response], body described as a free objectdeclare the body: #[Response(type: 'array{…}')]
cannot run …Resource::toArray(): …the resource failed on its sample: give the model a factory, @property tags or casts, or a #[ResourceFactory]
the factory of … failed: …the factory of the model throws: fix it, or give the resource a #[ResourceFactory]
operationId … already used, renamed …_2two operations have the same id: name the routes, or use method_name
[unsupported] …: … needs 3.2.0the version of the document cannot write a feature: see Configuring a document

In your own extensions

An extension adds diagnostics through the context instead of throwing:

use Ark4ne\OpenApi\Context\Stage;

$context->diagnostics->warning(
    Stage::Request,
    'the phone rule needs a region',
    $operation->route->label(),
);

See Extending.