@@ -53,22 +53,16 @@ data ElmOptions = ElmOptions
55 urlPrefix :: UrlPrefix
55 urlPrefix :: UrlPrefix
56− , elmTypeAlterations :: (EType -> EType)
56+ , elmTypeAlterations :: (EType -> EType)
57 -- ^ Alterations to perform on ETypes before code generation.
57 -- ^ Alterations to perform on ETypes before code generation.
58 , elmAlterations :: (ETypeDef -> ETypeDef)
58 , elmAlterations :: (ETypeDef -> ETypeDef)
59 -- ^ Alterations to perform on ETypeDefs before code generation.
59 -- ^ Alterations to perform on ETypeDefs before code generation.
60− , elmToString :: (EType -> Text)
60+ , elmToString :: (EType -> Text)
61 -- ^ Elm functions creating a string from a given type.
61 -- ^ Elm functions creating a string from a given type.
62 , emptyResponseElmTypes :: [EType]
62 , emptyResponseElmTypes :: [EType]
63 -- ^ Types that represent an empty Http response.
63 -- ^ Types that represent an empty Http response.
64 , stringElmTypes :: [EType]
64 , stringElmTypes :: [EType]
65 -- ^ Types that represent a String.
65 -- ^ Types that represent a String.
66− , expectJsonMethod :: Text
67− -- ^ The function to use for JSON responses.
68− , expectStringMethod :: Text
69− -- ^ The function to use for string responses.
70− , httpErrorType :: Text
71− -- ^ The type to use for Http errors.
@@ -92,9 +86,6 @@ The default options are:
92> , stringElmTypes =
86> , stringElmTypes =
93> [ getType (Proxy :: Proxy String)
87> [ getType (Proxy :: Proxy String)
94> , getType (Proxy :: Proxy T.Text) ]
88> , getType (Proxy :: Proxy T.Text) ]
95−> , expectJsonMethod = "Http.expectJson"
96−> , expectStringMethod = "Http.expectString"
97−> , httpErrorType = "Http.Error"
100defElmOptions :: ElmOptions
91defElmOptions :: ElmOptions
@@ -110,9 +101,6 @@ defElmOptions = ElmOptions
110 [ toElmType (Proxy :: Proxy String)
101 [ toElmType (Proxy :: Proxy String)
111 , toElmType (Proxy :: Proxy T.Text)
102 , toElmType (Proxy :: Proxy T.Text)
113− , expectJsonMethod = "Http.expectJson"
114− , expectStringMethod = "Http.expectString"
115− , httpErrorType = "Http.Error"
@@ -131,7 +119,6 @@ The default required imports are:
131> import Set
119> import Set
132> import Http
120> import Http
133> import String
121> import String
135> import Url.Builder
122> import Url.Builder
137defElmImports :: Text
124defElmImports :: Text
@@ -145,7 +132,6 @@ defElmImports =
145 , "import Set"
132 , "import Set"
146 , "import Http"
133 , "import Http"
147 , "import String"
134 , "import String"
149 , "import Url.Builder"
135 , "import Url.Builder"
@@ -259,7 +245,7 @@ generateElmForRequest opts request =
260 request ^. F.reqFuncName . to (replace . F.camelCase) . to stext
246 request ^. F.reqFuncName . to (replace . F.camelCase) . to stext
262− replace = T.replace "-" "" . T.replace "." "" . T.replace " " ""
248+ replace = T.replace "-" "" . T.replace "." ""
264 typeSignature =
250 typeSignature =
265 mkTypeSignature opts request
251 mkTypeSignature opts request
@@ -321,7 +307,7 @@ mkTypeSignature opts request =
321 toMsgType :: Maybe Doc
307 toMsgType :: Maybe Doc
322 toMsgType = do
308 toMsgType = do
323 result <- fmap elmTypeRef $ request ^. F.reqReturnType
309 result <- fmap elmTypeRef $ request ^. F.reqReturnType
324− Just ("(Result" <+> stext (httpErrorType opts) <+> parens result <+> "-> msg)")
310+ Just ("(Result Http.Error " <+> parens result <+> " -> msg)")
326 returnType :: Maybe Doc
312 returnType :: Maybe Doc
327 returnType = do
313 returnType = do
@@ -339,7 +325,7 @@ elmCaptureArg segment =
339 "capture_" <>
325 "capture_" <>
340 F.captureArg segment ^. F.argName . to (stext . replace . F.unPathSegment)
326 F.captureArg segment ^. F.argName . to (stext . replace . F.unPathSegment)
342− replace = T.replace "-" "_" . T.replace " " "_"
328+ replace = T.replace "-" "_"
345elmQueryArg :: F.QueryArg EType -> Doc
331elmQueryArg :: F.QueryArg EType -> Doc
@@ -510,14 +496,14 @@ mkRequest opts request =
511 case request ^. F.reqReturnType of
497 case request ^. F.reqReturnType of
512 Just elmTypeExpr
498 Just elmTypeExpr
513− | isEmptyType opts $ (elmTypeAlterations opts) elmTypeExpr
499+ | isEmptyType opts elmTypeExpr
514 -- let elmConstructor = T.pack (renderElm elmTypeExpr)
500 -- let elmConstructor = T.pack (renderElm elmTypeExpr)
516− stext (expectStringMethod opts) <> line <+> indent i "(\\x -> case x of" <> line <+>
502+ "Http.expectString " <> line <+> indent i "(\\x -> case x of" <> line <+>
517 indent i "Err e -> toMsg (Err e)" <> line <+>
503 indent i "Err e -> toMsg (Err e)" <> line <+>
518 indent i "Ok _ -> toMsg (Ok ()))"
504 indent i "Ok _ -> toMsg (Ok ()))"
519 Just elmTypeExpr ->
505 Just elmTypeExpr ->
520− stext (expectJsonMethod opts) <+> "toMsg" <+> renderDecoderName ((elmTypeAlterations opts) elmTypeExpr)
506+ "Http.expectJson toMsg" <+> renderDecoderName elmTypeExpr
521 Nothing -> error "mkHttpRequest: no reqReturnType?"
507 Nothing -> error "mkHttpRequest: no reqReturnType?"
522 -- case request ^. F.reqReturnType of
508 -- case request ^. F.reqReturnType of
523 -- Just elmTypeExpr | isEmptyType opts elmTypeExpr ->
509 -- Just elmTypeExpr | isEmptyType opts elmTypeExpr ->
@@ -575,9 +561,9 @@ mkUrl opts segments =
575 F.Cap arg ->
561 F.Cap arg ->
577 toStringSrc =
563 toStringSrc =
578− toString opts (elmTypeAlterations opts (maybeOf (arg ^. F.argType)))
564+ toString opts (maybeOf (arg ^. F.argType))
580− "Url.percentEncode " <> pipeRight [elmCaptureArg s, toStringSrc]
566+ pipeRight [elmCaptureArg s, toStringSrc]
583mkQueryParams
569mkQueryParams
@@ -595,7 +581,7 @@ response body.
596isEmptyType :: ElmOptions -> EType -> Bool
582isEmptyType :: ElmOptions -> EType -> Bool
597isEmptyType opts elmTypeExpr =
583isEmptyType opts elmTypeExpr =
598− (elmTypeAlterations opts elmTypeExpr) `elem` emptyResponseElmTypes opts
584+ elmTypeExpr `elem` emptyResponseElmTypes opts
601{- | Determines whether we call `toString` on URL captures and query params of
587{- | Determines whether we call `toString` on URL captures and query params of
@@ -603,7 +589,7 @@ this type in Elm.
604isElmStringType :: ElmOptions -> EType -> Bool
590isElmStringType :: ElmOptions -> EType -> Bool
605isElmStringType opts elmTypeExpr =
591isElmStringType opts elmTypeExpr =
606− (elmTypeAlterations opts elmTypeExpr) `elem` stringElmTypes opts
592+ elmTypeExpr `elem` stringElmTypes opts
608{- | Determines whether a type is 'Maybe a' where 'a' is something akin to a 'String'.
594{- | Determines whether a type is 'Maybe a' where 'a' is something akin to a 'String'.