From 2b9dc43158fcb71a87a7e2922783339947b5d95a Mon Sep 17 00:00:00 2001 From: Pierre Gayvallet Date: Fri, 28 Feb 2020 16:39:06 +0100 Subject: [PATCH] add dynamic property to type definition (#58852) --- ...vedobjectstypemappingdefinition.dynamic.md | 13 +++ ...erver.savedobjectstypemappingdefinition.md | 3 +- ...objectstypemappingdefinition.properties.md | 2 + .../server/saved_objects/mappings/types.ts | 3 + .../build_active_mappings.test.ts.snap | 79 +++++++++++++++++++ .../core/build_active_mappings.test.ts | 19 ++++- src/core/server/server.api.md | 2 +- 7 files changed, 118 insertions(+), 3 deletions(-) create mode 100644 docs/development/core/server/kibana-plugin-server.savedobjectstypemappingdefinition.dynamic.md diff --git a/docs/development/core/server/kibana-plugin-server.savedobjectstypemappingdefinition.dynamic.md b/docs/development/core/server/kibana-plugin-server.savedobjectstypemappingdefinition.dynamic.md new file mode 100644 index 0000000000000..0efab7bebfbe5 --- /dev/null +++ b/docs/development/core/server/kibana-plugin-server.savedobjectstypemappingdefinition.dynamic.md @@ -0,0 +1,13 @@ + + +[Home](./index.md) > [kibana-plugin-server](./kibana-plugin-server.md) > [SavedObjectsTypeMappingDefinition](./kibana-plugin-server.savedobjectstypemappingdefinition.md) > [dynamic](./kibana-plugin-server.savedobjectstypemappingdefinition.dynamic.md) + +## SavedObjectsTypeMappingDefinition.dynamic property + +The dynamic property of the mapping. either `false` or 'strict'. Defaults to strict + +Signature: + +```typescript +dynamic?: false | 'strict'; +``` diff --git a/docs/development/core/server/kibana-plugin-server.savedobjectstypemappingdefinition.md b/docs/development/core/server/kibana-plugin-server.savedobjectstypemappingdefinition.md index 99983d3a9f02b..8c1a279894ffd 100644 --- a/docs/development/core/server/kibana-plugin-server.savedobjectstypemappingdefinition.md +++ b/docs/development/core/server/kibana-plugin-server.savedobjectstypemappingdefinition.md @@ -41,5 +41,6 @@ const typeDefinition: SavedObjectsTypeMappingDefinition = { | Property | Type | Description | | --- | --- | --- | -| [properties](./kibana-plugin-server.savedobjectstypemappingdefinition.properties.md) | SavedObjectsMappingProperties | | +| [dynamic](./kibana-plugin-server.savedobjectstypemappingdefinition.dynamic.md) | false | 'strict' | The dynamic property of the mapping. either false or 'strict'. Defaults to strict | +| [properties](./kibana-plugin-server.savedobjectstypemappingdefinition.properties.md) | SavedObjectsMappingProperties | The underlying properties of the type mapping | diff --git a/docs/development/core/server/kibana-plugin-server.savedobjectstypemappingdefinition.properties.md b/docs/development/core/server/kibana-plugin-server.savedobjectstypemappingdefinition.properties.md index 555870c3fdd7d..f6be5214ec6d9 100644 --- a/docs/development/core/server/kibana-plugin-server.savedobjectstypemappingdefinition.properties.md +++ b/docs/development/core/server/kibana-plugin-server.savedobjectstypemappingdefinition.properties.md @@ -4,6 +4,8 @@ ## SavedObjectsTypeMappingDefinition.properties property +The underlying properties of the type mapping + Signature: ```typescript diff --git a/src/core/server/saved_objects/mappings/types.ts b/src/core/server/saved_objects/mappings/types.ts index 578fdcea3718e..bc556c0429981 100644 --- a/src/core/server/saved_objects/mappings/types.ts +++ b/src/core/server/saved_objects/mappings/types.ts @@ -45,6 +45,9 @@ * @public */ export interface SavedObjectsTypeMappingDefinition { + /** The dynamic property of the mapping. either `false` or 'strict'. Defaults to strict */ + dynamic?: false | 'strict'; + /** The underlying properties of the type mapping */ properties: SavedObjectsMappingProperties; } diff --git a/src/core/server/saved_objects/migrations/core/__snapshots__/build_active_mappings.test.ts.snap b/src/core/server/saved_objects/migrations/core/__snapshots__/build_active_mappings.test.ts.snap index e82fbfc85dfa0..68f90ea70a0c6 100644 --- a/src/core/server/saved_objects/migrations/core/__snapshots__/build_active_mappings.test.ts.snap +++ b/src/core/server/saved_objects/migrations/core/__snapshots__/build_active_mappings.test.ts.snap @@ -60,3 +60,82 @@ Object { }, } `; + +exports[`buildActiveMappings handles the \`dynamic\` property of types 1`] = ` +Object { + "_meta": Object { + "migrationMappingPropertyHashes": Object { + "config": "87aca8fdb053154f11383fce3dbf3edf", + "firstType": "635418ab953d81d93f1190b70a8d3f57", + "migrationVersion": "4a1746014a75ade3a714e1db5763276f", + "namespace": "2f4316de49999235636386fe51dc06c1", + "references": "7997cf5a56cc02bdc9c93361bde732b0", + "secondType": "72d57924f415fbadb3ee293b67d233ab", + "thirdType": "510f1f0adb69830cf8a1c5ce2923ed82", + "type": "2f4316de49999235636386fe51dc06c1", + "updated_at": "00da57df13e94e9d98437d13ace4bfe0", + }, + }, + "dynamic": "strict", + "properties": Object { + "config": Object { + "dynamic": "true", + "properties": Object { + "buildNum": Object { + "type": "keyword", + }, + }, + }, + "firstType": Object { + "dynamic": "strict", + "properties": Object { + "field": Object { + "type": "keyword", + }, + }, + }, + "migrationVersion": Object { + "dynamic": "true", + "type": "object", + }, + "namespace": Object { + "type": "keyword", + }, + "references": Object { + "properties": Object { + "id": Object { + "type": "keyword", + }, + "name": Object { + "type": "keyword", + }, + "type": Object { + "type": "keyword", + }, + }, + "type": "nested", + }, + "secondType": Object { + "dynamic": false, + "properties": Object { + "field": Object { + "type": "long", + }, + }, + }, + "thirdType": Object { + "properties": Object { + "field": Object { + "type": "text", + }, + }, + }, + "type": Object { + "type": "keyword", + }, + "updated_at": Object { + "type": "date", + }, + }, +} +`; diff --git a/src/core/server/saved_objects/migrations/core/build_active_mappings.test.ts b/src/core/server/saved_objects/migrations/core/build_active_mappings.test.ts index 9d220cfdf94b7..33e1a395e64a2 100644 --- a/src/core/server/saved_objects/migrations/core/build_active_mappings.test.ts +++ b/src/core/server/saved_objects/migrations/core/build_active_mappings.test.ts @@ -17,7 +17,7 @@ * under the License. */ -import { IndexMapping } from './../../mappings'; +import { IndexMapping, SavedObjectsTypeMappingDefinitions } from './../../mappings'; import { buildActiveMappings, diffMappings } from './build_active_mappings'; describe('buildActiveMappings', () => { @@ -49,6 +49,23 @@ describe('buildActiveMappings', () => { ); }); + test('handles the `dynamic` property of types', () => { + const typeMappings: SavedObjectsTypeMappingDefinitions = { + firstType: { + dynamic: 'strict', + properties: { field: { type: 'keyword' } }, + }, + secondType: { + dynamic: false, + properties: { field: { type: 'long' } }, + }, + thirdType: { + properties: { field: { type: 'text' } }, + }, + }; + expect(buildActiveMappings(typeMappings)).toMatchSnapshot(); + }); + test('generated hashes are stable', () => { const properties = { aaa: { type: 'keyword', fields: { a: { type: 'keyword' }, b: { type: 'text' } } }, diff --git a/src/core/server/server.api.md b/src/core/server/server.api.md index 8f4feb7169651..42bc1ce214b19 100644 --- a/src/core/server/server.api.md +++ b/src/core/server/server.api.md @@ -2058,7 +2058,7 @@ export interface SavedObjectsType { // @public export interface SavedObjectsTypeMappingDefinition { - // (undocumented) + dynamic?: false | 'strict'; properties: SavedObjectsMappingProperties; }