Skip to content

Commit 1b453f9

Browse files
authoredOct 31, 2024··
Schema Does Not Load With URI myproto:///schema.json (#248)
1 parent 493010d commit 1b453f9

File tree

2 files changed

+55
-2
lines changed

2 files changed

+55
-2
lines changed
 

‎src/services/jsonSchemaService.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@ export class JSONSchemaService implements IJSONSchemaService {
490490
};
491491

492492
const resolveExternalLink = (node: JSONSchema, uri: string, refSegment: string | undefined, parentHandle: SchemaHandle): PromiseLike<any> => {
493-
if (contextService && !/^[A-Za-z][A-Za-z0-9+\-.+]*:\/\/.*/.test(uri)) {
493+
if (contextService && !/^[A-Za-z][A-Za-z0-9+\-.+]*:\/.*/.test(uri)) {
494494
uri = contextService.resolveRelativePath(uri, parentHandle.uri);
495495
}
496496
uri = normalizeId(uri);

‎src/test/schema.test.ts

+54-1
Original file line numberDiff line numberDiff line change
@@ -1998,7 +1998,60 @@ suite('JSON Schema', () => {
19981998
const testDoc = toDocument(JSON.stringify({ $schema: httpUrl, bar: 2 }));
19991999
let validation = await ls.doValidation(testDoc.textDoc, testDoc.jsonDoc);
20002000
assert.deepStrictEqual(validation.map(v => v.message), ['Value must be 3.']);
2001-
assert.deepStrictEqual([httpsUrl], accesses);
2001+
assert.deepStrictEqual([httpsUrl], accesses);
20022002
});
20032003

2004+
test('combined schemas and URIs without host', async function () {
2005+
const schemas: SchemaConfiguration[] = [{
2006+
uri: 'myproto:///schema.json',
2007+
fileMatch: ['foo.json'],
2008+
},
2009+
{
2010+
uri: 'https://myschemastore/schema2.json',
2011+
fileMatch: ['foo.json'],
2012+
}
2013+
];
2014+
const schemaContents: { [uri: string]: JSONSchema } = {
2015+
['myproto:/schema.json']: {
2016+
type: 'object',
2017+
properties: {
2018+
bar: {
2019+
type: 'string'
2020+
}
2021+
}
2022+
},
2023+
['https://myschemastore/schema2.json']: {
2024+
type: 'object',
2025+
properties: {
2026+
foo: {
2027+
type: 'string'
2028+
}
2029+
}
2030+
}
2031+
};
2032+
2033+
const accesses: string[] = [];
2034+
2035+
2036+
const schemaRequestService: SchemaRequestService = async (uri: string) => {
2037+
if (uri === `https://myschemastore/schema2.json` || uri === `myproto:/schema.json`) {
2038+
return '{}';
2039+
}
2040+
throw new Error('Unknown schema ' + uri);
2041+
};
2042+
2043+
2044+
const ls = getLanguageService({ workspaceContext, schemaRequestService });
2045+
ls.configure({ schemas });
2046+
2047+
{
2048+
const { textDoc, jsonDoc } = toDocument('{ }', undefined, 'foo://bar/folder/foo.json');
2049+
const res = await ls.doValidation(textDoc, jsonDoc);
2050+
console.log(res);
2051+
}
2052+
2053+
});
2054+
2055+
2056+
20042057
});

0 commit comments

Comments
 (0)
Please sign in to comment.