Skip to content

Commit

Permalink
Handle case when schema not JS object (#656)
Browse files Browse the repository at this point in the history
* Handle case when schema not JS object

Signed-off-by: Yevhen Vydolob <[email protected]>

* Change test name

Signed-off-by: Yevhen Vydolob <[email protected]>
  • Loading branch information
evidolob authored Feb 8, 2022
1 parent 2a6da17 commit 2f34acf
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
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

0 comments on commit 2f34acf

Please sign in to comment.