Skip to content

Support skipping fields from generated schema via zen:"ignore"#25

Open
hi-rai wants to merge 1 commit into
mainfrom
dev/himanshu/support-to-ignore-fields
Open

Support skipping fields from generated schema via zen:"ignore"#25
hi-rai wants to merge 1 commit into
mainfrom
dev/himanshu/support-to-ignore-fields

Conversation

@hi-rai

@hi-rai hi-rai commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

Add a zen:"ignore" struct tag that excludes a field from the generated Zod schema and TypeScript type. Unlike json:"-", it leaves JSON serialization untouched and also works on embedded (anonymous) fields - useful for fields that must stay on the wire (e.g. deprecated fields kept for API compatibility) but shouldn't surface in the generated types.

@hi-rai hi-rai requested review from ramilamparo and satvik007 June 19, 2026 04:28
@hi-rai hi-rai self-assigned this Jun 19, 2026
Base automatically changed from dev/himanshu/modernize-tooling to main June 25, 2026 11:35
Add a `zen:"ignore"` struct tag that excludes a field from the generated
Zod schema and TypeScript type. Unlike `json:"-"`, it leaves JSON
serialization untouched and also works on embedded (anonymous) fields -
useful for fields that must stay on the wire (e.g. deprecated fields kept
for API compatibility) but shouldn't surface in the generated types.
@hi-rai hi-rai force-pushed the dev/himanshu/support-to-ignore-fields branch from 431608e to 0d0e54d Compare June 25, 2026 12:01

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clean, well-scoped PR. The implementation is correct across all four field-iteration sites, the isFieldIgnored helper is idiomatic, the documentation is clear, and the test covers the key scenarios (plain field, field with json tag, embedded struct).

Two minor nits left as inline comments — neither is blocking:

  1. The shadowing loop in getTypeStruct (line 419) doesn't filter zen:"ignore" fields from the embedded struct — functionally harmless but slightly inconsistent.
  2. The test only exercises the convertStruct path; a self-referencing struct test would cover all four isFieldIgnored call sites.

No security or performance concerns.

Comment thread zod_test.go
Comment on lines +154 to +166
func TestStructWithIgnoredField(t *testing.T) {
type HasSecret struct {
Secret string
}
type User struct {
Name string
Age int
Internal string `zen:"ignore"`
Password string `zen:"ignore" json:"password"`
HasSecret ` zen:"ignore"`
}
assertSchema(t, User{})
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Good test — it covers plain ignored fields, ignored + json tag, and ignored embedded structs. However, this only exercises the convertStruct code path. The other three sites where isFieldIgnored was added (getStructShape, and both loops in getTypeStruct) are only reached for self-referencing structs.

Consider adding a self-referencing struct test to cover all four code paths:

func TestRecursiveStructWithIgnoredField(t *testing.T) {
	type Node struct {
		Value    string
		Internal string `zen:"ignore"`
		Next     *Node  `json:"next"`
	}
	assertSchema(t, Node{})
}

@github-actions github-actions Bot deleted a comment from claude Bot Jun 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant