|
1 | 1 | # php-openapi |
2 | | -READ OpenAPI yaml files and make the content accessable in PHP objects. |
| 2 | + |
| 3 | +READ OpenAPI yaml and json files and make the content accessable in PHP objects. |
| 4 | + |
| 5 | +## Install |
| 6 | + |
| 7 | + composer require cebe/php-openapi |
| 8 | + |
| 9 | +## Requirements |
| 10 | + |
| 11 | +- PHP 7.0 or higher |
| 12 | + |
| 13 | +## Usage |
| 14 | + |
| 15 | +Read OpenAPI spec from JSON: |
| 16 | + |
| 17 | +```php |
| 18 | +use cebe\openapi\Reader; |
| 19 | + |
| 20 | +$openapi = Reader::readFromJson(file_get_contents('openapi.json')); |
| 21 | +``` |
| 22 | + |
| 23 | +Read OpenAPI spec from YAML: |
| 24 | + |
| 25 | +```php |
| 26 | +use cebe\openapi\Reader; |
| 27 | + |
| 28 | +$openapi = Reader::readFromYaml(file_get_contents('openapi.yaml')); |
| 29 | +``` |
| 30 | + |
| 31 | +Access specification data: |
| 32 | + |
| 33 | +```php |
| 34 | +echo $openapi->openapi; // openAPI version, e.g. 3.0.0 |
| 35 | +echo $openapi->info->title; // API title |
| 36 | +foreach($openapi->paths as $path => $definition) { |
| 37 | + // iterate path definitions |
| 38 | +} |
| 39 | +``` |
| 40 | + |
| 41 | +Object properties are exactly like in the [OpenAPI specification](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#openapi-specification). |
| 42 | +You may also access additional properties added by specification extensions. |
| 43 | + |
| 44 | + |
| 45 | +## Completeness |
| 46 | + |
| 47 | +This library is currently work in progress, the following list tracks completeness: |
| 48 | + |
| 49 | +- [ ] read OpenAPI 3.0 JSON |
| 50 | +- [ ] read OpenAPI 3.0 YAML |
| 51 | +- [ ] OpenAPI 3.0 Schema |
| 52 | + - [x] OpenAPI Object |
| 53 | + - [x] Info Object |
| 54 | + - [x] Contact Object |
| 55 | + - [x] License Object |
| 56 | + - [x] Server Object |
| 57 | + - [x] Server Variable Object |
| 58 | + - [ ] Components Object |
| 59 | + - [ ] Paths Object |
| 60 | + - [ ] Path Item Object |
| 61 | + - [ ] Operation Object |
| 62 | + - [x] External Documentation Object |
| 63 | + - [ ] Parameter Object |
| 64 | + - [ ] Request Body Object |
| 65 | + - [ ] Media Type Object |
| 66 | + - [ ] Encoding Object |
| 67 | + - [ ] Responses Object |
| 68 | + - [ ] Response Object |
| 69 | + - [ ] Callback Object |
| 70 | + - [ ] Example Object |
| 71 | + - [ ] Link Object |
| 72 | + - [ ] Header Object |
| 73 | + - [ ] Tag Object |
| 74 | + - [ ] Reference Object |
| 75 | + - [ ] Schema Object |
| 76 | + - [ ] Discriminator Object |
| 77 | + - [ ] XML Object |
| 78 | + - [ ] Security Scheme Object |
| 79 | + - [ ] OAuth Flows Object |
| 80 | + - [ ] OAuth Flow Object |
| 81 | + - [ ] Security Requirement Object |
0 commit comments