diff --git a/src/Servant/PY.hs b/src/Servant/PY.hs index 275efdd..8fdc16c 100644 --- a/src/Servant/PY.hs +++ b/src/Servant/PY.hs @@ -48,6 +48,9 @@ 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 +-- | Generate the data necessary to generate Python code +-- for all the endpoints of an API, but try to get as much type-information +-- into Python docstrings, in order to aid discoverability of client functions. pythonTyped :: HasForeign Python Text api => Proxy api -> Foreign Text api pythonTyped p = foreignFor (Proxy :: Proxy Python) (Proxy :: Proxy Text) p defReq diff --git a/src/Servant/PY/Internal.hs b/src/Servant/PY/Internal.hs index b2facc7..7e6db3f 100644 --- a/src/Servant/PY/Internal.hs +++ b/src/Servant/PY/Internal.hs @@ -28,7 +28,6 @@ module Servant.PY.Internal , captures , withFormattedCaptures , buildDocString - , buildDocStringWithTypes , buildHeaderDict , functionArguments , formatBuilder @@ -286,7 +285,7 @@ capturesToFormatArgs segments = map getSegment $ filter isCapture segments getSegment _ = "" getCapture s = s ^. argName . _PathSegment -buildDocString :: PyRequest -> CommonGeneratorOptions -> T.Text +buildDocString :: forall f. Req f -> CommonGeneratorOptions -> T.Text buildDocString req opts = T.toUpper method <> " \"" <> url <> "\n" <> includeArgs <> "\n\n" <> indent' <> "Returns: " <> "\n" @@ -301,19 +300,3 @@ buildDocString req opts = T.toUpper method <> " \"" <> url <> "\n" returnVal = case returnMode opts of DangerMode -> "JSON response from the endpoint" RawResponse -> "response (requests.Response) from issuing the request" - -buildDocStringWithTypes :: PyTypedRequest -> CommonGeneratorOptions -> T.Text -buildDocStringWithTypes req opts = T.toUpper method <> " \"" <> url <> "\n" - <> includeArgs <> "\n\n" - <> indent' <> "Returns: " <> "\n" - <> indent' <> indent' <> returnVal - where args = capturesToFormatArgs $ req ^.. reqUrl.path.traverse - method = decodeUtf8 $ req ^. reqMethod - url = makePyUrl' $ req ^.. reqUrl.path.traverse - includeArgs = if null args then "" else argDocs - argDocs = indent' <> "Args: " <> "\n" - <> indent' <> indent' <> T.intercalate ("\n" <> indent' <> indent') args - indent' = indentation opts indent - returnVal = case returnMode opts of - DangerMode -> "JSON response from the endpoint" - RawResponse -> "response (requests.Response) from issuing the request" diff --git a/src/Servant/PY/Requests.hs b/src/Servant/PY/Requests.hs index a8667c0..3092dfe 100644 --- a/src/Servant/PY/Requests.hs +++ b/src/Servant/PY/Requests.hs @@ -91,7 +91,7 @@ generatePyTypedRequestWith :: CommonGeneratorOptions -> PyTypedRequest -> Text generatePyTypedRequestWith opts req = "\n" <> "def " <> fname <> "(" <> argsStr <> "):\n" <> indent' <> docStringMarker - <> indent' <> buildDocStringWithTypes req opts <> "\n" + <> indent' <> buildDocString req opts <> "\n" <> indent' <> docStringMarker <> indent' <> "url = " <> makePyUrl opts req (indent' <> indent') <> "\n\n" <> headerDef