Skip to content

Commit b48b893

Browse files
authored
fix/openapi/general (#678)
1 parent f1ed0ba commit b48b893

File tree

6 files changed

+17
-16
lines changed

6 files changed

+17
-16
lines changed

build/phar-manifest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
$tag = @exec('git describe --tags 2>&1');
66

7-
if (strpos($tag, '-') === false && strpos($tag, 'No names found') === false) {
7+
if (!str_contains($tag, '-') && !str_contains($tag, 'No names found')) {
88
print $tag;
99
} else {
1010
$branch = @exec('git rev-parse --abbrev-ref HEAD');

src/PHPDraft/Model/Category.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public function parse(object $object): self
5050
$struct->deps = $deps;
5151
$struct->parse($item->content, $deps);
5252

53-
if (isset($item->content->content) && is_array($item->content->content) && isset($item->content->content[0]->meta->id)) {
53+
if (isset($item->content->content[0]->meta->id)) {
5454
$this->structures[$item->content->content[0]->meta->id] = $struct;
5555
} elseif (isset($item->content->meta->id->content)) {
5656
$this->structures[$item->content->meta->id->content] = $struct;

src/PHPDraft/Model/Elements/ObjectStructureElement.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,6 @@ protected function construct_string_return(string $value): string
215215
}
216216

217217
$status_string = join(', ', $this->status);
218-
return "<tr><td><span>{$this->key->value}</span>{$variable}</td><td>{$type}</td><td> <span class=\"status\">{$status_string}</span></td><td>{$desc}</td><td>{$value}</td></tr>";
218+
return "<tr><td><span>{$this->key->value}</span>$variable</td><td>$type</td><td> <span class=\"status\">$status_string</span></td><td>$desc</td><td>$value</td></tr>";
219219
}
220220
}

src/PHPDraft/Model/HTTPResponse.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,6 @@ public function is_equal_to(object $b): bool
190190
*/
191191
public function __toString(): string
192192
{
193-
return "{$this->statuscode}_{$this->description}";
193+
return "{$this->statuscode}_$this->description";
194194
}
195195
}

src/PHPDraft/Model/HierarchyElement.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,16 @@ abstract class HierarchyElement
5050
*
5151
* @param object $object an object to parse
5252
*
53-
* @return void
53+
* @return self
5454
*/
55-
public function parse(object $object)
55+
public function parse(object $object): self
5656
{
57-
if (isset($object->meta) && isset($object->meta->title)) {
57+
if (isset($object->meta->title)) {
5858
$this->title = $object->meta->title->content ?? $object->meta->title;
5959
}
6060

6161
if (!isset($object->content) || !is_array($object->content)) {
62-
return;
62+
return $this;
6363
}
6464

6565
foreach ($object->content as $key => $item) {
@@ -72,6 +72,8 @@ public function parse(object $object)
7272
if ($object->content !== null && $object->content !== []) {
7373
$object->content = array_slice($object->content, 0);
7474
}
75+
76+
return $this;
7577
}
7678

7779
/**

src/PHPDraft/Out/OpenAPI/OpenApiRenderer.php

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -456,25 +456,24 @@ private function getSchemaProperty(BasicStructureElement|ElementStructureElement
456456

457457
if ($value->type === 'enum') {
458458
$propery_data['type'] = in_array('nullable', $value->status, true) ? [ $value->type, 'null' ] : $value->type;
459-
$options = [];
459+
$options = [];
460+
if (!is_iterable($value->value->value)) {
461+
return $propery_data;
462+
}
460463
foreach ($value->value->value as $option) {
461464
if ($option instanceof ElementStructureElement) {
462-
$options[] = ['const' => $option->value, 'title' => $option->value];
465+
$options[] = [ 'const' => $option->value, 'title' => $option->value ];
463466
}
464467
}
465468
$propery_data['oneOf'] = $options;
466469

467470
return $propery_data;
468-
}
469-
470-
if ($value->type === 'array') {
471+
} elseif ($value->type === 'array') {
471472
$propery_data['type'] = array_unique(array_map(fn($item) => $item->type, $value->value->value));
472473
$propery_data['example'] = array_merge(array_filter(array_map(fn($item) => $item->value, $value->value->value)));
473474

474475
return $propery_data;
475-
}
476-
477-
if ($value->type === 'object') {
476+
} elseif ($value->type === 'object') {
478477
$propery_data['type'] = $value->type;
479478
$propery_data['properties'] = $this->getComponent($value->value)['properties'];
480479

0 commit comments

Comments
 (0)