From cbb7f7cd8fe5ae304c75b3b5509980c5e39792fc Mon Sep 17 00:00:00 2001 From: Chris Nizzardini Date: Fri, 10 May 2024 21:21:58 -0400 Subject: [PATCH] Hidden properties take precedence in being hidden (#547) Hidden properties were correctly not showing in operation response sample, but still displaying in schema sample. This hides them always. --- src/Lib/Schema/SchemaFactory.php | 4 +++- tests/TestCase/Lib/SwaggerSchemaTest.php | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Lib/Schema/SchemaFactory.php b/src/Lib/Schema/SchemaFactory.php index f53ec576..7af21d2b 100644 --- a/src/Lib/Schema/SchemaFactory.php +++ b/src/Lib/Schema/SchemaFactory.php @@ -134,7 +134,9 @@ private function getProperties(Model $model, int $propertyType, ?DocBlock $docBl $factory = new SchemaPropertyFactory($this->validator, $docBlock); foreach ($model->getProperties() as $property) { - $return[$property->getName()] = $factory->create($property); + if (!$property->isHidden()) { + $return[$property->getName()] = $factory->create($property); + } } $return = array_merge($return, $this->getPropertyAnnotations($model)); diff --git a/tests/TestCase/Lib/SwaggerSchemaTest.php b/tests/TestCase/Lib/SwaggerSchemaTest.php index 8f8f5050..cfb1838a 100644 --- a/tests/TestCase/Lib/SwaggerSchemaTest.php +++ b/tests/TestCase/Lib/SwaggerSchemaTest.php @@ -70,7 +70,7 @@ public function test_employee_table_properties(): void $this->assertEquals('date', $employee['properties']['hire_date']['format']); $this->assertTrue($employee['properties']['read']['readOnly']); - $this->assertTrue($employee['properties']['write']['writeOnly']); + $this->assertArrayNotHasKey('write', $employee['properties']); $this->assertArrayNotHasKey('hide', $employee['properties']); foreach (['birth_date', 'first_name', 'last_name', 'gender', 'hire_date',] as $property) {