Skip to content

Commit 7329afd

Browse files
committed
fix: add support for enums with single enumeration
1 parent 3d09cb4 commit 7329afd

File tree

5 files changed

+64
-12
lines changed

5 files changed

+64
-12
lines changed

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[0]->meta->id)) {
53+
if (isset($item->content->content) && is_array($item->content->content) && 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/EnumStructureElement.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,16 @@ public function parse(?object $object, array &$dependencies): self
5656
$dependencies[] = $object->content->element;
5757
}
5858
$this->value = $object->content->content;
59-
$this->deps = $dependencies;
60-
61-
return $this;
6259
}
6360

64-
foreach ($object->attributes->enumerations->content as $sub_item) {
65-
$element = new ElementStructureElement();
66-
$element->parse($sub_item, $dependencies);
67-
$this->value[] = $element;
61+
if (isset($object->attributes->enumerations->content) && $object->attributes->enumerations->content !== []) {
62+
$this->value = [];
63+
64+
foreach ($object->attributes->enumerations->content as $sub_item) {
65+
$element = new ElementStructureElement();
66+
$element->parse($sub_item, $dependencies);
67+
$this->value[] = $element;
68+
}
6869
}
6970

7071
$this->deps = $dependencies;

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

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,19 @@ public static function parseObjectProvider(): array
186186
$base3->is_variable = false;
187187
$base3->deps = [];
188188

189+
$base4 = new EnumStructureElement();
190+
$base4->key = new ElementStructureElement();
191+
$base4->value = [ $value1 ];
192+
$base4->key->type = 'string';
193+
$base4->key->value = 'item';
194+
$base4->status = [];
195+
$base4->element = 'enum';
196+
$base4->type = 'Some simple enum';
197+
$base4->is_variable = false;
198+
$base4->description = null;
199+
$base4->ref = null;
200+
$base4->deps = ['Some simple enum'];
201+
189202
$return['base enum'] = [
190203
'{
191204
"element":"enum",
@@ -288,6 +301,44 @@ public static function parseObjectProvider(): array
288301
}',
289302
$base3,
290303
];
304+
$return['enum with single enumeration and content'] = [
305+
'{
306+
"element":"enum",
307+
"meta":{
308+
"id":{
309+
"element":"string",
310+
"content":"Some simple enum"
311+
}
312+
},
313+
"attributes":{
314+
"enumerations":{
315+
"element":"array",
316+
"content":[
317+
{
318+
"element":"string",
319+
"attributes":{
320+
"typeAttributes":{
321+
"element":"array",
322+
"content":[
323+
{
324+
"element":"string",
325+
"content":"fixed"
326+
}
327+
]
328+
}
329+
},
330+
"content":"item"
331+
}
332+
]
333+
}
334+
},
335+
"content": {
336+
"element": "string",
337+
"content": "item"
338+
}
339+
}',
340+
$base4,
341+
];
291342

292343
return $return;
293344
}

