File tree Expand file tree Collapse file tree 2 files changed +42
-0
lines changed
src/languageservice/services Expand file tree Collapse file tree 2 files changed +42
-0
lines changed Original file line number Diff line number Diff line change @@ -505,6 +505,7 @@ export class YAMLSchemaService extends JSONSchemaService {
505505 if ( ! refUri . startsWith ( '/' ) ) return resolvedAgainstParent ;
506506 const parentResource = resourceIndexByUri . get ( parentSchemaURL ) ?. root ;
507507 const parentResourceId = parentResource ?. $id || parentResource ?. id ;
508+ if ( ! parentResourceId ) return resolvedAgainstParent ;
508509 const resolvedParentId = _resolveAgainstBase ( parentSchemaURL , parentResourceId ) ;
509510 if ( ! resolvedParentId . startsWith ( 'http://' ) && ! resolvedParentId . startsWith ( 'https://' ) ) return resolvedAgainstParent ;
510511
Original file line number Diff line number Diff line change @@ -219,6 +219,47 @@ describe('JSON Schema', () => {
219219 ) ;
220220 } ) ;
221221
222+ it ( 'Resolving absolute-path $refs without top-level id' , function ( testDone ) {
223+ const service = new SchemaService . YAMLSchemaService ( requestServiceMock , workspaceContext ) ;
224+ service . setSchemaContributions ( {
225+ schemas : {
226+ 'file:///main/schema.yaml' : {
227+ type : 'object' ,
228+ properties : {
229+ name : {
230+ $ref : '/main/schema2.yaml' ,
231+ } ,
232+ } ,
233+ } ,
234+ 'file:///main/schema2.yaml' : {
235+ type : 'string' ,
236+ description : 'Something.' ,
237+ } ,
238+ } ,
239+ } ) ;
240+
241+ service
242+ . getResolvedSchema ( 'file:///main/schema.yaml' )
243+ . then ( ( fs ) => {
244+ assert . deepEqual ( fs . errors , [ ] ) ;
245+ assert . deepEqual ( fs . schema . properties [ 'name' ] , {
246+ type : 'string' ,
247+ description : 'Something.' ,
248+ _$ref : '/main/schema2.yaml' ,
249+ _baseUrl : 'file:///main/schema2.yaml' ,
250+ url : 'file:///main/schema2.yaml' ,
251+ } ) ;
252+ } )
253+ . then (
254+ ( ) => {
255+ return testDone ( ) ;
256+ } ,
257+ ( error ) => {
258+ testDone ( error ) ;
259+ }
260+ ) ;
261+ } ) ;
262+
222263 it ( 'Preserves markdownDescription on $ref siblings' , function ( testDone ) {
223264 const service = new SchemaService . YAMLSchemaService ( requestServiceMock , workspaceContext ) ;
224265 service . setSchemaContributions ( {
You can’t perform that action at this time.
0 commit comments