|
| 1 | +{-# LANGUAGE CPP #-} |
1 | 2 | {-# LANGUAGE ConstraintKinds #-}
|
2 | 3 | {-# LANGUAGE DataKinds #-}
|
3 | 4 | {-# LANGUAGE KindSignatures #-}
|
|
7 | 8 | {-# LANGUAGE UndecidableInstances #-}
|
8 | 9 | module Servant.OpenApi.Internal.TypeLevel.API where
|
9 | 10 |
|
10 |
| -import Data.Type.Bool (If) |
11 |
| -import GHC.Exts (Constraint) |
| 11 | +import GHC.Exts (Constraint) |
12 | 12 | import Servant.API
|
| 13 | +#if MIN_VERSION_servant(0,19,0) |
| 14 | +import Servant.API.Generic (ToServantApi) |
| 15 | +#endif |
13 | 16 |
|
14 | 17 | -- | Build a list of endpoints from an API.
|
15 | 18 | type family EndpointsList api where
|
16 | 19 | EndpointsList (a :<|> b) = AppendList (EndpointsList a) (EndpointsList b)
|
17 | 20 | EndpointsList (e :> a) = MapSub e (EndpointsList a)
|
| 21 | +#if MIN_VERSION_servant(0,19,0) |
| 22 | + EndpointsList (NamedRoutes api) = EndpointsList (ToServantApi api) |
| 23 | +#endif |
18 | 24 | EndpointsList a = '[a]
|
19 | 25 |
|
20 | 26 | -- | Check whether @sub@ is a sub API of @api@.
|
@@ -43,6 +49,9 @@ type family Or (a :: Constraint) (b :: Constraint) :: Constraint where
|
43 | 49 | type family IsIn sub api :: Constraint where
|
44 | 50 | IsIn e (a :<|> b) = Or (IsIn e a) (IsIn e b)
|
45 | 51 | IsIn (e :> a) (e :> b) = IsIn a b
|
| 52 | +#if MIN_VERSION_servant(0,19,0) |
| 53 | + IsIn e (NamedRoutes api) = IsIn e (ToServantApi api) |
| 54 | +#endif |
46 | 55 | IsIn e e = ()
|
47 | 56 |
|
48 | 57 | -- | Check whether a type is a member of a list of types.
|
@@ -83,5 +92,7 @@ type family BodyTypes' c api :: [*] where
|
83 | 92 | BodyTypes' c (ReqBody' mods cs a :> api) = AddBodyType c cs a (BodyTypes' c api)
|
84 | 93 | BodyTypes' c (e :> api) = BodyTypes' c api
|
85 | 94 | BodyTypes' c (a :<|> b) = AppendList (BodyTypes' c a) (BodyTypes' c b)
|
| 95 | +#if MIN_VERSION_servant(0,19,0) |
| 96 | + BodyTypes' c (NamedRoutes api) = BodyTypes' c (ToServantApi api) |
| 97 | +#endif |
86 | 98 | BodyTypes' c api = '[]
|
87 |
| - |
|
0 commit comments