Skip to content

Commit b6f8873

Browse files
shin19991207datho7561
authored andcommitted
fix to preserve markdownDescribtion on $ref siblings
Signed-off-by: Morgan Chang <shin19991207@gmail.com>
1 parent 37a7b17 commit b6f8873

File tree

3 files changed

+80
-0
lines changed

3 files changed

+80
-0
lines changed

src/languageservice/services/yamlSchemaService.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ const REF_SIBLING_NONCONSTRAINT_KEYS = new Set([
7575
'$comment',
7676
'title',
7777
'description',
78+
'markdownDescription',
7879
'$vocabulary',
7980
'examples',
8081
'default',

test/hover.test.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -945,6 +945,39 @@ Source: [${SCHEMA_ID}](file:///${SCHEMA_ID})`
945945
`Yaml Language Server (https://github.com/redhat-developer/yaml-language-server)\n\nSource: [${SCHEMA_ID}](file:///${SCHEMA_ID})`
946946
);
947947
});
948+
949+
it('Hover prefers markdownDescription for $ref siblings', async () => {
950+
schemaProvider.addSchema(SCHEMA_ID, {
951+
$schema: 'http://json-schema.org/draft-07/schema#',
952+
type: 'object',
953+
properties: {
954+
foo: {
955+
type: 'string',
956+
title: 'foo title',
957+
description: 'foo desc',
958+
markdownDescription: 'foo md desc **bold** \n * line \n* another \n\n',
959+
},
960+
bar: {
961+
$ref: '#/$defs/veggie',
962+
title: 'bar title',
963+
description: 'bar desc',
964+
markdownDescription: 'bar md desc **bold** \n * line \n* another \n\n',
965+
},
966+
},
967+
$defs: {
968+
veggie: {
969+
type: 'string',
970+
enum: ['potato', 'carrot'],
971+
},
972+
},
973+
});
974+
const hover = await parseSetup('b|a|r: potato');
975+
assert.strictEqual(MarkupContent.is(hover.contents), true);
976+
assert.strictEqual((hover.contents as MarkupContent).kind, 'markdown');
977+
assert.ok((hover.contents as MarkupContent).value.includes('bar md desc **bold**'));
978+
assert.ok((hover.contents as MarkupContent).value.includes('* another'));
979+
assert.ok(!(hover.contents as MarkupContent).value.includes('bar desc'));
980+
});
948981
});
949982

950983
describe('Hover on anyOf', () => {

test/schema.test.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,52 @@ describe('JSON Schema', () => {
219219
);
220220
});
221221

222+
it('Preserves markdownDescription on $ref siblings', function (testDone) {
223+
const service = new SchemaService.YAMLSchemaService(requestServiceMock, workspaceContext);
224+
service.setSchemaContributions({
225+
schemas: {
226+
'https://myschemastore/main/schema.json': {
227+
$schema: 'http://json-schema.org/draft-07/schema#',
228+
id: 'https://myschemastore/main/schema.json',
229+
type: 'object',
230+
properties: {
231+
bar: {
232+
$ref: '#/$defs/veggie',
233+
title: 'bar title',
234+
description: 'bar desc',
235+
markdownDescription: 'bar md desc **bold** \n * line \n* another \n\n',
236+
},
237+
},
238+
$defs: {
239+
veggie: {
240+
type: 'string',
241+
enum: ['potato', 'carrot'],
242+
},
243+
},
244+
},
245+
},
246+
});
247+
248+
service
249+
.getResolvedSchema('https://myschemastore/main/schema.json')
250+
.then((resolvedSchema) => {
251+
assert.strictEqual(resolvedSchema.schema.properties['bar'].description, 'bar desc');
252+
assert.strictEqual(
253+
resolvedSchema.schema.properties['bar'].markdownDescription,
254+
'bar md desc **bold** \n * line \n* another \n\n'
255+
);
256+
assert.deepStrictEqual(resolvedSchema.schema.properties['bar'].enum, ['potato', 'carrot']);
257+
})
258+
.then(
259+
() => {
260+
return testDone();
261+
},
262+
(error) => {
263+
testDone(error);
264+
}
265+
);
266+
});
267+
222268
describe('Compound Schema Documents', () => {
223269
let validationHandler: ValidationHandler;
224270
let yamlSettings: SettingsState;

0 commit comments

Comments
 (0)