Skip to content

Commit

Permalink
Merge pull request #286 from Anupya/Anupya/minor-bugs
Browse files Browse the repository at this point in the history
Remove chance of unexpected type coercion and remove unnecessary param to `TextEncoder`
  • Loading branch information
niklasf authored Oct 20, 2023
2 parents a1535a5 + d1282de commit 41b8380
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
26 changes: 12 additions & 14 deletions doc/scripts/generate-code-samples.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@
// from https://github.com/Direct-Freight/df-api-docs/blob/master/scripts/generate-code-samples.js
'use strict'
require('shelljs/global');
var fs = require('fs')
var stringifyObject = require('stringify-object');
var SwaggerSnippet = require('swagger-snippet')
const fs = require('fs')
const SwaggerSnippet = require('swagger-snippet')

if(process.argv[2] != 'skip-pre-bundle')
if(process.argv[2] !== 'skip-pre-bundle')
{
console.log("first bundle combined file to ensure it is up to date");
exec('swagger-repo bundle -o ./web_deploy/swagger.json'); //this wants a single dot
Expand Down Expand Up @@ -45,19 +44,18 @@ var results = SwaggerSnippet.getSwaggerSnippets(SwaggerFile,

results.forEach(function(result)
{
var path = result.url.replace(/http.*api\//,'').replace(/\//g,'@');
const pretty = stringifyObject(result.snippets, { indent: ' ', singleQuotes: false });
const path = result.url.replace(/http.*api\//,'').replace(/\//g,'@');
result.snippets.forEach(function(snippet)
{
var ext = '.txt';
var lang = snippet.id;
let ext = '.txt';
let lang = snippet.id;
lang = lang[0].toUpperCase() + lang.substring(1); //uppercase first letter
if(lang == 'Shell_curl') { ext = '.sh'; lang = 'curl'; }
if(lang == 'Shell_wget') { ext = '.sh'; lang = 'wget'; }
if(lang.substring(0,4) == 'Perl') { ext = '.pl'; }
if(lang.substring(0,6) == 'Python') { ext = '.py'; }
if(lang.substring(0,3) == 'Php') { ext = '.php'; }
var dir = 'spec/code_samples/' + lang + '/' + path + '/';
if(lang === 'Shell_curl') { ext = '.sh'; lang = 'curl'; }
if(lang === 'Shell_wget') { ext = '.sh'; lang = 'wget'; }
if(lang.substring(0,4) === 'Perl') { ext = '.pl'; }
if(lang.substring(0,6) === 'Python') { ext = '.py'; }
if(lang.substring(0,3) === 'Php') { ext = '.php'; }
const dir = 'spec/code_samples/' + lang + '/' + path + '/';
mkdir('-p',dir);
fs.writeFile(dir + result.method.toLowerCase() + ext,snippet.content, (err) => {
if (err)
Expand Down
2 changes: 1 addition & 1 deletion example/tournament-entry-code/browser.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
async function hmacSha256(secret, data) {
const utf8 = new TextEncoder('utf-8');
const utf8 = new TextEncoder();
const algorithm = {name: 'HMAC', hash: 'SHA-256'};
const key = await crypto.subtle.importKey('raw', utf8.encode(secret), algorithm, false, ['sign']);
return await crypto.subtle.sign(algorithm, key, utf8.encode(data));
Expand Down

0 comments on commit 41b8380

Please sign in to comment.