Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add missing field descriptions for anyOf #1007

Merged
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
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
96 changes: 96 additions & 0 deletions test/hover.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -764,6 +764,102 @@ Source: [${SCHEMA_ID}](file:///${SCHEMA_ID})`
);
expect(telemetry.messages).to.be.empty;
});
it('should show the parent description in anyOf (no child descriptions)', async () => {
schemaProvider.addSchema(SCHEMA_ID, {
title: 'The Root',
description: 'Root Object',
type: 'object',
properties: {
optionalZipFile: {
title: 'ZIP file',
anyOf: [{ type: 'string', pattern: '\\.zip$' }, { type: 'null' }],
default: null,
description: 'Optional ZIP file path.',
},
},
required: ['optionalZipFile'],
additionalProperties: false,
});
const content = 'optionalZipF|i|le:';
const result = await parseSetup(content);

assert.strictEqual(MarkupContent.is(result.contents), true);
assert.strictEqual(
(result.contents as MarkupContent).value,
`#### ZIP file || ZIP file\n\nOptional ZIP file path.\n\nSource: [${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'],
},
},
});

const content = 'ch|i|ld:';
const 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