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 20, 2019
1 parent e773104 commit db5b82a
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,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 = !$swagger && $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/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 db5b82a

Please sign in to comment.