@@ -0,0 +1,22 @@
1+{-# OPTIONS_GHC -Wno-orphans #-}
2+{-# LANGUAGE FlexibleContexts #-}
3+{-# LANGUAGE MonoLocalBinds #-}
4+{-# LANGUAGE OverloadedLists #-}
5+{-# LANGUAGE OverloadedStrings #-}
6+module Data.Money.OpenApi where
7+
8+import Data.Fixed
9+import Data.Money.Internal
10+import Data.OpenApi
11+import Data.Typeable
12+
13+instance (KnownCurrency c, Typeable (Money c)) => ToSchema (Money c) where
14+ declareNamedSchema _ = do
15+ centiSchema <- declareSchemaRef (Proxy :: Proxy Centi)
16+ strSchema <- declareSchemaRef (Proxy :: Proxy String)
17+ return $ NamedSchema (Just "Money") $
18+ mempty { _schemaType = Just OpenApiObject
19+ , _schemaProperties = [ ("currency", strSchema)
20+ , ("amount", centiSchema) ]
21+ , _schemaRequired = [ "currency", "amount" ]
22+ }