Make Link take a Maybe argument for MatrixParam, just like QueryParam

This commit is contained in:
Alp Mestanogullari 2015-06-19 11:30:44 +02:00
parent 82328247e6
commit 0e22d19800
2 changed files with 4 additions and 4 deletions

View file

@ -303,10 +303,10 @@ instance (KnownSymbol sym, HasLink sub)
-- MatrixParam instances
instance (KnownSymbol sym, ToText v, HasLink sub)
=> HasLink (MatrixParam sym v :> sub) where
type MkLink (MatrixParam sym v :> sub) = v -> MkLink sub
toLink _ l v =
type MkLink (MatrixParam sym v :> sub) = Maybe v -> MkLink sub
toLink _ l mv =
toLink (Proxy :: Proxy sub) $
addMatrixParam (SingleParam k (toText v)) l
maybe id (addMatrixParam . SingleParam k . toText) mv l
where
k = symbolVal (Proxy :: Proxy sym)

View file

@ -67,7 +67,7 @@ spec = describe "Servant.Utils.Links" $ do
:> "child"
:> MatrixParam "gender" String
:> Get '[JSON] String)
apiLink l3 ["Hubert?x=;&", "Cumberdale"] "Edward?"
apiLink l3 ["Hubert?x=;&", "Cumberdale"] (Just "Edward?")
`shouldBeURI` "parent;name[]=Hubert%3Fx%3D%3B%26;\
\name[]=Cumberdale/child;gender=Edward%3F"