Skip to content

Commit 7575e78

Browse files
authored
Fix error if schema doesn't contain type (redhat-developer#328)
* redhat-developer#317 fix error if schema doesn't contain type Signed-off-by: Yevhen Vydolob <yvydolob@redhat.com> * Remove unused import Signed-off-by: Yevhen Vydolob <yvydolob@redhat.com>
1 parent b9fda68 commit 7575e78

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

src/languageservice/services/yamlCompletion.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -773,6 +773,7 @@ export class YAMLCompletion extends JSONCompletion {
773773
let insertText = '';
774774
if (!schema) {
775775
insertText = `$${insertIndex++}`;
776+
return { insertText, insertIndex };
776777
}
777778
let type = Array.isArray(schema.type) ? schema.type[0] : schema.type;
778779
if (!type) {

test/autoCompletion.test.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import path = require('path');
1010
import { createExpectedCompletion } from './utils/verifyError';
1111
import { ServiceSetup } from './utils/serviceSetup';
1212
import { CompletionList } from 'vscode-languageserver';
13+
import { expect } from 'chai';
1314

1415
const languageSettingsSetup = new ServiceSetup().withCompletion();
1516
const languageService = configureLanguageService(languageSettingsSetup.languageSettings);
@@ -1262,6 +1263,39 @@ suite('Auto Completion Tests', () => {
12621263
})
12631264
.then(done, done);
12641265
});
1266+
1267+
it('should handle array schema without items', async () => {
1268+
languageService.addSchema(SCHEMA_ID, {
1269+
type: 'array',
1270+
items: {
1271+
anyOf: [
1272+
{
1273+
type: 'object',
1274+
properties: {
1275+
fooBar: {
1276+
type: 'object',
1277+
properties: {
1278+
name: {
1279+
type: 'string',
1280+
},
1281+
aaa: {
1282+
type: 'array',
1283+
},
1284+
},
1285+
required: ['name', 'aaa'],
1286+
},
1287+
},
1288+
},
1289+
],
1290+
},
1291+
});
1292+
1293+
const content = '---\n- \n';
1294+
const completion = await parseSetup(content, 6);
1295+
expect(completion.items).lengthOf(1);
1296+
expect(completion.items[0].label).eq('fooBar');
1297+
expect(completion.items[0].insertText).eq('fooBar:\n name: $1\n aaa:\n - $2');
1298+
});
12651299
});
12661300
});
12671301
});

0 commit comments

Comments
 (0)