Skip to content

Commit 29bb39a

Browse files
authored
Fix handling of *Of schemas (#50)
1 parent fc0f412 commit 29bb39a

File tree

8 files changed

+402
-35
lines changed

8 files changed

+402
-35
lines changed

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"php": ">=5.6.0"
2020
},
2121
"require-dev": {
22-
"phperf/phpunit": "4.8.37"
22+
"phperf/phpunit": "4.8.38"
2323
},
2424
"autoload": {
2525
"psr-4": {

composer.lock

+21-21
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/JsonSchema/TypeBuilder.php

+12-9
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,21 @@ public function __construct($schema, $path, PhpBuilder $phpBuilder)
4040
*/
4141
private function processLogicType()
4242
{
43-
$orSchemas = null;
4443
if ($this->schema->allOf !== null) {
45-
$orSchemas = $this->schema->allOf;
46-
} elseif ($this->schema->anyOf !== null) {
47-
$orSchemas = $this->schema->anyOf;
48-
} elseif ($this->schema->oneOf !== null) {
49-
$orSchemas = $this->schema->oneOf;
44+
foreach ($this->schema->allOf as $i => $item) {
45+
$this->result->add($this->phpBuilder->getType($item, $this->path . '->allOf[' . $i . ']'));
46+
}
47+
}
48+
49+
if ($this->schema->anyOf !== null) {
50+
foreach ($this->schema->anyOf as $i => $item) {
51+
$this->result->add($this->phpBuilder->getType($item, $this->path . '->anyOf[' . $i . ']'));
52+
}
5053
}
5154

52-
if ($orSchemas !== null) {
53-
foreach ($orSchemas as $item) {
54-
$this->result->add($this->phpBuilder->getType($item, $this->path));
55+
if ($this->schema->oneOf !== null) {
56+
foreach ($this->schema->oneOf as $i => $item) {
57+
$this->result->add($this->phpBuilder->getType($item, $this->path . '->oneOf[' . $i . ']'));
5558
}
5659
}
5760
}

src/PhpFunction.php

+7-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,13 @@ protected function toString()
4949
$tail = (new PhpDocTag(PhpDoc::TAG_CODE_COVERAGE_IGNORE_END))->render() . "\n";
5050
}
5151

52-
$body = trim($this->body);
52+
$body = $this->body;
53+
if ($body === null) {
54+
$body = '';
55+
}
56+
57+
$body = trim($body);
58+
5359
if ($body !== '') {
5460
$body = $this->indentLines($body . "\n");
5561
}

tests/src/PHPUnit/Issues/Issue40Test.php

-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ function (PhpClass $class, $path, $schema) use ($app, $appNs) {
6060
exec('git diff ' . $appPath, $out);
6161
$out = implode("\n", $out);
6262
$this->assertSame('', $out, "Generated files changed");
63-
6463
}
6564

6665

0 commit comments

Comments
 (0)