diff --git a/x-pack/legacy/plugins/ml/server/new_platform/results_service_schema.ts b/x-pack/legacy/plugins/ml/server/new_platform/results_service_schema.ts index b9a70b8e14197..fd8ecba0b20df 100644 --- a/x-pack/legacy/plugins/ml/server/new_platform/results_service_schema.ts +++ b/x-pack/legacy/plugins/ml/server/new_platform/results_service_schema.ts @@ -15,7 +15,9 @@ const criteriaFieldSchema = schema.object({ export const anomaliesTableDataSchema = { jobIds: schema.arrayOf(schema.string()), criteriaFields: schema.arrayOf(criteriaFieldSchema), - influencers: schema.arrayOf(schema.maybe(schema.string())), + influencers: schema.arrayOf( + schema.maybe(schema.object({ fieldName: schema.string(), fieldValue: schema.any() })) + ), aggregationInterval: schema.string(), threshold: schema.number(), earliestMs: schema.number(), @@ -26,6 +28,23 @@ export const anomaliesTableDataSchema = { influencersFilterQuery: schema.maybe(schema.any()), }; +export const categoryDefinitionSchema = { + jobId: schema.maybe(schema.string()), + categoryId: schema.string(), +}; + +export const maxAnomalyScoreSchema = { + jobIds: schema.arrayOf(schema.string()), + earliestMs: schema.number(), + latestMs: schema.number(), +}; + +export const categoryExamplesSchema = { + jobId: schema.string(), + categoryIds: schema.arrayOf(schema.string()), + maxExamples: schema.number(), +}; + export const partitionFieldValuesSchema = { jobId: schema.string(), searchTerm: schema.maybe(schema.any()), diff --git a/x-pack/legacy/plugins/ml/server/routes/results_service.ts b/x-pack/legacy/plugins/ml/server/routes/results_service.ts index b44b82ec486d7..5d107b2d97809 100644 --- a/x-pack/legacy/plugins/ml/server/routes/results_service.ts +++ b/x-pack/legacy/plugins/ml/server/routes/results_service.ts @@ -11,6 +11,9 @@ import { wrapError } from '../client/error_wrapper'; import { RouteInitialization } from '../new_platform/plugin'; import { anomaliesTableDataSchema, + categoryDefinitionSchema, + categoryExamplesSchema, + maxAnomalyScoreSchema, partitionFieldValuesSchema, } from '../new_platform/results_service_schema'; import { resultsServiceProvider } from '../models/results_service'; @@ -83,7 +86,7 @@ export function resultsServiceRoutes({ xpackMainPlugin, router }: RouteInitializ { path: '/api/ml/results/anomalies_table_data', validate: { - body: schema.object({ ...anomaliesTableDataSchema }), + body: schema.object(anomaliesTableDataSchema), }, }, licensePreRoutingFactory(xpackMainPlugin, async (context, request, response) => { @@ -110,10 +113,7 @@ export function resultsServiceRoutes({ xpackMainPlugin, router }: RouteInitializ { path: '/api/ml/results/category_definition', validate: { - body: schema.object({ - jobId: schema.maybe(schema.string()), - categoryId: schema.string(), - }), + body: schema.object(categoryDefinitionSchema), }, }, licensePreRoutingFactory(xpackMainPlugin, async (context, request, response) => { @@ -140,11 +140,7 @@ export function resultsServiceRoutes({ xpackMainPlugin, router }: RouteInitializ { path: '/api/ml/results/max_anomaly_score', validate: { - body: schema.object({ - jobIds: schema.arrayOf(schema.string()), - earliestMs: schema.number(), - latestMs: schema.number(), - }), + body: schema.object(maxAnomalyScoreSchema), }, }, licensePreRoutingFactory(xpackMainPlugin, async (context, request, response) => { @@ -171,11 +167,7 @@ export function resultsServiceRoutes({ xpackMainPlugin, router }: RouteInitializ { path: '/api/ml/results/category_examples', validate: { - body: schema.object({ - jobId: schema.string(), - categoryIds: schema.arrayOf(schema.string()), - maxExamples: schema.number(), - }), + body: schema.object(categoryExamplesSchema), }, }, licensePreRoutingFactory(xpackMainPlugin, async (context, request, response) => { @@ -202,7 +194,7 @@ export function resultsServiceRoutes({ xpackMainPlugin, router }: RouteInitializ { path: '/api/ml/results/partition_fields_values', validate: { - body: schema.object({ ...partitionFieldValuesSchema }), + body: schema.object(partitionFieldValuesSchema), }, }, licensePreRoutingFactory(xpackMainPlugin, async (context, request, response) => {