Skip to content

Commit c68af3b

Browse files
AC-10541: Rest API Fix
1 parent 151d320 commit c68af3b

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

app/code/Magento/Webapi/Controller/Rest/ParamsOverrider.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
namespace Magento\Webapi\Controller\Rest;
88

99
use Magento\Framework\App\ObjectManager;
10+
use Magento\Framework\Exception\NoSuchEntityException;
1011
use Magento\Framework\Webapi\Rest\Request\ParamOverriderInterface;
1112
use Magento\Webapi\Model\Config\Converter;
1213
use Magento\Framework\Reflection\MethodsMap;
@@ -53,9 +54,12 @@ public function __construct(
5354
* @param array $inputData Incoming data from request
5455
* @param array $parameters Contains parameters to replace or default
5556
* @return array Data in same format as $inputData with appropriate parameters added or changed
57+
* @throws NoSuchEntityException
5658
*/
5759
public function override(array $inputData, array $parameters)
5860
{
61+
$inputData = $this->validateInputData($inputData);
62+
5963
foreach ($parameters as $name => $paramData) {
6064
$arrayKeys = explode('.', $name);
6165
if ($paramData[Converter::KEY_FORCE] || !$this->isNestedArrayValueSet($inputData, $arrayKeys)) {
@@ -71,6 +75,27 @@ public function override(array $inputData, array $parameters)
7175
return $inputData;
7276
}
7377

78+
/**
79+
* Validates InputData
80+
*
81+
* @param array $inputData
82+
* @return array
83+
*/
84+
private function validateInputData(array $inputData): array
85+
{
86+
$result = [];
87+
88+
$data = array_filter($inputData, function ($k) use (&$result) {
89+
$key = is_string($k) ? strtolower(str_replace('_', "", $k)) : $k;
90+
return !isset($result[$key]) && ($result[$key] = true);
91+
}, ARRAY_FILTER_USE_KEY);
92+
93+
return array_map(function ($value) {
94+
return is_array($value) ? $this->validateInputData($value) : $value;
95+
}, $data);
96+
}
97+
98+
7499
/**
75100
* Determine if a nested array value is set.
76101
*

0 commit comments

Comments
 (0)