nijens/openapi-bundle
A Symfony bundle for generating OpenAPI documentation from your API using annotations or attributes, with configurable spec generation and Swagger UI integration to help you document and explore endpoints quickly.
This is nijens/openapi-bundle, a Symfony bundle for OpenAPI-driven request validation and parameter handling. In a Laravel codebase it is not a drop-in package: Laravel does not load Symfony bundles automatically. Treat it as a strong reference implementation or use it in a Symfony service that shares your OpenAPI contract.
Minimal steps in a Symfony host:
composer require nijens/openapi-bundleconfig/bundles.phpFirst useful use case: validate a required header such as X-Tenant-Id or Authorization before the controller runs. In 3.1.0 this is the lowest-friction feature to adopt because it does not require changing your response models or DTO layer.
In Laravel, first look at the package’s request-validation and deserialization classes rather than the bundle bootstrapping. If you only need header validation, a small Laravel middleware backed by your OpenAPI spec may be simpler than adopting the bundle wholesale.
Header validation as middleware-like guardrails. Declare headers in the OpenAPI spec, then let the bundle validate presence, type, and format. Use this for auth, tenant, correlation, API-version, and idempotency headers.
Deserialize parameters into objects. 3.1.0 adds parameter deserialization into deserialization objects. Use this to replace manual $request->query('page') / (int) casting with typed DTOs:
final class Pagination
{
public function __construct(
public readonly int $page = 1,
public readonly int $perPage = 20,
) {}
}
Map query/path/header parameters to DTOs and validate the DTO after deserialization. This keeps controllers thin and makes parameter rules testable.
Spec-first workflow. Keep the OpenAPI file in the repo. Update the spec and the DTO together. Run spec linting in CI and exercise one happy-path and one failing request per endpoint.
Shared contract across Laravel and Symfony services. If your Laravel app calls a Symfony service using this bundle, generate clients from the same spec. The new header validation and object deserialization make the Symfony side stricter, which reduces contract drift for Laravel consumers.
Testing pattern. Add feature tests for:
php artisan integration. Use the bundle in Symfony or reuse its validation/deserialization approach manually.X-Tenant-Id versus x-tenant-id and document the canonical form."abc" into an int property may coerce or fail depending on the serializer. Validate after deserialization and return a controlled 400/422 response.How can I help you explore Laravel packages today?