Skip to content
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
1 change: 1 addition & 0 deletions src/languageservice/services/yamlSchemaService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,7 @@ export class YAMLSchemaService extends JSONSchemaService {
if (!refUri.startsWith('/')) return resolvedAgainstParent;
const parentResource = resourceIndexByUri.get(parentSchemaURL)?.root;
const parentResourceId = parentResource?.$id || parentResource?.id;
if (!parentResourceId) return resolvedAgainstParent;
const resolvedParentId = _resolveAgainstBase(parentSchemaURL, parentResourceId);
if (!resolvedParentId.startsWith('http://') && !resolvedParentId.startsWith('https://')) return resolvedAgainstParent;

Expand Down
44 changes: 44 additions & 0 deletions test/schema.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,50 @@ describe('JSON Schema', () => {
);
});

it('Resolving absolute-path $refs without top-level id', function (testDone) {
const service = new SchemaService.YAMLSchemaService(requestServiceMock, workspaceContext);
service.setSchemaContributions({
schemas: {
'file:///main/schema.json': {
type: 'object',
properties: {
name: {
$ref: '/main/schema2.json',
},
},
required: ['name'],
},
'file:///main/schema2.json': {
type: 'string',
enum: ['alice', 'bob'],
description: 'Allowed names.',
},
},
});

service
.getResolvedSchema('file:///main/schema.json')
.then((fs) => {
assert.deepEqual(fs.errors, []);
assert.deepEqual(fs.schema.properties['name'], {
type: 'string',
enum: ['alice', 'bob'],
description: 'Allowed names.',
_$ref: '/main/schema2.json',
_baseUrl: 'file:///main/schema2.json',
url: 'file:///main/schema2.json',
});
})
.then(
() => {
return testDone();
},
(error) => {
testDone(error);
}
);
});

it('Preserves markdownDescription on $ref siblings', function (testDone) {
const service = new SchemaService.YAMLSchemaService(requestServiceMock, workspaceContext);
service.setSchemaContributions({
Expand Down
Loading