Skip to content

Commit 1b561e1

Browse files
authored
Merge pull request #24 from biocad/maksbotan/servant-0.19-namedroutes
Add support for NamedRoutes Combine #23 and marinelli/servant-openapi3@ee829b5 Thanks to @aveltras and @marinelli!
2 parents 78d4fb4 + cb78c08 commit 1b561e1

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

src/Servant/OpenApi/Internal.hs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ import Network.HTTP.Media (MediaType)
3838
import Servant.API
3939
import Servant.API.Description (FoldDescription, reflectDescription)
4040
import Servant.API.Modifiers (FoldRequired)
41+
#if MIN_VERSION_servant(0,19,0)
42+
import Servant.API.Generic (ToServantApi)
43+
#endif
4144

4245
import Servant.OpenApi.Internal.TypeLevel.API
4346

@@ -416,6 +419,11 @@ instance (HasOpenApi sub) => HasOpenApi (Fragment a :> sub) where
416419
toOpenApi _ = toOpenApi (Proxy :: Proxy sub)
417420
#endif
418421

422+
#if MIN_VERSION_servant(0,19,0)
423+
instance (HasOpenApi (ToServantApi sub)) => HasOpenApi (NamedRoutes sub) where
424+
toOpenApi _ = toOpenApi (Proxy :: Proxy (ToServantApi sub))
425+
#endif
426+
419427
-- =======================================================================
420428
-- Below are the definitions that should be in Servant.API.ContentTypes
421429
-- =======================================================================

src/Servant/OpenApi/Internal/TypeLevel/API.hs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{-# LANGUAGE CPP #-}
12
{-# LANGUAGE ConstraintKinds #-}
23
{-# LANGUAGE DataKinds #-}
34
{-# LANGUAGE KindSignatures #-}
@@ -7,14 +8,19 @@
78
{-# LANGUAGE UndecidableInstances #-}
89
module Servant.OpenApi.Internal.TypeLevel.API where
910

10-
import Data.Type.Bool (If)
11-
import GHC.Exts (Constraint)
11+
import GHC.Exts (Constraint)
1212
import Servant.API
13+
#if MIN_VERSION_servant(0,19,0)
14+
import Servant.API.Generic (ToServantApi)
15+
#endif
1316

1417
-- | Build a list of endpoints from an API.
1518
type family EndpointsList api where
1619
EndpointsList (a :<|> b) = AppendList (EndpointsList a) (EndpointsList b)
1720
EndpointsList (e :> a) = MapSub e (EndpointsList a)
21+
#if MIN_VERSION_servant(0,19,0)
22+
EndpointsList (NamedRoutes api) = EndpointsList (ToServantApi api)
23+
#endif
1824
EndpointsList a = '[a]
1925

2026
-- | Check whether @sub@ is a sub API of @api@.
@@ -43,6 +49,9 @@ type family Or (a :: Constraint) (b :: Constraint) :: Constraint where
4349
type family IsIn sub api :: Constraint where
4450
IsIn e (a :<|> b) = Or (IsIn e a) (IsIn e b)
4551
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
4655
IsIn e e = ()
4756

4857
-- | Check whether a type is a member of a list of types.
@@ -83,5 +92,7 @@ type family BodyTypes' c api :: [*] where
8392
BodyTypes' c (ReqBody' mods cs a :> api) = AddBodyType c cs a (BodyTypes' c api)
8493
BodyTypes' c (e :> api) = BodyTypes' c api
8594
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
8698
BodyTypes' c api = '[]
87-

0 commit comments

Comments
 (0)