Skip to content

Commit f9637ae

Browse files
committed
Add test case to reproduce missing class if allOf is present
1 parent 1f36c46 commit f9637ae

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed

src/Schema.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,7 @@ private function processObject($data, Context $options, $path, $result = null)
593593

594594
if ($this->useObjectAsArray) {
595595
$result = array();
596-
} elseif (!$result instanceof ObjectItemContract) {
596+
} else/*if (!$result instanceof ObjectItemContract || null !== $this->objectItemClass)*/ {
597597
//* todo check performance impact
598598
if (null === $this->objectItemClass) {
599599
$result = new ObjectItem();

tests/src/Helper/ClassWithAllOf.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
4+
namespace Swaggest\JsonSchema\Tests\Helper;
5+
6+
7+
use Swaggest\JsonSchema\Constraint\Properties;
8+
use Swaggest\JsonSchema\Schema;
9+
use Swaggest\JsonSchema\Structure\ClassStructure;
10+
11+
class ClassWithAllOf extends ClassStructure
12+
{
13+
public $myProperty;
14+
15+
/**
16+
* @param Properties|static $properties
17+
* @param Schema $ownerSchema
18+
*/
19+
public static function setUpProperties($properties, Schema $ownerSchema)
20+
{
21+
$properties->myProperty = Schema::string();
22+
23+
$not = new Schema();
24+
$not->not = Schema::integer();
25+
$ownerSchema->allOf[0] = $not;
26+
}
27+
28+
29+
}

tests/src/PHPUnit/ClassStructure/ClassStructureTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55

66
use Swaggest\JsonSchema\Exception\TypeException;
7+
use Swaggest\JsonSchema\Tests\Helper\ClassWithAllOf;
78
use Swaggest\JsonSchema\Tests\Helper\LevelThreeClass;
89
use Swaggest\JsonSchema\Tests\Helper\SampleStructure;
910
use Swaggest\JsonSchema\Tests\Helper\StructureWithItems;
@@ -88,5 +89,12 @@ public function testSampleInvalid()
8889
));
8990
}
9091

92+
public function testAllOfClassInstance()
93+
{
94+
$value = ClassWithAllOf::import((object)array('myProperty'=>'abc'));
95+
$this->assertSame('abc', $value->myProperty);
96+
$this->assertTrue($value instanceof ClassWithAllOf);
97+
}
98+
9199

92100
}

0 commit comments

Comments
 (0)