Skip to content

Commit 00183d5

Browse files
Sean MolenaarSean Molenaar
authored andcommitted
Fix every request and response lists growing expontionally
1 parent 1d64eef commit 00183d5

File tree

7 files changed

+53
-19
lines changed

7 files changed

+53
-19
lines changed

src/PHPDraft/Model/Elements/DataStructureElement.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ function __toString()
204204
'<td>' . '<span>' . $this->key . "</span>" . '</td>' .
205205
'<td>' . $type . '</td>' .
206206
'<td> <span class="status">' . $this->status . '</span></td>' .
207-
'<td><span>' . $this->description . '</span></td>' .
207+
'<td>' . $this->description . '</td>' .
208208
'<td>' . $value . '</td>' .
209209
'</tr>';
210210

src/PHPDraft/Model/Elements/EnumStructureElement.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ function __toString()
102102
$return = '<tr>' .
103103
'<td><span>' . $this->value . '</span></td>' .
104104
'<td>' . $type . '</td>' .
105-
'<td><span>' . $this->description . '</span></td>' .
105+
'<td>' . $this->description . '</td>' .
106106
'</tr>';
107107

108108
return $return;

src/PHPDraft/Model/HTTPRequest.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
namespace PHPDraft\Model;
1010

11+
use Michelf\MarkdownExtra;
1112
use PHPDraft\Model\Elements\RequestBodyElement;
1213

1314
class HTTPRequest implements Comparable
@@ -26,21 +27,27 @@ class HTTPRequest implements Comparable
2627
*/
2728
public $method;
2829

30+
/**
31+
* Description of the request
32+
*
33+
* @var string
34+
*/
35+
public $description;
36+
2937
/**
3038
* Parent class
3139
*
3240
* @var Transition
3341
*/
3442
public $parent;
3543

44+
3645
/**
3746
* Body of the request (if POST or PUT)
3847
*
3948
* @var mixed
4049
*/
4150
public $body = null;
42-
43-
4451
/**
4552
* Structure of the request (if POST or PUT)
4653
*
@@ -74,7 +81,9 @@ public function parse($object)
7481
if ($value->element === 'dataStructure') {
7582
$this->parse_structure($value);
7683
continue;
77-
} elseif ($value->element === 'asset') {
84+
} elseif ($value->element === 'copy'){
85+
$this->description = MarkdownExtra::defaultTransform($value->content);
86+
}elseif ($value->element === 'asset') {
7887
if (in_array('messageBody', $value->meta->classes)) {
7988
$this->body[] = (isset($value->content)) ? $value->content : null;
8089
$this->headers['Content-Type'] =

src/PHPDraft/Model/HTTPResponse.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
namespace PHPDraft\Model;
1010

11+
use Michelf\MarkdownExtra;
1112
use PHPDraft\Model\Elements\DataStructureElement;
1213

1314
class HTTPResponse implements Comparable
@@ -19,6 +20,13 @@ class HTTPResponse implements Comparable
1920
*/
2021
public $statuscode;
2122

23+
/**
24+
* Description of the object
25+
*
26+
* @var string
27+
*/
28+
public $description;
29+
2230
/**
2331
* Response headers
2432
*
@@ -70,6 +78,7 @@ public function parse($object)
7078
$this->parse_content($object);
7179

7280
return $this;
81+
7382
}
7483

7584
/**
@@ -101,6 +110,9 @@ protected function parse_content($object)
101110
if ($value->element === 'dataStructure') {
102111
$this->parse_structure($value->content);
103112
continue;
113+
}else if ($value->element === 'copy'){
114+
$this->description = MarkdownExtra::defaultTransform($value->content);
115+
continue;
104116
}
105117

106118
if (isset($value->attributes)) {
@@ -137,6 +149,6 @@ protected function parse_structure($objects)
137149
*/
138150
public function is_equal_to($b)
139151
{
140-
return (($this->statuscode === $b->statuscode) && ($this->headers === $b->headers) && ($this->content === $b->content));
152+
return (($this->statuscode === $b->statuscode) && ($this->description === $b->description));
141153
}
142154
}

