10
10
use cebe \openapi \exceptions \IOException ;
11
11
use cebe \openapi \exceptions \TypeErrorException ;
12
12
use cebe \openapi \exceptions \UnresolvableReferenceException ;
13
+ use cebe \openapi \json \JsonPointer ;
13
14
use cebe \openapi \spec \OpenApi ;
14
15
use Symfony \Component \Yaml \Yaml ;
15
16
@@ -57,9 +58,12 @@ public static function readFromYaml(string $yaml, string $baseType = OpenApi::cl
57
58
* @param string $baseType the base Type to instantiate. This must be an instance of [[SpecObjectInterface]].
58
59
* The default is [[OpenApi]] which is the base type of a OpenAPI specification file.
59
60
* You may choose a different type if you instantiate objects from sub sections of a specification.
60
- * @param bool $resolveReferences whether to automatically resolve references in the specification.
61
+ * @param bool|string $resolveReferences whether to automatically resolve references in the specification.
61
62
* If `true`, all [[Reference]] objects will be replaced with their referenced spec objects by calling
62
63
* [[SpecObjectInterface::resolveReferences()]].
64
+ * Since version 1.5.0 this can be a string indicating the reference resolving mode:
65
+ * - `inline` only resolve references to external files.
66
+ * - `all` resolve all references exceot recursive references.
63
67
* @return SpecObjectInterface|OpenApi the OpenApi object instance.
64
68
* The type of the returned object depends on the `$baseType` argument.
65
69
* @throws TypeErrorException in case invalid spec data is supplied.
@@ -75,8 +79,13 @@ public static function readFromJsonFile(string $fileName, string $baseType = Ope
75
79
throw $ e ;
76
80
}
77
81
$ spec = static ::readFromJson ($ fileContent , $ baseType );
78
- $ spec ->setReferenceContext (new ReferenceContext ($ spec , $ fileName ));
79
- if ($ resolveReferences ) {
82
+ $ context = new ReferenceContext ($ spec , $ fileName );
83
+ $ spec ->setReferenceContext ($ context );
84
+ if ($ resolveReferences !== false ) {
85
+ if (is_string ($ resolveReferences )) {
86
+ $ context ->mode = $ resolveReferences ;
87
+ }
88
+ $ spec ->setDocumentContext ($ spec , new JsonPointer ('' ));
80
89
$ spec ->resolveReferences ();
81
90
}
82
91
return $ spec ;
@@ -90,9 +99,12 @@ public static function readFromJsonFile(string $fileName, string $baseType = Ope
90
99
* @param string $baseType the base Type to instantiate. This must be an instance of [[SpecObjectInterface]].
91
100
* The default is [[OpenApi]] which is the base type of a OpenAPI specification file.
92
101
* You may choose a different type if you instantiate objects from sub sections of a specification.
93
- * @param bool $resolveReferences whether to automatically resolve references in the specification.
102
+ * @param bool|string $resolveReferences whether to automatically resolve references in the specification.
94
103
* If `true`, all [[Reference]] objects will be replaced with their referenced spec objects by calling
95
104
* [[SpecObjectInterface::resolveReferences()]].
105
+ * Since version 1.5.0 this can be a string indicating the reference resolving mode:
106
+ * - `inline` only resolve references to external files.
107
+ * - `all` resolve all references exceot recursive references.
96
108
* @return SpecObjectInterface|OpenApi the OpenApi object instance.
97
109
* The type of the returned object depends on the `$baseType` argument.
98
110
* @throws TypeErrorException in case invalid spec data is supplied.
@@ -108,8 +120,13 @@ public static function readFromYamlFile(string $fileName, string $baseType = Ope
108
120
throw $ e ;
109
121
}
110
122
$ spec = static ::readFromYaml ($ fileContent , $ baseType );
111
- $ spec ->setReferenceContext (new ReferenceContext ($ spec , $ fileName ));
112
- if ($ resolveReferences ) {
123
+ $ context = new ReferenceContext ($ spec , $ fileName );
124
+ $ spec ->setReferenceContext ($ context );
125
+ if ($ resolveReferences !== false ) {
126
+ if (is_string ($ resolveReferences )) {
127
+ $ context ->mode = $ resolveReferences ;
128
+ }
129
+ $ spec ->setDocumentContext ($ spec , new JsonPointer ('' ));
113
130
$ spec ->resolveReferences ();
114
131
}
115
132
return $ spec ;
0 commit comments