Southclaws / supervillain

Converts Go structs to Zod schemas
MIT License
77 stars 6 forks source link

Handle interface implementations with pointer receivers #12

Closed josiah-tt closed 9 months ago

josiah-tt commented 10 months ago

PRs #10 and #11 added reflection-based checks for interface implementations (internal interfaces defining a ZodSchema() methods, and the json.Marshaler interface). But since ConvertType() unwraps pointers before proceeding with conversion, and the underlying type does not implement the interface if the method was defined with a pointer receiver, we did not detect interface implementations using pointer receivers.

This change addresses that problem by checking .Implements() both on the type directly and on a pointer to the type.