Skip to content

Commit 0e0c69c

Browse files
committed
add hasPropertyValue() method
to check if a property has been defined without checking for defaults. fixes #142
1 parent 9d3755d commit 0e0c69c

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

src/SpecBaseObject.php

+14
Original file line numberDiff line numberDiff line change
@@ -305,11 +305,25 @@ protected function addError(string $error, $class = '')
305305
$this->_errors[] = end($shortName).$error;
306306
}
307307

308+
/**
309+
* @param string $name property name.
310+
* @return bool true when this object has a property with a non-null value or the property is defined in the OpenAPI spec.
311+
* @deprecated since 1.6.0
312+
*/
308313
protected function hasProperty(string $name): bool
309314
{
310315
return isset($this->_properties[$name]) || isset($this->attributes()[$name]);
311316
}
312317

318+
/**
319+
* @param string $name property name.
320+
* @return bool true, when a property has a non-null value (does not check for default values)
321+
*/
322+
protected function hasPropertyValue(string $name): bool
323+
{
324+
return isset($this->_properties[$name]);
325+
}
326+
313327
protected function requireProperties(array $names)
314328
{
315329
foreach ($names as $name) {

src/spec/Schema.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ protected function attributeDefaults(): array
127127
// nullable is only relevant, when a type is specified
128128
// return null as default when there is no type
129129
// return false as default when there is a type
130-
'nullable' => $this->hasProperty('type') ? false : null,
130+
'nullable' => $this->hasPropertyValue('type') ? false : null,
131131
];
132132
}
133133

tests/spec/SchemaTest.php

-5
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,6 @@ public function testRead()
4545

4646
public function testNullable()
4747
{
48-
self::markTestIncomplete(
49-
'Test currently fails as it was not run when https://github.com/cebe/php-openapi/pull/132 was merged. '
50-
.'See https://github.com/cebe/php-openapi/issues/142 for status'
51-
);
52-
5348
/** @var $schema Schema */
5449
$schema = Reader::readFromJson('{"type": "string"}', Schema::class);
5550
$this->assertEquals(Type::STRING, $schema->type);

0 commit comments

Comments
 (0)