diff --git a/src/languageserver/handlers/notificationHandlers.ts b/src/languageserver/handlers/notificationHandlers.ts index 04f939dd0..93dfd6183 100644 --- a/src/languageserver/handlers/notificationHandlers.ts +++ b/src/languageserver/handlers/notificationHandlers.ts @@ -8,7 +8,7 @@ import { LanguageService, SchemaConfiguration } from '../../languageservice/yaml import { CustomSchemaRequest, DynamicCustomSchemaRequestRegistration, - KubernetesURLNotification, + KubernetesURLsNotification, SchemaAssociationNotification, SchemaSelectionRequests, VSCodeContentRequestRegistration, @@ -37,13 +37,13 @@ export class NotificationHandlers { this.schemaAssociationNotificationHandler(associations) ); this.connection.onNotification(DynamicCustomSchemaRequestRegistration.type, () => this.dynamicSchemaRequestHandler()); - this.connection.onNotification(KubernetesURLNotification.type, (url) => this.kubernetesURLNotification(url)); + this.connection.onNotification(KubernetesURLsNotification.type, (url) => this.kubernetesURLsNotification(url)); this.connection.onNotification(VSCodeContentRequestRegistration.type, () => this.vscodeContentRequestHandler()); this.connection.onNotification(SchemaSelectionRequests.type, () => this.schemaSelectionRequestHandler()); } - private kubernetesURLNotification(url: string): void { - this.yamlSettings.kubernetesSchemaUrl = url; + private kubernetesURLsNotification(urls: string[]): void { + this.yamlSettings.kubernetesSchemaUrls = urls; } /** diff --git a/src/languageserver/handlers/settingsHandlers.ts b/src/languageserver/handlers/settingsHandlers.ts index da2fc50bc..f96f91f68 100644 --- a/src/languageserver/handlers/settingsHandlers.ts +++ b/src/languageserver/handlers/settingsHandlers.ts @@ -338,7 +338,7 @@ export class SettingsHandler { languageSettings.schemas.push({ uri, fileMatch: fileMatch, schema: schema, priority: priorityLevel }); } - if (uri === this.yamlSettings.kubernetesSchemaUrl) { + if (this.yamlSettings.kubernetesSchemaUrls.includes(uri)) { if (fileMatch.constructor === Array) { fileMatch.forEach((url) => { this.yamlSettings.specificValidatorPaths.push(url); @@ -349,4 +349,4 @@ export class SettingsHandler { } return languageSettings; } -} \ No newline at end of file +} diff --git a/src/requestTypes.ts b/src/requestTypes.ts index 5eadf8201..04cb299d4 100644 --- a/src/requestTypes.ts +++ b/src/requestTypes.ts @@ -46,8 +46,8 @@ export namespace DynamicCustomSchemaRequestRegistration { export const type: NotificationType<{}> = new NotificationType('yaml/registerCustomSchemaRequest'); } -export namespace KubernetesURLNotification { - export const type: NotificationType = new NotificationType('yaml/kubernetesURL'); +export namespace KubernetesURLsNotification { + export const type: NotificationType = new NotificationType('yaml/kubernetesURLs'); } export namespace VSCodeContentRequestRegistration { diff --git a/src/yamlSettings.ts b/src/yamlSettings.ts index f1617747b..e791419f3 100644 --- a/src/yamlSettings.ts +++ b/src/yamlSettings.ts @@ -77,7 +77,7 @@ export class SettingsState { customTags = []; schemaStoreEnabled = true; schemaStoreUrl = JSON_SCHEMASTORE_URL; - kubernetesSchemaUrl = KUBERNETES_SCHEMA_URL; + kubernetesSchemaUrls = [KUBERNETES_SCHEMA_URL]; indentation: string | undefined = undefined; disableAdditionalProperties = false; disableDefaultProperties = false; diff --git a/test/schemaValidation.test.ts b/test/schemaValidation.test.ts index bf07b3e96..03fc36420 100644 --- a/test/schemaValidation.test.ts +++ b/test/schemaValidation.test.ts @@ -1905,26 +1905,23 @@ obj: expect(telemetry.messages).to.be.empty; }); - it('custom kubernetes schema should return validation errors', (done) => { + it('single custom kubernetes schema should return validation errors', async () => { + const customKubernetesSchemaVersion = 'https://raw.githubusercontent.com/yannh/kubernetes-json-schema/master/v1.26.1-standalone-strict/all.json'; + yamlSettings.kubernetesSchemaUrls = [customKubernetesSchemaVersion]; const settingsHandler = new SettingsHandler({} as Connection, languageService, yamlSettings, validationHandler, telemetry); const initialSettings = languageSettingsSetup.withKubernetes(true).languageSettings; const kubernetesSettings = settingsHandler.configureSchemas( - 'https://raw.githubusercontent.com/yannh/kubernetes-json-schema/master/v1.26.1-standalone-strict/all.json', - ['**'], + customKubernetesSchemaVersion, + ['*k8s.yml'], undefined, initialSettings, SchemaPriority.SchemaAssociation ); languageService.configure(kubernetesSettings); const content = `apiVersion: apps/v1\nkind: Deployment\nfoo: bar`; - const validator = parseSetup(content); - validator - .then(function (result) { - assert.equal(result.length, 1); - // eslint-disable-next-line - assert.equal(result[0].message, `Property foo is not allowed.`); - }) - .then(done, done); + const result = await parseSetup(content, 'invalid-k8s.yml'); + expect(result.length).to.eq(1); + expect(result[0].message).to.eq('Property foo is not allowed.'); }); }); });