Skip to content

Commit

Permalink
Schema Does Not Load With URI myproto:///schema.json
Browse files Browse the repository at this point in the history
  • Loading branch information
aeschli committed Oct 31, 2024
1 parent 493010d commit 9b585fd
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/services/jsonSchemaService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ export class JSONSchemaService implements IJSONSchemaService {
};

const resolveExternalLink = (node: JSONSchema, uri: string, refSegment: string | undefined, parentHandle: SchemaHandle): PromiseLike<any> => {
if (contextService && !/^[A-Za-z][A-Za-z0-9+\-.+]*:\/\/.*/.test(uri)) {
if (contextService && !/^[A-Za-z][A-Za-z0-9+\-.+]*:\/.*/.test(uri)) {
uri = contextService.resolveRelativePath(uri, parentHandle.uri);
}
uri = normalizeId(uri);
Expand Down
55 changes: 54 additions & 1 deletion src/test/schema.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1998,7 +1998,60 @@ suite('JSON Schema', () => {
const testDoc = toDocument(JSON.stringify({ $schema: httpUrl, bar: 2 }));
let validation = await ls.doValidation(testDoc.textDoc, testDoc.jsonDoc);
assert.deepStrictEqual(validation.map(v => v.message), ['Value must be 3.']);
assert.deepStrictEqual([httpsUrl], accesses);
assert.deepStrictEqual([httpsUrl], accesses);
});

test('combined schemas and URIs without host', async function () {
const schemas: SchemaConfiguration[] = [{
uri: 'myproto:///schema.json',
fileMatch: ['foo.json'],
},
{
uri: 'https://myschemastore/schema2.json',
fileMatch: ['foo.json'],
}
];
const schemaContents: { [uri: string]: JSONSchema } = {
['myproto:/schema.json']: {
type: 'object',
properties: {
bar: {
type: 'string'
}
}
},
['https://myschemastore/schema2.json']: {
type: 'object',
properties: {
foo: {
type: 'string'
}
}
}
};

const accesses: string[] = [];


const schemaRequestService: SchemaRequestService = async (uri: string) => {
if (uri === `https://myschemastore/schema2.json` || uri === `myproto:/schema.json`) {
return '{}';
}
throw new Error('Unknown schema ' + uri);
};


const ls = getLanguageService({ workspaceContext, schemaRequestService });
ls.configure({ schemas });

{
const { textDoc, jsonDoc } = toDocument('{ }', undefined, 'foo://bar/folder/foo.json');
const res = await ls.doValidation(textDoc, jsonDoc);
console.log(res);
}

});



});

0 comments on commit 9b585fd

Please sign in to comment.