mirror of
https://github.com/typeable/bucks.git
synced 2024-08-17 02:50:36 +03:00
Add OpenApi support.
This commit is contained in:
parent
c506d9d43b
commit
4101a201c2
@ -19,6 +19,11 @@ flag aeson
|
||||
default: False
|
||||
manual: True
|
||||
|
||||
flag openapi
|
||||
description: Enable OpenAPI instances
|
||||
default: False
|
||||
manual: True
|
||||
|
||||
flag rel8
|
||||
description: Enable Rel8 support
|
||||
default: False
|
||||
@ -38,6 +43,10 @@ library
|
||||
other-modules: Data.Money.JSON
|
||||
build-depends: aeson >= 2.0 && < 3.0
|
||||
ghc-options: -DUSE_AESON
|
||||
if flag(openapi)
|
||||
other-modules: Data.Money.OpenApi
|
||||
build-depends: openapi3
|
||||
ghc-options: -DUSE_OPENAPI
|
||||
if flag(rel8)
|
||||
other-modules: Data.Money.Rel8
|
||||
build-depends: rel8 >= 1.4,
|
||||
|
@ -7,6 +7,9 @@ import Data.Money.Internal as Export
|
||||
#ifdef USE_AESON
|
||||
import Data.Money.JSON as Export ()
|
||||
#endif
|
||||
#ifdef USE_OPENAPI
|
||||
import Data.Money.OpenApi as Export ()
|
||||
#endif
|
||||
#ifdef USE_REL8
|
||||
import Data.Money.Rel8 as Export ()
|
||||
#endif
|
||||
|
22
src/Data/Money/OpenApi.hs
Normal file
22
src/Data/Money/OpenApi.hs
Normal file
@ -0,0 +1,22 @@
|
||||
{-# OPTIONS_GHC -Wno-orphans #-}
|
||||
{-# LANGUAGE FlexibleContexts #-}
|
||||
{-# LANGUAGE MonoLocalBinds #-}
|
||||
{-# LANGUAGE OverloadedLists #-}
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
module Data.Money.OpenApi where
|
||||
|
||||
import Data.Fixed
|
||||
import Data.Money.Internal
|
||||
import Data.OpenApi
|
||||
import Data.Typeable
|
||||
|
||||
instance (KnownCurrency c, Typeable (Money c)) => ToSchema (Money c) where
|
||||
declareNamedSchema _ = do
|
||||
centiSchema <- declareSchemaRef (Proxy :: Proxy Centi)
|
||||
strSchema <- declareSchemaRef (Proxy :: Proxy String)
|
||||
return $ NamedSchema (Just "Money") $
|
||||
mempty { _schemaType = Just OpenApiObject
|
||||
, _schemaProperties = [ ("currency", strSchema)
|
||||
, ("amount", centiSchema) ]
|
||||
, _schemaRequired = [ "currency", "amount" ]
|
||||
}
|
@ -6,6 +6,7 @@ packages:
|
||||
flags:
|
||||
bucks:
|
||||
aeson: true
|
||||
openapi: true
|
||||
rel8: true
|
||||
|
||||
nix:
|
||||
|
Loading…
Reference in New Issue
Block a user