diff --git a/nri-test-encoding/nri-test-encoding.cabal b/nri-test-encoding/nri-test-encoding.cabal index 57ca15b9..62cd74c3 100644 --- a/nri-test-encoding/nri-test-encoding.cabal +++ b/nri-test-encoding/nri-test-encoding.cabal @@ -60,9 +60,9 @@ library , filepath >=1.4.2.1 && <1.5 , nri-prelude >=0.1.0.0 && <0.7 , nri-redis >=0.1.0.0 && <0.4 - , servant >=0.16.2 && <0.21 - , servant-auth-server >=0.4.5.1 && <0.5 - , servant-server >=0.16.2 && <0.21 + , servant >=0.20.2 && <0.21 + , servant-auth-server >=0.4.9.0 && <0.5 + , servant-server >=0.20.2 && <0.21 , text >=1.2.3.1 && <2.2 default-language: Haskell2010 @@ -101,8 +101,8 @@ test-suite tests , filepath >=1.4.2.1 && <1.5 , nri-prelude >=0.1.0.0 && <0.7 , nri-redis >=0.1.0.0 && <0.4 - , servant >=0.16.2 && <0.21 - , servant-auth-server >=0.4.5.1 && <0.5 - , servant-server >=0.16.2 && <0.21 + , servant >=0.20.2 && <0.21 + , servant-auth-server >=0.4.9.0 && <0.5 + , servant-server >=0.20.2 && <0.21 , text >=1.2.3.1 && <2.2 default-language: Haskell2010 diff --git a/nri-test-encoding/package.yaml b/nri-test-encoding/package.yaml index c49e5157..23f73507 100644 --- a/nri-test-encoding/package.yaml +++ b/nri-test-encoding/package.yaml @@ -19,9 +19,9 @@ dependencies: - base >= 4.17 && < 4.20 - bytestring >= 0.10.8.2 && < 0.13 - filepath >= 1.4.2.1 && < 1.5 - - servant >= 0.16.2 && < 0.21 - - servant-auth-server >= 0.4.5.1 && < 0.5 - - servant-server >= 0.16.2 && < 0.21 + - servant >= 0.20.2 && < 0.21 + - servant-auth-server >= 0.4.9.0 && < 0.5 + - servant-server >= 0.20.2 && < 0.21 - text >= 1.2.3.1 && < 2.2 - nri-prelude >= 0.1.0.0 && < 0.7 - nri-redis >= 0.1.0.0 && < 0.4 diff --git a/nri-test-encoding/src/Test/Encoding/Routes.hs b/nri-test-encoding/src/Test/Encoding/Routes.hs index aa502859..ce33fe9b 100644 --- a/nri-test-encoding/src/Test/Encoding/Routes.hs +++ b/nri-test-encoding/src/Test/Encoding/Routes.hs @@ -1,6 +1,7 @@ {-# LANGUAGE GADTs #-} {-# LANGUAGE PolyKinds #-} {-# LANGUAGE RankNTypes #-} +{-# LANGUAGE UndecidableInstances #-} {-# OPTIONS_GHC -fno-warn-orphans #-} -- | Test helpers to ensure we don't change types or encodings of types @@ -27,6 +28,7 @@ import qualified Servant import Servant.API ( Capture', Header', + NamedRoutes, QueryFlag, QueryParam', QueryParams, @@ -207,6 +209,9 @@ class IsApi a where instance (IsApi a, IsApi b) => IsApi (a :<|> b) where crawl _ = crawl (Proxy :: Proxy a) ++ crawl (Proxy :: Proxy b) +instance (IsApi (ToServantApi a)) => IsApi (NamedRoutes a) where + crawl _ = crawl (Proxy :: Proxy (ToServantApi a)) + instance (KnownSymbol s, IsApi a) => IsApi (s :> a) where crawl _ = crawl (Proxy :: Proxy a) diff --git a/nri-test-encoding/test/Main.hs b/nri-test-encoding/test/Main.hs index e2bf0ea6..6fab2da7 100644 --- a/nri-test-encoding/test/Main.hs +++ b/nri-test-encoding/test/Main.hs @@ -1,3 +1,5 @@ +{-# LANGUAGE DuplicateRecordFields #-} + module Main (main) where import Data.Aeson @@ -54,16 +56,68 @@ instance HasExamples Bar where description = "description" } +data Baz = Baz + { title :: Text, + description :: Text + } + deriving (Generic) + +instance ToJSON Baz + +instance HasExamples Baz where + examples _ = + example + "Baz" + Baz + { title = "title", + description = "description" + } + +data Qux = Qux + { title :: Text, + description :: Text + } + deriving (Generic) + +instance ToJSON Qux + +instance HasExamples Qux where + examples _ = + example + "Qux" + Qux + { title = "title", + description = "description" + } + data Routes route = Routes { foo :: route :- "foos" - :> Capture ":id" Int + :> Capture "id" Int :> Get '[JSON] Foo, bars :: route :- "bars" - :> Get '[JSON] [Bar] + :> Get '[JSON] [Bar], + baz :: route :- NamedRoutes BazRoutes + } + deriving (Generic) + +data BazRoutes route = BazRoutes + { baz :: + route + :- "baz" + :> Get '[JSON] Baz, + qux :: route :- "quxs" :> Capture "id" Int :> NamedRoutes QuxRoutes + } + deriving (Generic) + +newtype QuxRoutes route = QuxRoutes + { qux :: + route + :- "details" + :> Get '[JSON] Qux } deriving (Generic) diff --git a/nri-test-encoding/test/golden-results/'GET-baz.json b/nri-test-encoding/test/golden-results/'GET-baz.json new file mode 100644 index 00000000..9c0ab323 --- /dev/null +++ b/nri-test-encoding/test/golden-results/'GET-baz.json @@ -0,0 +1,5 @@ +Baz +{ + "description": "description", + "title": "title" +} \ No newline at end of file diff --git a/nri-test-encoding/test/golden-results/'GET-foos-::id.json b/nri-test-encoding/test/golden-results/'GET-foos-:id.json similarity index 100% rename from nri-test-encoding/test/golden-results/'GET-foos-::id.json rename to nri-test-encoding/test/golden-results/'GET-foos-:id.json diff --git a/nri-test-encoding/test/golden-results/'GET-quxs-:id-details.json b/nri-test-encoding/test/golden-results/'GET-quxs-:id-details.json new file mode 100644 index 00000000..6acd7f1e --- /dev/null +++ b/nri-test-encoding/test/golden-results/'GET-quxs-:id-details.json @@ -0,0 +1,5 @@ +Qux +{ + "description": "description", + "title": "title" +} \ No newline at end of file diff --git a/nri-test-encoding/test/golden-results/route-types.json b/nri-test-encoding/test/golden-results/route-types.json index 705ab51c..80b3890f 100644 --- a/nri-test-encoding/test/golden-results/route-types.json +++ b/nri-test-encoding/test/golden-results/route-types.json @@ -1,2 +1,4 @@ 'GET bars response [ Bar ] -'GET foos/::id response Foo \ No newline at end of file +'GET baz response Baz +'GET foos/:id response Foo +'GET quxs/:id/details response Qux \ No newline at end of file