@@ -0,0 +1,80 @@
1+{-# LANGUAGE LambdaCase #-}
2+{-# LANGUAGE TypeOperators #-}
3+{-# LANGUAGE DataKinds #-}
4+{-# LANGUAGE TypeApplications #-}
5+{-# LANGUAGE DerivingVia #-}
6+{-# LANGUAGE StandaloneDeriving #-}
7+{-# LANGUAGE DeriveGeneric #-}
8+
9+
10+import Roboservant
11+import Servant
12+import Data.Hashable
13+import GHC.Generics
14+import Data.Aeson
15+
16+data Input = Input1 { foo :: String }
17+ | Input2 { bar :: Int }
18+ deriving (Generic, Eq)
19+
20+instance FromJSON Input
21+instance ToJSON Input
22+
23+
24+deriving via (Compound Input) instance Breakdown Input
25+deriving via (Compound Input) instance BuildFrom Input
26+
27+
28+-- deriving via (Atom Input) instance Breakdown Input
29+-- deriving via (Atom Input) instance BuildFrom Input
30+
31+instance Hashable Input
32+
33+
34+data Output = Output1 { ofoo :: String }
35+ | Output2 { obar :: Int }
36+ deriving (Generic, Eq)
37+
38+instance FromJSON Output
39+instance ToJSON Output
40+
41+instance Hashable Output
42+
43+deriving via (Compound Output) instance Breakdown Output
44+deriving via (Compound Output) instance BuildFrom Output
45+
46+-- deriving via (Atom Output) instance Breakdown Output
47+-- deriving via (Atom Output) instance BuildFrom Output
48+
49+
50+handler :: Input -> Handler Output
51+handler = pure . \case
52+ Input1 foo -> Output1 foo
53+ Input2 bar -> Output2 bar
54+
55+main =
56+ -- 28s at 80 reps
57+ -- fuzz @Api server defaultConfig (pure ())
58+ pure ()
59+
60+-- 18.5s at 80 reps
61+-- reifiedApi = toReifiedApi flattened endpoints
62+
63+flattened = flattenServer @Api server
64+
65+endpoints = Proxy @(Endpoints Api)
66+
67+defaultConfig :: Config
68+defaultConfig = Config {
69+ -- you can pass extra values in using the seed argument. This can be useful
70+ -- for things that might not be produceable within the api, like auth tokens.
71+ seed = [hashedDyn "blah"]
72+ , maxRuntime = 0.5
73+ -- if we get to 1000 interactions with the api, call it quits.
74+ , maxReps = 1000
75+ -- if you're using this inside quickcheck or hedgehog, you might want to set this
76+ -- from their seed to make sure it stays deterministic
77+ , rngSeed = 0
78+ -- 0 to 100: fail tests if we hit less than this percentage of endpoints.
79+ , coverageThreshold = 0
80+ }