Skip to content

Commit

Permalink
fix: add OpenAPI fields (#644)
Browse files Browse the repository at this point in the history
  • Loading branch information
SMillerDev authored Oct 21, 2024
1 parent cf72033 commit 2d4a5e9
Show file tree
Hide file tree
Showing 13 changed files with 280 additions and 84 deletions.
8 changes: 8 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[*.html]
indent_size = 2
indent_style = space

[*.php]
indent_size = 2
tab_width = 2
indent_style = space
9 changes: 4 additions & 5 deletions src/PHPDraft/Model/Elements/BasicStructureElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ abstract class BasicStructureElement implements StructureElement
/**
* Object status (required|optional).
*
* @var string|null
* @var string[]
*/
public ?string $status = '';
public array $status = [];
/**
* Parent structure.
*
Expand Down Expand Up @@ -130,14 +130,13 @@ protected function parse_common(object $object, array &$dependencies): void

$this->is_variable = $object->attributes->variable->content ?? false;

$this->status = null;
if (isset($object->attributes->typeAttributes->content)) {
$data = array_map(function ($item) {
return $item->content;
}, $object->attributes->typeAttributes->content);
$this->status = join(', ', $data);
$this->status = $data;
} elseif (isset($object->attributes->typeAttributes)) {
$this->status = join(', ', $object->attributes->typeAttributes);
$this->status = $object->attributes->typeAttributes;
}

if (!in_array($this->type, self::DEFAULTS, true) && $this->type !== null) {
Expand Down
3 changes: 2 additions & 1 deletion src/PHPDraft/Model/Elements/ObjectStructureElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ protected function construct_string_return(string $value): string
$desc = MarkdownExtra::defaultTransform($this->description);
}

return "<tr><td><span>{$this->key->value}</span>{$variable}</td><td>{$type}</td><td> <span class=\"status\">{$this->status}</span></td><td>{$desc}</td><td>{$value}</td></tr>";
$status_string = join(', ', $this->status);
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>";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public static function parseObjectProvider(): array
$val2->value = 'Objective-C';
$val2->type = 'string';
$base1->value = [$val1, $val2];
$base1->status = null;
$base1->status = [];
$base1->element = 'array';
$base1->type = null;
$base1->is_variable = false;
Expand All @@ -82,7 +82,7 @@ public static function parseObjectProvider(): array
$val2->value = 'another item';
$val2->type = 'string';
$base2->value = [$val1, $val2];
$base2->status = null;
$base2->status = [];
$base2->element = 'array';
$base2->type = 'Some simple array';
$base2->is_variable = false;
Expand All @@ -101,7 +101,7 @@ public static function parseObjectProvider(): array
$val2->value = null;
$val2->type = 'array';
$base3->value = [$val1, $val2];
$base3->status = 'optional';
$base3->status = ['optional'];
$base3->element = 'member';
$base3->type = 'array';
$base3->is_variable = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public static function parseValueProvider(): array

$obj2 = clone $obj;
$obj2->attributes->typeAttributes = [1, 2];
$answer->status = '1, 2';
$answer->status = [1, 2];

$return[] = [$obj2, $answer];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public static function parseObjectProvider(): array
$base1 = new EnumStructureElement();
$base1->key = null;
$base1->value = [ $value1, $value2 ];
$base1->status = null;
$base1->status = [];
$base1->element = 'enum';
$base1->type = 'Some simple enum';
$base1->is_variable = false;
Expand All @@ -164,7 +164,7 @@ public static function parseObjectProvider(): array
$base2->key->type = 'string';
$base2->key->value = 'car_id_list';
$base2->value = 'world';
$base2->status = null;
$base2->status = [];
$base2->element = 'enum';
$base2->type = 'string';
$base2->description = null;
Expand All @@ -177,7 +177,7 @@ public static function parseObjectProvider(): array
$base3->key->type = 'number';
$base3->key->value = '5';
$base3->value = '5';
$base3->status = 'optional';
$base3->status = ['optional'];
$base3->element = 'member';
$base3->type = 'number';
$base3->description = "List of car identifiers to retrieve";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public static function parseObjectProvider(): array
$base1->key->type = 'string';
$base1->key->value = 'name';
$base1->value = 'P10';
$base1->status = 'optional';
$base1->status = ['optional'];
$base1->element = 'member';
$base1->type = 'string';
$base1->is_variable = false;
Expand All @@ -95,7 +95,7 @@ public static function parseObjectProvider(): array
$base2->key->type = 'string';
$base2->key->value = 'Auth2';
$base2->value = 'something';
$base2->status = 'required';
$base2->status = ['required'];
$base2->element = 'member';
$base2->type = 'string';
$base2->is_variable = false;
Expand Down
4 changes: 2 additions & 2 deletions src/PHPDraft/Model/Elements/Tests/RequestBodyElementTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public static function parseObjectProvider(): array
$base1->key->value = 'name';
$base1->key->description = null;
$base1->value = 'P10';
$base1->status = 'optional';
$base1->status = ['optional'];
$base1->element = 'member';
$base1->type = 'string';
$base1->is_variable = false;
Expand All @@ -156,7 +156,7 @@ public static function parseObjectProvider(): array
$base2->key->value = 'Auth2';
$base2->key->description = null;
$base2->value = 'something';
$base2->status = 'required';
$base2->status = ['required'];
$base2->element = 'member';
$base2->type = 'string';
$base2->is_variable = false;
Expand Down
4 changes: 2 additions & 2 deletions src/PHPDraft/Model/HierarchyElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ abstract class HierarchyElement
/**
* Description of the element.
*
* @var string
* @var string|null
*/
public string $description;
public ?string $description = NULL;

/**
* Child elements.
Expand Down
2 changes: 1 addition & 1 deletion src/PHPDraft/Model/Tests/ObjectElementTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public function testValueSetup(): void
*/
public function testStatusSetup(): void
{
$this->assertSame('', $this->class->status);
$this->assertSame([], $this->class->status);
}

/**
Expand Down
Loading

0 comments on commit 2d4a5e9

Please sign in to comment.