Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@ export const ScriptPathToExecutableSchema = schema.string({
validate: validateNonEmptyString,
});

export const ScriptTagsSchema = schema.arrayOf(
// @ts-expect-error TS2769: No overload matches this call. (due to now `oneOf()` type is defined)
schema.oneOf(Object.keys(SCRIPT_TAGS).map((osType) => schema.literal(osType))),
{ minSize: 1, maxSize: Object.keys(SCRIPT_TAGS).length, validate: validateNoDuplicateValues }
);
export const getScriptsTagSchema = (type: 'patch' | 'post') =>
// @ts-expect-error TS2769: No overload matches this call. (due to how `oneOf()` type is defined)
schema.arrayOf(schema.oneOf(Object.keys(SCRIPT_TAGS).map((osType) => schema.literal(osType))), {
minSize: type === 'patch' ? 0 : 1,
maxSize: Object.keys(SCRIPT_TAGS).length,
validate: validateNoDuplicateValues,
});
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
ScriptPathToExecutableSchema,
ScriptPlatformSchema,
ScriptRequiresInputSchema,
ScriptTagsSchema,
getScriptsTagSchema,
} from './common';

export const CreateScriptRequestSchema = {
Expand All @@ -29,7 +29,7 @@ export const CreateScriptRequestSchema = {
instructions: schema.maybe(ScriptInstructionsSchema),
example: schema.maybe(ScriptExampleSchema),
pathToExecutable: schema.maybe(ScriptPathToExecutableSchema),
tags: schema.maybe(ScriptTagsSchema),
tags: schema.maybe(getScriptsTagSchema('post')),
}),
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,11 @@

import { schema, type TypeOf } from '@kbn/config-schema';
import {
ScriptDescriptionSchema,
ScriptExampleSchema,
ScriptFileSchema,
ScriptInstructionsSchema,
ScriptNameSchema,
ScriptPathToExecutableSchema,
ScriptPlatformSchema,
ScriptRequiresInputSchema,
ScriptTagsSchema,
getScriptsTagSchema,
} from './common';
import type { DeepMutable } from '../../../endpoint/types';
import { validateNonEmptyString } from '../schema_utils';
Expand All @@ -27,11 +23,11 @@ export const PatchUpdateScriptRequestSchema = {
platform: schema.maybe(ScriptPlatformSchema),
file: schema.maybe(ScriptFileSchema),
requiresInput: schema.maybe(ScriptRequiresInputSchema),
description: schema.maybe(ScriptDescriptionSchema),
instructions: schema.maybe(ScriptInstructionsSchema),
example: schema.maybe(ScriptExampleSchema),
pathToExecutable: schema.maybe(ScriptPathToExecutableSchema),
tags: schema.maybe(ScriptTagsSchema),
description: schema.maybe(schema.string()),
instructions: schema.maybe(schema.string()),
example: schema.maybe(schema.string()),
pathToExecutable: schema.maybe(schema.string()),
tags: schema.maybe(getScriptsTagSchema('patch')),
version: schema.maybe(schema.string({ minLength: 1, validate: validateNonEmptyString })),
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,20 @@ describe('Scripts library schemas', () => {
).toBeTruthy();
});

it.each([
{ field: 'description', value: '' },
{ field: 'instructions', value: '' },
{ field: 'example', value: '' },
{ field: 'pathToExecutable', value: '' },
{ field: 'tags', value: [] },
])('should accept `$field` field with `$value` value', ({ field, value }) => {
expect(
PatchUpdateScriptRequestSchema.body.validate({
[field]: value,
})
).toBeTruthy();
});

it.each`
title | bodyPayload
---------- -------------
Expand Down
Loading