Skip to content

Commit e316519

Browse files
authored
Update README.md
1 parent 0943eba commit e316519

File tree

1 file changed

+31
-2
lines changed

1 file changed

+31
-2
lines changed

README.md

+31-2
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,11 @@ You may also access additional properties added by [specification extensions](ht
110110
### Writing API Description Files
111111

112112
```php
113+
use cebe\openapi\spec\OpenApi;
114+
use cebe\openapi\spec\PathItem;
115+
113116
// create base API Description
114-
$openapi = new \cebe\openapi\spec\OpenApi([
117+
$openapi = new OpenApi([
115118
'openapi' => '3.0.2',
116119
'info' => [
117120
'title' => 'Test API',
@@ -120,7 +123,7 @@ $openapi = new \cebe\openapi\spec\OpenApi([
120123
'paths' => [],
121124
]);
122125
// manipulate description as needed
123-
$openapi->paths['/test'] = new \cebe\openapi\spec\PathItem([
126+
$openapi->paths['/test'] = new PathItem([
124127
'description' => 'something'
125128
]);
126129
// ...
@@ -145,6 +148,32 @@ results in the following JSON data:
145148
}
146149
```
147150

151+
### Writing API Description Files using prepared Objects
152+
153+
Since version 1.2.0, the above example can also be written like this (passing objects instead of arrays):
154+
155+
```php
156+
use cebe\openapi\spec\OpenApi;
157+
use cebe\openapi\spec\PathItem;
158+
use cebe\openapi\spec\Info;
159+
160+
161+
// create base API Description
162+
$openapi = new OpenApi([
163+
'openapi' => '3.0.2',
164+
'info' => new Info([
165+
'title' => 'Test API',
166+
'version' => '1.0.0',
167+
]),
168+
'paths' => [
169+
'/test' => new PathItem([
170+
'description' => 'something'
171+
]),
172+
],
173+
]);
174+
$json = \cebe\openapi\Writer::writeToJson($openapi);
175+
```
176+
148177
### Reading API Description Files and Resolving References
149178

150179
In the above we have passed the raw JSON or YAML data to the Reader. In order to be able to resolve

0 commit comments

Comments
 (0)