src/PHPDraft/Model/Transition.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,9 @@ function parse($object)
106106
}
107107
foreach ($transition_item->content as $item) {
108108
$value = null;
109+
if (!in_array($item->element, ['httpRequest', 'httpResponse'])) {
110+
continue;
111+
}
109112
switch ($item->element) {
110113
case 'httpRequest':
111114
$value = new HTTPRequest($this);
@@ -117,19 +120,24 @@ function parse($object)
117120
break;
118121
default:
119122
continue;
123+
break;
120124
}
121125
$value->parse($item);
122126

123127
if (empty($list)) {
124128
$list[] = $value;
125129
continue;
126130
}
131+
$add = true;
127132
foreach ($list as $existing_value) {
128-
phpdraft_var_dump($value->is_equal_to($existing_value));
129-
if (!$value->is_equal_to($existing_value)) {
130-
$list[] = $value;
133+
if ($value->is_equal_to($existing_value)) {
134+
$add = false;
131135
}
132136
}
137+
if ($add) {
138+
$list[] = $value;
139+
}
140+
133141
}
134142
}
135143

src/PHPDraft/Out/HTML/default.phtml

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ $base = $this->categories;
5353
<a href="#<?= $category->get_href(); ?>"><?= $category->title; ?></a>
5454
<a class="btn-xs pull-right" role="button" data-toggle="collapse"
5555
href="#collapse-<?= $category->get_href(); ?>" aria-expanded="false"
56-
aria-controls="collapseMenu">
56+
aria-controls="collapse-<?= $category->get_href(); ?>">
5757
<span class="glyphicon glyphicon-plus"></span>
5858
</a>
5959
</h3>
@@ -91,7 +91,7 @@ $base = $this->categories;
9191
<a href="#datastructures">Data Structures</a>
9292
<a class="btn-xs pull-right" role="button" data-toggle="collapse"
9393
href="#collapse-structures" aria-expanded="false"
94-
aria-controls="collapseMenu">
94+
aria-controls="collapse-structures">
9595
<span class="glyphicon glyphicon-plus"></span>
9696
</a>
9797
</h3>
@@ -138,8 +138,7 @@ $base = $this->categories;
138138
</h3>
139139
</div>
140140
<div class="panel-body">
141-
<a type="button"
142-
class="btn btn-default curl"
141+
<a class="btn btn-default curl"
143142
role="button"
144143
title="cURL command"
145144
tabindex="0"
@@ -152,7 +151,7 @@ $base = $this->categories;
152151
</a>
153152
<p class="lead"><?= $transition->description; ?></p>
154153
<?php if (!empty($transition->requests)): ?>
155-
<?php foreach ($transition->requests as $request): ?>
154+
<?php foreach ($transition->requests as $key=>$request): ?>
156155
<div class="panel panel-default">
157156
<div class="panel-heading">
158157
<h4 class="request panel-title"
@@ -163,8 +162,9 @@ $base = $this->categories;
163162
</h4>
164163
</div>
165164

166-
<div class="collapse in request-panel panel-body"
165+
<div class="collapse <?php if ($key<1):?>in<?php endif;?> request-panel panel-body"
167166
id="request-coll-<?= $transition->get_href(); ?>">
167+
<?= $request->description;?>
168168
<?php if ($transition->url_variables !== []): ?>
169169
<h5>Example URI</h5>
170170
<span class="base-url"><?= $this->base_data['HOST']; ?></span>
@@ -219,7 +219,7 @@ $base = $this->categories;
219219
<?php endforeach; ?>
220220
<?php endif; ?>
221221
<?php if (isset($transition->responses)): ?>
222-
<?php foreach ($transition->responses as $response): ?>
222+
<?php foreach ($transition->responses as $key=>$response): ?>
223223
<div class="panel panel-default">
224224
<div class="panel-heading">
225225
<h4 class="panel-title response"
@@ -231,8 +231,9 @@ $base = $this->categories;
231231
class="glyphicon indicator glyphicon-menu-down pull-right"></span>
232232
</h4>
233233
</div>
234-
<div class="panel-body collapse in response-panel"
234+
<div class="panel-body collapse <?php if ($key<1):?>in<?php endif;?> response-panel"
235235
id="request-coll--<?= $transition->get_href() . '-' . $response->statuscode; ?>">
236+
<?=$response->description;?>
236237
<?php if ($response->headers !== []): ?>
237238
<h5>Headers</h5>
238239
<ul class="headers list-unstyled">

src/PHPDraft/Parse/JsonToHTML.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,12 @@ public function get_html($template = 'default', $image = null, $css = null, $js
6060
{
6161
$gen = new TemplateGenerator($template, $image);
6262

63-
$gen->css[] = $css;
64-
$gen->js[] = $js;
63+
if(!empty($css)){
64+
$gen->css[] = explode(',',$css);
65+
}
66+
if(!empty($css)){
67+
$gen->js[] = explode(',',$js);
68+
}
6569
$gen->sorting = $this->sorting;
6670

6771
return $gen->get($this->object);

0 commit comments

Comments
 (0)