Skip to content

Commit

Permalink
Create cases SO schema and register forwardCompatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
cnasikas committed Nov 1, 2024
1 parent 7dea07f commit 44617e3
Show file tree
Hide file tree
Showing 5 changed files with 130 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,51 +10,49 @@ import { modelVersion1 } from './model_versions';
describe('Model versions', () => {
describe('1', () => {
it('returns the model version correctly', () => {
expect(modelVersion1).toMatchInlineSnapshot(`
Object {
"changes": Array [
Object {
"addedMappings": Object {
"customFields": Object {
"properties": Object {
"key": Object {
"type": "keyword",
},
"type": Object {
"type": "keyword",
},
"value": Object {
"fields": Object {
"boolean": Object {
"ignore_malformed": true,
"type": "boolean",
},
"date": Object {
"ignore_malformed": true,
"type": "date",
},
"ip": Object {
"ignore_malformed": true,
"type": "ip",
},
"number": Object {
"ignore_malformed": true,
"type": "long",
},
"string": Object {
"type": "text",
},
expect(modelVersion1.changes).toMatchInlineSnapshot(`
Array [
Object {
"addedMappings": Object {
"customFields": Object {
"properties": Object {
"key": Object {
"type": "keyword",
},
"type": Object {
"type": "keyword",
},
"value": Object {
"fields": Object {
"boolean": Object {
"ignore_malformed": true,
"type": "boolean",
},
"date": Object {
"ignore_malformed": true,
"type": "date",
},
"ip": Object {
"ignore_malformed": true,
"type": "ip",
},
"number": Object {
"ignore_malformed": true,
"type": "long",
},
"string": Object {
"type": "text",
},
"type": "keyword",
},
"type": "keyword",
},
"type": "nested",
},
"type": "nested",
},
"type": "mappings_addition",
},
],
}
"type": "mappings_addition",
},
]
`);
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

import type { SavedObjectsModelVersion } from '@kbn/core-saved-objects-server';
import { casesSchemaV1 } from './schemas';

/**
* Adds custom fields to the cases SO.
Expand Down Expand Up @@ -54,4 +55,7 @@ export const modelVersion1: SavedObjectsModelVersion = {
},
},
],
schemas: {
forwardCompatibility: casesSchemaV1.extends({}, { unknowns: 'ignore' }),
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

export * from './latest';

export { casesSchema as casesSchemaV1 } from './v1';
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

export * from './v1';
71 changes: 71 additions & 0 deletions x-pack/plugins/cases/server/saved_object_types/cases/schemas/v1.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

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

const UserSchema = schema.object({
email: schema.nullable(schema.string()),
full_name: schema.nullable(schema.string()),
username: schema.nullable(schema.string()),
profile_uid: schema.nullable(schema.string()),
});

const UserProfileSchema = schema.object({ uid: schema.string() });

const ConnectorSchema = schema.object({
name: schema.string(),
type: schema.string(),
fields: schema.arrayOf(schema.object({ key: schema.string(), value: schema.string() })),
});

const ExternalServiceSchema = schema.object({
connector_name: schema.string(),
external_id: schema.string(),
external_title: schema.string(),
external_url: schema.string(),
pushed_at: schema.string(),
pushed_by: UserSchema,
});

const SettingsSchema = schema.object({ syncAlerts: schema.boolean() });

const CustomFieldsSchema = schema.arrayOf(
schema.object({
key: schema.string(),
type: schema.string(),
value: schema.nullable(schema.any()),
})
);

export const casesSchema = schema.object({
assignees: schema.arrayOf(UserProfileSchema),
category: schema.maybe(schema.nullable(schema.string())),
closed_at: schema.nullable(schema.string()),
closed_by: schema.nullable(UserSchema),
created_at: schema.string(),
created_by: UserSchema,
connector: ConnectorSchema,
customFields: schema.maybe(schema.nullable(CustomFieldsSchema)),
description: schema.string(),
duration: schema.nullable(schema.number()),
external_service: schema.nullable(ExternalServiceSchema),
owner: schema.string(),
settings: SettingsSchema,
severity: schema.oneOf([
schema.literal(10),
schema.literal(20),
schema.literal(30),
schema.literal(40),
]),
status: schema.oneOf([schema.literal(0), schema.literal(10), schema.literal(20)]),
tags: schema.arrayOf(schema.string()),
title: schema.string(),
total_alerts: schema.number(),
total_comments: schema.number(),
updated_at: schema.nullable(schema.string()),
updated_by: schema.nullable(UserSchema),
});

0 comments on commit 44617e3

Please sign in to comment.