Output
Each document is written on a Laravel filesystem disk, as readable JSON or as YAML.
Disk, directory and file
'output' => [
'disk' => null, // the default disk
'directory' => 'openapi',
'file' => '{document}.json',
'format' => 'json', // or 'yaml'
],
| Key | Effect |
|---|---|
disk | a disk of config/filesystems.php; null for the default disk |
directory | the directory on the disk; empty for its root |
file | the file name; {document} is the name of the document, {locale} its language |
format | json, or yaml (needs symfony/yaml) |
A document overrides any of them in its own output. The published v1 does:
'documents' => [
'v1' => [
// openapi/openapi-v1.json
'output' => ['file' => 'openapi-{document}.json'],
],
],
Serving the document publicly
Write it on the public disk to serve it as a static file:
'output' => [
'disk' => 'public',
'directory' => 'docs',
'file' => '{document}.json',
'format' => 'json',
],
php artisan storage:link
php artisan openapi:generate # storage/app/public/docs/v1.json, served at /storage/docs/v1.json
The package does not render the document: point Swagger UI, Redoc, Scalar or any other viewer to the file.
YAML
composer require symfony/yaml
Set format to yaml and give the file a .yaml extension, or choose the format for one run:
php artisan openapi:generate --format=yaml
--format replaces the configured format, and the extension of the file follows it (v1.json becomes v1.yaml).
Standard output
--stdout prints the document instead of writing it, for a pipe or another tool. It takes one document (and one
language); the diagnostics go to the error output:
php artisan openapi:generate --document=v1 --stdout > openapi.json
php artisan openapi:generate --document=v1 --stdout --format=yaml > openapi.yaml
Dry run
--dry-run generates and validates every document without writing anything. Combined with --strict, it is the check
to run in CI; see Continuous integration.
Validation
Before it is written, every document is validated: by the
rules of OpenAPI Writer, and against the official OpenAPI JSON
Schema when opis/json-schema is installed. A violation of severity error fails the document (it is not
written); the others are warnings, on which --strict fails.