Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/RefResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class RefResolver
public $url;
/** @var null|RefResolver */
private $rootResolver;
private int $max_deep_nesting = 200; //Change this via options submitted to ::import if needed

/**
* @param mixed $resolutionScope
Expand Down Expand Up @@ -102,9 +103,10 @@ public function setupResolutionScope($id, $data)
* RefResolver constructor.
* @param JsonSchema $rootData
*/
public function __construct($rootData = null)
public function __construct($rootData = null, int $max_nest_level = 200)
{
$this->rootData = $rootData;
$this->max_deep_nesting = $max_nest_level;
}

public function setRootData($rootData)
Expand Down Expand Up @@ -224,8 +226,8 @@ public function resolveReference($referencePath)
*/
public function preProcessReferences($data, Context $options, $nestingLevel = 0)
{
if ($nestingLevel > 200) {
throw new Exception('Too deep nesting level', Exception::DEEP_NESTING);
if ($nestingLevel > $this->max_deep_nesting) { //Updated due to specific recursion depth from Amazon product JSON Schemas - yep 200 was not enough
throw new Exception('Too deep nesting level. Suggest submitting maxNestLevel via options', Exception::DEEP_NESTING);
}
if (is_array($data)) {
foreach ($data as $key => $item) {
Expand Down Expand Up @@ -264,4 +266,4 @@ public function preProcessReferences($data, Context $options, $nestingLevel = 0)
}


}
}
2 changes: 1 addition & 1 deletion src/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public function in($data, ?Context $options = null)
$options->import = true;

if ($options->refResolver === null) {
$options->refResolver = new RefResolver($data);
$options->refResolver = new RefResolver($data, $options->maxNestLevel ?? 200);
} else {
$options->refResolver->setRootData($data);
}
Expand Down