Merge pull request #132 from haskell-servant/fix-129-queryparam-link
Tweak the HasLink instance for QueryParam, fixes #129
This commit is contained in:
commit
7399f30cc4
2 changed files with 10 additions and 10 deletions
|
@ -49,7 +49,7 @@
|
||||||
-- or without those:
|
-- or without those:
|
||||||
--
|
--
|
||||||
-- >>> let with = Proxy :: Proxy ("bye" :> QueryParam "name" String :> Delete '[JSON] ())
|
-- >>> let with = Proxy :: Proxy ("bye" :> QueryParam "name" String :> Delete '[JSON] ())
|
||||||
-- >>> print $ safeLink api with "Hubert"
|
-- >>> print $ safeLink api with (Just "Hubert")
|
||||||
-- bye?name=Hubert
|
-- bye?name=Hubert
|
||||||
--
|
--
|
||||||
-- >>> let without = Proxy :: Proxy ("bye" :> Delete '[JSON] ())
|
-- >>> let without = Proxy :: Proxy ("bye" :> Delete '[JSON] ())
|
||||||
|
@ -273,10 +273,10 @@ instance (KnownSymbol sym, HasLink sub) => HasLink (sym :> sub) where
|
||||||
-- QueryParam instances
|
-- QueryParam instances
|
||||||
instance (KnownSymbol sym, ToText v, HasLink sub)
|
instance (KnownSymbol sym, ToText v, HasLink sub)
|
||||||
=> HasLink (QueryParam sym v :> sub) where
|
=> HasLink (QueryParam sym v :> sub) where
|
||||||
type MkLink (QueryParam sym v :> sub) = v -> MkLink sub
|
type MkLink (QueryParam sym v :> sub) = Maybe v -> MkLink sub
|
||||||
toLink _ l v =
|
toLink _ l mv =
|
||||||
toLink (Proxy :: Proxy sub)
|
toLink (Proxy :: Proxy sub) $
|
||||||
(addQueryParam (SingleParam k (toText v)) l)
|
maybe id (addQueryParam . SingleParam k . toText) mv l
|
||||||
where
|
where
|
||||||
k :: String
|
k :: String
|
||||||
k = symbolVal (Proxy :: Proxy sym)
|
k = symbolVal (Proxy :: Proxy sym)
|
||||||
|
@ -303,10 +303,10 @@ instance (KnownSymbol sym, HasLink sub)
|
||||||
-- MatrixParam instances
|
-- MatrixParam instances
|
||||||
instance (KnownSymbol sym, ToText v, HasLink sub)
|
instance (KnownSymbol sym, ToText v, HasLink sub)
|
||||||
=> HasLink (MatrixParam sym v :> sub) where
|
=> HasLink (MatrixParam sym v :> sub) where
|
||||||
type MkLink (MatrixParam sym v :> sub) = v -> MkLink sub
|
type MkLink (MatrixParam sym v :> sub) = Maybe v -> MkLink sub
|
||||||
toLink _ l v =
|
toLink _ l mv =
|
||||||
toLink (Proxy :: Proxy sub) $
|
toLink (Proxy :: Proxy sub) $
|
||||||
addMatrixParam (SingleParam k (toText v)) l
|
maybe id (addMatrixParam . SingleParam k . toText) mv l
|
||||||
where
|
where
|
||||||
k = symbolVal (Proxy :: Proxy sym)
|
k = symbolVal (Proxy :: Proxy sym)
|
||||||
|
|
||||||
|
|
|
@ -61,13 +61,13 @@ spec = describe "Servant.Utils.Links" $ do
|
||||||
let l2 = Proxy :: Proxy ("hello" :> Capture "name" String
|
let l2 = Proxy :: Proxy ("hello" :> Capture "name" String
|
||||||
:> QueryParam "capital" Bool
|
:> QueryParam "capital" Bool
|
||||||
:> Delete '[JSON] ())
|
:> Delete '[JSON] ())
|
||||||
apiLink l2 "bye" True `shouldBeURI` "hello/bye?capital=true"
|
apiLink l2 "bye" (Just True) `shouldBeURI` "hello/bye?capital=true"
|
||||||
|
|
||||||
let l3 = Proxy :: Proxy ("parent" :> MatrixParams "name" String
|
let l3 = Proxy :: Proxy ("parent" :> MatrixParams "name" String
|
||||||
:> "child"
|
:> "child"
|
||||||
:> MatrixParam "gender" String
|
:> MatrixParam "gender" String
|
||||||
:> Get '[JSON] 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;\
|
`shouldBeURI` "parent;name[]=Hubert%3Fx%3D%3B%26;\
|
||||||
\name[]=Cumberdale/child;gender=Edward%3F"
|
\name[]=Cumberdale/child;gender=Edward%3F"
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue