specdocular / php-openapi
Object-oriented OpenAPI implementation for PHP
Installs: 268
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/specdocular/php-openapi
Requires
- php: ^8.2
- myclabs/deep-copy: ^1.12
- specdocular/php-json-schema: ^0.1.0
- webmozart/assert: ^1.11
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.8.0
- justinrainbow/json-schema: ^6.0
- pestphp/pest: ^3.2
- pestphp/pest-plugin-type-coverage: ^3.0
- phpstan/phpstan: ^2.1
- phpstan/phpstan-phpunit: ^2.0
- phpstan/phpstan-strict-rules: ^2.0
- phpstan/phpstan-webmozart-assert: ^2.0
- rector/rector: ^2.0
- slevomat/coding-standard: ^8.15
- squizlabs/php_codesniffer: *
- vimeo/psalm: ^6.0.0
README
An object-oriented OpenAPI 3.1.x builder for PHP. Build complete API specifications with a fluent, chainable API that hides the complexity of the OpenAPI specification.
Installation
composer require specdocular/php-openapi
Usage
use Specdocular\OpenAPI\Schema\Objects\OpenAPI\OpenAPI; use Specdocular\OpenAPI\Schema\Objects\Info\Info; use Specdocular\OpenAPI\Schema\Objects\PathItem\PathItem; use Specdocular\OpenAPI\Schema\Objects\Operation\Operation; use Specdocular\OpenAPI\Schema\Objects\Schema\Schema; use Specdocular\JsonSchema\Draft202012\Keywords\Properties\Property; $openApi = OpenAPI::v311( Info::create('Pet Store', '1.0.0') ->description('A sample Pet Store API') ); // Define schemas $petSchema = Schema::object() ->properties( Property::create('id', Schema::string()->format('uuid')), Property::create('name', Schema::string()), ) ->required('id', 'name'); // Export as JSON $json = json_encode($openApi, JSON_PRETTY_PRINT);
Features
- Fluent, chainable API for all OpenAPI 3.1.x objects
- Full support for Paths, Operations, Schemas, Responses, Request Bodies, Parameters, Security Schemes, and more
- Automatic component reference collection and management
- Built on specdocular/php-json-schema for schema definitions
- Framework-agnostic — no dependencies on Laravel or any framework
Related Packages
| Package | Description |
|---|---|
| specdocular/php-json-schema | JSON Schema Draft 2020-12 builder (foundation) |
| specdocular/laravel-openapi | Laravel integration for OpenAPI generation (uses this package) |
| specdocular/laravel-rules-to-schema | Convert Laravel validation rules to JSON Schema |
License
MIT. See LICENSE for details.