|
Given: Is it possible to validate only 1 field? e.g. name Thanks |
Answered by
Oudwins
Jul 20, 2025
Replies: 1 comment 2 replies
|
Hey! I'm not sure from the question if you want to use a schema in a struct schema to validate a value or if you want to validate a struct with a subset of fields from a struct schema. For the first the only way to do it right now is: var MyFieldSchema = z.String()
var MyStructSchema = z.Struct(z.Shape{
"Field": MyFieldSchema,
})
// validate a string value
MyFieldSchema.Validate(&f) For the second you would need to use pick or merge see the docs on those utility fns |
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Yes you can do that through the pick method. see the docs: https://zog.dev/reference#complex-types
You would just do
edit: this is not very well documented in the docs. Probably should add a section on composability of schemas.
edit2: You can also do what you are doing and avoid code duplication by just having a local private global that has that specific schema like I mentioned in my first comment: