From 3a3b1919e91dc48515d4c43f574118855d316bce Mon Sep 17 00:00:00 2001 From: Chris Nizzardini Date: Tue, 1 Oct 2024 22:10:04 -0400 Subject: [PATCH] Fix bug, isNullable is not being set from Attribute --- 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()); + } +}