diff --git a/src/languageservice/services/yamlCompletion.ts b/src/languageservice/services/yamlCompletion.ts index 0ef71bab..be21a8bb 100644 --- a/src/languageservice/services/yamlCompletion.ts +++ b/src/languageservice/services/yamlCompletion.ts @@ -925,7 +925,8 @@ export class YamlCompletion { if (propertySchema) { this.addSchemaValueCompletions(propertySchema, separatorAfter, collector, types, 'value'); } - } else if (s.schema.additionalProperties) { + } + if (s.schema.additionalProperties) { this.addSchemaValueCompletions(s.schema.additionalProperties, separatorAfter, collector, types, 'value'); } } diff --git a/test/autoCompletionFix.test.ts b/test/autoCompletionFix.test.ts index f81c68aa..c720ce76 100644 --- a/test/autoCompletionFix.test.ts +++ b/test/autoCompletionFix.test.ts @@ -1183,6 +1183,30 @@ objB: expect(completion.items[0].insertText).to.be.equal('test1'); }); + it('should suggest defaultSnippets from additionalProperties', async () => { + const schema: JSONSchema = { + type: 'object', + properties: { + id: { + type: 'string', + }, + }, + additionalProperties: { + anyOf: [ + { + type: 'string', + defaultSnippets: [{ label: 'snippet', body: 'snippetBody' }], + }, + ], + }, + }; + schemaProvider.addSchema(SCHEMA_ID, schema); + const content = 'value: |\n|'; + const completion = await parseCaret(content); + + expect(completion.items.map((i) => i.insertText)).to.be.deep.equal(['snippetBody']); + }); + describe('should suggest prop of the object (based on not completed prop name)', () => { const schema: JSONSchema = { definitions: {