Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Schema Does Not Load With URI myproto:///schema.json #248

Merged
merged 1 commit into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}

});



});
Loading