diff --git a/src/OpenApi/OpenApiSchemaParser.php b/src/OpenApi/OpenApiSchemaParser.php index 32b01e9..743dead 100644 --- a/src/OpenApi/OpenApiSchemaParser.php +++ b/src/OpenApi/OpenApiSchemaParser.php @@ -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); @@ -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; + } }