diff --git a/api/sessions/connection.gen.go b/api/sessions/connection.gen.go index fc5b001f23..fadd6a5ab6 100644 --- a/api/sessions/connection.gen.go +++ b/api/sessions/connection.gen.go @@ -6,7 +6,7 @@ type Connection struct { ClientTcpPort uint32 `json:"client_tcp_port,omitempty"` EndpointTcpAddress string `json:"endpoint_tcp_address,omitempty"` EndpointTcpPort uint32 `json:"endpoint_tcp_port,omitempty"` - BytesUp uint64 `json:"bytes_up,omitempty"` - BytesDown uint64 `json:"bytes_down,omitempty"` + BytesUp uint64 `json:"bytes_up,string,omitempty"` + BytesDown uint64 `json:"bytes_down,string,omitempty"` ClosedReason string `json:"closed_reason,omitempty"` } diff --git a/internal/api/genapi/input.go b/internal/api/genapi/input.go index 61e9410230..bdd1df42b2 100644 --- a/internal/api/genapi/input.go +++ b/internal/api/genapi/input.go @@ -58,6 +58,7 @@ type fieldInfo struct { SubtypeNames []string Query bool SkipDefault bool + JsonTags []string // Appended to a field's `json` tag (comma separated) } type structInfo struct { @@ -832,6 +833,13 @@ var inputStructs = []*structInfo{ { inProto: &sessions.Connection{}, outFile: "sessions/connection.gen.go", + fieldOverrides: []fieldInfo{ + // uint64 fields get marshalled by protobuf as strings, so we have + // to tell the json parser that their json representation is a + // string but they go into Go uint64 types. + {Name: "BytesUp", JsonTags: []string{"string"}}, + {Name: "BytesDown", JsonTags: []string{"string"}}, + }, }, { inProto: &sessions.Session{}, diff --git a/internal/api/genapi/templates.go b/internal/api/genapi/templates.go index 53eb935aea..25e54d5289 100644 --- a/internal/api/genapi/templates.go +++ b/internal/api/genapi/templates.go @@ -85,6 +85,9 @@ func fillTemplates() { if override.FieldType != "" { field.FieldType = override.FieldType } + if len(override.JsonTags) != 0 { + field.JsonTags = override.JsonTags + } in.generatedStructure.fields[i] = field } } @@ -578,6 +581,7 @@ func hasResponseType(types []string, typ string) bool { var structTemplate = template.Must(template.New("").Funcs( template.FuncMap{ "hasResponseType": hasResponseType, + "stringsjoin": strings.Join, }, ).Parse( fmt.Sprint(`// Code generated by "make api"; DO NOT EDIT. @@ -595,7 +599,7 @@ import ( ) type {{ .Name }} struct { {{ range .Fields }} -{{ .Name }} {{ .FieldType }} `, "`json:\"{{ .ProtoName }},omitempty\"`", `{{ end }} +{{ .Name }} {{ .FieldType }} `, "`json:\"{{ .ProtoName }}{{ if ( ne ( len ( .JsonTags ) ) 0 ) }},{{ stringsjoin .JsonTags \",\" }}{{ end }},omitempty\"`", `{{ end }} {{ if ( not ( eq ( len ( .CreateResponseTypes ) ) 0 ) )}} response *api.Response {{ else if ( eq .Name "Error" ) }}