chamber-orchestra/openapi-doc-bundle
Install the Bundle
Add to your composer.json:
"require": {
"chamber-orchestra/openapi-doc-bundle": "^1.0"
}
Then register in config/bundles.php:
return [
// ...
ChamberOrchestra\OpenApiDocBundle\ApiDocBundle::class => ['all' => true],
];
First Use Case: Document an ADR Action
Create an action class with #[Operation] and #[Route]:
use ChamberOrchestra\OpenApiDocBundle\Attribute\Operation;
use ChamberOrchestra\OpenApiDocBundle\Attribute\Route;
use Symfony\Component\HttpFoundation\Response;
#[Route('/api/users', methods: ['GET'])]
#[Operation(description: 'List all users')]
class ListUsersAction
{
public function __invoke(): Response
{
return new Response('[]');
}
}
Generate Docs Run the console command:
php bin/console openapi-doc:generate
Outputs to doc.yaml (default path).
Action Class Design
src/Action/ (or any scanned directory).#[Route] for HTTP metadata (path, methods).#[Operation] for OpenAPI-specific details (description, request/response bodies).DTO/Response Handling
Dev\ViewBundle\View\ViewInterface.#[Route('/api/users/{id}', methods: ['GET'])]
#[Operation(responses: ['200' => new GetUserResponse()])]
class GetUserAction { ... }
Form Integration
FormTypeInterface, the FormParser auto-generates OpenAPI schemas.#[Route('/api/users', methods: ['POST'])]
#[Operation(request: new UserType())]
class CreateUserAction { ... }
Security Schemes
proto.yaml:
components:
securitySchemes:
bearerAuth:
type: http
scheme: bearer
#[Operation(security: ['bearerAuth: []'])]
Custom Parsers
OperationParserInterface or ComponentParserInterface for custom logic.services.yaml:
services:
App\Parser\CustomParser:
tags: ['openapi_doc.operation_parser']
Missing Attributes
DescriberException: Class must have both #[Operation] and #[Route].Unsupported Return Types
#[Operation(responses: ['200' => new \stdClass()])] for simple cases or implement a custom parser.Circular References
$ref in proto.yaml or simplify DTO structure.Parser Order Matters
priority tag:
tags: ['openapi_doc.operation_parser', { priority: 100 }]
--dry-run flag to inspect parsed data without writing files.$operationRegistry = $container->get(OperationRegistry::class);
$operations = $operationRegistry->toArray();
php bin/console debug:config chamber_orchestra_openapi_doc
Custom Attributes
#[Property] for fine-grained schema control:
#[Property(required: true, attr: ['example' => 'value'])]
public string $name;
Proto.yaml Merging
proto.yaml:
components:
schemas:
User:
type: object
properties:
id: { type: integer, readOnly: true }
Conditional Documentation
#[Ignore] (custom attribute) by creating a parser to filter them.Performance
# config/packages/chamber_orchestra_openapi_doc.yaml
chamber_orchestra_openapi_doc:
cache: true
How can I help you explore Laravel packages today?