From 418f83cd27a16e2e0700579df82fb8fbffae452b Mon Sep 17 00:00:00 2001 From: Shliakhov Danylo Date: Sat, 12 Oct 2024 22:09:19 +0300 Subject: [PATCH] refactor: improve fix using tdakkota suggestion --- gen/_template/json/encode.tmpl | 2 +- gen/_template/response_encode.tmpl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/gen/_template/json/encode.tmpl b/gen/_template/json/encode.tmpl index 1320ee8c5..5369a1d36 100644 --- a/gen/_template/json/encode.tmpl +++ b/gen/_template/json/encode.tmpl @@ -70,7 +70,7 @@ if {{ $.Var }}.Set { {{/* Encode value that implements jx.Encoder with respect to nil semantic */}} {{- define "json/enc_value" -}} {{- $t := $.Type -}} -{{- if or ($t.NilSemantic.Invalid) ($t.NilSemantic.Optional) -}} +{{- if or ($t.NilSemantic.Invalid) ($t.NilSemantic.Optional) }} if {{ $.Var }} != nil { {{- template "json/enc_field" $ }} {{ $.Var }}.Encode(e) diff --git a/gen/_template/response_encode.tmpl b/gen/_template/response_encode.tmpl index a800ab0e9..1deab59c5 100644 --- a/gen/_template/response_encode.tmpl +++ b/gen/_template/response_encode.tmpl @@ -168,7 +168,7 @@ func encode{{ $op.Name }}Response(response {{ $op.Responses.GoType }}, w http.Re return errors.Wrap(err, "flush streaming") } {{- else }} - e := new(jx.Encoder); + e := new(jx.Encoder) {{- template "json/enc" elem $type $var }} if _, err := e.WriteTo(w); err != nil { return errors.Wrap(err, "write")