Exclude migrationVersion and references from getRootPropertiesObjects result (#30081)

This commit is contained in:
Mike Côté 2019-02-05 13:12:33 -05:00 committed by GitHub
parent 6b74470eae
commit f852812012
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 1 deletions

View file

@ -33,12 +33,18 @@ import { getRootProperties } from './get_root_properties';
* @param {EsMappingsDsl} mappings
* @return {EsPropertyMappings}
*/
const blacklist = [
'migrationVersion',
'references',
];
export function getRootPropertiesObjects(mappings) {
const rootProperties = getRootProperties(mappings);
return Object.entries(rootProperties).reduce((acc, [key, value]) => {
// we consider the existence of the properties or type of object to designate that this is an object datatype
if (value.properties || value.type === 'object') {
if (!blacklist.includes(key) && (value.properties || value.type === 'object')) {
acc[key] = value;
}

View file

@ -167,3 +167,25 @@ test(`includes one object with type === 'object' and excludes one object without
}
});
});
test('excludes references and migrationVersion which are part of the blacklist', () => {
const mappings = {
properties: {
references: {
type: 'object',
},
migrationVersion: {
type: 'object',
},
foo: {
type: 'object',
},
},
};
const result = getRootPropertiesObjects(mappings);
expect(result).toEqual({
foo: {
type: 'object',
},
});
});