docs/reference/spec-attributes.md
This page is generated automatically from the swagger-php sources.
For improvements head over to GitHub and create a PR ;)
Spec attributes are typed PHP 8.1+ attributes in the OpenApi\Spec namespace — the foundation of the
spec-attributes pipeline (--mode spec or --mode hybrid).
They are immutable data containers with no serialization logic. Relationships between attributes are
declared via contains() (what children an attribute absorbs) and merge() (what parent an attribute
composes into). The Assembler resolves nesting, and Augmenters
enrich the collected specification before compilation.
Typed subclasses (e.g. Operation\Get, Parameter\Path, Flow\AuthorizationCode) pre-fill common
fields to reduce boilerplate — the base class can always be used directly.
Base class for custom attributes.
By default not allowed to contain other attributes, but can be inline nested into any other attribute (including itself).
Container for reusable component definitions.
Place on a class to declare standalone components that go into the components section of the OpenAPI document. The Components attribute itself is not emitted — its children are promoted to their respective Specification buckets.
The primary use case is for DTOs that are NOT roots and therefore cannot be declared at class level on their own: Parameter, Header, Link, and Example. Other types (Schema, PathItem, SecurityScheme, named Response/RequestBody) are already roots and can be declared directly on a class without needing a Components wrapper.
#[Components] class SharedComponents { #[Parameter(parameter: 'tenant_id', name: 'tenant_id', in: 'path', schema: new Schema(type: 'string'))] public string $tenantId;
#[Header(header: 'X-Rate-Limit', schema: new Schema(type: 'integer'))]
public string $rateLimit;
#[Example(example: 'dog', summary: 'A dog', value: ['name' => 'Fido'])]
public string $dogExample;
}
<a href="#schema">Schema</a>, <a href="#parameter">Parameter</a>, <a href="#response">Response</a>, <a href="#requestbody">RequestBody</a>, <a href="#header">Header</a>, <a href="#security-scheme">Security\Scheme</a>, <a href="#link">Link</a>, <a href="#example">Example</a>, <a href="#pathitem">PathItem</a>
Contact information for the exposed API.
<a href="#info">Info</a>
string|nullstring|nullstring|nullAids in serialization, deserialization, and validation when request bodies or responses can be one of several schemas (used with oneOf, anyOf, allOf).
<a href="#schema">Schema</a>
string|nullarray<string,string>|nullDescribes the encoding for a single property in a media type.
<a href="#mediatype">MediaType</a>
string|nullstring|nulllist<Header>|nullstring|nullbool|nullbool|nullDescribes an example value for a parameter, media type, or schema.
<a href="#components">Components</a>, <a href="#header">Header</a>, <a href="#mediatype">MediaType</a>, <a href="#parameter">Parameter</a>, <a href="#parameter-cookie">Parameter\Cookie</a>, <a href="#parameter-header">Parameter\Header</a>, <a href="#parameter-path">Parameter\Path</a>, <a href="#parameter-query">Parameter\Query</a>
string|nullstring|nullstring|nullmixedstring|nullstring|nullAllows referencing an external resource for extended documentation.
<a href="#tag">Tag</a>
string|nullstring|nullConfiguration details for a supported OAuth2 flow.
Typed subtypes pre-fill the flow type:
OA\Flow\Implicit - implicit grant (authorizationUrl required)
OA\Flow\Password - resource owner password credentials (tokenUrl required)
OA\Flow\ClientCredentials - client credentials grant (tokenUrl required)
OA\Flow\AuthorizationCode - authorization code grant (authorizationUrl + tokenUrl required)
#[OA\Security\Scheme\OAuth2(securityScheme: 'oauth2', flows: [ new OA\Flow\AuthorizationCode( authorizationUrl: 'https://example.com/oauth/authorize', tokenUrl: 'https://example.com/oauth/token', scopes: ['read:pets' => 'Read pets', 'write:pets' => 'Write pets'], ), ])]
Produces: components: securitySchemes: oauth2: type: oauth2 flows: authorizationCode: authorizationUrl: https://example.com/oauth/authorize tokenUrl: https://example.com/oauth/token scopes: read:pets: Read pets write:pets: Write pets
<a href="#security-scheme">Security\Scheme</a>, <a href="#security-scheme-apikey">Security\Scheme\ApiKey</a>, <a href="#security-scheme-http">Security\Scheme\Http</a>, <a href="#security-scheme-mutualtls">Security\Scheme\MutualTls</a>, <a href="#security-scheme-oauth2">Security\Scheme\OAuth2</a>, <a href="#security-scheme-openidconnect">Security\Scheme\OpenIdConnect</a>
string|nullstring|nullstring|nullstring|nullarray<string,string>|nullConfiguration for the OAuth2 Authorization Code flow.
<a href="#security-scheme">Security\Scheme</a>
string|nullstring|nullstring|nullarray<string,string>|nullConfiguration for the OAuth2 Client Credentials flow.
<a href="#security-scheme">Security\Scheme</a>
string|nullstring|nullarray<string,string>|nullConfiguration for the OAuth2 Implicit flow.
<a href="#security-scheme">Security\Scheme</a>
string|nullstring|nullarray<string,string>|nullConfiguration for the OAuth2 Resource Owner Password flow.
<a href="#security-scheme">Security\Scheme</a>
string|nullstring|nullarray<string,string>|nullDescribes a single HTTP header.
<a href="#components">Components</a>, <a href="#response">Response</a>
<a href="#mediatype">MediaType</a>, <a href="#example">Example</a>
string|nullstring|nullbool|nullbool|nullstring|nullstring|nullbool|nullSchema|nullmixedlist<Example>|nulllist<MediaType>|nullMetadata about the API.
<a href="#contact">Contact</a>, <a href="#license">License</a>
string|nullstring|nullstring|nullstring|nullContact|nullLicense|nullstring|nullLicense information for the exposed API.
<a href="#info">Info</a>
string|nullstring|nullstring|nullDescribes a possible design-time link for a response.
<a href="#components">Components</a>, <a href="#response">Response</a>
string|nullstring|nullstring|nullarray<string,mixed>|nullmixedstring|nullstring|nullServer|nullDescribes the content payload for a specific media type.
<a href="#header">Header</a>, <a href="#parameter">Parameter</a>, <a href="#parameter-cookie">Parameter\Cookie</a>, <a href="#parameter-header">Parameter\Header</a>, <a href="#parameter-path">Parameter\Path</a>, <a href="#parameter-query">Parameter\Query</a>, <a href="#requestbody">RequestBody</a>, <a href="#response">Response</a>
<a href="#encoding">Encoding</a>, <a href="#example">Example</a>
string|nullSchema|nullmixedlist<Example>|nulllist<Encoding>|array<string,Encoding>|nullThe root element of an OpenAPI definition.
<a href="#security-requirement">Security\Requirement</a>
string|nulllist<Security\Requirement>|nullDescribes a single API operation on a path.
Typed subclasses pre-fill the HTTP method — use them instead of specifying method manually:
#[OA\Operation\Get(path: '/pets/{id}', responses: [ new OA\Response(response: 200, description: 'A pet', content: [ new OA\MediaType(schema: new OA\Schema(ref: Pet::class)), ]), ])] public function show(int $id) {}
Produces: paths: /pets/{id}: get: operationId: show responses: '200': description: A pet content: application/json: schema: $ref: '#/components/schemas/Pet'
For webhooks, use webhook instead of path:
#[OA\Operation\Post(webhook: 'petAdopted', responses: [...])]
<a href="#parameter">Parameter</a>, <a href="#response">Response</a>, <a href="#requestbody">RequestBody</a>, <a href="#server">Server</a>, <a href="#security-requirement">Security\Requirement</a>
string|nullstring|nullstring|nullstring|nullstring|nullstring|nulllist<string>|nulllist<Parameter>|nullRequestBody|nulllist<Response>|nullarray<string,mixed>|nullbool|nulllist<Security\Requirement>|nulllist<Server>|nullExternalDocumentation|nullShorthand for an HTTP DELETE operation.
<a href="#parameter">Parameter</a>, <a href="#response">Response</a>, <a href="#requestbody">RequestBody</a>, <a href="#server">Server</a>, <a href="#security-requirement">Security\Requirement</a>
string|nullstring|nullstring|nullstring|nullstring|nulllist<string>|nulllist<OA\Parameter>|nullOpenApi\Spec\RequestBody|nulllist<OA\Response>|nullarray<string,mixed>|nullbool|nulllist<OA\Security\Requirement>|nulllist<OA\Server>|nullOpenApi\Spec\ExternalDocumentation|nullShorthand for an HTTP GET operation.
<a href="#parameter">Parameter</a>, <a href="#response">Response</a>, <a href="#requestbody">RequestBody</a>, <a href="#server">Server</a>, <a href="#security-requirement">Security\Requirement</a>
string|nullstring|nullstring|nullstring|nullstring|nulllist<string>|nulllist<OA\Parameter>|nullOpenApi\Spec\RequestBody|nulllist<OA\Response>|nullarray<string,mixed>|nullbool|nulllist<OA\Security\Requirement>|nulllist<OA\Server>|nullOpenApi\Spec\ExternalDocumentation|nullShorthand for an HTTP HEAD operation.
<a href="#parameter">Parameter</a>, <a href="#response">Response</a>, <a href="#requestbody">RequestBody</a>, <a href="#server">Server</a>, <a href="#security-requirement">Security\Requirement</a>
string|nullstring|nullstring|nullstring|nullstring|nulllist<string>|nulllist<OA\Parameter>|nullOpenApi\Spec\RequestBody|nulllist<OA\Response>|nullarray<string,mixed>|nullbool|nulllist<OA\Security\Requirement>|nulllist<OA\Server>|nullOpenApi\Spec\ExternalDocumentation|nullShorthand for an HTTP OPTIONS operation.
<a href="#parameter">Parameter</a>, <a href="#response">Response</a>, <a href="#requestbody">RequestBody</a>, <a href="#server">Server</a>, <a href="#security-requirement">Security\Requirement</a>
string|nullstring|nullstring|nullstring|nullstring|nulllist<string>|nulllist<OA\Parameter>|nullOpenApi\Spec\RequestBody|nulllist<OA\Response>|nullarray<string,mixed>|nullbool|nulllist<OA\Security\Requirement>|nulllist<OA\Server>|nullOpenApi\Spec\ExternalDocumentation|nullShorthand for an HTTP PATCH operation.
<a href="#parameter">Parameter</a>, <a href="#response">Response</a>, <a href="#requestbody">RequestBody</a>, <a href="#server">Server</a>, <a href="#security-requirement">Security\Requirement</a>
string|nullstring|nullstring|nullstring|nullstring|nulllist<string>|nulllist<OA\Parameter>|nullOpenApi\Spec\RequestBody|nulllist<OA\Response>|nullarray<string,mixed>|nullbool|nulllist<OA\Security\Requirement>|nulllist<OA\Server>|nullOpenApi\Spec\ExternalDocumentation|nullShorthand for an HTTP POST operation.
<a href="#parameter">Parameter</a>, <a href="#response">Response</a>, <a href="#requestbody">RequestBody</a>, <a href="#server">Server</a>, <a href="#security-requirement">Security\Requirement</a>
string|nullstring|nullstring|nullstring|nullstring|nulllist<string>|nulllist<OA\Parameter>|nullOpenApi\Spec\RequestBody|nulllist<OA\Response>|nullarray<string,mixed>|nullbool|nulllist<OA\Security\Requirement>|nulllist<OA\Server>|nullOpenApi\Spec\ExternalDocumentation|nullShorthand for an HTTP PUT operation.
<a href="#parameter">Parameter</a>, <a href="#response">Response</a>, <a href="#requestbody">RequestBody</a>, <a href="#server">Server</a>, <a href="#security-requirement">Security\Requirement</a>
string|nullstring|nullstring|nullstring|nullstring|nulllist<string>|nulllist<OA\Parameter>|nullOpenApi\Spec\RequestBody|nulllist<OA\Response>|nullarray<string,mixed>|nullbool|nulllist<OA\Security\Requirement>|nulllist<OA\Server>|nullOpenApi\Spec\ExternalDocumentation|nullShorthand for an HTTP TRACE operation.
<a href="#parameter">Parameter</a>, <a href="#response">Response</a>, <a href="#requestbody">RequestBody</a>, <a href="#server">Server</a>, <a href="#security-requirement">Security\Requirement</a>
string|nullstring|nullstring|nullstring|nullstring|nulllist<string>|nulllist<OA\Parameter>|nullOpenApi\Spec\RequestBody|nulllist<OA\Response>|nullarray<string,mixed>|nullbool|nulllist<OA\Security\Requirement>|nulllist<OA\Server>|nullOpenApi\Spec\ExternalDocumentation|nullDescribes a single operation parameter.
Typed subtypes pre-fill in (and required for path):
OA\Parameter\Path - path parameters (in: path, required: true)OA\Parameter\Query - query string parameters (in: query)OA\Parameter\Header - header parameters (in: header)OA\Parameter\Cookie - cookie parameters (in: cookie)Inline on an operation:
#[OA\Operation\Get(path: '/pets', parameters: [ new OA\Parameter\Query(name: 'status', schema: new OA\Schema(type: 'string', enum: ['active', 'sold'])), ])]
Or as a reusable component (set parameter for the component key):
#[OA\Parameter\Path(parameter: 'petId', name: 'id', schema: new OA\Schema(type: 'integer'))]
Produces: components: parameters: petId: name: id in: path required: true schema: type: integer
<a href="#components">Components</a>, <a href="#operation">Operation</a>, <a href="#operation-delete">Operation\Delete</a>, <a href="#operation-get">Operation\Get</a>, <a href="#operation-head">Operation\Head</a>, <a href="#operation-options">Operation\Options</a>, <a href="#operation-patch">Operation\Patch</a>, <a href="#operation-post">Operation\Post</a>, <a href="#operation-put">Operation\Put</a>, <a href="#operation-trace">Operation\Trace</a>, <a href="#pathitem">PathItem</a>
<a href="#mediatype">MediaType</a>, <a href="#example">Example</a>
string|nullstring|nullstring|nullstring|nullbool|nullbool|nullbool|nullstring|nullstring|nullbool|nullbool|nullSchema|nullmixedlist<Example>|nulllist<MediaType>|nullA parameter passed via an HTTP cookie.
<a href="#operation">Operation</a>, <a href="#pathitem">PathItem</a>
<a href="#mediatype">MediaType</a>, <a href="#example">Example</a>
string|nullstring|nullstring|nullbool|nullbool|nullstring|nullbool|nullOpenApi\Spec\Schema|nullmixed|nulllist<OA\Example>|nulllist<OA\MediaType>|nullA parameter passed via an HTTP header.
<a href="#operation">Operation</a>, <a href="#pathitem">PathItem</a>
<a href="#mediatype">MediaType</a>, <a href="#example">Example</a>
string|nullstring|nullstring|nullbool|nullbool|nullstring|nullbool|nullOpenApi\Spec\Schema|nullmixed|nulllist<OA\Example>|nulllist<OA\MediaType>|nullA parameter passed via the URL path (always required).
<a href="#operation">Operation</a>, <a href="#pathitem">PathItem</a>
<a href="#mediatype">MediaType</a>, <a href="#example">Example</a>
string|nullstring|nullstring|nullbool|nullstring|nullstring|nullbool|nullOpenApi\Spec\Schema|nullmixed|nulllist<OA\Example>|nulllist<OA\MediaType>|nullA parameter passed via the URL query string.
<a href="#operation">Operation</a>, <a href="#pathitem">PathItem</a>
<a href="#mediatype">MediaType</a>, <a href="#example">Example</a>
string|nullstring|nullstring|nullbool|nullbool|nullbool|nullstring|nullstring|nullbool|nullbool|nullOpenApi\Spec\Schema|nullmixed|nulllist<OA\Example>|nulllist<OA\MediaType>|nullDescribes shared metadata for all operations under a path.
Place on a controller class — the path is inferred from its operations. Parameters, summary, description and servers are emitted at path level in the OpenAPI output. Prefix, tags, security and responses are controller-level features that compose via class hierarchy and apply to all contained operations.
Shared path-level properties (parameters, summary, description, servers per OpenAPI spec):
#[PathItem(parameters: [new Parameter\Path(name: 'id', schema: new Schema(type: 'integer'))])] class ProductController { #[Operation\Get(path: '/products/{id}')] public function get() {} }
The path in the output is inferred from the operations — no need to declare it on PathItem, avoiding duplication.
Prefix composition with inherited metadata:
#[PathItem(prefix: '/api/v1')] class BaseController {}
#[PathItem(prefix: '/users', tags: ['Users'], security: [new Security\Requirement(scheme: 'bearerAuth')])] #[Response(response: 401, description: 'Unauthorized')] #[Response(response: 500, description: 'Server error')] class UserController extends BaseController { #[Operation\Get(path: '/list')] // resolved: /api/v1/users/list, tags: ['Users'] public function list() {}
#[Operation\Get(path: '/{id}')] // resolved: /api/v1/users/{id}, tags: ['Users']
public function get() {}
}
Prefixes compose by walking the class hierarchy — each ancestor PathItem contributes its prefix segment. All collection properties merge additively: tags, security, responses, and parameters accumulate from the full ancestor chain. Deduplication is by value (tags), by scheme (security), by status code (responses), and by name+in (parameters).
<a href="#components">Components</a>
<a href="#parameter">Parameter</a>, <a href="#server">Server</a>, <a href="#response">Response</a>, <a href="#security-requirement">Security\Requirement</a>
string|nullstring|nullstring|nullstring|nulllist<Parameter>|nulllist<Server>|nulllist<string>|nulllist<Security\Requirement>|nulllist<Response>|nullDefines a single property within a Schema object.
<a href="#schema">Schema</a>
string|nullSchema|nullDescribes a single request body.
<a href="#components">Components</a>, <a href="#operation">Operation</a>, <a href="#operation-delete">Operation\Delete</a>, <a href="#operation-get">Operation\Get</a>, <a href="#operation-head">Operation\Head</a>, <a href="#operation-options">Operation\Options</a>, <a href="#operation-patch">Operation\Patch</a>, <a href="#operation-post">Operation\Post</a>, <a href="#operation-put">Operation\Put</a>, <a href="#operation-trace">Operation\Trace</a>
<a href="#mediatype">MediaType</a>
string|nullstring|nullbool|nullstring|nulllist<MediaType>|nullDescribes a single response from an API operation.
<a href="#components">Components</a>, <a href="#operation">Operation</a>, <a href="#operation-delete">Operation\Delete</a>, <a href="#operation-get">Operation\Get</a>, <a href="#operation-head">Operation\Head</a>, <a href="#operation-options">Operation\Options</a>, <a href="#operation-patch">Operation\Patch</a>, <a href="#operation-post">Operation\Post</a>, <a href="#operation-put">Operation\Put</a>, <a href="#operation-trace">Operation\Trace</a>, <a href="#pathitem">PathItem</a>
<a href="#header">Header</a>, <a href="#mediatype">MediaType</a>, <a href="#link">Link</a>
string|int|nullstring|nullstring|nulllist<Header>|nulllist<MediaType>|nulllist<Link>|nullDefines the structure and validation rules for a data type.
On a class — becomes a reusable component schema (name inferred from class):
#[OA\Schema] class Pet { #[OA\Property] public string $name; #[OA\Property] public ?int $age; }
Produces: components: schemas: Pet: type: object properties: name: { type: string } age: { type: integer, nullable: true }
Inline — used within parameters, responses, or other schemas:
new OA\Schema(type: 'array', items: new OA\Schema(ref: Pet::class))
<a href="#components">Components</a>, <a href="#schema">Schema</a>
<a href="#property">Property</a>, <a href="#schema">Schema</a>
string|nullstring|nullstring|nullstring|nullstring|list<string>|nullstring|nullbool|nullint|nullint|nullstring|nullstring|nullstring|nullint|float|nullint|float|nullint|float|bool|nullint|float|bool|nullint|float|nullSchema|string|nullint|nullint|nullbool|nulllist<Schema>|nullSchema|bool|nullint|nullint|nullSchema|bool|nulllist<Property|Schema>|nulllist<string>|nullSchema|bool|nullarray<string,Schema>|nullint|nullint|nullSchema|bool|nullSchema|nullarray<string,list<string>>|nullarray<string,Schema>|nulllist<Schema>|nulllist<Schema>|nulllist<Schema>|nullSchema|nullSchema|nullSchema|nullSchema|nulllist<string|int|float|bool|\UnitEnum|class-string<\UnitEnum>|null>|nullmixedmixedlist<mixed>|nullbool|nullbool|nullbool|nullmixedDiscriminator|nullExternalDocumentation|nullXml|nullA security requirement declaring which security schemes apply.
Each requirement instance represents one entry in the security array (OR logic). Multiple schemes within a single requirement represent AND logic.
<a href="#openapi">OpenApi</a>, <a href="#operation">Operation</a>, <a href="#operation-delete">Operation\Delete</a>, <a href="#operation-get">Operation\Get</a>, <a href="#operation-head">Operation\Head</a>, <a href="#operation-options">Operation\Options</a>, <a href="#operation-patch">Operation\Patch</a>, <a href="#operation-post">Operation\Post</a>, <a href="#operation-put">Operation\Put</a>, <a href="#operation-trace">Operation\Trace</a>, <a href="#pathitem">PathItem</a>
string|nulllist<string>|nullarray<string,list<string>>|nullDefines a security scheme that can be used by the operations.
Typed subtypes are available for each security scheme type:
OA\Security\Scheme\Http - HTTP authentication (Basic, Bearer, etc.)OA\Security\Scheme\ApiKey - API key in header, query, or cookieOA\Security\Scheme\OAuth2 - OAuth2 with one or more flowsOA\Security\Scheme\OpenIdConnect - OpenID Connect discoveryOA\Security\Scheme\MutualTls - Mutual TLS authentication<a href="#components">Components</a>
<a href="#flow">Flow</a>
string|nullstring|nullstring|nullstring|nullstring|nullstring|nullstring|nullstring|nulllist<OA\Flow>|nullstring|nullAn API key security scheme (header, query, or cookie).
<a href="#flow">Flow</a>
string|nullstring|nullstring|nullstring|nullAn HTTP authentication security scheme (Basic, Bearer, etc.).
<a href="#flow">Flow</a>
string|nullstring|nullstring|nullstring|nullA Mutual TLS security scheme.
<a href="#flow">Flow</a>
string|nullstring|nullAn OAuth2 security scheme with one or more flows.
<a href="#flow">Flow</a>
string|nullstring|nulllist<OA\Flow>|nullAn OpenID Connect Discovery security scheme.
<a href="#flow">Flow</a>
string|nullstring|nullstring|nullRepresents a Server.
<a href="#operation">Operation</a>, <a href="#operation-delete">Operation\Delete</a>, <a href="#operation-get">Operation\Get</a>, <a href="#operation-head">Operation\Head</a>, <a href="#operation-options">Operation\Options</a>, <a href="#operation-patch">Operation\Patch</a>, <a href="#operation-post">Operation\Post</a>, <a href="#operation-put">Operation\Put</a>, <a href="#operation-trace">Operation\Trace</a>, <a href="#pathitem">PathItem</a>
<a href="#servervariable">ServerVariable</a>
string|nullstring|nulllist<ServerVariable>|nullRepresents a Server Variable for server URL template substitution.
<a href="#server">Server</a>
string|nullstring|nullstring|nulllist<string>|nullAdds metadata to a single tag used by the Operation Object.
<a href="#externaldocumentation">ExternalDocumentation</a>
string|nullstring|nullExternalDocumentation|nullMetadata for XML representation of a schema property.
<a href="#schema">Schema</a>
string|nullstring|nullstring|nullbool|nullbool|null