Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions nri-test-encoding/nri-test-encoding.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
6 changes: 3 additions & 3 deletions nri-test-encoding/package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions nri-test-encoding/src/Test/Encoding/Routes.hs
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -27,6 +28,7 @@ import qualified Servant
import Servant.API
( Capture',
Header',
NamedRoutes,
QueryFlag,
QueryParam',
QueryParams,
Expand Down Expand Up @@ -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)
Expand Down
58 changes: 56 additions & 2 deletions nri-test-encoding/test/Main.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{-# LANGUAGE DuplicateRecordFields #-}

module Main (main) where

import Data.Aeson
Expand Down Expand Up @@ -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)

Expand Down
5 changes: 5 additions & 0 deletions nri-test-encoding/test/golden-results/'GET-baz.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Baz
{
"description": "description",
"title": "title"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Qux
{
"description": "description",
"title": "title"
}
4 changes: 3 additions & 1 deletion nri-test-encoding/test/golden-results/route-types.json
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
'GET bars response [ Bar ]
'GET foos/::id response Foo
'GET baz response Baz
'GET foos/:id response Foo
'GET quxs/:id/details response Qux