Skip to content

Commit

Permalink
chore: keep $refs linking to json-schema.org unresolved
Browse files Browse the repository at this point in the history
  • Loading branch information
P0lip committed Feb 25, 2021
1 parent 08012e2 commit fb1d730
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/ruleset/__tests__/__fixtures__/json-schema-org-ruleset.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"rules": {
"json-schema": {
"given": "$",
"then": {
"function": "valid",
"functionOptions": {
"$ref": "http://json-schema.org/draft-04/schema#"
}
}
}
}
}
21 changes: 21 additions & 0 deletions src/ruleset/__tests__/reader.jest.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,27 @@ describe('Rulesets reader', () => {
});
});

it('should not resolve json-schema.org $refs', async () => {
expect(await readRuleset(getFixturePath('json-schema-org-ruleset.json'))).toEqual(
expect.objectContaining({
rules: {
'json-schema': {
enabled: true,
given: '$',
recommended: true,
severity: DiagnosticSeverity.Warning,
then: {
function: 'valid',
functionOptions: {
$ref: 'http://json-schema.org/draft-04/schema#',
},
},
},
},
}),
);
});

describe('Exceptions loading', () => {
it('should handle loading a standalone ruleset', async () => {
const ruleset = await readRuleset(path.join(__dirname, './__fixtures__/exceptions/standalone.yaml'));
Expand Down
8 changes: 8 additions & 0 deletions src/ruleset/readRuleset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,14 @@ const createRulesetProcessor = (
baseUri: rulesetUri,
dereferenceInline: false,
uriCache,
transformRef(opts) {
const host = opts.ref?.host();
if (host === 'json-schema.org') {
return;
}

return opts.ref;
},
async parseResolveResult(opts) {
opts.result = parseContent(opts.result, opts.targetAuthority.pathname());
return opts;
Expand Down

0 comments on commit fb1d730

Please sign in to comment.