From 42c70bff80d99f422242a3f6d8dd47f8c34f5269 Mon Sep 17 00:00:00 2001 From: Chris Nizzardini Date: Tue, 1 Oct 2024 22:15:55 -0400 Subject: [PATCH] Fix bug, isNullable is not being set from Attribute (#560) --- src/Lib/Attribute/AbstractSchemaProperty.php | 3 ++- .../TestCase/Lib/Attribute/OpenApiSchemaPropertyTest.php | 9 ++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/Lib/Attribute/AbstractSchemaProperty.php b/src/Lib/Attribute/AbstractSchemaProperty.php index 5673e27e..3e0e0eef 100644 --- a/src/Lib/Attribute/AbstractSchemaProperty.php +++ b/src/Lib/Attribute/AbstractSchemaProperty.php @@ -91,7 +91,8 @@ public function create(): SchemaProperty ->setReadOnly($this->isReadOnly) ->setWriteOnly($this->isWriteOnly) ->setRequired($this->isRequired) - ->setEnum($this->enum ?? []); + ->setEnum($this->enum ?? []) + ->setNullable($this->isNullable); if ($schemaProperty->getType() === 'array') { $schemaProperty->setItems($this->items ?? []); diff --git a/tests/TestCase/Lib/Attribute/OpenApiSchemaPropertyTest.php b/tests/TestCase/Lib/Attribute/OpenApiSchemaPropertyTest.php index d0be2e10..4009aadf 100644 --- a/tests/TestCase/Lib/Attribute/OpenApiSchemaPropertyTest.php +++ b/tests/TestCase/Lib/Attribute/OpenApiSchemaPropertyTest.php @@ -1,4 +1,5 @@ 'object']))->create(); $this->assertEquals(['type' => 'object'], $property->getItems()); } -} \ No newline at end of file + + public function test_is_nullable(): void + { + $property = (new OpenApiSchemaProperty(name: 'test', type: 'string', isNullable: true))->create(); + $this->assertTrue($property->isNullable()); + } +}