Skip to content

Commit 8e80f9b

Browse files
authored
Update RefResolver.php
Update to allow submitting of a max nest level depth variable via the Schema object.
1 parent 5b59616 commit 8e80f9b

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/RefResolver.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class RefResolver
1313
public $url;
1414
/** @var null|RefResolver */
1515
private $rootResolver;
16-
private static int $MAX_DEEP_NESTING = 500; //Change this if you receive DEEP_NESTING exceptions
16+
private int $max_deep_nesting = 200; //Change this via options submitted to ::import if needed
1717

1818
/**
1919
* @param mixed $resolutionScope
@@ -103,9 +103,10 @@ public function setupResolutionScope($id, $data)
103103
* RefResolver constructor.
104104
* @param JsonSchema $rootData
105105
*/
106-
public function __construct($rootData = null)
106+
public function __construct($rootData = null, int $max_nest_level = 200)
107107
{
108108
$this->rootData = $rootData;
109+
$this->max_deep_nesting = $max_nest_level;
109110
}
110111

111112
public function setRootData($rootData)
@@ -225,8 +226,8 @@ public function resolveReference($referencePath)
225226
*/
226227
public function preProcessReferences($data, Context $options, $nestingLevel = 0)
227228
{
228-
if ($nestingLevel > self::$MAX_DEEP_NESTING) { //Updated due to specific recursion depth from Amazon product JSON Schemas - yep 200 was not enough
229-
throw new Exception('Too deep nesting level', Exception::DEEP_NESTING);
229+
if ($nestingLevel > $this->max_deep_nesting) { //Updated due to specific recursion depth from Amazon product JSON Schemas - yep 200 was not enough
230+
throw new Exception('Too deep nesting level. Suggest submitting maxNestLevel via options', Exception::DEEP_NESTING);
230231
}
231232
if (is_array($data)) {
232233
foreach ($data as $key => $item) {

0 commit comments

Comments
 (0)