Fix resolving refs in external refs. Fixes #121

This commit is contained in:
Martin Aeschlimann 2021-12-29 16:18:18 +01:00
Родитель c552a8a5a2
Коммит df2bd7fcef
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 2609A01E695523E3
2 изменённых файлов: 38 добавлений и 1 удалений

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

@ -580,7 +580,7 @@ export class JSONSchemaService implements IJSONSchemaService {
if (!seenRefs.has(ref)) {
const id = segments[1];
if (id !== undefined && isSubSchemaRef(id)) { // A $ref to a sub-schema with an $id (i.e #hello)
tryMergeSubSchema(next, id, handle);
tryMergeSubSchema(next, id, parentHandle);
} else { // A $ref to a JSON Pointer (i.e #/definitions/foo)
mergeByJsonPointer(next, parentSchema, parentHandle.uri, id); // can set next.$ref again, use seenRefs to avoid circle
}

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

@ -450,6 +450,43 @@ suite('JSON Schema', () => {
});
});
test('Resolving external $ref to ref', async function () {
const service = new SchemaService.JSONSchemaService(newMockRequestService(), workspaceContext);
service.setSchemaContributions({
schemas: {
"https://myschemastore/main/schema1.json": {
id: 'https://myschemastore/main/schema1.json',
type: 'object',
properties: {
p1: {
'$ref': 'https://myschemastore/main/schema2.json#red'
}
}
},
"https://myschemastore/main/schema2.json": {
id: 'https://myschemastore/main/schema2.json',
definitions: {
"_red": {
$id: '#red',
$ref: '#yellow'
},
"_yellow": {
$id: '#yellow',
type: 'number',
const: 5
}
}
}
}
});
const resolvedSchema = await service.getResolvedSchema('https://myschemastore/main/schema1.json');
assert.deepStrictEqual(resolvedSchema?.schema.properties?.p1, {
type: 'number',
const: 5
});
});
test('Resolving external $ref recursive', async function () {
const service = new SchemaService.JSONSchemaService(newMockRequestService(), workspaceContext);
service.setSchemaContributions({