Configuring a document
A document is one entry of documents in config/openapi.php. Its key is its name: --document=v1 on the command
line, {document} in the name of its file.
'documents' => [
'v1' => [
'openapi' => '3.1.2',
'strict' => true,
'vendor_extensions' => 'none',
'info' => [
'title' => env('APP_NAME', 'API'),
'version' => '1.0.0',
'summary' => null,
'description' => null,
'terms_of_service' => null,
'contact' => [
'name' => 'API team',
'url' => 'https://example.com',
'email' => 'api@example.com',
],
'license' => ['name' => 'MIT', 'identifier' => 'MIT'],
],
'self' => null,
'external_docs' => [
'url' => 'https://docs.example.com',
'description' => 'The guides',
],
'servers' => [],
'routes' => ['include' => ['api/*']],
'security_schemes' => [],
'security' => [],
'use_references' => true,
'output' => ['file' => 'openapi-{document}.json'],
'extensions' => ['x-api-id' => 'books'],
],
],
Every key is read when a command runs. An invalid one fails the command with the key, the expected value and the received one:
openapi.documents.v1.openapi: expected one of 3.0.0, 3.0.1, 3.0.2, 3.0.3, 3.0.4, 3.1.0, 3.1.1, 3.1.2, 3.2.0, got "4.0"
OpenAPI version
openapi is the version written: 3.0.0 to 3.0.4, 3.1.0 to 3.1.2, or 3.2.0. The default is 3.1.2.
The generator always describes the latest model;
OpenAPI Writer converts what the version needs: nullable and exclusiveMinimum for 3.0, const as a one-value enum, and so on. What a version cannot write at all
depends on strict:
| Feature | Needs | strict: true (default) | strict: false |
|---|---|---|---|
webhooks | 3.1 | fails | dropped, with a warning |
Tag.parent, summary and kind of a tag, $self, Server.name | 3.2 | fails | dropped, with a warning |
the query HTTP method, the querystring parameter, itemSchema | 3.2 | fails | dropped, with a warning |
vendor_extensions: redoc writes some of them as Redoc extensions instead: x-webhooks before 3.1, x-tagGroups
(the tag groups) before 3.2.
query method and $self.Info
info gives the Info Object: title and version are required; summary and license.identifier are written from
3.1. description is CommonMark; integrations may append notes
to it.
Servers
The servers of a document are its servers, or the global servers when it has none:
'servers' => [
[
'url' => 'https://{env}.example.com',
'description' => 'The API',
'name' => null, // written from 3.2
'variables' => [
'env' => [
'default' => 'production',
'enum' => ['staging', 'production'],
'description' => 'Environment',
],
],
],
],
The global default is APP_URL. A route with a domain gets its own server on its operation; see
Routes & operations.
Self and external documentation
self: the public URI of the document, written as$selffrom 3.2.external_docs:urlanddescriptionof the document's external documentation.
Security
security_schemes and security are described in
Security & errors.
References
With use_references (the default), resources and enums are components of components.schemas, referenced by $ref;
a component no longer referenced is left out. With false, every schema is written inline.
Extensions
extensions gives the x-* extensions of the document root:
'extensions' => ['x-api-id' => 'books', 'x-audience' => 'public'],
To add extensions to operations or schemas, write a pass.