From 215fb9c4dad8ecb878c4cfc5413563c73cbe70f2 Mon Sep 17 00:00:00 2001 From: Vincent KERDRAON Date: Fri, 7 Jul 2023 19:23:51 -0700 Subject: [PATCH] Fix `json:",omitempty"` The json struct tag can be used without a first argument. In this case, the field name must be used. See https://pkg.go.dev/encoding/json Example code: type Person struct { Phone string `json:",omitempty"` } --- typescriptify/typescriptify.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/typescriptify/typescriptify.go b/typescriptify/typescriptify.go index efc026a..00e8855 100644 --- a/typescriptify/typescriptify.go +++ b/typescriptify/typescriptify.go @@ -523,6 +523,10 @@ func (t *TypeScriptify) getJSONFieldName(field reflect.StructField, isPtr bool) jsonTagParts := strings.Split(jsonTag, ",") if len(jsonTagParts) > 0 { jsonFieldName = strings.Trim(jsonTagParts[0], t.Indent) + //`json:",omitempty"` is valid + if jsonFieldName == "" { + jsonFieldName = field.Name + } } hasOmitEmpty := false ignored := false