From cfd8413c69e13936611ba8c0df1e8771c7f14a21 Mon Sep 17 00:00:00 2001 From: Daito Akimura Date: Thu, 13 Mar 2025 10:47:59 +0900 Subject: [PATCH 1/2] fix(typedapi): unmarshal DateDecayFunction --- typedapi/types/datedecayfunction.go | 39 +++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/typedapi/types/datedecayfunction.go b/typedapi/types/datedecayfunction.go index a5e4a5cc9e..652f3d5165 100644 --- a/typedapi/types/datedecayfunction.go +++ b/typedapi/types/datedecayfunction.go @@ -21,8 +21,11 @@ package types import ( + "bytes" "encoding/json" + "errors" "fmt" + "io" "github.com/elastic/go-elasticsearch/v8/typedapi/types/enums/multivaluemode" ) @@ -37,6 +40,42 @@ type DateDecayFunction struct { MultiValueMode *multivaluemode.MultiValueMode `json:"multi_value_mode,omitempty"` } +func (s *DateDecayFunction) UnmarshalJSON(data []byte) error { + + dec := json.NewDecoder(bytes.NewReader(data)) + + for { + t, err := dec.Token() + if err != nil { + if errors.Is(err, io.EOF) { + break + } + return err + } + + switch t { + + case "multi_value_mode": + if err := dec.Decode(&s.MultiValueMode); err != nil { + return fmt.Errorf("%s | %w", "MultiValueMode", err) + } + default: + if key, ok := t.(string); ok { + if s.DecayFunctionBaseDateMathDuration == nil { + s.DecayFunctionBaseDateMathDuration = make(map[string]DecayPlacementDateMathDuration) + } + raw := new(DecayPlacementDateMathDuration) + if err := dec.Decode(&raw); err != nil { + return fmt.Errorf("%s | %w", "DecayPlacementDateMathDuration", err) + } + s.DecayFunctionBaseDateMathDuration[key] = *raw + } + + } + } + return nil +} + // MarhsalJSON overrides marshalling for types with additional properties func (s DateDecayFunction) MarshalJSON() ([]byte, error) { type opt DateDecayFunction From 4bdea6deef4517946bbab390116542ef4cc9b041 Mon Sep 17 00:00:00 2001 From: Daito Akimura Date: Thu, 13 Mar 2025 11:03:21 +0900 Subject: [PATCH 2/2] chore: Trigger CI