Documents

Output

Where and how the documents are written - disk, file name, JSON or YAML, standard output.

Each document is written on a Laravel filesystem disk, as readable JSON or as YAML.

Disk, directory and file

config/openapi.php
'output' => [
    'disk' => null,              // the default disk
    'directory' => 'openapi',
    'file' => '{document}.json',
    'format' => 'json',          // or 'yaml'
],
KeyEffect
diska disk of config/filesystems.php; null for the default disk
directorythe directory on the disk; empty for its root
filethe file name; {document} is the name of the document, {locale} its language
formatjson, or yaml (needs symfony/yaml)

A document overrides any of them in its own output. The published v1 does:

config/openapi.php
'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:

config/openapi.php
'output' => [
    'disk' => 'public',
    'directory' => 'docs',
    'file' => '{document}.json',
    'format' => 'json',
],
Terminal
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

Terminal
composer require symfony/yaml

Set format to yaml and give the file a .yaml extension, or choose the format for one run:

Terminal
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:

Terminal
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.