This repository was archived by the owner on Aug 18, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 631
/
Copy pathExample.hs
42 lines (29 loc) · 1.71 KB
/
Example.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
module Cardano.Wallet.API.V1.Swagger.Example where
import Universum
import Test.QuickCheck (Arbitrary (..), Gen, listOf1)
import Cardano.Wallet.Orphans.Arbitrary ()
import Pos.Arbitrary.Wallet.Web.ClientTypes ()
import Pos.Wallet.Web.ClientTypes (CUpdateInfo)
import Pos.Wallet.Web.Methods.Misc (WalletStateSnapshot (..))
import qualified Data.Map.Strict as Map
class Arbitrary a => Example a where
example :: Gen a
example = arbitrary
instance Example ()
instance Example a => Example (NonEmpty a)
-- NOTE: we don't want to see empty list examples in our swagger doc :)
instance Example a => Example [a] where
example = listOf1 example
-- NOTE: we don't want to see "null" examples in our swagger doc :)
instance Example a => Example (Maybe a) where
example = Just <$> example
-- NOTE: we don't want to see empty maps in our swagger doc :)
instance (Ord k, Example k, Example v) => Example (Map k v) where
example = Map.fromList <$> listOf1 ((,) <$> example <*> example)
instance Example CUpdateInfo
instance Example WalletStateSnapshot
-- IMPORTANT: if executing `grep "[]\|null" wallet-new/spec/swagger.json` returns any element - then we have to add Example instances for those objects because we don't want to see [] or null examples in our docs.
--
-- TODO: We should probably add this as a part of our swagger CI script and fail swagger if we find some of them - with instruction to the developer above what is said above.
--
-- Most of it comes to removing Nothing from `Arbitrary (Maybe a)` instance and removing empty list from `Arbitrary [a]` instance. It could be done automatically with some quickcheck hacks but I think it would be an overkill.