@@ -110,8 +110,11 @@ You may also access additional properties added by [specification extensions](ht
110
110
### Writing API Description Files
111
111
112
112
``` php
113
+ use cebe\openapi\spec\OpenApi;
114
+ use cebe\openapi\spec\PathItem;
115
+
113
116
// create base API Description
114
- $openapi = new \cebe\openapi\spec\ OpenApi([
117
+ $openapi = new OpenApi([
115
118
'openapi' => '3.0.2',
116
119
'info' => [
117
120
'title' => 'Test API',
@@ -120,7 +123,7 @@ $openapi = new \cebe\openapi\spec\OpenApi([
120
123
'paths' => [],
121
124
]);
122
125
// manipulate description as needed
123
- $openapi->paths['/test'] = new \cebe\openapi\spec\ PathItem([
126
+ $openapi->paths['/test'] = new PathItem([
124
127
'description' => 'something'
125
128
]);
126
129
// ...
@@ -145,6 +148,32 @@ results in the following JSON data:
145
148
}
146
149
```
147
150
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
+
148
177
### Reading API Description Files and Resolving References
149
178
150
179
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