Skip to content
This repository was archived by the owner on Aug 18, 2020. It is now read-only.

Commit 161b636

Browse files
author
Ben Ford
committed
Fix the swagger output
See conversation here haskell-servant/servant-swagger#80
1 parent 954d8bb commit 161b636

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

faucet/src/Cardano/Faucet.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ withdraw wd = withSublogger (LoggerName "withdraw") $ do
3939
logError ("Error withdrawing " <> (wd ^. to show . packed)
4040
<> " error: "
4141
<> (err ^. to show . packed))
42-
return $ WithdrawlError err
42+
return $ WithdrawlError (show err ^. packed)
4343
Right wr -> do
4444
let txn = wrData wr
4545
amount = unV1 $ txAmount txn

faucet/src/Cardano/Faucet/Types/API.hs

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import Control.Lens hiding ((.=))
2121
import Data.Aeson (FromJSON (..), ToJSON (..), object, withObject, (.:), (.=))
2222
import Data.Monoid ((<>))
2323
import Data.Text (Text)
24+
import qualified Data.Char as Char
2425
-- import Data.Text (Text)
2526
import Data.Typeable (Typeable)
2627
import GHC.Generics (Generic)
@@ -60,30 +61,33 @@ instance ToSchema WithdrawlRequest where
6061
--------------------------------------------------------------------------------
6162
-- | The result of processing a 'WithdrawlRequest'
6263
data WithdrawlResult =
63-
WithdrawlError ClientError -- ^ Error with http client error
64+
WithdrawlError Text -- ^ Error with http client error
6465
| WithdrawlSuccess Transaction -- ^ Success with transaction details
6566
deriving (Show, Typeable, Generic)
6667

6768
instance ToJSON WithdrawlResult where
6869
toJSON (WithdrawlSuccess txn) =
6970
object ["success" .= txn]
7071
toJSON (WithdrawlError err) =
71-
object ["error" .= show err]
72+
object ["error" .= err]
7273

7374
wdDesc :: Text
7475
wdDesc = "An object with either a success field containing the transaction or "
7576
<> "an error field containing the ClientError from the wallet as a string"
7677

7778
instance ToSchema WithdrawlResult where
78-
declareNamedSchema _ = do
79-
txnSchema <- declareSchemaRef (Proxy :: Proxy Transaction)
80-
errSchema <- declareSchemaRef (Proxy :: Proxy String)
81-
return $ NamedSchema (Just "WithdrawlResult") $ mempty
82-
& type_ .~ SwaggerObject
83-
& properties .~ (mempty
84-
& at "success" ?~ txnSchema
85-
& at "error" ?~ errSchema)
86-
& description .~ (Just $ wdDesc)
79+
declareNamedSchema = genericDeclareNamedSchema defaultSchemaOptions
80+
{ constructorTagModifier = map Char.toLower . drop (length ("Withdrawl" :: String)) }
81+
& mapped.mapped.schema.description ?~ wdDesc
82+
-- declareNamedSchema _ = do
83+
-- txnSchema <- declareSchemaRef (Proxy :: Proxy Transaction)
84+
-- errSchema <- declareSchemaRef (Proxy :: Proxy Char)
85+
-- return $ NamedSchema (Just "WithdrawlResult") $ mempty
86+
-- & type_ .~ SwaggerObject
87+
-- & properties .~ (mempty
88+
-- & at "success" ?~ txnSchema
89+
-- & at "error" ?~ errSchema)
90+
-- & description .~ (Just $ wdDesc)
8791

8892
--------------------------------------------------------------------------------
8993
-- | A request to deposit ADA back into the wallet __not currently used__

0 commit comments

Comments
 (0)