Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ecs@mappings multifields to all fields, not only external ones #2055

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions internal/docs/exported_fields.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ func renderExportedFields(fieldsParentDir string) (string, error) {
// SkipEmptyFields parameter when rendering fields. In other cases we want to
// keep them to accept them for validation.
SkipEmptyFields: true,

// Disable adding the additional multifields included in ecs@mappings, so they
// don't appear in the rendered configuration.
DisableAppendECSMultifields: true,
}
validator, err := fields.CreateValidatorForDirectory(fieldsParentDir, fields.WithInjectFieldsOptions(injectOptions))
if err != nil {
Expand Down
4 changes: 4 additions & 0 deletions internal/fields/dependency_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,10 @@ type InjectFieldsOptions struct {
// fields that are only used for validation of documents, but are not needed on built packages.
IncludeValidationSettings bool

// DisableAppendECSMultifields can be set to disable the injection of the additional multifields
// included in ecs@mappings component teplate.
DisableAppendECSMultifields bool

root string
}

Expand Down
13 changes: 8 additions & 5 deletions internal/fields/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,14 @@ func createValidatorForDirectoryAndPackageRoot(fieldsParentDir string, finder pa
}

v.Schema = append(fields, v.Schema...)

if !v.injectFieldsOptions.DisableAppendECSMultifields {
// ecs@mappings adds additional multifields that are not defined anywhere.
// Adding them in all cases so packages can be tested in versions of the stack that
// add the ecs@mappings component template.
jsoriano marked this conversation as resolved.
Show resolved Hide resolved
v.Schema = appendECSMappingMultifields(v.Schema, "")
}

return v, nil
}

Expand Down Expand Up @@ -325,11 +333,6 @@ func initDependencyManagement(packageRoot string, specVersion semver.Version, im
schema = ecsSchema
}

// ecs@mappings adds additional multifields that are not defined anywhere.
// Adding them in all cases so packages can be tested in versions of the stack that
// add the ecs@mappings component template.
schema = appendECSMappingMultifields(schema, "")

return fdm, schema, nil
}

Expand Down