Skip to content

Commit 729f217

Browse files
authored
Merge pull request #116 from tomaj/json-property-with-name-type
Property with name `type` is now available in json schema
2 parents 5d2cf8c + beb9748 commit 729f217

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Updates should follow the [Keep a CHANGELOG](http://keepachangelog.com/) princip
1414

1515
* Yaml format for OpenApiHandler is available only if symfony/yaml is installed
1616
* RedirectOutput use new RedirectResponse
17+
* Property with name `type` is now available in json schema
1718

1819
## 2.6.0 - 2021-10-08
1920

src/Handlers/OpenApiHandler.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -593,9 +593,12 @@ private function transformSchema(array $schema)
593593
return json_decode(str_replace('#/definitions/', '#/components/schemas/', json_encode($schema, JSON_UNESCAPED_SLASHES)), true);
594594
}
595595

596-
private function transformTypes(array &$schema)
596+
private function transformTypes(array &$schema, ?string $parent = null)
597597
{
598598
foreach ($schema as $key => &$value) {
599+
if ($parent === 'properties') {
600+
continue;
601+
}
599602
if ($key === 'type' && is_array($value)) {
600603
if (count($value) === 2 && in_array('null', $value)) {
601604
unset($value[array_search('null', $value)]);
@@ -605,7 +608,7 @@ private function transformTypes(array &$schema)
605608
throw new InvalidArgumentException('Type cannot be array and if so, one element have to be "null"');
606609
}
607610
} elseif (is_array($value)) {
608-
$this->transformTypes($value);
611+
$this->transformTypes($value, $key);
609612
}
610613
}
611614
}

0 commit comments

Comments
 (0)