Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,8 +2,9 @@

## 2.7.0

* **BC**: Change `api_platform.listener.request.add_format` priority from 7 to 28 to execute it before firewall (priority 8) (#3599)
* **BC**: Use `@final` annotation in ORM filters (#4109)
* **BC** Change `api_platform.listener.request.add_format` priority from 7 to 28 to execute it before firewall (priority 8) (#3599)
* Doctrine: **BC** Use `@final` annotation in ORM filters (#4109)
* OpenAPI: **BC** Better nullable handling in JSON Schema / OpenAPI (#3518)
* Allow defining `exception_to_status` per operation (#3519)
* Doctrine: Better exception to find which resource is linked to an exception (#3965)
* Doctrine: Allow mixed type value for date filter (notice if invalid) (#3870)
Expand Down
2 changes: 1 addition & 1 deletion src/JsonSchema/SchemaFactory.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -228,7 +228,7 @@ 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 = $this->typeFactory->getType(new Type($builtinType, !$propertyMetadata->isRequired() || $type->isNullable(), $className, $isCollection), $format, $propertyMetadata->isReadableLink(), $serializerContext, $schema);

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Being nullable is not enought here, we also need to check if the property is required.
If it's not required, it means this property should be nullable.

}

if (\array_key_exists('type', $propertySchema) && \array_key_exists('$ref', $valueSchema)) {
Expand Down
29 changes: 29 additions & 0 deletions tests/Swagger/Serializer/DocumentationNormalizerV3Test.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -394,14 +394,17 @@ private function doTestNormalize(OperationMethodResolverInterface $operationMeth
'minLength' => 3,
'maxLength' => 20,
'pattern' => '^dummyPattern$',
'nullable' => true,
]),
'name' => new \ArrayObject([
'type' => 'string',
'description' => 'This is a name.',
'nullable' => true,
]),
'description' => new \ArrayObject([
'type' => 'string',
'description' => 'This is an initializable but not writable property.',
'nullable' => true,
]),
'dummyDate' => new \ArrayObject([
'nullable' => true,
Expand DownExpand Up@@ -567,10 +570,12 @@ private function doTestNormalizeWithNameConverter(bool $legacy = false): void
'name' => new \ArrayObject([
'type' => 'string',
'description' => 'This is a name.',
'nullable' => true,
]),
'name_converted' => new \ArrayObject([
'type' => 'string',
'description' => 'This is a converted name.',
'nullable' => true,
]),
],
]),
Expand DownExpand Up@@ -706,6 +711,7 @@ public function testNormalizeWithApiKeysEnabled(): void
'name' => new \ArrayObject([
'type' => 'string',
'description' => 'This is a name.',
'nullable' => true,
]),
],
]),
Expand DownExpand Up@@ -945,6 +951,7 @@ public function testNormalizeWithOnlyNormalizationGroups(): void
'name' => new \ArrayObject([
'type' => 'string',
'description' => 'This is a name.',
'nullable' => true,
]),
],
]),
Expand All@@ -956,6 +963,7 @@ public function testNormalizeWithOnlyNormalizationGroups(): void
'gerard' => new \ArrayObject([
'type' => 'string',
'description' => 'This is a gerard.',
'nullable' => true,
]),
],
]),
Expand DownExpand Up@@ -1073,6 +1081,7 @@ public function testNormalizeWithOpenApiDefinitionName(): void
'type' => 'integer',
'description' => 'This is an id.',
'readOnly' => true,
'nullable' => true,
]),
],
]),
Expand DownExpand Up@@ -1290,6 +1299,7 @@ public function testNormalizeWithOnlyDenormalizationGroups(): void
'name' => new \ArrayObject([
'type' => 'string',
'description' => 'This is a name.',
'nullable' => true,
]),
],
]),
Expand All@@ -1301,6 +1311,7 @@ public function testNormalizeWithOnlyDenormalizationGroups(): void
'gerard' => new \ArrayObject([
'type' => 'string',
'description' => 'This is a gerard.',
'nullable' => true,
]),
],
]),
Expand DownExpand Up@@ -1520,6 +1531,7 @@ public function testNormalizeWithNormalizationAndDenormalizationGroups(): void
'name' => new \ArrayObject([
'type' => 'string',
'description' => 'This is a name.',
'nullable' => true,
]),
],
]),
Expand All@@ -1531,6 +1543,7 @@ public function testNormalizeWithNormalizationAndDenormalizationGroups(): void
'gerard' => new \ArrayObject([
'type' => 'string',
'description' => 'This is a gerard.',
'nullable' => true,
]),
],
]),
Expand DownExpand Up@@ -2072,6 +2085,7 @@ public function testNormalizeWithNestedNormalizationGroups(): void
'name' => new \ArrayObject([
'type' => 'string',
'description' => 'This is a name.',
'nullable' => true,
]),
],
]),
Expand All@@ -2083,6 +2097,7 @@ public function testNormalizeWithNestedNormalizationGroups(): void
'name' => new \ArrayObject([
'type' => 'string',
'description' => 'This is a name.',
'nullable' => true,
]),
'relatedDummy' => new \ArrayObject([
'description' => 'This is a related dummy \o/.',
Expand All@@ -2101,6 +2116,7 @@ public function testNormalizeWithNestedNormalizationGroups(): void
'name' => new \ArrayObject([
'type' => 'string',
'description' => 'This is a name.',
'nullable' => true,
]),
],
]),
Expand DownExpand Up@@ -2250,6 +2266,7 @@ private function doTestNormalizeWithFilters($filterLocator): void
'name' => new \ArrayObject([
'description' => 'This is a name.',
'type' => 'string',
'nullable' => true,
]),
],
]),
Expand DownExpand Up@@ -2432,6 +2449,7 @@ private function doTestNormalizeWithSubResource(OperationAwareFormatsProviderInt
'type' => 'array',
'description' => 'This is a name.',
'items' => ['$ref' => '#/components/schemas/Answer'],
'nullable' => true,
]),
],
]),
Expand All@@ -2444,6 +2462,7 @@ private function doTestNormalizeWithSubResource(OperationAwareFormatsProviderInt
'type' => 'array',
'description' => 'This is a name.',
'items' => ['$ref' => '#/components/schemas/Answer'],
'nullable' => true,
]),
],
]),
Expand DownExpand Up@@ -2556,12 +2575,14 @@ public function testNormalizeWithPropertyOpenApiContext(): void
'type' => 'integer',
'description' => 'This is an id.',
'readOnly' => true,
'nullable' => true,
]),
'name' => new \ArrayObject([
'type' => 'string',
'description' => 'This is a name.',
'enum' => ['one', 'two'],
'example' => 'one',
'nullable' => true,
]),
],
]),
Expand DownExpand Up@@ -2688,12 +2709,14 @@ public function testNormalizeWithPaginationClientEnabled(): void
'type' => 'integer',
'description' => 'This is an id.',
'readOnly' => true,
'nullable' => true,
]),
'name' => new \ArrayObject([
'type' => 'string',
'description' => 'This is a name.',
'enum' => ['one', 'two'],
'example' => 'one',
'nullable' => true,
]),
],
]),
Expand DownExpand Up@@ -2826,12 +2849,14 @@ public function testNormalizeWithPaginationCustomDefaultAndMaxItemsPerPage(): vo
'type' => 'integer',
'description' => 'This is an id.',
'readOnly' => true,
'nullable' => true,
]),
'name' => new \ArrayObject([
'type' => 'string',
'description' => 'This is a name.',
'enum' => ['one', 'two'],
'example' => 'one',
'nullable' => true,
]),
],
]),
Expand DownExpand Up@@ -2968,12 +2993,14 @@ public function testLegacyNormalizeWithPaginationCustomDefaultAndMaxItemsPerPage
'type' => 'integer',
'description' => 'This is an id.',
'readOnly' => true,
'nullable' => true,
]),
'name' => new \ArrayObject([
'type' => 'string',
'description' => 'This is a name.',
'enum' => ['one', 'two'],
'example' => 'one',
'nullable' => true,
]),
],
]),
Expand DownExpand Up@@ -3212,10 +3239,12 @@ private function doTestNormalizeWithCustomFormatsDefinedAtOperationLevel(Operati
'type' => 'integer',
'description' => 'This is an id.',
'readOnly' => true,
'nullable' => true,
]),
'name' => new \ArrayObject([
'type' => 'string',
'description' => 'This is a name.',
'nullable' => true,
]),
],
]),
Expand Down