tests/statics/drafter/html/basic.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3140,7 +3140,7 @@ <h5 class="card-title">
31403140
data-placement="left"
31413141
data-toggle="popover"
31423142
data-html="true"
3143-
data-content="<textarea rows='8' cols='75'>curl -XPOST -H &#039;Authorization: Bearer {access_token}&#039; &#039;https://owner-api.teslamotors.com/api/1/vehicles/1/command/sun_roof_control?state=open&amp;amp;percent=50&#039;</textarea>">
3143+
data-content="<textarea rows='8' cols='75'>curl -XPOST -H &#039;Authorization: Bearer {access_token}&#039; &#039;https://owner-api.teslamotors.com/api/1/vehicles/1/command/sun_roof_control?state=0&amp;amp;percent=50&#039;</textarea>">
31443144
<span class="fas fa-copy"></span>
31453145
</a>
31463146
<h5>Example URI</h5>
@@ -3170,7 +3170,7 @@ <h5>URI Parameters</h5>
31703170
<tbody>
31713171
<tr><td><span>vehicle_id</span></td><td><code>string</code></td><td> <span class="status">required</span></td><td><p>The id of the Vehicle.</p>
31723172
</td><td><span class="example-value pull-right">1</span></td></tr><tr><td><span>state</span></td><td><code>enum</code></td><td> <span class="status">required</span></td><td><p>The desired state of the panoramic roof. The approximate percent open values for each state are <code>open</code> = 100%, <code>close</code> = 0%, <code>comfort</code> = 80%, and <code>vent</code> = ~15%</p>
3173-
</td><td><div class="enum-struct"><tr><td>open</td><td><code>enum</code></td><td></td></tr></div></td></tr><tr><td><span>percent</span></td><td><code>string</code></td><td> <span class="status">optional</span></td><td><p>The percentage to move the roof to.</p>
3173+
</td><td><div class="enum-struct"><ul class="list-group mdl-list"><li class="list-group-item mdl-list__item"><code>string</code> - <span class="example-value pull-right">open</span></li><li class="list-group-item mdl-list__item"><code>string</code> - <span class="example-value pull-right">close</span></li><li class="list-group-item mdl-list__item"><code>string</code> - <span class="example-value pull-right">comfort</span></li><li class="list-group-item mdl-list__item"><code>string</code> - <span class="example-value pull-right">vent</span></li><li class="list-group-item mdl-list__item"><code>string</code> - <span class="example-value pull-right">move</span></li></ul></div></td></tr><tr><td><span>percent</span></td><td><code>string</code></td><td> <span class="status">optional</span></td><td><p>The percentage to move the roof to.</p>
31743174
</td><td><span class="example-value pull-right">50</span></td></tr> </tbody>
31753175
</table>
31763176
</div>

tests/statics/drafter/html/material.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3153,7 +3153,7 @@ <h5 class="card-title">
31533153
<div id="modal-SOME_ID" class="modal">
31543154
<div class="modal-content">
31553155
<label> Example cURL request:
3156-
<textarea rows='75' cols='75'>curl -XPOST -H &#039;Authorization: Bearer {access_token}&#039; &#039;https://owner-api.teslamotors.com/api/1/vehicles/1/command/sun_roof_control?state=open&amp;amp;percent=50&#039;</textarea>
3156+
<textarea rows='75' cols='75'>curl -XPOST -H &#039;Authorization: Bearer {access_token}&#039; &#039;https://owner-api.teslamotors.com/api/1/vehicles/1/command/sun_roof_control?state=0&amp;amp;percent=50&#039;</textarea>
31573157
</label>
31583158
</div>
31593159
<div class="modal-footer">
@@ -3188,7 +3188,7 @@ <h5>URI Parameters</h5>
31883188
<tbody>
31893189
<tr><td><span>vehicle_id</span></td><td><code>string</code></td><td> <span class="status">required</span></td><td><p>The id of the Vehicle.</p>
31903190
</td><td><span class="example-value pull-right">1</span></td></tr><tr><td><span>state</span></td><td><code>enum</code></td><td> <span class="status">required</span></td><td><p>The desired state of the panoramic roof. The approximate percent open values for each state are <code>open</code> = 100%, <code>close</code> = 0%, <code>comfort</code> = 80%, and <code>vent</code> = ~15%</p>
3191-
</td><td><div class="enum-struct"><tr><td>open</td><td><code>enum</code></td><td></td></tr></div></td></tr><tr><td><span>percent</span></td><td><code>string</code></td><td> <span class="status">optional</span></td><td><p>The percentage to move the roof to.</p>
3191+
</td><td><div class="enum-struct"><ul class="list-group mdl-list"><li class="list-group-item mdl-list__item"><code>string</code> - <span class="example-value pull-right">open</span></li><li class="list-group-item mdl-list__item"><code>string</code> - <span class="example-value pull-right">close</span></li><li class="list-group-item mdl-list__item"><code>string</code> - <span class="example-value pull-right">comfort</span></li><li class="list-group-item mdl-list__item"><code>string</code> - <span class="example-value pull-right">vent</span></li><li class="list-group-item mdl-list__item"><code>string</code> - <span class="example-value pull-right">move</span></li></ul></div></td></tr><tr><td><span>percent</span></td><td><code>string</code></td><td> <span class="status">optional</span></td><td><p>The percentage to move the roof to.</p>
31923192
</td><td><span class="example-value pull-right">50</span></td></tr> </tbody>
31933193
</table>
31943194
</div>

0 commit comments

Comments
 (0)