diff --git a/README.md b/README.md index 8af9711..ad8e875 100644 --- a/README.md +++ b/README.md @@ -41,6 +41,7 @@ type UserEntry struct { MaybeFieldWithStar *string `json:"address"` Nickname string `json:"nickname,omitempty"` Role UserRole `json:"role"` + CreatedAt time.Time `json:"created_at,omitzero"` Complex ComplexType `json:"complex"` unexported bool // Unexported fields are omitted @@ -85,6 +86,7 @@ export interface UserEntry { address?: string; nickname?: string; role: UserRole; + created_at?: string /* RFC3339 */; complex: ComplexType; } export interface ListUsersResponse { diff --git a/examples/simple/index.ts b/examples/simple/index.ts index 0e291aa..90e57a6 100755 --- a/examples/simple/index.ts +++ b/examples/simple/index.ts @@ -27,6 +27,7 @@ export interface UserEntry { address?: string; nickname?: string; role: UserRole; + created_at?: string /* RFC3339 */; complex: ComplexType; } export interface ListUsersResponse { diff --git a/examples/simple/simple.go b/examples/simple/simple.go index 03de5b0..1158ab8 100644 --- a/examples/simple/simple.go +++ b/examples/simple/simple.go @@ -1,6 +1,10 @@ package simple -import "github.com/google/uuid" +import ( + "time" + + "github.com/google/uuid" +) // Comments are kept :) type ComplexType map[string]map[uint16]*uint32 @@ -24,9 +28,10 @@ type UserEntry struct { Bar uuid.UUID `json:"bar"` } `json:"prefs"` - MaybeFieldWithStar *string `json:"address"` - Nickname string `json:"nickname,omitempty"` - Role UserRole `json:"role"` + MaybeFieldWithStar *string `json:"address"` + Nickname string `json:"nickname,omitempty"` + Role UserRole `json:"role"` + CreatedAt time.Time `json:"created_at,omitzero"` Complex ComplexType `json:"complex"` unexported bool // Unexported fields won't be in the output diff --git a/tygo/write.go b/tygo/write.go index 3caf4f2..a002eef 100644 --- a/tygo/write.go +++ b/tygo/write.go @@ -320,7 +320,7 @@ func (g *PackageGenerator) writeStructFields(s *strings.Builder, fields []*ast.F continue } - optional = jsonTag.HasOption("omitempty") + optional = jsonTag.HasOption("omitempty") || jsonTag.HasOption("omitzero") } yamlTag, err := tags.Get("yaml") if err == nil {