From d1282de42204ed662383663c3b598f0905200d80 Mon Sep 17 00:00:00 2001 From: Anupya Pamidimukkala Date: Fri, 20 Oct 2023 11:23:21 -0400 Subject: [PATCH] remove chance of unexpected type coercion and unnecessary param --- doc/scripts/generate-code-samples.js | 26 +++++++++++------------- example/tournament-entry-code/browser.js | 2 +- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/doc/scripts/generate-code-samples.js b/doc/scripts/generate-code-samples.js index f6c24f67..7b28deaf 100755 --- a/doc/scripts/generate-code-samples.js +++ b/doc/scripts/generate-code-samples.js @@ -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 @@ -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) diff --git a/example/tournament-entry-code/browser.js b/example/tournament-entry-code/browser.js index 5522dd91..6174ffb3 100644 --- a/example/tournament-entry-code/browser.js +++ b/example/tournament-entry-code/browser.js @@ -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));