erasys / openapi-php
Open API 3.0 builder and validation library for PHP that helps you write valid specs.
Installs: 65 372
Dependents: 4
Suggesters: 0
Security: 0
Stars: 20
Watchers: 13
Forks: 13
Open Issues: 1
Requires
- php: ^8.2
- illuminate/contracts: ^10.14.1
- justinrainbow/json-schema: ^5.2
- symfony/yaml: ^v6.3
Requires (Dev)
- phpunit/phpunit: ^9.6.8
- squizlabs/php_codesniffer: ^3.7.2
README
Open API 3.0 builder and validation library for PHP that helps you write valid specs.
This project is compliant with PSR-1, PSR-2 and PSR-4. If you notice compliance oversights, please send a patch via pull request.
Features
- Fully documented object-oriented representation of the Open API 3.0+ specification with helper methods to write valid documents.
- Supports Illuminate (Laravel)
Jsonable
andArrayable
. - Generates an specification in plain PHP arrays, plain objects, JSON or YAML.
- Validates Open API documents against the Open API 3.0.x JSON Schema.
Install
Via Composer
$ composer require erasys/openapi-php
Via Git
$ git clone https://github.com/erasys/openapi-php.git
Usage
Basic example:
<?php use erasys\OpenApi\Spec\v3 as OASv3; $doc = new OASv3\Document( new OASv3\Info('My API', '1.0.0', 'My API description'), [ '/foo/bar' => new OASv3\PathItem( [ 'get' => new OASv3\Operation( [ '200' => new OASv3\Response('Successful response.'), 'default' => new OASv3\Response('Default error response.'), ] ), ] ), ] ); $yaml = $doc->toYaml(); $json = $doc->toJson(); $arr = $doc->toArray(); $obj = $doc->toObject();
Testing
$ composer test
or
$ vendor/bin/phpunit $ vendor/bin/phpcs
Contributing
Please see CONTRIBUTING for details.
License
The MIT License (MIT). Please see License File for more information.