READ OpenAPI yaml and json files and make the content accessable in PHP objects.
composer require cebe/php-openapi
- PHP 7.0 or higher
Read OpenAPI spec from JSON:
use cebe\openapi\Reader;
$openapi = Reader::readFromJson(file_get_contents('openapi.json'));
Read OpenAPI spec from YAML:
use cebe\openapi\Reader;
$openapi = Reader::readFromYaml(file_get_contents('openapi.yaml'));
Access specification data:
echo $openapi->openapi; // openAPI version, e.g. 3.0.0
echo $openapi->info->title; // API title
foreach($openapi->paths as $path => $definition) {
// iterate path definitions
}
Object properties are exactly like in the OpenAPI specification. You may also access additional properties added by specification extensions.
This library is currently work in progress, the following list tracks completeness:
- read OpenAPI 3.0 JSON
- read OpenAPI 3.0 YAML
- OpenAPI 3.0 Schema
- OpenAPI Object
- Info Object
- Contact Object
- License Object
- Server Object
- Server Variable Object
- Components Object
- Paths Object
- Path Item Object
- Operation Object
- External Documentation Object
- Parameter Object
- Request Body Object
- Media Type Object
- Encoding Object
- Responses Object
- Response Object
- Callback Object
- Example Object
- Link Object
- Header Object
- Tag Object
- Reference Object
- Schema Object
- load/read
-
additionalProperties
field
-
- validation
- load/read
- Discriminator Object
- XML Object
- Security Scheme Object
- OAuth Flows Object
- OAuth Flow Object
- Security Requirement Object