Writing OpenAPI extensions using attributes in swagger-php — is this supported?
I'm using swagger-php and documenting my API using PHP 8 attributes. I want to add custom extensions like x-tagGroups to my OpenAPI output. However, the documentation is unclear, and when I try to use OpenApi\Attributes\Extension or OpenApi\Attributes\ExtensionProperty, I get the error: "Undefined type 'OpenApi\Attributes\Extension'". I’ve checked my swagger-php version using 'composer show zircote/swagger-php' which shows version 5.1.3. Here’s what I’m trying to do. I want the final OpenAPI output to include this:
x-tagGroups:
- name: Group A
tags:
- Example
I tried writing it as an attribute like this:
#[OA\OpenApi(
tags: [ new OA\Tag(name: 'Example') ],
extensions: [
new OA\Extension(
name: 'x-tagGroups',
value: [
['name' => 'Group A', 'tags' => ['Example']],
],
),
]
)]
But it seems like the Extension class doesn’t exist (and neither does ExtensionProperty). Has support for OpenAPI extensions via attributes been added in swagger-php? If not, is there a workaround (like using annotations instead, or injecting it after generation)? (P.S Sorry for the formatting. It wasn't letting me add line breaks).