Fix validation of subfields of flattened objects#2088
Conversation
💚 Build Succeeded
cc @jsoriano |
| if ancestor.Type == "flattened" { | ||
| return true | ||
| } |
There was a problem hiding this comment.
If it finds an ancestor with a different type of "flattened", should this return false directly here?
I was thinking in the case of the ancestor being something like: ancestor.Type = object and ancestor.ObjectTYpe == "keyword"
There was a problem hiding this comment.
Not sure, there are packages defining mappings for subfields of flattened objects (for example here). This doesn't make a lot of sense as a mapping, but this is allowed now, and can be used for example to provide documentation.
We probably should not allow to define mappings under flattened fields, but this would be a different task, and checked in a different place. And we would need to provide something for cases where developers want to provide docs for flattened subfields.
There was a problem hiding this comment.
Not sure, there are packages defining mappings for subfields of flattened objects (for example here). This doesn't make a lot of sense as a mapping, but this is allowed now, and can be used for example to provide documentation.
Ok, I didn't know about this kind of usage.
We probably should not allow to define mappings under flattened fields, but this would be a different task, and checked in a different place. And we would need to provide something for cases where developers want to provide docs for flattened subfields.
Agreed!
| i := strings.LastIndex(key, ".") | ||
| key = key[:i] | ||
| ancestor := FindElementDefinition(key, schema) |
There was a problem hiding this comment.
Could this be replaced by findParentElementDefinition ?
| i := strings.LastIndex(key, ".") | |
| key = key[:i] | |
| ancestor := FindElementDefinition(key, schema) | |
| ancestor := findParentElementDefinition(key, schema) |
There was a problem hiding this comment.
mmm I guess it would be needed to somehow return also the key of the field, or being able to retrieve it from the ancestor struct.
There was a problem hiding this comment.
Yep, this is the problem I found, we still need to loop over the ancestors.
mrodm
left a comment
There was a problem hiding this comment.
LGTM! Checked locally too with logsdb enabled for audtid_manager package.
When a document doesn't has subobjects, like when
subobjects: falseor synthetic mode is used, if an undocumented field is found, we need to check its ancestors to see if it is a member of a flattened object.This is producing failures for
auditd_managerpackage when LogsDB is enabled: https://buildkite.com/elastic/integrations/builds/15559