@@ -33,6 +33,7 @@ $inputFormat = null;
33
33
$ outputFile = null ;
34
34
$ outputFormat = null ;
35
35
$ silentMode = false ;
36
+ $ referenceMode = ReferenceContext::RESOLVE_MODE_ALL ;
36
37
foreach ($ argv as $ k => $ arg ) {
37
38
if ($ k == 0 ) {
38
39
continue ;
@@ -54,6 +55,15 @@ foreach($argv as $k => $arg) {
54
55
error ("Conflicting arguments: only one of --read-json or --read-yaml is allowed! " , "usage " );
55
56
}
56
57
break ;
58
+ case '--resolve-none ' :
59
+ $ referenceMode = false ;
60
+ break ;
61
+ case '--resolve-external ' :
62
+ $ referenceMode = ReferenceContext::RESOLVE_MODE_INLINE ;
63
+ break ;
64
+ case '--resolve-all ' :
65
+ $ referenceMode = ReferenceContext::RESOLVE_MODE_ALL ;
66
+ break ;
57
67
case '--write-yaml ' :
58
68
if ($ outputFormat === null ) {
59
69
$ outputFormat = 'yaml ' ;
@@ -89,6 +99,11 @@ foreach($argv as $k => $arg) {
89
99
} else {
90
100
if ($ command === null ) {
91
101
$ command = $ arg ;
102
+ // inline is an alias for "convert --resolve-external"
103
+ if ($ command === 'inline ' ) {
104
+ $ command = 'convert ' ;
105
+ $ referenceMode = ReferenceContext::RESOLVE_MODE_INLINE ;
106
+ }
92
107
} elseif ($ inputFile === null ) {
93
108
$ inputFile = $ arg ;
94
109
} elseif ($ outputFile === null ) {
@@ -109,9 +124,7 @@ switch ($command) {
109
124
$ openApi = read_input ($ inputFile , $ inputFormat );
110
125
$ referenceContext = new ReferenceContext ($ openApi , $ inputFile ? realpath ($ inputFile ) : '' );
111
126
$ referenceContext ->throwException = false ;
112
- // TODO apply reference context mode
113
- // $referenceContext->mode = ReferenceContext::RESOLVE_MODE_ALL;
114
- // $referenceContext->mode = ReferenceContext::RESOLVE_MODE_INLINE;
127
+ $ referenceContext ->mode = ReferenceContext::RESOLVE_MODE_INLINE ;
115
128
$ openApi ->resolveReferences ($ referenceContext );
116
129
117
130
$ openApi ->setDocumentContext ($ openApi , new \cebe \openapi \json \JsonPointer ('' ));
@@ -189,12 +202,13 @@ switch ($command) {
189
202
190
203
$ openApi = read_input ($ inputFile , $ inputFormat );
191
204
try {
192
- // TODO apply reference context mode
193
- // $referenceContext->mode = ReferenceContext::RESOLVE_MODE_ALL;
194
- // $referenceContext->mode = ReferenceContext::RESOLVE_MODE_INLINE;
195
205
// set document context for correctly converting recursive references
196
206
$ openApi ->setDocumentContext ($ openApi , new \cebe \openapi \json \JsonPointer ('' ));
197
- $ openApi ->resolveReferences ();
207
+ if ($ referenceMode ) {
208
+ $ referenceContext = new ReferenceContext ($ openApi , $ inputFile ? realpath ($ inputFile ) : '' );
209
+ $ referenceContext ->mode = $ referenceMode ;
210
+ $ openApi ->resolveReferences ($ referenceContext );
211
+ }
198
212
} catch (\cebe \openapi \exceptions \UnresolvableReferenceException $ e ) {
199
213
error ("[ \e[33m {$ e ->context }\e[0m] " . $ e ->getMessage ());
200
214
}
@@ -310,14 +324,26 @@ Usage:
310
324
Exits with code 2 on validation errors, 1 on other errors and 0 on success.
311
325
312
326
\Bconvert\C Convert a JSON or YAML input file to JSON or YAML output file.
313
- References are being resolved so the output will be a single API Description file.
314
327
315
328
If no input file is specified input will be read from STDIN.
316
329
If no output file is specified output will be written to STDOUT.
317
330
The tool will try to auto-detect the content type of the input and output file, but may fail
318
331
to do so, you may specify \Y--read-yaml\C or \Y--read-json\C to force the input file type.
319
332
and \Y--write-yaml\C or \Y--write-json\C to force the output file type.
320
333
334
+ By default all references are resolved (replaced with the object refered to). You can control
335
+ handling of references with the following arguments:
336
+
337
+ \Y--resolve-none\C Do not resolve references.
338
+ \Y--resolve-external\C Only resolve references that point to external files.
339
+ This process is often referred to as "inlining".
340
+ \Y--resolve-all\C Resolve all references (default).
341
+ Recursive pointers will stay references.
342
+
343
+ \Binline\C Convert a JSON or YAML input file to JSON or YAML output file and
344
+ resolve all external references. The output will be a single API Description file.
345
+ This is a shortcut for calling \Bconvert\C \Y--resolve-external\C.
346
+
321
347
\Bhelp\C Shows this usage information.
322
348
323
349
Options:
0 commit comments