From d37c09a13a168c735d5b01a9edc6f9ffe7d7d783 Mon Sep 17 00:00:00 2001 From: Ewan Harris Date: Tue, 23 Jan 2024 13:34:53 +0000 Subject: [PATCH] fix(go-sdk): dont escape HTML characters in conditions The behaviour of json.Marshal is to escape any HTML characters in a string, by using json.Encoder we are able to disable the escaping of these characters --- config/clients/go/template/model.mustache | 6 ++++++ config/clients/go/template/model_simple.mustache | 9 ++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/config/clients/go/template/model.mustache b/config/clients/go/template/model.mustache index 684af1d3..af4c3925 100644 --- a/config/clients/go/template/model.mustache +++ b/config/clients/go/template/model.mustache @@ -3,6 +3,12 @@ package {{packageName}} {{#models}} import ( +{{#model}} +{{^isEnum}} + "bytes" +{{/isEnum}} +{{/model}} + "encoding/json" {{#imports}} "{{import}}" diff --git a/config/clients/go/template/model_simple.mustache b/config/clients/go/template/model_simple.mustache index aa694c0d..e0d1146c 100644 --- a/config/clients/go/template/model_simple.mustache +++ b/config/clients/go/template/model_simple.mustache @@ -277,7 +277,14 @@ func (o {{classname}}) MarshalJSON() ([]byte, error) { } {{/isAdditionalPropertiesTrue}} - return json.Marshal(toSerialize) + var b bytes.Buffer + enc := json.NewEncoder(&b) + enc.SetEscapeHTML(false) + err := enc.Encode(toSerialize) + if err != nil { + return nil, err + } + return b.Bytes(), nil } {{#isAdditionalPropertiesTrue}}