From acbc5d0c964816b77b43386390d18f2bd6b587ed Mon Sep 17 00:00:00 2001 From: Alena Petraki <a.petraki@perx.ru> Date: Tue, 9 Jul 2024 09:57:24 +0000 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=D0=BA=D0=B8=20=D0=BB=D0=BE=D0=BA=D0=B0=D0=BB=D0=B8=D0=B7=D0=B0?= =?UTF-8?q?=D1=86=D0=B8=D0=B8=20Items=20API:=20=D0=98=D1=81=D0=BF=D1=80?= =?UTF-8?q?=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D0=B0=20=D0=BE=D1=88=D0=B8=D0=B1?= =?UTF-8?q?=D0=BA=D0=B0=20`ReferenceField=20encode=20error:=20incorrect=20?= =?UTF-8?q?type:=20"map",=20expected=20"*Reference"`=20=D0=BF=D1=80=D0=B8?= =?UTF-8?q?=20=D0=BF=D0=BE=D0=BB=D1=83=D1=87=D0=B5=D0=BD=D0=B8=D0=B8=20?= =?UTF-8?q?=D0=BB=D0=BE=D0=BA=D0=B0=D0=BB=D0=B8=D0=B7=D0=B0=D1=86=D0=B8?= =?UTF-8?q?=D0=B8=20=D1=8D=D0=BB=D0=B5=D0=BC=D0=B5=D0=BD=D1=82=D0=B0=20?= =?UTF-8?q?=D1=81=20=D0=BF=D0=BE=D0=BB=D0=B5=D0=BC=20=D1=82=D0=B8=D0=BF?= =?UTF-8?q?=D0=B0=20Reference?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/items/item.go | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/pkg/items/item.go b/pkg/items/item.go index b29dfe98..a145bf53 100644 --- a/pkg/items/item.go +++ b/pkg/items/item.go @@ -219,7 +219,7 @@ func (i *Item) Localize(localizer *localizer.Localizer) (err error) { func (i Item) Encode(ctx context.Context, s *schema.Schema) (*Item, error) { if i.Data != nil { - dt, err := schema.Encode(nil, s, i.Data) + dt, err := schema.Encode(ctx, s, i.Data) if err != nil { // return errors.WithField(err, "data") return nil, err @@ -228,7 +228,7 @@ func (i Item) Encode(ctx context.Context, s *schema.Schema) (*Item, error) { } if len(i.Translations) > 0 { for l, v := range i.Translations { - dt, err := schema.Encode(nil, s, v) + dt, err := schema.Encode(ctx, s, v) if err != nil { // return errors.WithField(err, fmt.Sprintf("translations.%s", l)) return nil, err @@ -240,7 +240,6 @@ func (i Item) Encode(ctx context.Context, s *schema.Schema) (*Item, error) { } func (i Item) Decode(ctx context.Context, s *schema.Schema) (res *Item, err error) { - if i.Data != nil { i.Data, err = s.Decode(ctx, i.Data) if err != nil { @@ -248,7 +247,15 @@ func (i Item) Decode(ctx context.Context, s *schema.Schema) (res *Item, err erro // return errors.WithField(err, "data") } } - + if len(i.Translations) > 0 { + for l, v := range i.Translations { + dt, err := schema.Decode(ctx, s, v) + if err != nil { + return nil, err + } + i.Translations[l] = dt.(map[string]interface{}) + } + } return &i, nil } -- GitLab