adamquaile / openapi-parser
Requires
- php: 8.2 - 8.4
- psr/container: ^2.0
- symfony/yaml: ^7.1
Requires (Dev)
- phpstan/phpstan: ^1.12
- phpstan/phpstan-phpunit: ^1.4
- phpunit/phpunit: ^11.3
- dev-main
- v0.1.1
- v0.1.0
- dev-license
- dev-petstore-fixes
- dev-namespace-reorg
- dev-openapi-object
- dev-components-object
- dev-media-type-support
- dev-encoding-object
- dev-paths-object-support
- dev-path-item-object-support
- dev-operation-object-support
- dev-responses-object
- dev-response-object
- dev-request-body-object
- dev-header-object
- dev-external-documentation-object
- dev-security-requirement-object
- dev-link-object
- dev-security-scheme-object
- dev-oauth-flows-objects
- dev-usage-example
- dev-missing-objects-in-feature-support-list
- dev-parameter-object
- dev-example-object
- dev-tag-object
- dev-reference-object
- dev-schema-object
- dev-xml-object
- dev-discriminator-object
- dev-php-version-support
- dev-servers
- dev-specification-extensions
- dev-openapi-features-readme
- dev-phpstan
- dev-server-variable-object
- dev-info-object
- dev-license-object
- dev-contact-object
- dev-github-tests
This package is auto-updated.
Last update: 2025-08-27 20:57:43 UTC
README
Parse (and maybe one day write) OpenAPI files in PHP.
For now, it's strict and is not intended to support invalid specification files. Please ensure you validate them before parsing with this library.
Installation
composer require adamquaile/openapi-parser
Usage
Here's an example usage of the library. Check ./tests/Feature for more examples.
<?php use AdamQ\OpenApiParser\OpenApiParser; $openapiParser = new OpenApiParser(); $openapi = $openapiParser->parseYamlString( file_get_contents('openapi.yaml') ); echo $openapi->info->version;
Compatibility
This library is not yet at version 1.0, so all of the following may change at any time.
PHP Version Support
This library aims to support any PHP version under active support and any versions that are not end-of life where possible. Support for new versions may require a new major version, at which point EOL versions will be dropped.
OpenAPI Parser Version | PHP 7 | PHP 8.0 | PHP 8.1 | PHP 8.2 | PHP 8.3 | PHP 8.4 |
---|---|---|---|---|---|---|
0.x | ❌ | ❌ | ❌ | ✅ | ✅ | ✅ |
OpenAPI Version Support
OpenAPI Parser Version | Swagger (2.0) | OpenAPI (3.0) | OpenAPI (3.1) |
---|---|---|---|
0.x | ❌ | ⚠️ | ✅ |
This library is being developed at a time when OpenAPI 3.1 is already quite widely-used. There's a lot to cover in creating this project, so 3.0 support is not a priority. Pull requests will be considered and 3.0 support is the goal, but efforts will be focused on later versions.
OpenAPI Feature Support (How complete is this library)
Feature | Support | Notes |
---|---|---|
Specification Extensions | ✅ | |
Parsing from YAML | ✅ | |
Parsing from JSON | ❌ | |
Resolving $ref references | ❌ | |
Validation | ❌ |
Object | Support | Notes |
---|---|---|
OpenAPI Object | ✅ | |
Info Object | ✅ | |
Contact Object | ✅ | |
License Object | ✅ | 1 |
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 | ⚠️ | 2 |
Example Object | ✅ | |
Link Object | ✅ | |
Header Object | ✅ | |
Tag Object | ✅ | |
Reference Object | ✅ | |
Schema Object | ⚠️3 | |
Discriminator Object | ✅ | |
XML Object | ✅ | |
Security Scheme Object | ✅ | |
OAuth Flows Object | ✅ | |
OAuth Flow Object | ✅ | |
Security Requirement Object | ✅ |