cortexphp / openapi
A fluent OpenAPI 3.1 builder for PHP, built on top of cortexphp/json-schema
1.1.0
2026-09-16 23:01 UTC
Requires
- php: ^8.4
- ext-json: *
- cortexphp/json-schema: ^2.0
- opis/json-schema: ^2.4
Requires (Dev)
- pestphp/pest: ^5.0
- pestphp/pest-plugin-mutate: ^5.0.1
- pestphp/pest-plugin-phpstan: ^5.0
- pestphp/pest-plugin-rector: ^5.0
- pestphp/pest-plugin-type-coverage: ^5.0
- phpstan/phpstan: ^2.1.32
- phpstan/phpstan-strict-rules: ^2.0
- rector/rector: ^2.2
- symfony/yaml: ^8.1.6
- symplify/easy-coding-standard: ~13.1.0
Suggests
- symfony/yaml: Required for OpenApi::toYaml() output (^6.0 || ^7.0).
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-09-16 23:03:30 UTC
README
A modern, fluent builder for OpenAPI 3.1 specs, built on top of cortexphp/json-schema so that schemas are first-class JSON Schema 2020-12 and everything plays nicely with the rest of the Cortex ecosystem.
Features
- Full OpenAPI 3.1 object graph (paths, webhooks, callbacks, components, security, tags)
- Schemas via
cortexphp/json-schema— no parallel schema DSL to learn - Vendor extensions (
x-*) and$refon every object - JSON and YAML output (YAML via optional
symfony/yaml) - Meta-schema validation against the official OpenAPI 3.1 schemas (bundled, offline)
Requirements
- PHP 8.4+
Installation
composer require cortexphp/openapi
For YAML output:
composer require symfony/yaml
Quick Start
use Cortex\JsonSchema\Schema; use Cortex\JsonSchema\Enums\SchemaFormat; use Cortex\OpenApi\OpenApi; use Cortex\OpenApi\Objects\{Info, Tag, PathItem, Operation, Response, MediaType, Parameter, Components, Reference}; $userSchema = Schema::object('User')->properties( Schema::string('id')->format(SchemaFormat::Uuid)->required(), Schema::string('name')->required(), Schema::integer('age')->minimum(0), ); $openApi = OpenApi::create() ->info(Info::create('Example API', '1.0.0')) ->tags(Tag::create('Users')->description('User endpoints')) ->components(Components::create()->schema('User', $userSchema)) ->paths( PathItem::create('/users/{id}') ->parameters(Parameter::path('id', Schema::string()->format(SchemaFormat::Uuid))) ->operations( Operation::get() ->operationId('users.show') ->tags('Users') ->responses( Response::ok()->content(MediaType::json(Reference::schema('User'))), Response::notFound(), ), ), ); echo $openApi->toJson(JSON_PRETTY_PRINT);
Documentation
Credits
License
The MIT License (MIT). Please see License File for more information.