packages feed

servant-foreign 0.8 → 0.8.1

raw patch · 3 files changed

+32/−3 lines, 3 filesnew-uploader

Files

servant-foreign.cabal view
@@ -1,5 +1,5 @@ name:                servant-foreign-version:             0.8+version:             0.8.1 synopsis:            Helpers for generating clients for servant APIs in any programming language description:   Helper types and functions for generating client functions for servant APIs in any programming language
src/Servant/Foreign/Internal.hs view
@@ -211,6 +211,21 @@         { _argName = PathSegment str         , _argType = ftype } +instance (KnownSymbol sym, HasForeignType lang ftype [t], HasForeign lang ftype sublayout)+  => HasForeign lang ftype (CaptureAll sym t :> sublayout) where+  type Foreign ftype (CaptureAll sym t :> sublayout) = Foreign ftype sublayout++  foreignFor lang Proxy Proxy req =+    foreignFor lang Proxy (Proxy :: Proxy sublayout) $+      req & reqUrl . path <>~ [Segment (Cap arg)]+          & reqFuncName . _FunctionName %~ (++ ["by", str])+    where+      str   = pack . symbolVal $ (Proxy :: Proxy sym)+      ftype = typeFor lang (Proxy :: Proxy ftype) (Proxy :: Proxy [t])+      arg   = Arg+        { _argName = PathSegment str+        , _argType = ftype }+ instance (Elem JSON list, HasForeignType lang ftype a, ReflectMethod method)   => HasForeign lang ftype (Verb method status list a) where   type Foreign ftype (Verb method status list a) = Req ftype
test/Servant/ForeignSpec.hs view
@@ -46,6 +46,7 @@  :<|> "test" :> QueryParam "param" Int :> ReqBody '[JSON] [String] :> Post '[JSON] NoContent  :<|> "test" :> QueryParams "params" Int :> ReqBody '[JSON] String :> Put '[JSON] NoContent  :<|> "test" :> Capture "id" Int :> Delete '[JSON] NoContent+ :<|> "test" :> CaptureAll "ids" Int :> Get '[JSON] [Int]  testApi :: [Req String] testApi = listFromAPI (Proxy :: Proxy LangX) (Proxy :: Proxy String) (Proxy :: Proxy TestApi)@@ -53,9 +54,9 @@ listFromAPISpec :: Spec listFromAPISpec = describe "listFromAPI" $ do   it "generates 4 endpoints for TestApi" $ do-    length testApi `shouldBe` 4+    length testApi `shouldBe` 5 -  let [getReq, postReq, putReq, deleteReq] = testApi+  let [getReq, postReq, putReq, deleteReq, captureAllReq] = testApi    it "collects all info for get request" $ do     shouldBe getReq $ defReq@@ -105,4 +106,17 @@       , _reqBody       = Nothing       , _reqReturnType = Just "voidX"       , _reqFuncName   = FunctionName ["delete", "test", "by", "id"]+      }++  it "collects all info for capture all request" $ do+    shouldBe captureAllReq $ defReq+      { _reqUrl        = Url+          [ Segment $ Static "test"+          , Segment $ Cap (Arg "ids" "listX of intX") ]+          []+      , _reqMethod     = "GET"+      , _reqHeaders    = []+      , _reqBody       = Nothing+      , _reqReturnType = Just "listX of intX"+      , _reqFuncName   = FunctionName ["get", "test", "by", "ids"]       }