Skip to content

Commit

Permalink
display parent description for anyOf
Browse files Browse the repository at this point in the history
  • Loading branch information
ytausch committed Jan 7, 2025
1 parent 142f2a4 commit 062ed12
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/languageservice/services/yamlHover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export class YAMLHover {
};

const removePipe = (value: string): string => {
return value.replace(/\|\|\s*$/, '');
return value.replace(/\s\|\|\s*$/, '');
};

return this.schemaService.getSchemaForResource(document.uri, doc).then((schema) => {
Expand Down Expand Up @@ -141,7 +141,7 @@ export class YAMLHover {
if (s.schema.anyOf && isAllSchemasMatched(node, matchingSchemas, s.schema)) {
//if append title and description of all matched schemas on hover
title = '';
markdownDescription = '';
markdownDescription = s.schema.description ? (s.schema.description + '\n') : '';
s.schema.anyOf.forEach((childSchema: JSONSchema, index: number) => {
title += childSchema.title || s.schema.closestTitle || '';
markdownDescription += childSchema.markdownDescription || this.toMarkdown(childSchema.description) || '';
Expand Down
72 changes: 71 additions & 1 deletion test/hover.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -774,7 +774,7 @@ Source: [${SCHEMA_ID}](file:///${SCHEMA_ID})`
title: 'ZIP file',
anyOf: [{ type: "string", pattern: "\\.zip$" }, { type: "null" }],
default: null,
description: "Optional ZIP file path."
description: "Optional ZIP file path.",
},
},
required: ['optionalZipFile'],
Expand All @@ -790,6 +790,76 @@ Source: [${SCHEMA_ID}](file:///${SCHEMA_ID})`
);
expect(telemetry.messages).to.be.empty;
});
it('should concat parent and child descriptions in anyOf', async () => {
schemaProvider.addSchema(SCHEMA_ID, {
title: 'The Root',
description: 'Root Object',
type: 'object',
properties: {
child: {
title: 'Child',
anyOf: [
{
$ref: '#/definitions/FirstChoice',
},
{
$ref: '#/definitions/SecondChoice',
},
],
description: "The parent description."
},
},
required: ['child'],
additionalProperties: false,
definitions: {
FirstChoice: {
title: 'FirstChoice',
description: 'The first choice',
type: 'object',
properties: {
choice: {
title: 'Choice',
default: 'first',
enum: ['first'],
type: 'string',
},
property_a: {
title: 'Property A',
type: 'string',
},
},
required: ['property_a'],
},
SecondChoice: {
title: 'SecondChoice',
description: 'The second choice',
type: 'object',
properties: {
choice: {
title: 'Choice',
default: 'second',
enum: ['second'],
type: 'string',
},
property_b: {
title: 'Property B',
type: 'string',
},
},
required: ['property_b'],
},
},
});

let content = 'ch|i|ld:';
let result = await parseSetup(content);
assert.strictEqual(MarkupContent.is(result.contents), true);
assert.strictEqual(
(result.contents as MarkupContent).value,
`#### FirstChoice || SecondChoice\n\nThe parent description.\nThe first choice || The second choice\n\nSource: [${SCHEMA_ID}](file:///${SCHEMA_ID})`
);
expect(telemetry.messages).to.be.empty;
})
});

describe('Bug fixes', () => {
Expand Down

0 comments on commit 062ed12

Please sign in to comment.