Skip to content

Commit

Permalink
[JSONSchema] Add nullable property description
Browse files Browse the repository at this point in the history
  • Loading branch information
kayneth committed Dec 18, 2019
1 parent 5fa9b56 commit 35f6bd9
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* GraphQL: Allow to format GraphQL errors based on exceptions (#3063)
* GraphQL: Add page-based pagination (#3175)
* OpenAPI: Add PHP default values to the documentation (#2386)
* OpenAPI: Add nullable schema components properties

## 2.5.3

Expand Down
3 changes: 2 additions & 1 deletion src/JsonSchema/SchemaFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,8 @@ private function buildPropertySchema(Schema $schema, string $definitionName, str
$className = $valueType->getClassName();
}

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

$propertySchema = new \ArrayObject($propertySchema + $valueSchema);
Expand Down
2 changes: 2 additions & 0 deletions tests/Swagger/Serializer/DocumentationNormalizerV2Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,7 @@ private function doTestNormalize(OperationMethodResolverInterface $operationMeth
'type' => 'string',
'description' => 'This is a \DateTimeInterface object.',
'format' => 'date-time',
'nullable' => true,
]), ],
]),
]),
Expand Down Expand Up @@ -2020,6 +2021,7 @@ public function testNormalizeWithNestedNormalizationGroups(): void
'relatedDummy' => new \ArrayObject([
'description' => 'This is a related dummy \o/.',
'$ref' => '#/definitions/'.$relatedDummyRef,
'nullable' => true,
]),
],
]),
Expand Down
2 changes: 2 additions & 0 deletions tests/Swagger/Serializer/DocumentationNormalizerV3Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,7 @@ private function doTestNormalize(OperationMethodResolverInterface $operationMeth
'type' => 'string',
'description' => 'This is a \DateTimeInterface object.',
'format' => 'date-time',
'nullable' => true,
]),
],
]),
Expand Down Expand Up @@ -1998,6 +1999,7 @@ public function testNormalizeWithNestedNormalizationGroups(): void
'relatedDummy' => new \ArrayObject([
'description' => 'This is a related dummy \o/.',
'$ref' => '#/components/schemas/'.$relatedDummyRef,
'nullable' => true,
]),
],
]),
Expand Down

0 comments on commit 35f6bd9

Please sign in to comment.