Skip to content

Commit 4dd589e

Browse files
Ocramiusteohhanhui
authored andcommitted
Use {"nullable": true, "anyOf": [{"$ref": ...}]} to comply with OpenAPI 3.0
OpenAPI 3.1 is not yet released, but fixes nullability in the way we had fixed it before (via `{"oneOf": [{"type": "null"}, ...]}`) in OAI/OpenAPI-Specification#1977. Until OpenAPI 3.1 is released, things like ``{"type": ["integer", "null"]}` are not valid definitions (because `"null"` is not yet a recognized type). We'll stick to OpenAPI 3.0 for now, using: * `{"nullable": true, ...}` for simple types * `{"nullable": true, "anyOf": [{"$ref": ...}]}` for type references
1 parent aac6d9c commit 4dd589e

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

TypeFactory.php

+8-6
Original file line numberDiff line numberDiff line change
@@ -180,11 +180,13 @@ private function addNullabilityToTypeDefinition(array $jsonSchema, Type $type, a
180180
return $jsonSchema;
181181
}
182182

183-
return [
184-
'oneOf' => [
185-
['type' => 'null'],
186-
$jsonSchema,
187-
],
188-
];
183+
if (\array_key_exists('$ref', $jsonSchema)) {
184+
return [
185+
'nullable' => true,
186+
'anyOf' => [$jsonSchema],
187+
];
188+
}
189+
190+
return array_merge($jsonSchema, ['nullable' => true]);
189191
}
190192
}

0 commit comments

Comments
 (0)