Skip to content

Commit

Permalink
Staging #438 - Improve code samples
Browse files Browse the repository at this point in the history
Addresses: #438
  • Loading branch information
nils-work committed Sep 17, 2024
1 parent db35c06 commit f9c79d5
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 36 deletions.
10 changes: 5 additions & 5 deletions slate/source/stylesheets/_variables.scss
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ under the License.
// BACKGROUND COLORS
////////////////////
$nav-bg: #000000 !default;
$examples-bg: #2E3336 !default;
$code-bg: #1E2224 !default;
$code-annotation-bg: #191D1F !default;
$examples-bg: #444 !default;
$code-bg: #222 !default;
$code-annotation-bg: #333 !default;
$nav-subitem-bg: #1E2224 !default;
$nav-active-bg: #00A9CE !default;
$nav-active-parent-bg: #1E2224 !default; // parent links of the current section
$nav-active-parent-bg: #222 !default; // parent links of the current section
$lang-select-border: #000 !default;
$lang-select-bg: #1E2224 !default;
$lang-select-bg: #222 !default;
$lang-select-active-bg: $examples-bg !default; // feel free to change this to blue or something
$lang-select-pressed-bg: #111 !default; // color of language tab bg when mouse is pressed
$main-bg: #F3F7F9 !default;
Expand Down
5 changes: 3 additions & 2 deletions slate/source/stylesheets/screen.css.scss
Original file line number Diff line number Diff line change
Expand Up @@ -640,13 +640,14 @@ html, body {
@extend %code-font;
padding-top: 2em;
padding-bottom: 2em;
padding: 2em $main-padding;
padding: 1.5em $main-padding;
}

blockquote {
&>p {
background-color: $code-annotation-bg;
padding: $code-annotation-padding 2em;
/* padding: $code-annotation-padding 2em; */
padding: 0.6em 2em 0.8em 2em;
color: #eee;
}
}
Expand Down
10 changes: 5 additions & 5 deletions swagger-gen/widdershins-cdr/openapi3.js
Original file line number Diff line number Diff line change
Expand Up @@ -338,17 +338,17 @@ function getBodyParameterExamples(data) {
}
if (common.doContentType(data.consumes, 'json')) {
content += '```json\n';
content += safejson(obj,null,2) + '\n';
content += safejson(obj,null,2).replace(/\n+$/, '') + '\n';
content += '```\n\n';
}
if (common.doContentType(data.consumes, 'yaml')) {
content += '```yaml\n';
content += yaml.safeDump(obj) + '\n';
content += yaml.safeDump(obj).replace(/\n+$/, '') + '\n';
content += '```\n\n';
}
if (common.doContentType(data.consumes, 'form')) {
content += '```yaml\n';
content += yaml.safeDump(obj) + '\n';
content += yaml.safeDump(obj).replace(/\n+$/, '') + '\n';
content += '```\n\n';
}
if (common.doContentType(data.consumes, 'xml') && (typeof obj === 'object')) {
Expand Down Expand Up @@ -512,12 +512,12 @@ function getResponseExamples(data) {
}
if (common.doContentType(example.cta, 'json')) {
content += '```json\n';
content += safejson(example.value, null, 2) + '\n';
content += safejson(example.value, null, 2).replace(/\n+$/, '') + '\n';
content += '```\n\n';
}
if (common.doContentType(example.cta, 'yaml')) {
content += '```yaml\n';
content += yaml.safeDump(example.value) + '\n';
content += yaml.safeDump(example.value).replace(/\n+$/, '') + '\n';
content += '```\n\n';
}
let xmlObj = example.value;
Expand Down
12 changes: 5 additions & 7 deletions swagger-gen/widdershins-cdr/templates/openapi3/code_http.dot
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
{{=data.methodUpper}} {{=data.url}}{{=data.requiredQueryString}} HTTP/1.1
{{? data.host}}Host: {{=data.host}}{{?}}
{{?data.consumes.length}}Content-Type: {{=data.consumes[0]}}
{{?}}{{?data.produces.length}}Accept: {{=data.produces[0]}}{{?}}
{{?data.headerParameters.length}}{{~ data.headerParameters :p:index}}{{=p.name}}: {{=p.exampleValues.object}}
{{~}}
{{?}}
{{=data.methodUpper}} {{=data.url}}{{=data.requiredQueryString}} HTTP/1.1{{? data.host}}
Host: {{=data.host}}{{?}}{{?data.consumes.length}}
Content-Type: {{=data.consumes[0]}}{{?}}{{?data.produces.length}}
Accept: {{=data.produces[0]}}{{?}}{{?data.headerParameters.length}}{{~ data.headerParameters :p:index}}
{{=p.name}}: {{=p.exampleValues.object}}{{~}}{{?}}
24 changes: 11 additions & 13 deletions swagger-gen/widdershins-cdr/templates/openapi3/code_nodejs.dot
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
const fetch = require('node-fetch');
{{?data.bodyParameter.present}}const inputBody = '{{=data.bodyParameter.exampleValues.json}}';{{?}}
{{?data.allHeaders.length}}const headers = {
const fetch = require('node-fetch');{{?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.allHeaders.length}} headers: headers{{?}}
})
.then(function(res) {

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.allHeaders.length}}headers: headers{{?}}
}).then(function(res) {
return res.json();
}).then(function(body) {
console.log(body);
});
});
6 changes: 2 additions & 4 deletions swagger-gen/widdershins-cdr/templates/openapi3/main.dot
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,9 @@

{{? data.options.yaml }}
```yaml
{{=data.utils.yaml.safeDump(data.utils.getSample(schema,data.options,{},data.api))}}
{{??}}
{{=data.utils.yaml.safeDump(data.utils.getSample(schema,data.options,{},data.api))}}{{??}}
```json
{{=data.utils.safejson(data.utils.getSample(schema,data.options,{},data.api),null,2)}}
{{?}}
{{=data.utils.safejson(data.utils.getSample(schema,data.options,{},data.api),null,2)}}{{?}}
```

{{ var enums = []; }}
Expand Down
3 changes: 3 additions & 0 deletions swagger-gen/widdershins-cdr/templates/openapi3/operation.dot
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
{{?}}

{{ data.methodUpper = data.method.verb.toUpperCase(); }}
{{ data.orig_baseUrl = data.orig_baseUrl || data.baseUrl; }}
{{ data.baseUrl = (data.operation.servers && data.operation.servers[0].url) || data.orig_baseUrl; }}
{{ data.host = data.baseUrl.replace(/^https?:\/\//, '').split('/', 1)[0].toLowerCase(); }}
{{ data.url = data.utils.slashes(data.baseUrl + data.method.path); }}
{{ data.parameters = data.operation.parameters; }}
{{ data.enums = []; }}
Expand Down

0 comments on commit f9c79d5

Please sign in to comment.