add test for resolving external $ref to already resolved schema

This commit is contained in:
Martin Aeschlimann 2021-11-16 09:09:25 +01:00
Родитель 7d970dda10
Коммит f7386b4516
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 2609A01E695523E3
1 изменённых файлов: 46 добавлений и 28 удалений

Просмотреть файл

@ -461,7 +461,6 @@ suite('JSON Schema', () => {
});
});
test('Resolving external $ref recursive', async function () {
const service = new SchemaService.JSONSchemaService(newMockRequestService(), workspaceContext);
service.setSchemaContributions({
@ -501,6 +500,52 @@ suite('JSON Schema', () => {
});
});
test('Resolving external $ref to already resolved schema', async function () {
const service = new SchemaService.JSONSchemaService(newMockRequestService(), workspaceContext);
service.setSchemaContributions({
schemas: {
"https://myschemastore/main/schema1.json": {
type: 'object',
properties: {
p1: {
$ref: 'schema2.json#blue'
}
}
},
"https://myschemastore/main/schema3.json": {
type: 'object',
properties: {
p1: {
$ref: 'schema2.json#blue'
}
}
},
"https://myschemastore/main/schema2.json": {
definitions: {
"blue": {
$id: '#blue',
type: 'string',
const: 'blue'
}
}
}
}
});
const resolvedSchema1 = await service.getResolvedSchema('https://myschemastore/main/schema1.json');
assert.deepStrictEqual(resolvedSchema1?.schema.properties?.p1, {
type: 'string',
const: 'blue'
});
const resolvedSchema3 = await service.getResolvedSchema('https://myschemastore/main/schema3.json');
assert.deepStrictEqual(resolvedSchema3?.schema.properties?.p1, {
type: 'string',
const: 'blue'
});
});
test('Resolving $refs 5', async function() {
const service = new SchemaService.JSONSchemaService(newMockRequestService(), workspaceContext);
service.setSchemaContributions({
@ -710,33 +755,6 @@ suite('JSON Schema', () => {
});
});
test('Preloaded Schema, string as URI', async function () {
// for https://github.com/microsoft/monaco-editor/issues/2683
const service = new SchemaService.JSONSchemaService(newMockRequestService(), workspaceContext);
const id = 'a5f8f39b-c7ee-48f8-babe-b7146ed3c055';
const schema: JSONSchema = {
type: 'object',
properties: {
child: {
type: 'object',
properties: {
'grandchild': {
type: 'number',
description: 'Meaning of Life'
}
}
}
}
};
service.registerExternalSchema(id, ['*.json'], schema);
return service.getSchemaForResource('test.json').then((schema) => {
const section = schema?.getSection(['child', 'grandchild']);
assert.equal(section?.description, 'Meaning of Life');
});
});
test('Multiple matches', async function () {
const service = new SchemaService.JSONSchemaService(newMockRequestService(), workspaceContext);
const id1 = 'https://myschemastore/test1';