Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -85,6 +86,7 @@ export interface UserEntry {
address?: string;
nickname?: string;
role: UserRole;
created_at?: string /* RFC3339 */;
complex: ComplexType;
}
export interface ListUsersResponse {
Expand Down
1 change: 1 addition & 0 deletions examples/simple/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export interface UserEntry {
address?: string;
nickname?: string;
role: UserRole;
created_at?: string /* RFC3339 */;
complex: ComplexType;
}
export interface ListUsersResponse {
Expand Down
13 changes: 9 additions & 4 deletions examples/simple/simple.go
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tygo/write.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading