Skip to content

Commit

Permalink
chore: handle empty json tag values
Browse files Browse the repository at this point in the history
  • Loading branch information
Emyrk committed Dec 17, 2024
1 parent 043be3f commit abb2d09
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
5 changes: 4 additions & 1 deletion convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,10 @@ func (ts *Typescript) buildStruct(obj types.Object, st *types.Struct) (*bindings
// Completely ignore this field.
continue
}
tsField.Name = jsonTag.Name
// Empty tags are ignored.
if jsonTag.Name != "" {
tsField.Name = jsonTag.Name
}
if len(jsonTag.Options) > 0 && jsonTag.Options[0] == "omitempty" {
tsField.QuestionToken = true
}
Expand Down
6 changes: 6 additions & 0 deletions testdata/emptyjson/emptyjson.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package emptyjson

type JSONTag struct {
HostName string
CertName string `json:",omitempty"`
}
7 changes: 7 additions & 0 deletions testdata/emptyjson/emptyjson.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Code generated by 'guts'. DO NOT EDIT.

// From emptyjson/emptyjson.go
export interface JSONTag {
readonly HostName: string;
readonly CertName?: string;
}

0 comments on commit abb2d09

Please sign in to comment.