{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE TypeOperators #-}
module Servant.PY (
PythonGenerator
, python
, pythonTyped
, writePythonForAPI
, pyForAPI
, pyTypedForAPI
, writeTypedPythonForAPI
,
CommonGeneratorOptions(..)
, defCommonGeneratorOptions
, requests
,
concatCase
, snakeCase
, camelCase
,
listFromAPI
, NoTypes
, GenerateList(..)
, FunctionName(..)
) where
import Data.Proxy
import Data.Text (Text)
import qualified Data.Text as T
import Servant.Foreign
import Servant.PY.Internal
import Servant.PY.Python
import Servant.PY.Requests
python :: HasForeign NoTypes NoContent api => Proxy api -> Foreign NoContent api
python p = foreignFor (Proxy :: Proxy NoTypes) (Proxy :: Proxy NoContent) p defReq
pythonTyped :: HasForeign Python Text api => Proxy api -> Foreign Text api
pythonTyped p = foreignFor (Proxy :: Proxy Python) (Proxy :: Proxy Text) p defReq
pyForAPI :: (HasForeign NoTypes NoContent api, GenerateList NoContent (Foreign NoContent api))
=> Proxy api
-> PythonGenerator
-> Text
pyForAPI p gen = gen (UnTypedPythonRequest <$> listFromAPI (Proxy :: Proxy NoTypes) (Proxy :: Proxy NoContent) p)
writePythonForAPI :: (HasForeign NoTypes NoContent api, GenerateList NoContent (Foreign NoContent api))
=> Proxy api
-> PythonGenerator
-> FilePath
-> IO ()
writePythonForAPI p gen fp = writeFile fp (T.unpack $ pyForAPI p gen)
pyTypedForAPI :: (HasForeign Python T.Text api, GenerateList T.Text (Foreign T.Text api))
=> Proxy api
-> PythonGenerator
-> Text
pyTypedForAPI p gen = gen (TypedPythonRequest <$> listFromAPI (Proxy :: Proxy Python) (Proxy :: Proxy T.Text) p)
writeTypedPythonForAPI :: (HasForeign Python T.Text api, GenerateList T.Text (Foreign T.Text api))
=> Proxy api
-> PythonGenerator
-> FilePath
-> IO ()
writeTypedPythonForAPI p gen fp = writeFile fp (T.unpack $ pyTypedForAPI p gen)