Skip to content

Commit 837a7b6

Browse files
committed
Add null to Maybe a schemas
+ Generate a schema for `a` + Generate a schema with the `null` type + Combine both schemas with a `oneOf` to emulate `Maybe a` + Follows behaviour of other `Maybe` instances, e.g., `ToJSON`
1 parent 89825c4 commit 837a7b6

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/Data/OpenApi/Internal/Schema.hs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -623,7 +623,14 @@ instance ToSchema Float where declareNamedSchema = plain . paramSchemaToSc
623623
instance (Typeable (Fixed a), HasResolution a) => ToSchema (Fixed a) where declareNamedSchema = plain . paramSchemaToSchema
624624

625625
instance ToSchema a => ToSchema (Maybe a) where
626-
declareNamedSchema _ = declareNamedSchema (Proxy :: Proxy a)
626+
declareNamedSchema _ = do
627+
NamedSchema mName aSchema <- declareNamedSchema (Proxy :: Proxy a)
628+
629+
let aSchemaWithNull = mempty
630+
{ _schemaOneOf = Just [Inline aSchema, Inline mempty { _schemaType = Just OpenApiNull }]
631+
}
632+
633+
return $ NamedSchema mName aSchemaWithNull
627634

628635
instance (ToSchema a, ToSchema b) => ToSchema (Either a b) where
629636
-- To match Aeson instance

0 commit comments

Comments
 (0)