Skip to content

Commit

Permalink
FIX query parameters with an array type
Browse files Browse the repository at this point in the history
  • Loading branch information
digitv committed Jul 19, 2023
1 parent 0a5a960 commit 48dc1c0
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 15 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": "Swagger yaml generator",
"keywords": ["api", "swagger", "open auth"],
"license": "MIT",
"version": "1.4.4",
"version": "1.4.5",
"authors": [
{
"name": "Digit",
Expand Down
22 changes: 11 additions & 11 deletions oa/BaseValueDescribed.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,17 @@ abstract class BaseValueDescribed extends BaseAnnotation
*/
protected ?string $_phpType = null;

/**
* BaseValueDescribed constructor.
*
* @param array $values
*/
public function __construct(array $values)
{
$this->configureSelf($values, 'name');
$this->processType();
}

/**
* Check that variable name is nested (with dots)
* @return bool
Expand Down Expand Up @@ -153,17 +164,6 @@ public function toArrayRecursive(array &$target): void
}
}

/**
* BaseValueDescribed constructor.
*
* @param array $values
*/
public function __construct(array $values)
{
$this->configureSelf($values, 'name');
$this->processType();
}

/**
* Get object string representation.
*
Expand Down
3 changes: 2 additions & 1 deletion oa/Parameter.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* @Attribute("name",type="string"),
* @Attribute("type",type="string"),
* @Attribute("in",type="string"),
* @Attribute("style",type="string"),
* @Attribute("description",type="string"),
* })
*/
Expand Down Expand Up @@ -112,7 +113,7 @@ protected static function getDefaultStyles(): array
return [
// 'in.type' => 'style',
// 'in.*' => 'style',
'query.array' => 'deepObject',
'query.array' => 'form',
];
}
}
12 changes: 10 additions & 2 deletions src/RoutesParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -445,13 +445,21 @@ protected function convertRequestBodyIntoQueryParams(array $body): ?array
$properties = $bodyByContentType['schema']['properties'];
foreach ($properties as $property => $row) {
$type = $row['type'] ?? null;
$paramName = $property;
// Parse objects
if ($type === Variable::SW_TYPE_OBJECT) {
$paramsPlain = $this->convertRequestBodyObjectToPlainParamsForQuery($row, $property);
$paramsPlain = $this->convertRequestBodyObjectToPlainParamsForQuery($row, $paramName);
$params = array_merge($params, $paramsPlain);
continue;
}
$param = new Parameter(array_merge($row, ['in' => 'query', 'name' => $property]));
// Modify array
if ($type === Variable::SW_TYPE_ARRAY) {
$paramName .= '[]';
$typeItems = $row['items'] ?? Variable::SW_TYPE_STRING;
$typeItems = is_array($typeItems) ? $typeItems['type'] ?? Variable::SW_TYPE_STRING : $typeItems;
$row = array_merge($row, ['items' => $typeItems]);
}
$param = new Parameter(array_merge($row, ['in' => 'query', 'name' => $paramName]));
$params[$property] = $param->toArray();
}
}
Expand Down

0 comments on commit 48dc1c0

Please sign in to comment.