Skip to content

Commit

Permalink
fix: perf fixes, refs #213
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeRalphson committed Feb 17, 2020
1 parent 0306902 commit 4494892
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
8 changes: 2 additions & 6 deletions packages/reftools/lib/jptr.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
* @return the escaped string
*/
function jpescape(s) {
s = s.split('~').join('~0');
s = s.split('/').join('~1');
return s;
return s.replace(/\~/g, '~0').replace(/\//g, '~1');
}

/**
Expand All @@ -17,9 +15,7 @@ function jpescape(s) {
* @return the unescaped string
*/
function jpunescape(s) {
s = s.split('~1').join('/');
s = s.split('~0').join('~');
return s;
return s.replace(/\~1/g, '/').replace(/~0/g, '~');
}

// JSON Pointer specification: http://tools.ietf.org/html/rfc6901
Expand Down
12 changes: 7 additions & 5 deletions packages/swagger2openapi/oas-validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ let argv = yargs
.alias('w', 'whatwg')
.describe('whatwg', 'enable WHATWG URL parsing')
.boolean('yaml')
.default('yaml', true)
.alias('y', 'yaml')
.describe('yaml', 'skip YAML-safe test')
.help('h')
Expand Down Expand Up @@ -165,12 +166,12 @@ function handleResult(err, options) {
if (!options.yaml) {
try {
resultStr = yaml.stringify(result); // should be representable safely in yaml
let resultStr2 = yaml.stringify(result); // FIXME dropped 'noRefs:true' here
//let resultStr2 = yaml.stringify(result); // FIXME dropped 'noRefs:true' here
should(resultStr).not.be.exactly('{}','Result should not be empty');
should(resultStr).equal(resultStr2,'Result should have no object identity ref_s');
//should(resultStr).equal(resultStr2,'Result should have no object identity ref_s');
}
catch (ex) {
if (options.verbose>1) {
if (options.debug) {
fs.writeFileSync('./debug.yaml',resultStr,'utf8');
console.warn('Result dumped to debug.yaml fixed.yaml');
let fix = reref(result);
Expand Down Expand Up @@ -217,8 +218,9 @@ function* check(file, force, expectFailure) {

if ((name.indexOf('.yaml') >= 0) || (name.indexOf('.yml') >= 0) || (name.indexOf('.json') >= 0) || force) {

let srcStr;
if (!file.startsWith('http')) {
let srcStr = fs.readFileSync(path.resolve(file), options.encoding);
srcStr = fs.readFileSync(path.resolve(file), options.encoding);
try {
src = JSON.parse(srcStr);
}
Expand All @@ -244,6 +246,7 @@ function* check(file, force, expectFailure) {

options.original = src;
options.source = file;
options.text = srcStr;
options.expectFailure = false;
options.allowFailure = false;

Expand All @@ -258,7 +261,6 @@ function* check(file, force, expectFailure) {
options.allowFailure = true;
}


if (file.startsWith('http')) {
swagger2openapi.convertUrl(file, clone(options))
.then(function(options){
Expand Down

0 comments on commit 4494892

Please sign in to comment.