Skip to content

Commit 63ac955

Browse files
committed
Add a --warnings-as-errors flag to json-refs resolve
1 parent 44ef931 commit 63ac955

File tree

2 files changed

+33
-7
lines changed

2 files changed

+33
-7
lines changed

bin/json-refs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ program
9797
.option('-f, --force', 'Do not fail when the document has invalid JSON References')
9898
.option('-H, --header <header>', 'The header to use when retrieving a remote document', optionArrayAppender(), [])
9999
.option('-I, --filter <type>', 'The type of JSON References to resolved', optionArrayAppender(), [])
100+
.option('-w, --warnings-as-errors', 'Treat warnings as errors')
100101
.option('-y, --yaml', 'Output as YAML')
101102
.action(function (location) {
102103
var options = {
@@ -136,8 +137,8 @@ program
136137
Object.keys(results.refs).forEach(function (refPtr) {
137138
var refDetails = results.refs[refPtr];
138139

139-
if (refDetails.type === 'invalid' || refDetails.error) {
140-
errors.push(' ' + refPtr + ': ' + refDetails.error);
140+
if (refDetails.type === 'invalid' || refDetails.error || (that.warningsAsErrors && refDetails.warning)) {
141+
errors.push(' ' + refPtr + ': ' + (refDetails.warning ? refDetails.warning : refDetails.error));
141142
}
142143
});
143144
}

test/test-cli.js

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,12 @@ var resolveHelp = [
8282
'',
8383
' Options:',
8484
'',
85-
' -h, --help output usage information',
86-
' -f, --force Do not fail when the document has invalid JSON References',
87-
' -H, --header <header> The header to use when retrieving a remote document',
88-
' -I, --filter <type> The type of JSON References to resolved',
89-
' -y, --yaml Output as YAML',
85+
' -h, --help output usage information',
86+
' -f, --force Do not fail when the document has invalid JSON References',
87+
' -H, --header <header> The header to use when retrieving a remote document',
88+
' -I, --filter <type> The type of JSON References to resolved',
89+
' -w, --warnings-as-errors Treat warnings as errors',
90+
' -y, --yaml Output as YAML',
9091
'',
9192
''
9293
].join('\n');
@@ -355,6 +356,30 @@ describe('json-refs CLI', function () {
355356
});
356357
});
357358

359+
it('--warnings-as-errors option', function (done) {
360+
this.timeout(10000);
361+
362+
executeJsonRefs(['resolve', testDocumentLocation, '--warnings-as-errors'], function (stderr, stdout) {
363+
assert.equal(stdout, '');
364+
365+
assert.equal(stderr, [
366+
'',
367+
' error: Document has invalid references:',
368+
'',
369+
' #/missing: JSON Pointer points to missing location: #/some/missing/path',
370+
' #/warning: Extra JSON Reference properties will be ignored: ignored',
371+
' #/invalid: HTTP URIs must have a host.',
372+
' #/remote/relative/missing: JSON Pointer points to missing location: #/some/missing/path',
373+
' #/remote/relative/child/missing: JSON Pointer points to missing location: #/some/missing/path',
374+
' #/remote/relative/child/ancestor/missing: JSON Pointer points to missing location: #/some/missing/path',
375+
'',
376+
''
377+
].join('\n'));
378+
379+
done();
380+
});
381+
});
382+
358383
it('--yaml option', function (done) {
359384
this.timeout(10000);
360385

0 commit comments

Comments
 (0)