mirror of
https://github.com/typeable/bucks.git
synced 2024-09-17 18:37:21 +03:00
Add OpenApi support.
This commit is contained in:
parent
c506d9d43b
commit
4101a201c2
@ -19,6 +19,11 @@ flag aeson
|
|||||||
default: False
|
default: False
|
||||||
manual: True
|
manual: True
|
||||||
|
|
||||||
|
flag openapi
|
||||||
|
description: Enable OpenAPI instances
|
||||||
|
default: False
|
||||||
|
manual: True
|
||||||
|
|
||||||
flag rel8
|
flag rel8
|
||||||
description: Enable Rel8 support
|
description: Enable Rel8 support
|
||||||
default: False
|
default: False
|
||||||
@ -38,6 +43,10 @@ library
|
|||||||
other-modules: Data.Money.JSON
|
other-modules: Data.Money.JSON
|
||||||
build-depends: aeson >= 2.0 && < 3.0
|
build-depends: aeson >= 2.0 && < 3.0
|
||||||
ghc-options: -DUSE_AESON
|
ghc-options: -DUSE_AESON
|
||||||
|
if flag(openapi)
|
||||||
|
other-modules: Data.Money.OpenApi
|
||||||
|
build-depends: openapi3
|
||||||
|
ghc-options: -DUSE_OPENAPI
|
||||||
if flag(rel8)
|
if flag(rel8)
|
||||||
other-modules: Data.Money.Rel8
|
other-modules: Data.Money.Rel8
|
||||||
build-depends: rel8 >= 1.4,
|
build-depends: rel8 >= 1.4,
|
||||||
|
@ -7,6 +7,9 @@ import Data.Money.Internal as Export
|
|||||||
#ifdef USE_AESON
|
#ifdef USE_AESON
|
||||||
import Data.Money.JSON as Export ()
|
import Data.Money.JSON as Export ()
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef USE_OPENAPI
|
||||||
|
import Data.Money.OpenApi as Export ()
|
||||||
|
#endif
|
||||||
#ifdef USE_REL8
|
#ifdef USE_REL8
|
||||||
import Data.Money.Rel8 as Export ()
|
import Data.Money.Rel8 as Export ()
|
||||||
#endif
|
#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:
|
flags:
|
||||||
bucks:
|
bucks:
|
||||||
aeson: true
|
aeson: true
|
||||||
|
openapi: true
|
||||||
rel8: true
|
rel8: true
|
||||||
|
|
||||||
nix:
|
nix:
|
||||||
|
Loading…
Reference in New Issue
Block a user