|
20 | 20 | #include "overlapping-compat.h"
|
21 | 21 | module Servant.Docs.Internal where
|
22 | 22 |
|
| 23 | +import Debug.Trace |
23 | 24 | import Prelude ()
|
24 | 25 | import Prelude.Compat
|
25 | 26 |
|
@@ -116,7 +117,8 @@ instance Semigroup API where
|
116 | 117 | (<>) = mappend
|
117 | 118 |
|
118 | 119 | instance Monoid API where
|
119 |
| - API a1 b1 `mappend` API a2 b2 = API (a1 `mappend` a2) (b1 `mappend` b2) |
| 120 | + API a1 b1 `mappend` API a2 b2 = API (a1 `mappend` a2) |
| 121 | + (HM.unionWith combineAction b1 (traceShowId b2)) |
120 | 122 | mempty = API mempty mempty
|
121 | 123 |
|
122 | 124 | -- | An empty 'API'
|
@@ -223,6 +225,15 @@ data Response = Response
|
223 | 225 | , _respHeaders :: [HTTP.Header]
|
224 | 226 | } deriving (Eq, Ord, Show)
|
225 | 227 |
|
| 228 | +-- | Combine two Responses, we can't make a monoid because merging Status breaks |
| 229 | +-- the laws. |
| 230 | +-- |
| 231 | +-- As such, we invent a non-commutative, left associative operation |
| 232 | +-- 'combineResponse' to mush two together taking the status from the very left. |
| 233 | +combineResponse :: Response -> Response -> Response |
| 234 | +Response s ts bs hs `combineResponse` Response _ ts' bs' hs' |
| 235 | + = Response s (ts <> ts') (bs <> bs') (hs <> hs') |
| 236 | + |
226 | 237 | -- | Default response: status code 200, no response body.
|
227 | 238 | --
|
228 | 239 | -- Can be tweaked with two lenses.
|
@@ -265,11 +276,10 @@ data Action = Action
|
265 | 276 | -- laws.
|
266 | 277 | --
|
267 | 278 | -- As such, we invent a non-commutative, left associative operation
|
268 |
| --- 'combineAction' to mush two together taking the response, body and content |
269 |
| --- types from the very left. |
| 279 | +-- 'combineAction' to mush two together taking the response from the very left. |
270 | 280 | combineAction :: Action -> Action -> Action
|
271 |
| -Action a c h p n m ts body resp `combineAction` Action a' c' h' p' n' m' _ _ _ = |
272 |
| - Action (a <> a') (c <> c') (h <> h') (p <> p') (n <> n') (m <> m') ts body resp |
| 281 | +Action a c h p n m ts body resp `combineAction` Action a' c' h' p' n' m' ts' body' resp' = |
| 282 | + Action (a <> a') (c <> c') (h <> h') (p <> p') (n <> n') (m <> m') (ts <> ts') (body <> body') (resp `combineResponse` resp') |
273 | 283 |
|
274 | 284 | -- | Default 'Action'. Has no 'captures', no query 'params', expects
|
275 | 285 | -- no request body ('rqbody') and the typical response is 'defResponse'.
|
|
0 commit comments