diff --git a/Command/GenerateCommand.php b/Command/GenerateCommand.php index 6f49ec8..14852ab 100755 --- a/Command/GenerateCommand.php +++ b/Command/GenerateCommand.php @@ -79,7 +79,7 @@ protected function execute(InputInterface $input, OutputInterface $output) $request->request->url = $request->request->url->raw; } $pageFilename = strtolower($request->request->method) . '_' . str_ireplace(array('/','\\','.',' ','?'),'_', $request->name) . ".html"; - $request->page_path = 'requests/' . $pageFilename; + $request->page_path = 'requests/' . $item->name. '-' . $pageFilename; if (!property_exists($request, 'response') || !count($request->response)) { $output->writeln("Warning: {$request->name} has no response examples"); } @@ -89,6 +89,10 @@ protected function execute(InputInterface $input, OutputInterface $output) } foreach ($request->response as $key => $response) { + if (!property_exists($response, 'code')) { + $response->code = 200; + } + if ($response->code >=100 && $response->code <200) { $response->class = 'info'; } elseif ($response->code >=200 && $response->code <300) { @@ -154,6 +158,11 @@ protected function getTwig() }); $twig->addFunction($f); + + $twig->addFunction(new \Twig_SimpleFunction("upper", function ($data) { + return strtoupper($data); + })); + return $twig; } diff --git a/templates/request.html b/templates/request.html index d3660b8..2800945 100644 --- a/templates/request.html +++ b/templates/request.html @@ -60,7 +60,7 @@

{{request.name}}

Example Value - {% for parameter in request.request.body.formdata %} + {% for parameter in request.request.response.body.formdata %} {{parameter.key}} {{parameter.type}} @@ -90,6 +90,48 @@

Example responses

{% for response in request.response %}
{{response.name}}
+
+
+ {{upper(response.originalRequest.method)}} {{response.originalRequest.url.raw}} +
+
+ {% if response.originalRequest.method != 'GET' %} + {% if response.originalRequest.body.mode == 'formdata' %} +
+
Form-data Parameters
+
+ + + + + + + + + {% for parameter in response.originalRequest.body.formdata %} + + + + {% if parameter.type == 'file' %} + + {% else %} + + {% endif %} + + {% endfor %} +
KeyTypeExample Value
{{parameter.key}}{{parameter.type}}{{parameter.src}}{{parameter.value}}
+
+
+ {% endif %} + {% if response.originalRequest.body.mode == 'raw' %} +
+
JSON
+
+
{{prettify(response.originalRequest.body.raw)}}
+
+
+ {% endif %} + {% endif %}
{{response.code}} {{response.status}}