Make Link take a Maybe argument for MatrixParam, just like QueryParam
This commit is contained in:
parent
82328247e6
commit
0e22d19800
2 changed files with 4 additions and 4 deletions
|
@ -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)
|
||||
|
||||
|
|
|
@ -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"
|
||||
|
||||
|
|
Loading…
Reference in a new issue