Skip to content

Commit 83cec26

Browse files
committed
update documentation
1 parent 11bea88 commit 83cec26

File tree

1 file changed

+54
-4
lines changed

1 file changed

+54
-4
lines changed

README.md

Lines changed: 54 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
READ [OpenAPI](https://www.openapis.org/) 3.0.x YAML and JSON files and make the content accessible in PHP objects.
44

5+
It also provides a CLI tool for validating and converting OpenAPI 3.0.x YAML and JSON files.
6+
57
[![Latest Stable Version](https://poser.pugx.org/cebe/php-openapi/v/stable)](https://packagist.org/packages/cebe/php-openapi)
68
[![Build Status](https://travis-ci.org/cebe/php-openapi.svg?branch=master)](https://travis-ci.org/cebe/php-openapi)
79
[![License](https://poser.pugx.org/cebe/php-openapi/license)](https://packagist.org/packages/cebe/php-openapi)
@@ -20,28 +22,74 @@ READ [OpenAPI](https://www.openapis.org/) 3.0.x YAML and JSON files and make the
2022
This library provides a low level API for reading OpenAPI files. It is used by higher level tools to
2123
do awesome work:
2224

23-
- https://github.com/cebe/yii2-openapi Code Generator for REST API from OpenAPI spec
25+
- https://github.com/cebe/yii2-openapi Code Generator for REST API from OpenAPI spec, includes fake data generator.
2426
- https://github.com/cebe/yii2-app-api Yii framework application template for developing API-first applications
2527
- ... ([add yours](https://github.com/cebe/php-openapi/edit/master/README.md#L24))
2628

2729
## Usage
2830

31+
### CLI tool
32+
33+
$ vendor/bin/php-openapi help
34+
PHP OpenAPI 3 tool
35+
------------------
36+
by Carsten Brandt <[email protected]>
37+
38+
Usage:
39+
php-openapi <command> [<options>] [input.yml|input.json] [output.yml|output.json]
40+
41+
The following commands are available:
42+
43+
validate Validate the API description in the specified input file against the OpenAPI v3.0 schema.
44+
Note: the validation is performed in two steps. The results is composed of
45+
(1) structural errors found while reading the API description file, and
46+
(2) violations of the OpenAPI v3.0 schema.
47+
48+
If no input file is specified input will be read from STDIN.
49+
The tool will try to auto-detect the content type of the input, but may fail
50+
to do so, you may specify --read-yaml or --read-json to force the file type.
51+
52+
Exits with code 2 on validation errors, 1 on other errors and 0 on success.
53+
54+
convert Convert a JSON or YAML input file to JSON or YAML output file.
55+
References are being resolved so the output will be a single specification file.
56+
57+
If no input file is specified input will be read from STDIN.
58+
If no output file is specified output will be written to STDOUT.
59+
The tool will try to auto-detect the content type of the input and output file, but may fail
60+
to do so, you may specify --read-yaml or --read-json to force the input file type.
61+
and --write-yaml or --write-json to force the output file type.
62+
63+
help Shows this usage information.
64+
65+
Options:
66+
67+
--read-json force reading input as JSON. Auto-detect if not specified.
68+
--read-yaml force reading input as YAML. Auto-detect if not specified.
69+
--write-json force writing output as JSON. Auto-detect if not specified.
70+
--write-yaml force writing output as YAML. Auto-detect if not specified.
71+
72+
2973
### Reading Specification information
3074

31-
Read OpenAPI spec from JSON:
75+
Read OpenAPI spec from JSON file:
3276

3377
```php
3478
use cebe\openapi\Reader;
3579

36-
$openapi = Reader::readFromJson(file_get_contents('openapi.json'));
80+
// realpath is needed for resolving references with relative Paths or URLs
81+
$openapi = Reader::readFromJsonFile(realpath('openapi.json'));
3782
```
3883

3984
Read OpenAPI spec from YAML:
4085

4186
```php
4287
use cebe\openapi\Reader;
4388

44-
$openapi = Reader::readFromYaml(file_get_contents('openapi.yaml'));
89+
// realpath is needed for resolving references with relative Paths or URLs
90+
$openapi = Reader::readFromYamlFile(realpath('openapi.json'));
91+
// you may also specify the URL to your description file
92+
$openapi = Reader::readFromYamlFile('https://raw.githubusercontent.com/OAI/OpenAPI-Specification/3.0.2/examples/v3.0/petstore-expanded.yaml');
4593
```
4694

4795
Access specification data:
@@ -82,6 +130,8 @@ $openapi->resolveReferences(
82130
### Validation
83131

84132
The library provides simple validation operations, that check basic OpenAPI spec requirements.
133+
This is the same as "structural errors found while reading the API description file" from the CLI tool.
134+
This validation does not include checking against the OpenAPI v3.0 JSON schema.
85135

86136
```
87137
// return `true` in case no errors have been found, `false` in case of errors.

0 commit comments

Comments
 (0)