[ML] Fix runtime field validations not supporting special script types (#122469) (#125300)

* Fix validations not handling extra things like params or lang

* Add translations

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
(cherry picked from commit f8d932f70a)
This commit is contained in:
Quynh Nguyen 2022-02-10 15:07:37 -06:00 committed by GitHub
parent 27362eb699
commit d5a9f0b375
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 77 additions and 39 deletions

View file

@ -6,8 +6,9 @@
*/
import { schema, TypeOf } from '@kbn/config-schema';
import { i18n } from '@kbn/i18n';
import { TRANSFORM_STATE } from '../constants';
import { isRuntimeField } from '../shared_imports';
export const transformIdsSchema = schema.arrayOf(
schema.object({
@ -57,26 +58,17 @@ export interface CommonResponseStatusSchema {
}
export const runtimeMappingsSchema = schema.maybe(
schema.recordOf(
schema.string(),
schema.object({
type: schema.oneOf([
schema.literal('keyword'),
schema.literal('long'),
schema.literal('double'),
schema.literal('date'),
schema.literal('ip'),
schema.literal('boolean'),
schema.literal('geo_point'),
]),
script: schema.maybe(
schema.oneOf([
schema.string(),
schema.object({
source: schema.string(),
}),
])
),
})
schema.object(
{},
{
unknowns: 'allow',
validate: (v: object) => {
if (Object.values(v).some((o) => !isRuntimeField(o))) {
return i18n.translate('xpack.transform.invalidRuntimeFieldMessage', {
defaultMessage: 'Invalid runtime field',
});
}
},
}
)
);

View file

@ -11,6 +11,7 @@ export {
isPopulatedObject,
isRuntimeMappings,
patternValidator,
isRuntimeField,
} from '../../ml/common';
export { RUNTIME_FIELD_TYPES } from '../../../../src/plugins/data/common';