servant-csharp 0.0.2.0 → 0.0.3.0
raw patch · 3 files changed
+76/−18 lines, 3 filesPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
API changes (from Hackage documentation)
- CS: [template] :: GenerateCsConfig -> forall api. (HasForeign CSharp Text api, GenerateList Text (Foreign Text api)) => GenerateCsConfig -> Proxy api -> IO String
- CS: csForAPI :: (HasForeign CSharp Text api, GenerateList Text (Foreign Text api)) => Proxy api -> IO String
- CS: csForAPIWith :: (HasForeign CSharp Text api, GenerateList Text (Foreign Text api)) => GenerateCsConfig -> Proxy api -> IO String
- CS.JsonDotNet: [template] :: GenerateCsConfig -> forall api. (HasForeign CSharp Text api, GenerateList Text (Foreign Text api)) => GenerateCsConfig -> Proxy api -> IO String
- CS.JsonDotNet: csForAPI :: (HasForeign CSharp Text api, GenerateList Text (Foreign Text api)) => Proxy api -> IO String
- CS.JsonDotNet: csForAPIWith :: (HasForeign CSharp Text api, GenerateList Text (Foreign Text api)) => GenerateCsConfig -> Proxy api -> IO String
+ CS: [apitemplate] :: GenerateCsConfig -> forall api. (HasForeign CSharp Text api, GenerateList Text (Foreign Text api)) => GenerateCsConfig -> Proxy api -> IO String
+ CS: [enumtemplate] :: GenerateCsConfig -> GenerateCsConfig -> IO String
+ CS: apiCsForAPI :: (HasForeign CSharp Text api, GenerateList Text (Foreign Text api)) => Proxy api -> IO String
+ CS: apiCsForAPIWith :: (HasForeign CSharp Text api, GenerateList Text (Foreign Text api)) => GenerateCsConfig -> Proxy api -> IO String
+ CS: enumCsForAPI :: IO String
+ CS: enumCsForAPIWith :: GenerateCsConfig -> IO String
+ CS.JsonDotNet: [apitemplate] :: GenerateCsConfig -> forall api. (HasForeign CSharp Text api, GenerateList Text (Foreign Text api)) => GenerateCsConfig -> Proxy api -> IO String
+ CS.JsonDotNet: [enumtemplate] :: GenerateCsConfig -> GenerateCsConfig -> IO String
+ CS.JsonDotNet: apiCsForAPI :: (HasForeign CSharp Text api, GenerateList Text (Foreign Text api)) => Proxy api -> IO String
+ CS.JsonDotNet: apiCsForAPIWith :: (HasForeign CSharp Text api, GenerateList Text (Foreign Text api)) => GenerateCsConfig -> Proxy api -> IO String
+ CS.JsonDotNet: enumCsForAPI :: IO String
+ CS.JsonDotNet: enumCsForAPIWith :: GenerateCsConfig -> IO String
- CS: GenerateCsConfig :: String -> (forall api. (HasForeign CSharp Text api, GenerateList Text (Foreign Text api)) => GenerateCsConfig -> Proxy api -> IO String) -> [FilePath] -> GenerateCsConfig
+ CS: GenerateCsConfig :: String -> (forall api. (HasForeign CSharp Text api, GenerateList Text (Foreign Text api)) => GenerateCsConfig -> Proxy api -> IO String) -> (GenerateCsConfig -> IO String) -> [FilePath] -> GenerateCsConfig
- CS.JsonDotNet: GenerateCsConfig :: String -> (forall api. (HasForeign CSharp Text api, GenerateList Text (Foreign Text api)) => GenerateCsConfig -> Proxy api -> IO String) -> [FilePath] -> GenerateCsConfig
+ CS.JsonDotNet: GenerateCsConfig :: String -> (forall api. (HasForeign CSharp Text api, GenerateList Text (Foreign Text api)) => GenerateCsConfig -> Proxy api -> IO String) -> (GenerateCsConfig -> IO String) -> [FilePath] -> GenerateCsConfig
Files
- servant-csharp.cabal +1/−1
- src/CS.hs +4/−2
- src/CS/JsonDotNet.hs +71/−15
servant-csharp.cabal view
@@ -2,7 +2,7 @@ -- documentation, see http://haskell.org/cabal/users-guide/ name: servant-csharp-version: 0.0.2.0+version: 0.0.3.0 synopsis: Generate servant client library for C# description: Generate servant client library for C# homepage: https://github.com/cutsea110/servant-csharp.git
src/CS.hs view
@@ -1,5 +1,7 @@-module CS ( csForAPI- , csForAPIWith+module CS ( apiCsForAPI+ , apiCsForAPIWith+ , enumCsForAPI+ , enumCsForAPIWith , GenerateCsConfig(..) , def
src/CS/JsonDotNet.hs view
@@ -4,8 +4,10 @@ {-# LANGUAGE QuasiQuotes #-} {-# LANGUAGE RankNTypes #-} {-# LANGUAGE ScopedTypeVariables #-}-module CS.JsonDotNet ( csForAPI- , csForAPIWith+module CS.JsonDotNet ( apiCsForAPI+ , apiCsForAPIWith+ , enumCsForAPI+ , enumCsForAPIWith , GenerateCsConfig(..) , def@@ -30,21 +32,50 @@ data GenerateCsConfig = GenerateCsConfig { namespace :: String- , template :: forall api.- (HasForeign CSharp Text api,- GenerateList Text (Foreign Text api))- => GenerateCsConfig- -> Proxy api- -> IO String+ , apitemplate :: forall api.+ (HasForeign CSharp Text api,+ GenerateList Text (Foreign Text api))+ => GenerateCsConfig+ -> Proxy api+ -> IO String+ , enumtemplate :: GenerateCsConfig -> IO String , sources :: [FilePath] } def :: GenerateCsConfig def = GenerateCsConfig { namespace = "ServantClientAPI"- , template = defTemplate+ , apitemplate = defAPITemplate+ , enumtemplate = defEnumTemplate , sources = [] } +--------------------------------------------------------------------------+isEnumLikeDataDecl :: Decl -> Bool+isEnumLikeDataDecl (DataDecl _ DataType _ _ _ xs _)+ = all isEnumLikeConDecl xs+isEnumLikeDataDecl _ = False++isEnumLikeConDecl :: QualConDecl -> Bool+isEnumLikeConDecl (QualConDecl _ _ _ (ConDecl _ [])) = True+isEnumLikeConDecl _ = False++enumTypesFromFiles :: [FilePath] -> IO [(String, [String])]+enumTypesFromFiles hss+ = return . concat =<< mapM enumTypesFromFile hss++enumTypesFromFile :: FilePath -> IO [(String, [String])]+enumTypesFromFile hs = do+ ParseOk (Module _ _ _ _ _ _ decls) <- parseFile hs+ let xs = filter isEnumLikeDataDecl decls+ return $ map toTuple xs+ where+ conName :: QualConDecl -> String+ conName (QualConDecl _ _ _ (ConDecl (Ident name) [])) = name+ conName _ = error "invalid enum type"+ toTuple (DataDecl _ _ _ (Ident name) _ xs _)+ = (name, map conName xs)++-------------------------------------------------------------------------- -- | TODO : more typeable isNewtypeDecl :: Decl -> Bool isNewtypeDecl (DataDecl _ NewType _ _ _ _ _) = True@@ -71,6 +102,8 @@ where toTuple (DataDecl _ NewType _ (Ident name) _ [qcon] _) = (name, origType qcon)++-------------------------------------------------------------------------- retType :: Req Text -> String retType = T.unpack . fromJust . view reqReturnType @@ -148,20 +181,26 @@ requestBodyExists :: Req Text -> Bool requestBodyExists = not . null . rqBody -csForAPI :: (HasForeign CSharp Text api,+apiCsForAPI :: (HasForeign CSharp Text api, GenerateList Text (Foreign Text api)) => Proxy api -> IO String-csForAPI = csForAPIWith def+apiCsForAPI = apiCsForAPIWith def -csForAPIWith :: (HasForeign CSharp Text api,+apiCsForAPIWith :: (HasForeign CSharp Text api, GenerateList Text (Foreign Text api)) => GenerateCsConfig -> Proxy api -> IO String-csForAPIWith conf api = (template conf) conf api+apiCsForAPIWith conf api = (apitemplate conf) conf api -defTemplate :: (HasForeign CSharp Text api,+enumCsForAPI :: IO String+enumCsForAPI = enumCsForAPIWith def++enumCsForAPIWith :: GenerateCsConfig -> IO String+enumCsForAPIWith conf = (enumtemplate conf) conf++defAPITemplate :: (HasForeign CSharp Text api, GenerateList Text (Foreign Text api)) => GenerateCsConfig -> Proxy api -> IO String-defTemplate conf api = do+defAPITemplate conf api = do usingAliases <- usingAliasesFromFiles $ sources conf return [heredoc|/* generated by servant-csharp */ using Newtonsoft.Json;@@ -253,3 +292,20 @@ } } |]++defEnumTemplate conf = do+ es <- enumTypesFromFiles $ sources conf+ return [heredoc|/* generated by servant-csharp */+namespace ${namespace conf}+{+ $forall (name, cs) <- es+ #region ${name}+ public enum ${name}+ {+ $forall c <- cs+ ${c},+ }+ #endregion+}+|]+