From 3412f831ca6b52642afe57ed27a0031e8832c3cb Mon Sep 17 00:00:00 2001 From: devarsh10 Date: Thu, 12 Feb 2026 14:48:14 +0530 Subject: [PATCH 1/3] update twig file to access nested preferences --- templates/go/models/model.go.twig | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/templates/go/models/model.go.twig b/templates/go/models/model.go.twig index aee1a950bd..028011bace 100644 --- a/templates/go/models/model.go.twig +++ b/templates/go/models/model.go.twig @@ -21,6 +21,12 @@ func (model {{ definition.name | caseUcfirst }}) New(data []byte) *{{ definition return &model } +func (p *{{ definition.name | caseUcfirst }}) UnmarshalJSON(b []byte) error { + p.data = make([]byte, len(b)) + copy(p.data, b) + return nil +} + {%~ if definition.additionalProperties %} // Use this method to get response in desired type {%~ endif %} From 4792700753ecdca08a314bc188e970204aafd404 Mon Sep 17 00:00:00 2001 From: Devarsh Date: Fri, 13 Feb 2026 11:29:29 +0000 Subject: [PATCH 2/3] consider code rabbit suggestion --- templates/go/models/model.go.twig | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/templates/go/models/model.go.twig b/templates/go/models/model.go.twig index 028011bace..7b76a77e73 100644 --- a/templates/go/models/model.go.twig +++ b/templates/go/models/model.go.twig @@ -21,10 +21,14 @@ func (model {{ definition.name | caseUcfirst }}) New(data []byte) *{{ definition return &model } -func (p *{{ definition.name | caseUcfirst }}) UnmarshalJSON(b []byte) error { - p.data = make([]byte, len(b)) - copy(p.data, b) - return nil +func (p *{{ definition.name | caseUcfirst }}) UnmarshalJSON(b []byte) error { + p.data = make([]byte, len(b)) + copy(p.data, b) + + // Alias avoids infinite recursion (the alias has no methods). + type Alias {{ definition.name | caseUcfirst }} + aux := (*Alias)(p) + return json.Unmarshal(b, aux) } {%~ if definition.additionalProperties %} From 09fdb26d26cb95ea268f0add9ef9b36f23c4f49e Mon Sep 17 00:00:00 2001 From: Devarsh Date: Tue, 17 Feb 2026 08:46:29 +0000 Subject: [PATCH 3/3] make changes to save memory & replace misleading mssg --- templates/go/models/model.go.twig | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/templates/go/models/model.go.twig b/templates/go/models/model.go.twig index 7b76a77e73..5d7b5d3e93 100644 --- a/templates/go/models/model.go.twig +++ b/templates/go/models/model.go.twig @@ -21,22 +21,24 @@ func (model {{ definition.name | caseUcfirst }}) New(data []byte) *{{ definition return &model } -func (p *{{ definition.name | caseUcfirst }}) UnmarshalJSON(b []byte) error { - p.data = make([]byte, len(b)) - copy(p.data, b) - - // Alias avoids infinite recursion (the alias has no methods). - type Alias {{ definition.name | caseUcfirst }} - aux := (*Alias)(p) - return json.Unmarshal(b, aux) +{%~ if definition.additionalProperties %} +func (p *{{ definition.name | caseUcfirst }}) UnmarshalJSON(b []byte) error { + p.data = make([]byte, len(b)) + copy(p.data, b) + + // Alias avoids infinite recursion (the alias has no methods). + type Alias {{ definition.name | caseUcfirst }} + aux := (*Alias)(p) + return json.Unmarshal(b, aux) } +{%~ endif %} {%~ if definition.additionalProperties %} // Use this method to get response in desired type {%~ endif %} func (model *{{ definition.name | caseUcfirst }}) Decode(value interface{}) error { if len(model.data) <= 0 { - return errors.New("method Decode() cannot be used on nested struct") + return errors.New("model must be initialized from raw JSON via New() or JSON unmarshalling") } err := json.Unmarshal(model.data, value)