@@ -57,21 +57,26 @@ class HTTPRequest implements Comparable
5757 *
5858 * @var mixed
5959 */
60- public $ body = NULL ;
60+ public $ body = null ;
6161
6262 /**
63- * Identifier for the request.
63+ * Schema of the body of the request (if POST or PUT) .
6464 *
65- * @var string
65+ * @var mixed
6666 */
67- protected $ id ;
68-
67+ public $ body_schema = null ;
6968 /**
7069 * Structure of the request (if POST or PUT).
7170 *
7271 * @var RequestBodyElement
7372 */
7473 public $ struct = [];
74+ /**
75+ * Identifier for the request.
76+ *
77+ * @var string
78+ */
79+ protected $ id ;
7580
7681 /**
7782 * HTTPRequest constructor.
@@ -94,21 +99,38 @@ public function __construct(Transition &$parent)
9499 public function parse (stdClass $ object ): self
95100 {
96101 $ this ->method = $ object ->attributes ->method ->content ?? $ object ->attributes ->method ;
97- $ this ->title = isset ($ object ->meta ->title ) ? $ object ->meta ->title : NULL ;
102+ $ this ->title = isset ($ object ->meta ->title ) ? $ object ->meta ->title : null ;
98103
99104 if (($ this ->method === 'POST ' || $ this ->method === 'PUT ' ) && !empty ($ object ->content )) {
100105 foreach ($ object ->content as $ value ) {
101106 if ($ value ->element === 'dataStructure ' ) {
102107 $ this ->parse_structure ($ value );
103108 continue ;
104- } elseif ($ value ->element === 'copy ' ) {
109+ }
110+
111+ if ($ value ->element === 'copy ' ) {
105112 $ this ->description = MarkdownExtra::defaultTransform (htmlentities ($ value ->content ));
106- } elseif ($ value ->element === 'asset ' ) {
107- if (in_array ('messageBody ' , $ value ->meta ->classes )) {
108- $ this ->body [] = (isset ($ value ->content )) ? $ value ->content : NULL ;
109- $ this ->headers ['Content-Type ' ] =
110- (isset ($ value ->attributes ->contentType )) ? $ value ->attributes ->contentType : '' ;
111- }
113+ continue ;
114+ }
115+
116+ if ($ value ->element !== 'asset ' ) {
117+ continue ;
118+ }
119+ if (is_array ($ value ->meta ->classes ) && in_array ('messageBody ' , $ value ->meta ->classes )) {
120+ $ this ->body [] = (isset ($ value ->content )) ? $ value ->content : null ;
121+ $ this ->headers ['Content-Type ' ] = (isset ($ value ->attributes ->contentType )) ? $ value ->attributes ->contentType : '' ;
122+ continue ;
123+ }
124+
125+ if (isset ($ value ->meta ->classes ->content )
126+ && is_array ($ value ->meta ->classes ->content )
127+ && $ value ->meta ->classes ->content [0 ]->content === 'messageBody ' ) {
128+ $ this ->body [] = (isset ($ value ->content )) ? $ value ->content : null ;
129+ $ this ->headers ['Content-Type ' ] = (isset ($ value ->attributes ->contentType ->content )) ? $ value ->attributes ->contentType ->content : '' ;
130+ } elseif (isset ($ value ->meta ->classes ->content )
131+ && is_array ($ value ->meta ->classes ->content )
132+ && $ value ->meta ->classes ->content [0 ]->content === 'messageBodySchema ' ) {
133+ $ this ->body_schema = (isset ($ value ->content )) ? $ value ->content : null ;
112134 }
113135 }
114136 }
@@ -119,7 +141,7 @@ public function parse(stdClass $object): self
119141 }
120142 }
121143
122- if ($ this ->body === NULL ) {
144+ if ($ this ->body === null ) {
123145 $ this ->body = &$ this ->struct ;
124146 }
125147
@@ -152,15 +174,15 @@ public function get_id(): string
152174 * @param string $base_url URL to the base server
153175 * @param array $additional Extra options to pass to cURL
154176 *
177+ * @return string An executable cURL command
155178 * @throws Exception
156179 *
157- * @return string An executable cURL command
158180 */
159181 public function get_curl_command (string $ base_url , array $ additional = []): string
160182 {
161183 $ options = [];
162184
163- $ type = $ this ->headers ['Content-Type ' ] ?? NULL ;
185+ $ type = $ this ->headers ['Content-Type ' ] ?? null ;
164186
165187 $ options [] = '-X ' . $ this ->method ;
166188 if (empty ($ this ->body )) {
@@ -171,6 +193,9 @@ public function get_curl_command(string $base_url, array $additional = []): stri
171193 $ options [] = '--data-binary ' . escapeshellarg (join ('' , $ this ->body ));
172194 } elseif (is_subclass_of ($ this ->struct , StructureElement::class)) {
173195 foreach ($ this ->struct ->value as $ body ) {
196+ if (empty ($ body )) {
197+ continue ;
198+ }
174199 $ options [] = '--data-binary ' . escapeshellarg (strip_tags ($ body ->print_request ($ type )));
175200 }
176201 }
@@ -179,7 +204,8 @@ public function get_curl_command(string $base_url, array $additional = []): stri
179204 }
180205 $ options = array_merge ($ options , $ additional );
181206
182- return htmlspecialchars ('curl ' . join (' ' , $ options ) . ' ' . escapeshellarg ($ this ->parent ->build_url ($ base_url , TRUE )));
207+ return htmlspecialchars ('curl ' . join (' ' , $ options ) . ' ' . escapeshellarg ($ this ->parent ->build_url ($ base_url ,
208+ true )));
183209 }
184210
185211 /**
@@ -200,17 +226,17 @@ public function is_equal_to($b): bool
200226 * @param string $base_url URL to the base server
201227 * @param array $additional Extra options to pass to the service
202228 *
229+ * @return string
203230 * @throws Exception
204231 *
205- * @return string
206232 */
207233 public function get_hurl_link (string $ base_url , array $ additional = []): string
208234 {
209235 $ options = [];
210236
211- $ type = (isset ($ this ->headers ['Content-Type ' ])) ? $ this ->headers ['Content-Type ' ] : NULL ;
237+ $ type = (isset ($ this ->headers ['Content-Type ' ])) ? $ this ->headers ['Content-Type ' ] : null ;
212238
213- $ url = $ this ->parent ->build_url ($ base_url , TRUE );
239+ $ url = $ this ->parent ->build_url ($ base_url , true );
214240 $ url = explode ('? ' , $ url );
215241 if (isset ($ url [1 ])) {
216242 $ params = [];
0 commit comments