PHPackages                             stixx/openapi-command-bundle - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. stixx/openapi-command-bundle

ActiveSymfony-bundle[API Development](/categories/api)

stixx/openapi-command-bundle
============================

Create Command-Bus APIs with auto-generated OpenAPI docs and schema-driven request validation

0.11.1(1mo ago)11.2kMITPHPPHP ^8.4CI passing

Since Dec 10Pushed 1mo agoCompare

[ Source](https://github.com/stixx/openapi-command-bundle)[ Packagist](https://packagist.org/packages/stixx/openapi-command-bundle)[ RSS](/packages/stixx-openapi-command-bundle/feed)WikiDiscussions main Synced 3w ago

READMEChangelog (10)Dependencies (53)Versions (30)Used By (0)

OpenAPI Command Bundle
======================

[](#openapi-command-bundle)

[![Latest Version on Packagist](https://camo.githubusercontent.com/3f0d296e3225a6a52110786fb085be6b16f173113903d2f5ac79ed13adfc81a5/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f73746978782f6f70656e6170692d636f6d6d616e642d62756e646c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/stixx/openapi-command-bundle)[![Total Downloads](https://camo.githubusercontent.com/18784f5c3f1973ca955d2ad94328de16d3a3c8adf2fe064f58b280a0747d5d25/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f73746978782f6f70656e6170692d636f6d6d616e642d62756e646c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/stixx/openapi-command-bundle)[![License](https://camo.githubusercontent.com/d3471801d587e81b0e98dace65d01c7ef9eafb982611e7170b57f2b93a49318a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f73746978782f6f70656e6170692d636f6d6d616e642d62756e646c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/stixx/openapi-command-bundle)

The **OpenAPI Command Bundle** is a Symfony bundle that allows you to build HTTP APIs around Command Bus messages (DTOs) without the need for manual controller creation or Symfony `#[Route]` attributes on your commands.

By using standard OpenAPI operation attributes (from `zircote/swagger-php`) directly on your command DTOs, this bundle automatically generates Symfony routes and handles the entire request-to-command lifecycle: deserialization, validation, dispatching to the messenger bus, and responding.

Key Features
------------

[](#key-features)

- **OpenAPI-Driven Routing**: Define your API endpoints directly on your command DTOs using `#[OA\Post]`, `#[OA\Get]`, `#[OA\Put]`, etc.
- **No Manual Controllers**: A single `CommandController` handles all generated routes by default.
- **Automatic Deserialization**: Automatically maps JSON request bodies, route parameters, and query parameters to your command DTOs.
- **Two-Layer Validation**: Each request is checked against the OpenAPI schema (headers, query parameters, body shape via `league/openapi-psr7-validator`) *and* the deserialized command is validated with Symfony Validator constraints before it reaches your handler.
- **Messenger Integration**: Dispatches your commands directly to the Symfony Messenger bus.
- **Auto-Generated Documentation**: Seamlessly integrates with `NelmioApiDocBundle` to include your command-based routes in your OpenAPI/Swagger documentation.
- **Problem Details Support**: Returns RFC 7807 compliant error responses for validation and mapping errors.

Installation
------------

[](#installation)

### 1. Install via Composer

[](#1-install-via-composer)

```
composer require stixx/openapi-command-bundle
```

### 2. Enable the Bundle

[](#2-enable-the-bundle)

If you are using Symfony Flex, the bundle will be automatically enabled. Otherwise, add it to your `config/bundles.php`:

```
return [
    // ...
    Stixx\OpenApiCommandBundle\StixxOpenApiCommandBundle::class => ['all' => true],
];
```

Usage
-----

[](#usage)

### 1. Create a Command DTO

[](#1-create-a-command-dto)

Annotate your command with OpenAPI attributes. No Symfony `#[Route]` is needed.

```
namespace App\Command;

use OpenApi\Attributes as OA;
use Symfony\Component\Validator\Constraints as Assert;

#[OA\Post(
    path: '/api/projects',
    operationId: 'create_project',
    summary: 'Create a new project'
)]
final class CreateProjectCommand
{
    public function __construct(
        #[Assert\NotBlank]
        #[Assert\Length(min: 3, max: 50)]
        public string $name,

        #[Assert\Length(max: 255)]
        public ?string $description = null,
    ) {}
}
```

### 2. Create a Message Handler

[](#2-create-a-message-handler)

Implement a standard Symfony Messenger handler for your command.

```
namespace App\Handler;

use App\Command\CreateProjectCommand;
use Symfony\Component\Messenger\Attribute\AsMessageHandler;

#[AsMessageHandler]
final class CreateProjectHandler
{
    public function __invoke(CreateProjectCommand $command): array
    {
        // Your business logic here (e.g., persist to database)

        return [
            'id' => '123',
            'name' => $command->name,
        ];
    }
}
```

### 3. Call the API

[](#3-call-the-api)

The bundle automatically registers the route `/api/projects` (POST).

```
curl -X POST http://localhost:3000/api/projects \
     -H "Content-Type: application/json" \
     -d '{"name": "New Project", "description": "This is a project description"}'
```

The bundle will:

1. Detect the route and map it to `CreateProjectCommand`.
2. Deserialize the JSON body into the command object.
3. Validate the command using Symfony Validator.
4. Dispatch the command to the Messenger bus.
5. Return the handler's result as a JSON response with an appropriate status code (e.g., `201 Created`).

Configuration
-------------

[](#configuration)

You can customize the bundle's behavior in `config/packages/stixx_openapi_command.yaml`:

```
stixx_openapi_command:
    validation:
        enabled: true
        groups: ['Default']
    openapi:
        problem_details: true # Enable RFC 7807 problem details for errors
```

Documentation
-------------

[](#documentation)

For more detailed information, please refer to the following documentation:

- [Command Routing &amp; Request Handling](docs/command-routing.md)
- [Validation &amp; Error Handling](docs/validation.md)
- [OpenAPI Integration](docs/openapi.md)
- [Extension Points](docs/extension-points.md)

Stability &amp; supported API
-----------------------------

[](#stability--supported-api)

The bundle distinguishes a small public API surface from its internal implementation. Public surface is the contract you can safely depend on; internals can change in any release.

**Public (`@api`)** — guaranteed BC across minor releases:

TypeWhat it is`Stixx\OpenApiCommandBundle\StixxOpenApiCommandBundle`Bundle entry point`Stixx\OpenApiCommandBundle\Attribute\CommandObject`Marker attribute for command arguments`Stixx\OpenApiCommandBundle\Exception\ApiProblemException`Throw this from your code to express RFC 7807 problems`Stixx\OpenApiCommandBundle\Exception\ExceptionToApiProblemTransformerInterface`Replace to customize how exceptions become problem responses`Stixx\OpenApiCommandBundle\Responder\ResponderInterface`Implement to handle custom result shapes (CSV, XML, …)`Stixx\OpenApiCommandBundle\Response\StatusResolverInterface`Replace to customize status code resolution`Stixx\OpenApiCommandBundle\Validator\ValidatorInterface`Implement to add custom request-level validation`Stixx\OpenApiCommandBundle\Model\ProblemDetails`OpenAPI schema model — reference from your annotations`Stixx\OpenApiCommandBundle\Model\ProblemDetailsInvalidRequestBody`OpenAPI schema model — reference from your annotations`Stixx\OpenApiCommandBundle\Model\Violation`OpenAPI schema model — reference from your annotations**Internal (`@internal`)** — everything else, including default implementations like `JsonResponder`, `DefaultExceptionToApiProblemTransformer`, `RequestValidator`, the controllers, DI extension, compiler passes, route loaders, and event subscribers. Do not extend or rely on these directly; replace them through the `@api` interfaces above.

The bundle's configuration schema (the keys under `stixx_openapi_command:`) is also part of the supported API.

See [Extension Points](docs/extension-points.md) for a worked example of each extension interface.

Requirements
------------

[](#requirements)

- PHP 8.4+
- Symfony 7.3+ or 8.0+

License
-------

[](#license)

This bundle is released under the [MIT License](LICENSE).

###  Health Score

47

—

FairBetter than 93% of packages

Maintenance94

Actively maintained with recent releases

Popularity22

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~10 days

Recently: every ~3 days

Total

17

Last Release

32d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/f5f344c666ed6e0cf73ec40895b4dd76b8a4d9a50d963c88f6307f20ca6e8909?d=identicon)[jellevo](/maintainers/jellevo)

---

Top Contributors

[![stixx](https://avatars.githubusercontent.com/u/10729672?v=4)](https://github.com/stixx "stixx (121 commits)")

###  Code Quality

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/stixx-openapi-command-bundle/health.svg)

```
[![Health](https://phpackages.com/badges/stixx-openapi-command-bundle/health.svg)](https://phpackages.com/packages/stixx-openapi-command-bundle)
```

###  Alternatives

[shopware/core

Shopware platform is the core for all Shopware ecommerce products.

585.4M514](/packages/shopware-core)[sulu/sulu

Core framework that implements the functionality of the Sulu content management system

1.3k1.4M196](/packages/sulu-sulu)[easycorp/easyadmin-bundle

Admin generator for Symfony applications

4.3k17.5M373](/packages/easycorp-easyadmin-bundle)[shopware/platform

The Shopware e-commerce core

3.4k1.5M3](/packages/shopware-platform)[prestashop/prestashop

PrestaShop is an Open Source e-commerce platform, committed to providing the best shopping cart experience for both merchants and customers.

9.1k16.8k](/packages/prestashop-prestashop)[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.5k5.8M712](/packages/sylius-sylius)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
