Skip to content

Commit db5b82a

Browse files
committed
[JSONSchema] Add nullable property description
1 parent e773104 commit db5b82a

File tree

3 files changed

+5
-1
lines changed

3 files changed

+5
-1
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
* GraphQL: Allow to format GraphQL errors based on exceptions (#3063)
88
* GraphQL: Add page-based pagination (#3175)
99
* OpenAPI: Add PHP default values to the documentation (#2386)
10+
* OpenAPI: Add nullable schema components properties
1011

1112
## 2.5.3
1213

src/JsonSchema/SchemaFactory.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,8 @@ private function buildPropertySchema(Schema $schema, string $definitionName, str
199199
$className = $valueType->getClassName();
200200
}
201201

202-
$valueSchema = $this->typeFactory->getType(new Type($builtinType, $type->isNullable(), $className, $isCollection), $format, $propertyMetadata->isReadableLink(), $serializerContext, $schema);
202+
$valueSchema = !$swagger && $type->isNullable() ? ['nullable' => true] : [];
203+
$valueSchema += $this->typeFactory->getType(new Type($builtinType, $type->isNullable(), $className, $isCollection), $format, $propertyMetadata->isReadableLink(), $serializerContext, $schema);
203204
}
204205

205206
$propertySchema = new \ArrayObject($propertySchema + $valueSchema);

tests/Swagger/Serializer/DocumentationNormalizerV3Test.php

+2
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,7 @@ private function doTestNormalize(OperationMethodResolverInterface $operationMeth
388388
'type' => 'string',
389389
'description' => 'This is a \DateTimeInterface object.',
390390
'format' => 'date-time',
391+
'nullable' => true,
391392
]),
392393
],
393394
]),
@@ -1998,6 +1999,7 @@ public function testNormalizeWithNestedNormalizationGroups(): void
19981999
'relatedDummy' => new \ArrayObject([
19992000
'description' => 'This is a related dummy \o/.',
20002001
'$ref' => '#/components/schemas/'.$relatedDummyRef,
2002+
'nullable' => true,
20012003
]),
20022004
],
20032005
]),

0 commit comments

Comments
 (0)