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 @@ -75,6 +75,7 @@ const REF_SIBLING_NONCONSTRAINT_KEYS = new Set([
'$comment',
'title',
'description',
'markdownDescription',
'$vocabulary',
'examples',
'default',
Expand Down
33 changes: 33 additions & 0 deletions test/hover.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -945,6 +945,39 @@ Source: [${SCHEMA_ID}](file:///${SCHEMA_ID})`
`Yaml Language Server (https://github.com/redhat-developer/yaml-language-server)\n\nSource: [${SCHEMA_ID}](file:///${SCHEMA_ID})`
);
});

it('Hover prefers markdownDescription for $ref siblings', async () => {
schemaProvider.addSchema(SCHEMA_ID, {
$schema: 'http://json-schema.org/draft-07/schema#',
type: 'object',
properties: {
foo: {
type: 'string',
title: 'foo title',
description: 'foo desc',
markdownDescription: 'foo md desc **bold** \n * line \n* another \n\n',
},
bar: {
$ref: '#/$defs/veggie',
title: 'bar title',
description: 'bar desc',
markdownDescription: 'bar md desc **bold** \n * line \n* another \n\n',
},
},
$defs: {
veggie: {
type: 'string',
enum: ['potato', 'carrot'],
},
},
});
const hover = await parseSetup('b|a|r: potato');
assert.strictEqual(MarkupContent.is(hover.contents), true);
assert.strictEqual((hover.contents as MarkupContent).kind, 'markdown');
assert.ok((hover.contents as MarkupContent).value.includes('bar md desc **bold**'));
assert.ok((hover.contents as MarkupContent).value.includes('* another'));
assert.ok(!(hover.contents as MarkupContent).value.includes('bar desc'));
});
});

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

it('Preserves markdownDescription on $ref siblings', function (testDone) {
const service = new SchemaService.YAMLSchemaService(requestServiceMock, workspaceContext);
service.setSchemaContributions({
schemas: {
'https://myschemastore/main/schema.json': {
$schema: 'http://json-schema.org/draft-07/schema#',
id: 'https://myschemastore/main/schema.json',
type: 'object',
properties: {
bar: {
$ref: '#/$defs/veggie',
title: 'bar title',
description: 'bar desc',
markdownDescription: 'bar md desc **bold** \n * line \n* another \n\n',
},
},
$defs: {
veggie: {
type: 'string',
enum: ['potato', 'carrot'],
},
},
},
},
});

service
.getResolvedSchema('https://myschemastore/main/schema.json')
.then((resolvedSchema) => {
assert.strictEqual(resolvedSchema.schema.properties['bar'].description, 'bar desc');
assert.strictEqual(
resolvedSchema.schema.properties['bar'].markdownDescription,
'bar md desc **bold** \n * line \n* another \n\n'
);
assert.deepStrictEqual(resolvedSchema.schema.properties['bar'].enum, ['potato', 'carrot']);
})
.then(
() => {
return testDone();
},
(error) => {
testDone(error);
}
);
});

describe('Compound Schema Documents', () => {
let validationHandler: ValidationHandler;
let yamlSettings: SettingsState;
Expand Down
Loading