From 0926a689750a6c2a464e57c551db7b074dbf5e5f Mon Sep 17 00:00:00 2001 From: Malte Riesch Date: Fri, 6 Jul 2018 15:04:20 +0100 Subject: [PATCH 1/5] Added Formdata type and example value for type = file --- Command/GenerateCommand.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Command/GenerateCommand.php b/Command/GenerateCommand.php index 6f49ec8..b0baea8 100755 --- a/Command/GenerateCommand.php +++ b/Command/GenerateCommand.php @@ -89,6 +89,9 @@ protected function execute(InputInterface $input, OutputInterface $output) } foreach ($request->response as $key => $response) { + if (!property_exists($response, 'code')){ + continue; + } if ($response->code >=100 && $response->code <200) { $response->class = 'info'; } elseif ($response->code >=200 && $response->code <300) { From 59fa498886c757c0a64790a85395d5c6b728608d Mon Sep 17 00:00:00 2001 From: Malte Riesch Date: Tue, 10 Jul 2018 10:47:04 +0100 Subject: [PATCH 2/5] Added response's form data and json to the template --- templates/request.html | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/templates/request.html b/templates/request.html index d3660b8..b8b2aaf 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,43 @@

Example responses

{% for response in request.response %}
{{response.name}}
+ {% 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}}
From b218090763d8f8e0d2391fd375d05e24f6596119 Mon Sep 17 00:00:00 2001 From: Malte Riesch Date: Tue, 10 Jul 2018 10:53:15 +0100 Subject: [PATCH 3/5] Added default status code if it is missing (for example when generating your own json) --- Command/GenerateCommand.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Command/GenerateCommand.php b/Command/GenerateCommand.php index b0baea8..d3d741c 100755 --- a/Command/GenerateCommand.php +++ b/Command/GenerateCommand.php @@ -89,9 +89,10 @@ protected function execute(InputInterface $input, OutputInterface $output) } foreach ($request->response as $key => $response) { - if (!property_exists($response, 'code')){ - continue; + 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) { From e4e59c7c6fa6e7999e2e095031d221d65095619e Mon Sep 17 00:00:00 2001 From: Malte Riesch Date: Tue, 10 Jul 2018 11:09:29 +0100 Subject: [PATCH 4/5] Added the method and urls to each response example --- Command/GenerateCommand.php | 5 +++++ templates/request.html | 9 +++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/Command/GenerateCommand.php b/Command/GenerateCommand.php index d3d741c..81edad1 100755 --- a/Command/GenerateCommand.php +++ b/Command/GenerateCommand.php @@ -158,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 b8b2aaf..2800945 100644 --- a/templates/request.html +++ b/templates/request.html @@ -90,9 +90,14 @@

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
@@ -119,7 +124,7 @@

Example responses

{% endif %} {% if response.originalRequest.body.mode == 'raw' %} -
+
JSON
{{prettify(response.originalRequest.body.raw)}}
From 8627d949f476b4d9001ac16d5e23a1c4ec11102c Mon Sep 17 00:00:00 2001 From: Malte Riesch Date: Thu, 26 Jul 2018 13:35:01 +0100 Subject: [PATCH 5/5] adding the folder name to the generated file name of the request to avoid clashes --- Command/GenerateCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Command/GenerateCommand.php b/Command/GenerateCommand.php index 81edad1..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"); }