Skip to content

Commit 7beb5c9

Browse files
bmijnendonckxsoyuka
authored andcommitted
fix(openapi): example and default with nullable value not being shown
1 parent abb1fac commit 7beb5c9

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

src/JsonSchema/Metadata/Property/Factory/SchemaPropertyMetadataFactory.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,14 @@ public function create(string $resourceClass, string $property, array $options =
8888

8989
$types = $propertyMetadata->getBuiltinTypes() ?? [];
9090

91-
if (!\array_key_exists('default', $propertySchema) && !empty($default = $propertyMetadata->getDefault()) && (!\count($types) || null === ($className = $types[0]->getClassName()) || !$this->isResourceClass($className))) {
91+
if (!\array_key_exists('default', $propertySchema) && null !== ($default = $propertyMetadata->getDefault()) && (!\count($types) || null === ($className = $types[0]->getClassName()) || !$this->isResourceClass($className))) {
9292
if ($default instanceof \BackedEnum) {
9393
$default = $default->value;
9494
}
9595
$propertySchema['default'] = $default;
9696
}
9797

98-
if (!\array_key_exists('example', $propertySchema) && !empty($example = $propertyMetadata->getExample())) {
98+
if (!\array_key_exists('example', $propertySchema) && null !== ($example = $propertyMetadata->getExample())) {
9999
$propertySchema['example'] = $example;
100100
}
101101

src/Metadata/Property/Factory/DefaultPropertyMetadataFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public function create(string $resourceClass, string $property, array $options =
4545

4646
$defaultProperties = $reflectionClass->getDefaultProperties();
4747

48-
if (!\array_key_exists($property, $defaultProperties) || null === ($defaultProperty = $defaultProperties[$property])) {
48+
if (!\array_key_exists($property, $defaultProperties) || empty($defaultProperty = $defaultProperties[$property])) {
4949
return $propertyMetadata;
5050
}
5151

0 commit comments

Comments
 (0)