Skip to content

Commit

Permalink
Merge pull request #18 from PcComponentes/bugfix/new_json_schema_vali…
Browse files Browse the repository at this point in the history
…dator_compatibility

fix: new json schema validator compatibility
  • Loading branch information
calmohallag authored Nov 15, 2022
2 parents 0870f45 + abbdc6b commit 2d69067
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions src/OpenApi/OpenApiSchemaParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@ private function extractData(array $data): array
{
$aux = [];

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

foreach ($data as $key => $elem) {
if ('$ref' === $key) {
Expand Down Expand Up @@ -93,9 +91,9 @@ private function assertMethodRoot(string $path, string $method, $pathRoot): void
private function assertStatusCodeRoot(string $path, string $method, int $statusCode, $methodRoot): void
{
if (false === \array_key_exists('responses', $methodRoot) || false === \array_key_exists(
$statusCode,
$methodRoot['responses']
)) {
$statusCode,
$methodRoot['responses']
)) {
throw new \InvalidArgumentException(
\sprintf('%s response not found on %s path with %s method', $statusCode, $path, $method)
);
Expand Down Expand Up @@ -124,15 +122,14 @@ 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']);
if (false === \array_key_exists('nullable', $data)) {
return $data;
}

$data['type'] = \is_array($data['type'])
? \array_merge($data['type'], ['null'])
: [$data['type'], 'null'];

unset($data['nullable']);

return $data;
Expand Down

0 comments on commit 2d69067

Please sign in to comment.