Skip to content

Commit

Permalink
Fix empty properties
Browse files Browse the repository at this point in the history
  • Loading branch information
nchaulet committed Aug 2, 2022
1 parent 7e6084c commit 811e843
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 34 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,11 @@ function _generateMappings(
addDynamicMapping: any;
groupFieldName?: string;
}
): IndexTemplateMappings {
): {
properties: IndexTemplateMappings['properties'];
hasNonDynamicTemplateMappings: boolean;
} {
let hasNonDynamicTemplateMappings = false;
const props: Properties = {};
// TODO: this can happen when the fields property in fields.yml is present but empty
// Maybe validation should be moved to fields/field.ts
Expand Down Expand Up @@ -213,24 +217,29 @@ function _generateMappings(

switch (type) {
case 'group':
const mappings = _generateMappings(field.fields!, {
...ctx,
groupFieldName: ctx.groupFieldName
? `${ctx.groupFieldName}.${field.name}`
: field.name,
});
if (!mappings.hasNonDynamicTemplateMappings) {
return;
}

fieldProps = {
..._generateMappings(field.fields!, {
...ctx,
groupFieldName: ctx.groupFieldName
? `${ctx.groupFieldName}.${field.name}`
: field.name,
}),
properties: mappings.properties,
...generateDynamicAndEnabled(field),
};
break;
case 'group-nested':
fieldProps = {
..._generateMappings(field.fields!, {
properties: _generateMappings(field.fields!, {
...ctx,
groupFieldName: ctx.groupFieldName
? `${ctx.groupFieldName}.${field.name}`
: field.name,
}),
}).properties,
...generateNestedProps(field),
type: 'nested',
};
Expand Down Expand Up @@ -309,11 +318,12 @@ function _generateMappings(
}

props[field.name] = fieldProps;
hasNonDynamicTemplateMappings = true;
}
});
}

return { properties: props };
return { properties: props, hasNonDynamicTemplateMappings };
}

function generateDynamicAndEnabled(field: Field) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
type: group
release: beta
fields:
- name: labels.*
- name: labels
type: object
object_type: keyword
description: >
Expand Down

0 comments on commit 811e843

Please sign in to comment.