Skip to content
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
5 changes: 5 additions & 0 deletions src/languageservice/parser/jsonParser07.ts
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,11 @@ function validate(
return;
}

// schema should be an Object
if (typeof schema !== 'object') {
return;
}

if (!schema.url) {
schema.url = originalSchema.url;
}
Expand Down
2 changes: 1 addition & 1 deletion src/languageservice/services/yamlSchemaService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ export class YAMLSchemaService extends JSONSchemaService {
const highestPrioSchemas = this.highestPrioritySchemas(schemas);
const schemaHandle = super.createCombinedSchema(resource, highestPrioSchemas);
return schemaHandle.getResolvedSchema().then((schema) => {
if (schema.schema && typeof schema.schema !== 'string') {
if (schema.schema && typeof schema.schema === 'object') {
schema.schema.url = schemaHandle.url;
}

Expand Down
9 changes: 9 additions & 0 deletions test/schemaValidation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1560,6 +1560,15 @@ obj:
});

describe('Bug fixes', () => {
it('should handle not valid schema object', async () => {
const schema = 'Foo';
languageService.addSchema(SCHEMA_ID, schema as JSONSchema);
const content = `foo: bar`;
const result = await parseSetup(content);
expect(result).to.be.empty;
expect(telemetry.messages).to.be.empty;
});

it('should handle bad schema refs', async () => {
const schema = {
type: 'object',
Expand Down