Skip to content

Commit

Permalink
Merge pull request #8 from calmohallag/feature/allow-nullable-respons…
Browse files Browse the repository at this point in the history
…e-parameters

allow nullable response parameters
  • Loading branch information
calmohallag authored Oct 26, 2022
2 parents 73ab33f + 394033c commit 0870f45
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/OpenApi/OpenApiSchemaParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ public function fromResponse(string $path, string $method, int $statusCode, stri
private function extractData(array $data): array
{
$aux = [];

if (\array_key_exists('nullable', $data)) {
$data = $this->convertNullableTypeToJsonSchema($data);
}

foreach ($data as $key => $elem) {
if ('$ref' === $key) {
$aux = $this->findDefinition($elem);
Expand Down Expand Up @@ -116,4 +121,20 @@ private function assertContentTypeRoot(
);
}
}

private function convertNullableTypeToJsonSchema(array $data): array
{
$data['oneOf'] = [
['type' => null],
];

if (\array_key_exists('type', $data)) {
$data['oneOf'][] = ['type' => $data['type']];
unset($data['type']);
}

unset($data['nullable']);

return $data;
}
}

0 comments on commit 0870f45

Please sign in to comment.