I just ran into that the current implementation doesn't properly handle inline struct fields.
When a struct embeds another struct with the json:",inline" tag, the fields from the embedded struct should be flattened into the parent struct's schema.
Here's a test case that demonstrates the issue:
func TestInlineStructField(t *testing.T) {
type TestInline struct {
InlineField1 string `json:"inlineField1"`
InlineField2 *string `json:"inlineField2,omitempty"`
}
type Test struct {
*TestInline `json:",inline"`
TestField string `json:"testField"`
}
assert.Equal(t,
`export const TestSchema = z.object({
inlineField1: z.string(),
inlineField2: z.string().optional(),
testField: z.string(),
})
export type Test = z.infer<typeof TestSchema>
`, StructToZodSchema(Test{}))
}
I've already created a fix, will open a pull request soon.
Hey!
I just ran into that the current implementation doesn't properly handle inline struct fields.
When a struct embeds another struct with the
json:",inline"
tag, the fields from the embedded struct should be flattened into the parent struct's schema.Here's a test case that demonstrates the issue:
I've already created a fix, will open a pull request soon.