mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 17:59:23 -04:00
Deprecate schema-less specs in Vega (#73805)
* Deprecate schema-less specs in Vega Closes #30951 * update an error Message * update tests * update error message * Update vega_parser.ts Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
This commit is contained in:
parent
80a5c4bef7
commit
489b134927
4 changed files with 40 additions and 33 deletions
|
@ -28,6 +28,18 @@ jest.mock('../lib/vega', () => ({
|
|||
vegaLite: jest.requireActual('vega-lite'),
|
||||
}));
|
||||
|
||||
describe(`VegaParser.parseAsync`, () => {
|
||||
test(`should throw an error in case of $spec is not defined`, async () => {
|
||||
const vp = new VegaParser('{}');
|
||||
|
||||
await vp.parseAsync();
|
||||
|
||||
expect(
|
||||
vp.error.startsWith('Your specification requires a "$schema" field with a valid URL')
|
||||
).toBeTruthy();
|
||||
});
|
||||
});
|
||||
|
||||
describe(`VegaParser._setDefaultValue`, () => {
|
||||
function check(spec, expected, ...params) {
|
||||
return () => {
|
||||
|
@ -149,23 +161,14 @@ describe('VegaParser._resolveEsQueries', () => {
|
|||
);
|
||||
});
|
||||
|
||||
describe('VegaParser._parseSchema', () => {
|
||||
function check(schema, isVegaLite, warningCount) {
|
||||
describe('VegaParser.parseSchema', () => {
|
||||
function check(schema, isVegaLite) {
|
||||
return () => {
|
||||
const vp = new VegaParser({ $schema: schema });
|
||||
expect(vp._parseSchema()).toBe(isVegaLite);
|
||||
expect(vp.spec).toEqual({ $schema: schema });
|
||||
expect(vp.warnings).toHaveLength(warningCount);
|
||||
expect(vp.parseSchema(vp.spec).isVegaLite).toBe(isVegaLite);
|
||||
};
|
||||
}
|
||||
|
||||
test('should warn on no vega version specified', () => {
|
||||
const vp = new VegaParser({});
|
||||
expect(vp._parseSchema()).toBe(false);
|
||||
expect(vp.spec).toEqual({ $schema: 'https://vega.github.io/schema/vega/v5.json' });
|
||||
expect(vp.warnings).toHaveLength(1);
|
||||
});
|
||||
|
||||
test(
|
||||
'should not warn on current vega version',
|
||||
check('https://vega.github.io/schema/vega/v5.json', false, 0)
|
||||
|
|
|
@ -55,7 +55,6 @@ const locToDirMap: Record<string, ControlsLocation> = {
|
|||
top: 'column-reverse',
|
||||
bottom: 'column',
|
||||
};
|
||||
const DEFAULT_SCHEMA: string = 'https://vega.github.io/schema/vega/v5.json';
|
||||
|
||||
// If there is no "%type%" parameter, use this parser
|
||||
const DEFAULT_PARSER: string = 'elasticsearch';
|
||||
|
@ -117,8 +116,27 @@ export class VegaParser {
|
|||
if (this.isVegaLite !== undefined) throw new Error();
|
||||
|
||||
if (typeof this.spec === 'string') {
|
||||
this.spec = hjson.parse(this.spec, { legacyRoot: false });
|
||||
const spec = hjson.parse(this.spec, { legacyRoot: false });
|
||||
|
||||
if (!spec.$schema) {
|
||||
throw new Error(
|
||||
i18n.translate('visTypeVega.vegaParser.inputSpecDoesNotSpecifySchemaErrorMessage', {
|
||||
defaultMessage: `Your specification requires a {schemaParam} field with a valid URL for
|
||||
Vega (see {vegaSchemaUrl}) or
|
||||
Vega-Lite (see {vegaLiteSchemaUrl}).
|
||||
The URL is an identifier only. Kibana and your browser will never access this URL.`,
|
||||
values: {
|
||||
schemaParam: '"$schema"',
|
||||
vegaLiteSchemaUrl: 'https://vega.github.io/vega-lite/docs/spec.html#top-level',
|
||||
vegaSchemaUrl:
|
||||
'https://vega.github.io/vega/docs/specification/#top-level-specification-properties',
|
||||
},
|
||||
})
|
||||
);
|
||||
}
|
||||
this.spec = spec;
|
||||
}
|
||||
|
||||
if (!_.isPlainObject(this.spec)) {
|
||||
throw new Error(
|
||||
i18n.translate('visTypeVega.vegaParser.invalidVegaSpecErrorMessage', {
|
||||
|
@ -126,7 +144,7 @@ export class VegaParser {
|
|||
})
|
||||
);
|
||||
}
|
||||
this.isVegaLite = this._parseSchema();
|
||||
this.isVegaLite = this.parseSchema(this.spec).isVegaLite;
|
||||
this.useHover = !this.isVegaLite;
|
||||
|
||||
this._config = this._parseConfig();
|
||||
|
@ -497,23 +515,11 @@ export class VegaParser {
|
|||
|
||||
/**
|
||||
* Parse Vega schema element
|
||||
* @returns {boolean} is this a VegaLite schema?
|
||||
* @returns {object} isVegaLite, libVersion
|
||||
* @private
|
||||
*/
|
||||
_parseSchema() {
|
||||
if (!this.spec) return false;
|
||||
if (!this.spec.$schema) {
|
||||
this._onWarning(
|
||||
i18n.translate('visTypeVega.vegaParser.inputSpecDoesNotSpecifySchemaWarningMessage', {
|
||||
defaultMessage:
|
||||
'The input spec does not specify a {schemaParam}, defaulting to {defaultSchema}',
|
||||
values: { defaultSchema: `"${DEFAULT_SCHEMA}"`, schemaParam: '"$schema"' },
|
||||
})
|
||||
);
|
||||
this.spec.$schema = DEFAULT_SCHEMA;
|
||||
}
|
||||
|
||||
const schema = schemaParser(this.spec.$schema);
|
||||
private parseSchema(spec: VegaSpec) {
|
||||
const schema = schemaParser(spec.$schema);
|
||||
const isVegaLite = schema.library === 'vega-lite';
|
||||
const libVersion = isVegaLite ? vegaLite.version : vega.version;
|
||||
|
||||
|
@ -531,7 +537,7 @@ export class VegaParser {
|
|||
);
|
||||
}
|
||||
|
||||
return isVegaLite;
|
||||
return { isVegaLite, libVersion };
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -4283,7 +4283,6 @@
|
|||
"visTypeVega.vegaParser.dataExceedsSomeParamsUseTimesLimitErrorMessage": "データには {urlParam}、{valuesParam}、 {sourceParam} の内複数を含めることができません",
|
||||
"visTypeVega.vegaParser.hostConfigIsDeprecatedWarningMessage": "{deprecatedConfigName} は廃止されました。代わりに {newConfigName} を使用してください。",
|
||||
"visTypeVega.vegaParser.hostConfigValueTypeErrorMessage": "{configName} が含まれている場合、オブジェクトでなければなりません",
|
||||
"visTypeVega.vegaParser.inputSpecDoesNotSpecifySchemaWarningMessage": "インプット仕様で {schemaParam} が指定されていないため、デフォルトで {defaultSchema} になります",
|
||||
"visTypeVega.vegaParser.invalidVegaSpecErrorMessage": "無効な Vega 仕様",
|
||||
"visTypeVega.vegaParser.kibanaConfigValueTypeErrorMessage": "{configName} が含まれている場合、オブジェクトでなければなりません",
|
||||
"visTypeVega.vegaParser.mapStyleValueTypeWarningMessage": "{mapStyleConfigName} は {mapStyleConfigFirstAllowedValue} か {mapStyleConfigSecondAllowedValue} のどちらかです",
|
||||
|
|
|
@ -4284,7 +4284,6 @@
|
|||
"visTypeVega.vegaParser.dataExceedsSomeParamsUseTimesLimitErrorMessage": "数据不得包含 {urlParam}、{valuesParam} 和 {sourceParam} 中的多个值",
|
||||
"visTypeVega.vegaParser.hostConfigIsDeprecatedWarningMessage": "{deprecatedConfigName} 已弃用。请改用 {newConfigName}。",
|
||||
"visTypeVega.vegaParser.hostConfigValueTypeErrorMessage": "如果存在,{configName} 必须为对象",
|
||||
"visTypeVega.vegaParser.inputSpecDoesNotSpecifySchemaWarningMessage": "输入规范未指定 {schemaParam},其默认值为 {defaultSchema}",
|
||||
"visTypeVega.vegaParser.invalidVegaSpecErrorMessage": "Vega 规范无效",
|
||||
"visTypeVega.vegaParser.kibanaConfigValueTypeErrorMessage": "如果存在,{configName} 必须为对象",
|
||||
"visTypeVega.vegaParser.mapStyleValueTypeWarningMessage": "{mapStyleConfigName} 可能为 {mapStyleConfigFirstAllowedValue} 或 {mapStyleConfigSecondAllowedValue}",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue