Skip to content

Commit ba2f0cf

Browse files
committed
Update README about inline references
fixes #122
1 parent 859071c commit ba2f0cf

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

README.md

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,9 +195,20 @@ references to structures in external files, we must provide the full context.
195195

196196
```php
197197
use cebe\openapi\Reader;
198+
use cebe\openapi\spec\OpenAPI;
199+
use cebe\openapi\ReferenceContext;
200+
201+
// there are two different modes for resolving references:
202+
// ALL: resolve all references, which will result in a large description with a lot of repetition
203+
// but no references (except if there are recursive references, these will stop at some level)
204+
$mode = ReferenceContext::RESOLVE_MODE_ALL;
205+
// INLINE: only references to external files are resolved, references to places in the current file
206+
// are still Reference objects.
207+
$mode = ReferenceContext::RESOLVE_MODE_INLINE;
208+
198209
// an absolute URL or file path is needed to allow resolving external references
199-
$openapi = Reader::readFromJsonFile('https://www.example.com/api/openapi.json');
200-
$openapi = Reader::readFromYamlFile('https://www.example.com/api/openapi.yaml');
210+
$openapi = Reader::readFromJsonFile('https://www.example.com/api/openapi.json', OpenAPI::class, $mode);
211+
$openapi = Reader::readFromYamlFile('https://www.example.com/api/openapi.yaml', OpenAPI::class, $mode);
201212
```
202213

203214
If data has been loaded in a different way you can manually resolve references like this by giving a context:

0 commit comments

Comments
 (0)