@@ -67,12 +67,21 @@ instance GToSchema f => GToSchema (D1 d (C1 c f)) where
6767 gtoSchema _ = gtoSchema (Proxy :: Proxy f)
6868
6969-- | Record fields.
70−instance (Selector s, GToSchema f) => GToSchema (S1 s f) where
71− gtoSchema _ = schemaProperties . at fieldName ?~ Inline fieldSchema
70+instance {-# OVERLAPPABLE #-} (Selector s, GToSchema f) => GToSchema (S1 s f) where
71+ gtoSchema _ schema = schema
72+ & schemaProperties . at fieldName ?~ Inline fieldSchema
73+ & schemaRequired %~ (fieldName :)
7274 where
7375 fieldName = Text.pack (selName (undefined :: S1 s f p))
7476 fieldSchema = gtoSchema (Proxy :: Proxy f) mempty
7577
78+-- | Optional record fields.
79+instance {-# OVERLAPPING #-} (Selector s, ToSchema c) => GToSchema (S1 s (K1 i (Maybe c))) where
80+ gtoSchema _ = schemaProperties . at fieldName ?~ Inline fieldSchema
81+ where
82+ fieldName = Text.pack (selName (undefined :: S1 s f p))
83+ fieldSchema = toSchema (Proxy :: Proxy c)
84+
7685instance ToSchema c => GToSchema (K1 i c) where
7786 gtoSchema _ _ = toSchema (Proxy :: Proxy c)
7887