Skip to content

Commit 2d4a5e9

Browse files
authored
fix: add OpenAPI fields (#644)
1 parent cf72033 commit 2d4a5e9

13 files changed

+280
-84
lines changed

.editorconfig

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[*.html]
2+
indent_size = 2
3+
indent_style = space
4+
5+
[*.php]
6+
indent_size = 2
7+
tab_width = 2
8+
indent_style = space

src/PHPDraft/Model/Elements/BasicStructureElement.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ abstract class BasicStructureElement implements StructureElement
4545
/**
4646
* Object status (required|optional).
4747
*
48-
* @var string|null
48+
* @var string[]
4949
*/
50-
public ?string $status = '';
50+
public array $status = [];
5151
/**
5252
* Parent structure.
5353
*
@@ -130,14 +130,13 @@ protected function parse_common(object $object, array &$dependencies): void
130130

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

133-
$this->status = null;
134133
if (isset($object->attributes->typeAttributes->content)) {
135134
$data = array_map(function ($item) {
136135
return $item->content;
137136
}, $object->attributes->typeAttributes->content);
138-
$this->status = join(', ', $data);
137+
$this->status = $data;
139138
} elseif (isset($object->attributes->typeAttributes)) {
140-
$this->status = join(', ', $object->attributes->typeAttributes);
139+
$this->status = $object->attributes->typeAttributes;
141140
}
142141

143142
if (!in_array($this->type, self::DEFAULTS, true) && $this->type !== null) {

src/PHPDraft/Model/Elements/ObjectStructureElement.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ protected function construct_string_return(string $value): string
214214
$desc = MarkdownExtra::defaultTransform($this->description);
215215
}
216216

217-
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>";
217+
$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>";
218219
}
219220
}

src/PHPDraft/Model/Elements/Tests/ArrayStructureElementTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public static function parseObjectProvider(): array
6565
$val2->value = 'Objective-C';
6666
$val2->type = 'string';
6767
$base1->value = [$val1, $val2];
68-
$base1->status = null;
68+
$base1->status = [];
6969
$base1->element = 'array';
7070
$base1->type = null;
7171
$base1->is_variable = false;
@@ -82,7 +82,7 @@ public static function parseObjectProvider(): array
8282
$val2->value = 'another item';
8383
$val2->type = 'string';
8484
$base2->value = [$val1, $val2];
85-
$base2->status = null;
85+
$base2->status = [];
8686
$base2->element = 'array';
8787
$base2->type = 'Some simple array';
8888
$base2->is_variable = false;
@@ -101,7 +101,7 @@ public static function parseObjectProvider(): array
101101
$val2->value = null;
102102
$val2->type = 'array';
103103
$base3->value = [$val1, $val2];
104-
$base3->status = 'optional';
104+
$base3->status = ['optional'];
105105
$base3->element = 'member';
106106
$base3->type = 'array';
107107
$base3->is_variable = false;

src/PHPDraft/Model/Elements/Tests/BasicStructureElementTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ public static function parseValueProvider(): array
150150

151151
$obj2 = clone $obj;
152152
$obj2->attributes->typeAttributes = [1, 2];
153-
$answer->status = '1, 2';
153+
$answer->status = [1, 2];
154154

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

src/PHPDraft/Model/Elements/Tests/EnumStructureElementTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ public static function parseObjectProvider(): array
151151
$base1 = new EnumStructureElement();
152152
$base1->key = null;
153153
$base1->value = [ $value1, $value2 ];
154-
$base1->status = null;
154+
$base1->status = [];
155155
$base1->element = 'enum';
156156
$base1->type = 'Some simple enum';
157157
$base1->is_variable = false;
@@ -164,7 +164,7 @@ public static function parseObjectProvider(): array
164164
$base2->key->type = 'string';
165165
$base2->key->value = 'car_id_list';
166166
$base2->value = 'world';
167-
$base2->status = null;
167+
$base2->status = [];
168168
$base2->element = 'enum';
169169
$base2->type = 'string';
170170
$base2->description = null;
@@ -177,7 +177,7 @@ public static function parseObjectProvider(): array
177177
$base3->key->type = 'number';
178178
$base3->key->value = '5';
179179
$base3->value = '5';
180-
$base3->status = 'optional';
180+
$base3->status = ['optional'];
181181
$base3->element = 'member';
182182
$base3->type = 'number';
183183
$base3->description = "List of car identifiers to retrieve";

src/PHPDraft/Model/Elements/Tests/ObjectStructureElementTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public static function parseObjectProvider(): array
8282
$base1->key->type = 'string';
8383
$base1->key->value = 'name';
8484
$base1->value = 'P10';
85-
$base1->status = 'optional';
85+
$base1->status = ['optional'];
8686
$base1->element = 'member';
8787
$base1->type = 'string';
8888
$base1->is_variable = false;
@@ -95,7 +95,7 @@ public static function parseObjectProvider(): array
9595
$base2->key->type = 'string';
9696
$base2->key->value = 'Auth2';
9797
$base2->value = 'something';
98-
$base2->status = 'required';
98+
$base2->status = ['required'];
9999
$base2->element = 'member';
100100
$base2->type = 'string';
101101
$base2->is_variable = false;

src/PHPDraft/Model/Elements/Tests/RequestBodyElementTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ public static function parseObjectProvider(): array
142142
$base1->key->value = 'name';
143143
$base1->key->description = null;
144144
$base1->value = 'P10';
145-
$base1->status = 'optional';
145+
$base1->status = ['optional'];
146146
$base1->element = 'member';
147147
$base1->type = 'string';
148148
$base1->is_variable = false;
@@ -156,7 +156,7 @@ public static function parseObjectProvider(): array
156156
$base2->key->value = 'Auth2';
157157
$base2->key->description = null;
158158
$base2->value = 'something';
159-
$base2->status = 'required';
159+
$base2->status = ['required'];
160160
$base2->element = 'member';
161161
$base2->type = 'string';
162162
$base2->is_variable = false;

src/PHPDraft/Model/HierarchyElement.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ abstract class HierarchyElement
2727
/**
2828
* Description of the element.
2929
*
30-
* @var string
30+
* @var string|null
3131
*/
32-
public string $description;
32+
public ?string $description = NULL;
3333

3434
/**
3535
* Child elements.

src/PHPDraft/Model/Tests/ObjectElementTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public function testValueSetup(): void
8383
*/
8484
public function testStatusSetup(): void
8585
{
86-
$this->assertSame('', $this->class->status);
86+
$this->assertSame([], $this->class->status);
8787
}
8888

8989
/**

0 commit comments

Comments
 (0)