diff --git a/CHANGELOG.md b/CHANGELOG.md index a5a71bb0c67..25c28488991 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## 2.5.5 * GraphQL: Do not allow empty cursor values on `before` or `after` +* OpenAPI: Fix required fields by keeping them required even if they are not writable to allow valid read types generation on client side (#3381) ## 2.5.4 diff --git a/src/Metadata/Property/PropertyMetadata.php b/src/Metadata/Property/PropertyMetadata.php index 1cdb697fe75..c7e77d038e9 100644 --- a/src/Metadata/Property/PropertyMetadata.php +++ b/src/Metadata/Property/PropertyMetadata.php @@ -134,10 +134,6 @@ public function withWritable(bool $writable): self */ public function isRequired(): ?bool { - if (true === $this->required && false === $this->writable) { - return false; - } - return $this->required; } diff --git a/tests/Bridge/NelmioApiDoc/Parser/ApiPlatformParserTest.php b/tests/Bridge/NelmioApiDoc/Parser/ApiPlatformParserTest.php index f0f5802eacd..7bd9146c8ec 100644 --- a/tests/Bridge/NelmioApiDoc/Parser/ApiPlatformParserTest.php +++ b/tests/Bridge/NelmioApiDoc/Parser/ApiPlatformParserTest.php @@ -150,7 +150,7 @@ public function testSupportsAttributeNormalization() $this->assertEquals([ 'id' => [ 'dataType' => DataTypes::INTEGER, - 'required' => false, + 'required' => true, 'description' => 'The id.', 'readonly' => true, ], @@ -262,7 +262,7 @@ public function testParse() $this->assertEquals([ 'id' => [ 'dataType' => DataTypes::INTEGER, - 'required' => false, + 'required' => true, 'description' => 'The id.', 'readonly' => true, ], @@ -399,7 +399,7 @@ public function testParseRelation() 'children' => [ 'id' => [ 'dataType' => DataTypes::INTEGER, - 'required' => false, + 'required' => true, 'description' => null, 'readonly' => true, ], diff --git a/tests/Metadata/Property/PropertyMetadataTest.php b/tests/Metadata/Property/PropertyMetadataTest.php index afee7f6adb6..340af40a60c 100644 --- a/tests/Metadata/Property/PropertyMetadataTest.php +++ b/tests/Metadata/Property/PropertyMetadataTest.php @@ -84,14 +84,14 @@ public function testValueObject() $this->assertTrue($newMetadata->isInitializable()); } - public function testShouldReturnRequiredFalseWhenRequiredTrueIsSetButMaskedByWritableFalse() + public function testShouldReturnRequiredTrueEvenIfWritableFalseSoClientCanAssumeValueCannotBeUndefinedOnReadOperation() { $metadata = new PropertyMetadata(); $metadata = $metadata->withRequired(true); $metadata = $metadata->withWritable(false); - $this->assertFalse($metadata->isRequired()); + $this->assertTrue($metadata->isRequired()); } public function testShouldReturnPreviouslySetRequiredTrueWhenWritableFalseUnmasked()