-
Notifications
You must be signed in to change notification settings - Fork 59
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
A Maybe
field will be invalid against a null
#142
Comments
Maybe
field will be invalid against a null
I personally use We could alter A better solution would probably be to add some |
>>> data X = X { foo :: Maybe Int } deriving (Show, Eq, Generic)
>>> instance ToJSON X where toJSON = genericToJSON defaultOptions { omitNothingFields = True }
>>> instance ToSchema X
>>> validateToJSON (X Nothing)
["property \"foo\" is required, but not found in \"{}\""] |
Ah, I see Your problem is because of a weird behaviour feature (bug) of Generic-based This is how everything works if you just add another field (even without >>> data X = X { foo :: Maybe Int, bar :: Maybe String } deriving (Show, Eq, Generic)
>>> instance ToJSON X
>>> instance ToSchema X
>>> validateToJSON (X Nothing Nothing)
[] What's causing thisThe problem is specifically due to this line: recordSchema = gdeclareNamedSchema opts (Proxy :: Proxy (S1 s f)) s Which calls something with instance OVERLAPPABLE_ (Selector s, GToSchema f) => GToSchema (S1 s f) where ... over this one: instance OVERLAPPING_ (Selector s, ToSchema c) => GToSchema (S1 s (K1 i (Maybe c))) where ... even when there's a I think I'm going to send a PR fixing this right now. |
I'm getting validation errors against
Maybe
fields:Omitting
"foo"
from therequired
fields does not fix this issue.What's the right way to get maybe fields to validate correctly?
The text was updated successfully, but these errors were encountered: