Skip to content

Commit

Permalink
Adding nested type to switch and more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathan-buttner committed Apr 29, 2020
1 parent 4dd19a3 commit 5301a3f
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -367,3 +367,31 @@ test('tests processing nested field with property, nested field first', () => {
const mappings = generateMappings(processedFields);
expect(mappings).toEqual(expectedMapping);
});

test('tests processing nested leaf field with properties', () => {
const nestedYaml = `
- name: a
type: object
dynamic: false
- name: a.b
type: nested
enabled: false
`;
const expectedMapping = {
properties: {
a: {
dynamic: false,
properties: {
b: {
enabled: false,
type: 'nested',
},
},
},
},
};
const fields: Field[] = safeLoad(nestedYaml);
const processedFields = processFields(fields);
const mappings = generateMappings(processedFields);
expect(mappings).toEqual(expectedMapping);
});
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,7 @@ export function generateMappings(fields: Field[]): IndexTemplateMappings {
case 'group-nested':
fieldProps = generateMappings(field.fields!);
fieldProps.type = 'nested';
attemptAddDynamicAndEnabled(fieldProps, field);

if (field.hasOwnProperty('include_in_parent')) {
fieldProps.include_in_parent = field.include_in_parent;
}
if (field.hasOwnProperty('include_in_root')) {
fieldProps.include_in_root = field.include_in_root;
}
attemptAddNestedProps(fieldProps, field);
break;
case 'integer':
fieldProps.type = 'long';
Expand All @@ -111,6 +104,10 @@ export function generateMappings(fields: Field[]): IndexTemplateMappings {
fieldProps.type = 'object';
attemptAddDynamicAndEnabled(fieldProps, field);
break;
case 'nested':
fieldProps.type = 'nested';
attemptAddNestedProps(fieldProps, field);
break;
case 'array':
// this assumes array fields were validated in an earlier step
// adding an array field with no object_type would result in an error
Expand Down Expand Up @@ -145,6 +142,17 @@ function attemptAddDynamicAndEnabled(props: Properties, field: Field) {
}
}

function attemptAddNestedProps(props: Properties, field: Field) {
attemptAddDynamicAndEnabled(props, field);

if (field.hasOwnProperty('include_in_parent')) {
props.include_in_parent = field.include_in_parent;
}
if (field.hasOwnProperty('include_in_root')) {
props.include_in_root = field.include_in_root;
}
}

function generateMultiFields(fields: Fields): MultiFields {
const multiFields: MultiFields = {};
if (fields) {
Expand Down

0 comments on commit 5301a3f

Please sign in to comment.