Skip to content

Commit

Permalink
[ML] fix schema definition for job type (elastic#99954) (elastic#100002)
Browse files Browse the repository at this point in the history
Co-authored-by: Dima Arnautov <[email protected]>
  • Loading branch information
kibanamachine and darnautov authored May 13, 2021
1 parent fde1531 commit b09ab28
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
5 changes: 2 additions & 3 deletions x-pack/plugins/ml/server/routes/saved_objects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,15 @@
* 2.0.
*/

import { schema } from '@kbn/config-schema';
import { wrapError } from '../client/error_wrapper';
import { RouteInitialization, SavedObjectsRouteDeps } from '../types';
import { checksFactory, syncSavedObjectsFactory } from '../saved_objects';
import {
jobsAndSpaces,
jobsAndCurrentSpace,
syncJobObjects,
jobTypeSchema,
canDeleteJobSchema,
jobTypeSchema,
} from './schemas/saved_objects';
import { spacesUtilsProvider } from '../lib/spaces_utils';

Expand Down Expand Up @@ -308,7 +307,7 @@ export function savedObjectsRoutes(
{
path: '/api/ml/saved_objects/can_delete_job/{jobType}',
validate: {
params: schema.object({ jobType: jobTypeSchema }),
params: jobTypeSchema,
body: canDeleteJobSchema,
},
options: {
Expand Down
8 changes: 5 additions & 3 deletions x-pack/plugins/ml/server/routes/schemas/saved_objects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,21 @@

import { schema } from '@kbn/config-schema';

export const jobTypeSchema = schema.oneOf([
export const jobTypeLiterals = schema.oneOf([
schema.literal('anomaly-detector'),
schema.literal('data-frame-analytics'),
]);

export const jobTypeSchema = schema.object({ jobType: jobTypeLiterals });

export const jobsAndSpaces = schema.object({
jobType: jobTypeSchema,
jobType: jobTypeLiterals,
jobIds: schema.arrayOf(schema.string()),
spaces: schema.arrayOf(schema.string()),
});

export const jobsAndCurrentSpace = schema.object({
jobType: jobTypeSchema,
jobType: jobTypeLiterals,
jobIds: schema.arrayOf(schema.string()),
});

Expand Down

0 comments on commit b09ab28

Please sign in to comment.