Fix resolving refs in external refs. Fixes #121
This commit is contained in:
Родитель
c552a8a5a2
Коммит
df2bd7fcef
|
@ -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({
|
||||
|
|
Загрузка…
Ссылка в новой задаче