func()

in internal/fields/exceptionfields.go [85:142]


func (v *Validator) parseExceptionField(key string, definition FieldDefinition, val any) []string {
	switch definition.Type {
	case "constant_keyword":
	case "keyword", "text":
	case "date":
	case "float", "long", "double":
	case "ip":
	case "array":
		if v.specVersion.LessThan(semver2_0_0) {
			logger.Tracef("Skip validating field of type array with spec < 2.0.0 (key %q type %q spec %q)", key, definition.Type, v.specVersion)
			return []string{key}
		}
		return nil
	// Groups should only contain nested fields, not single values.
	case "group", "nested", "object":
		switch val := val.(type) {
		case map[string]any:
			// This is probably an element from an array of objects,
			// even if not recommended, it should be validated.
			if v.specVersion.LessThan(semver3_0_1) {
				logger.Tracef("Skip validating object (map[string]any) in package spec < 3.0.1 (key %q type %q spec %q)", key, definition.Type, v.specVersion)
				return []string{key}
			}
			return nil
		case []any:
			// This can be an array of array of objects. Elasticsearh will probably
			// flatten this. So even if this is quite unexpected, let's try to handle it.
			if v.specVersion.LessThan(semver3_0_1) {
				logger.Tracef("Skip validating object ([]any) because spec < 3.0.1 (key %q type %q spec %q)", key, definition.Type, v.specVersion)
				return []string{key}
			}
			return nil
		case nil:
			// The document contains a null, let's consider this like an empty array.
			logger.Tracef("Skip validating object empty array because spec < 3.0.1 (key %q type %q spec %q)", key, definition.Type, v.specVersion)
			return []string{key}
		default:
			switch {
			case definition.Type == "object" && definition.ObjectType != "":
				// This is the leaf element of an object without wildcards in the name, adapt the definition and try again.
				definition.Name = definition.Name + ".*"
				definition.Type = definition.ObjectType
				definition.ObjectType = ""
				return v.parseExceptionField(key, definition, val)
			case definition.Type == "object" && definition.ObjectType == "":
				// Legacy mapping, ambiguous definition not allowed by recent versions of the spec, ignore it.
				logger.Tracef("Skip legacy mapping: object field without \"object_type\" parameter: %q", key)
				return []string{key}
			}

			return nil
		}
	default:
		return nil
	}

	return nil
}