add dynamic property to type definition (#58852) (#58886)

This commit is contained in:
Pierre Gayvallet 2020-02-28 18:36:25 +01:00 committed by GitHub
parent 8ceec0ffa3
commit 30fca567f6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 118 additions and 3 deletions

View file

@ -0,0 +1,13 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [kibana-plugin-server](./kibana-plugin-server.md) &gt; [SavedObjectsTypeMappingDefinition](./kibana-plugin-server.savedobjectstypemappingdefinition.md) &gt; [dynamic](./kibana-plugin-server.savedobjectstypemappingdefinition.dynamic.md)
## SavedObjectsTypeMappingDefinition.dynamic property
The dynamic property of the mapping. either `false` or 'strict'. Defaults to strict
<b>Signature:</b>
```typescript
dynamic?: false | 'strict';
```

View file

@ -41,5 +41,6 @@ const typeDefinition: SavedObjectsTypeMappingDefinition = {
| Property | Type | Description |
| --- | --- | --- |
| [properties](./kibana-plugin-server.savedobjectstypemappingdefinition.properties.md) | <code>SavedObjectsMappingProperties</code> | |
| [dynamic](./kibana-plugin-server.savedobjectstypemappingdefinition.dynamic.md) | <code>false &#124; 'strict'</code> | The dynamic property of the mapping. either <code>false</code> or 'strict'. Defaults to strict |
| [properties](./kibana-plugin-server.savedobjectstypemappingdefinition.properties.md) | <code>SavedObjectsMappingProperties</code> | The underlying properties of the type mapping |

View file

@ -4,6 +4,8 @@
## SavedObjectsTypeMappingDefinition.properties property
The underlying properties of the type mapping
<b>Signature:</b>
```typescript

View file

@ -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;
}

View file

@ -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",
},
},
}
`;

View file

@ -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' } } },

View file

@ -2058,7 +2058,7 @@ export interface SavedObjectsType {
// @public
export interface SavedObjectsTypeMappingDefinition {
// (undocumented)
dynamic?: false | 'strict';
properties: SavedObjectsMappingProperties;
}