Skip to content

Commit

Permalink
Improve code samples templates (#278)
Browse files Browse the repository at this point in the history
* remove unnecessary new-lines in various code samples

* fix inputBody string in nodejs code sample
  • Loading branch information
lagebaue authored Mar 28, 2020
1 parent ef2a6b6 commit ca40f90
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 10 deletions.
4 changes: 2 additions & 2 deletions templates/openapi3/code_go.dot
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ func main() {

{{?data.allHeaders.length}}
headers := map[string][]string{
{{~data.allHeaders :p:index}}"{{=p.name}}": []string{"{{=p.exampleValues.object}}"},
{{~}}
{{~data.allHeaders :p:index}}"{{=p.name}}": []string{"{{=p.exampleValues.object}}"},{{?index < data.allHeaders.length-1}}
{{?}}{{~}}
}{{?}}

data := bytes.NewBuffer([]byte{jsonReq})
Expand Down
3 changes: 1 addition & 2 deletions templates/openapi3/code_javascript.dot
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
{{?data.bodyParameter.present}}const inputBody = '{{=data.bodyParameter.exampleValues.json}}';{{?}}
{{?data.allHeaders.length}}const headers = {
{{~data.allHeaders :p:index}} '{{=p.name}}':{{=p.exampleValues.json}}{{?index < data.allHeaders.length-1}},{{?}}
{{~}}
};
{{~}}};
{{?}}
fetch('{{=data.url}}{{=data.requiredQueryString}}',
{
Expand Down
7 changes: 3 additions & 4 deletions templates/openapi3/code_nodejs.dot
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
const fetch = require('node-fetch');
{{?data.bodyParameter.present}}const inputBody = '{{=data.bodyParameter.exampleValues.json}}';{{?}}
{{?data.bodyParameter.present}}const inputBody = {{=data.bodyParameter.exampleValues.json}};{{?}}
{{?data.allHeaders.length}}const headers = {
{{~data.allHeaders :p:index}} '{{=p.name}}':{{=p.exampleValues.json}}{{?index < data.allHeaders.length-1}},{{?}}
{{~}}
};
{{~}}};
{{?}}
fetch('{{=data.url}}{{=data.requiredQueryString}}',
{
method: '{{=data.methodUpper}}'{{?data.bodyParameter.present || data.allHeaders.length}},{{?}}
{{?data.bodyParameter.present}} body: inputBody{{?}}{{? data.bodyParameter.present && data.allHeaders.length}},{{?}}
{{?data.bodyParameter.present}} body: JSON.stringify(inputBody){{?}}{{? data.bodyParameter.present && data.allHeaders.length}},{{?}}
{{?data.allHeaders.length}} headers: headers{{?}}
})
.then(function(res) {
Expand Down
3 changes: 1 addition & 2 deletions templates/openapi3/code_php.dot
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ require 'vendor/autoload.php';
{{?data.allHeaders.length}}
$headers = array(
{{~data.allHeaders :p:index}}'{{=p.name}}' => '{{=p.exampleValues.object}}',
{{~}}
);{{?}}
{{?index < data.allHeaders.length-1}} {{?}}{{~}});{{?}}

$client = new \GuzzleHttp\Client();

Expand Down

0 comments on commit ca40f90

Please sign in to comment.