git.iko.soy/haskell-servant/servant-elm
on 95c49ab help sign in
.github/workflows/build.yamldeleted−41
since splitsnapshots
unifiedsplit
@@ -1,41 +0,0 @@
1−name: Haskell CI
2−
3−on:
4− push:
5− branches: [ "master" ]
6− pull_request:
7− branches: [ "master" ]
8−
9−permissions:
10− contents: read
11−
12−jobs:
13− build:
14−
15− runs-on: ubuntu-latest
16−
17− steps:
18− - uses: actions/checkout@v3
19−
20− - name: Install Nix
21− uses: cachix/install-nix-action@v20
22− with:
23− nix_path: nixpkgs=channel:nixos-unstable
24−
25− - name: Cache
26− uses: actions/cache@v3
27− env:
28− cache-name: cache-cabal
29− with:
30− path: ~/.stack
31− key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/*.cabal') }}-${{ hashFiles('**/stack.yaml') }}
32− restore-keys: |
33− ${{ runner.os }}-build-${{ env.cache-name }}-
34− ${{ runner.os }}-build-
35− ${{ runner.os }}-
36−
37− - name: Build
38− run: stack build --test --no-run-tests
39−
40− - name: Run tests
41− run: stack test
servant-elm.cabal+1−1
@@ -1,5 +1,5 @@
1name: servant-elm
1name: servant-elm
2−version: 0.7.3
2+version: 0.7.2
3synopsis: Automatically derive Elm functions to query servant webservices.
3synopsis: Automatically derive Elm functions to query servant webservices.
4description: Please see README.md
4description: Please see README.md
5homepage: http://github.com/mattjbray/servant-elm#readme
5homepage: http://github.com/mattjbray/servant-elm#readme
src/Servant/Elm/Internal/Generate.hs+12−26
@@ -53,22 +53,16 @@ data ElmOptions = ElmOptions
53 argument.
53 argument.
54 -}
54 -}
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.
72 }
66 }
73
67
74
68
@@ -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"
98> }
89> }
99-}
90-}
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)
112 ]
103 ]
113− , expectJsonMethod = "Http.expectJson"
114− , expectStringMethod = "Http.expectString"
115− , httpErrorType = "Http.Error"
116 }
104 }
117
105
118
106
@@ -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
134−> import Url
135> import Url.Builder
122> import Url.Builder
136-}
123-}
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"
148− , "import Url"
149 , "import Url.Builder"
135 , "import Url.Builder"
150 ]
136 ]
151
137
@@ -259,7 +245,7 @@ generateElmForRequest opts request =
259 fnName =
245 fnName =
260 request ^. F.reqFuncName . to (replace . F.camelCase) . to stext
246 request ^. F.reqFuncName . to (replace . F.camelCase) . to stext
261
247
262− replace = T.replace "-" "" . T.replace "." "" . T.replace " " ""
248+ replace = T.replace "-" "" . T.replace "." ""
263
249
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)")
325
311
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)
341 where
327 where
342− replace = T.replace "-" "_" . T.replace " " "_"
328+ replace = T.replace "-" "_"
343
329
344
330
345elmQueryArg :: F.QueryArg EType -> Doc
331elmQueryArg :: F.QueryArg EType -> Doc
@@ -510,14 +496,14 @@ mkRequest opts request =
510 expect =
496 expect =
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)
515 ->
501 ->
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 ->
576 let
562 let
577 toStringSrc =
563 toStringSrc =
578− toString opts (elmTypeAlterations opts (maybeOf (arg ^. F.argType)))
564+ toString opts (maybeOf (arg ^. F.argType))
579 in
565 in
580− "Url.percentEncode " <> pipeRight [elmCaptureArg s, toStringSrc]
566+ pipeRight [elmCaptureArg s, toStringSrc]
581
567
582
568
583mkQueryParams
569mkQueryParams
@@ -595,7 +581,7 @@ response body.
595-}
581-}
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
599
585
600
586
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.
603-}
589-}
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
607
593
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'.
609-}
595-}
stack.yaml+4−5
@@ -1,9 +1,8 @@
1−resolver: lts-20.11
1+resolver: lts-15.8
2packages:
2packages:
3- '.'
3- '.'
4+extra-deps:
5+# - elm-bridge-0.5.2
6+- ../elm-bridge
4flags: {}
7flags: {}
5extra-package-dbs: []
8extra-package-dbs: []
6−nix:
7− enable: true
8− packages:
9− - zlib
test/Common.hs+5−7
@@ -5,9 +5,9 @@ module Common where
5
5
6import Data.Proxy (Proxy (Proxy))
6import Data.Proxy (Proxy (Proxy))
7import Data.Text (Text)
7import Data.Text (Text)
8−import Servant.API ((:<|>), (:>), Capture, Get, Header,
8+import Servant.API ((:<|>), (:>), Capture, Get, GetNoContent, Header,
9 Header', Headers, JSON, Post,
9 Header', Headers, JSON, Post,
10− Put, QueryFlag, QueryParam,
10+ PostNoContent, Put, QueryFlag, QueryParam,
11 QueryParam', QueryParams, ReqBody, Required)
11 QueryParam', QueryParams, ReqBody, Required)
12import Servant.Elm (deriveBoth, defaultOptions)
12import Servant.Elm (deriveBoth, defaultOptions)
13
13
@@ -27,7 +27,7 @@ type TestApi =
27 :> Capture "id" Int
27 :> Capture "id" Int
28 :> Get '[JSON] Book
28 :> Get '[JSON] Book
29 :<|> "books"
29 :<|> "books"
30− :> Capture "title space" Text
30+ :> Capture "title" Text
31 :> Get '[JSON] Book
31 :> Get '[JSON] Book
32 :<|> "books"
32 :<|> "books"
33 :> QueryFlag "published"
33 :> QueryFlag "published"
@@ -38,11 +38,9 @@ type TestApi =
38 :> Get '[JSON] [Book]
38 :> Get '[JSON] [Book]
39 :<|> "books"
39 :<|> "books"
40 :> ReqBody '[JSON] Book
40 :> ReqBody '[JSON] Book
41− -- :> PostNoContent '[JSON] ()
41+ :> PostNoContent '[JSON] ()
42− :> Post '[JSON] ()
43 :<|> "nothing"
42 :<|> "nothing"
44− :> Get '[JSON] ()
45− -- :> GetNoContent '[JSON] ()
43+ :> GetNoContent '[JSON] ()
46 :<|> "nothing"
44 :<|> "nothing"
47 :> Put '[JSON] () -- old way to specify no content
45 :> Put '[JSON] () -- old way to specify no content
48 :<|> "with-a-header"
46 :<|> "with-a-header"
test/CompileSpec.hs+1−1
@@ -45,7 +45,7 @@ spec = do
45 api = (Proxy :: Proxy TestApi)
45 api = (Proxy :: Proxy TestApi)
46 let out =
46 let out =
47 T.unlines $
47 T.unlines $
48− [ T.pack $ Elm.moduleHeader Elm0p19 moduleName
48+ [ T.pack $ Elm.moduleHeader Elm0p18 moduleName
49 , ""
49 , ""
50 , imports
50 , imports
51 , ""
51 , ""
test/elm-sources/getBooksByIdSource.elm+2−3
@@ -8,7 +8,7 @@ type Book = Book
8jsonDecBook : Json.Decode.Decoder Book
8jsonDecBook : Json.Decode.Decoder Book
9jsonDecBook = Debug.todo ""
9jsonDecBook = Debug.todo ""
10
10
11−getBooksById : Int -> (Result Http.Error (Book) -> msg) -> Cmd msg
11+getBooksById : Int -> (Result Http.Error (Book) -> msg) -> Cmd msg
12getBooksById capture_id toMsg =
12getBooksById capture_id toMsg =
13 let
13 let
14 params =
14 params =
@@ -24,8 +24,7 @@ getBooksById capture_id toMsg =
24 , url =
24 , url =
25 Url.Builder.crossOrigin ""
25 Url.Builder.crossOrigin ""
26 [ "books"
26 [ "books"
27− , Url.percentEncode (capture_id
28− |> String.fromInt)
27+ , (capture_id |> String.fromInt)
29 ]
28 ]
30 params
29 params
31 , body =
30 , body =
test/elm-sources/getBooksByTitleSource.elm+3−3
@@ -7,8 +7,8 @@ import Json.Decode as J
7type alias Book = {}
7type alias Book = {}
8jsonDecBook = J.succeed {}
8jsonDecBook = J.succeed {}
9
9
10−getBooksByTitlespace : String -> (Result Http.Error (Book) -> msg) -> Cmd msg
10+getBooksByTitle : String -> (Result Http.Error (Book) -> msg) -> Cmd msg
11−getBooksByTitlespace capture_title_space toMsg =
11+getBooksByTitle capture_title toMsg =
12 let
12 let
13 params =
13 params =
14 List.filterMap identity
14 List.filterMap identity
@@ -23,7 +23,7 @@ getBooksByTitlespace capture_title_space toMsg =
23 , url =
23 , url =
24 Url.Builder.crossOrigin ""
24 Url.Builder.crossOrigin ""
25 [ "books"
25 [ "books"
26− , Url.percentEncode (capture_title_space)
26+ , (capture_title)
27 ]
27 ]
28 params
28 params
29 , body =
29 , body =
test/elm-sources/getBooksSource.elm+1−1
@@ -9,7 +9,7 @@ type alias Book = {}
9
9
10jsonDecBook = J.succeed {}
10jsonDecBook = J.succeed {}
11
11
12−getBooks : Bool -> (Maybe String) -> (Maybe Int) -> String -> (List (Maybe Bool)) -> (Result Http.Error ((List Book)) -> msg) -> Cmd msg
12+getBooks : Bool -> (Maybe String) -> (Maybe Int) -> String -> (List (Maybe Bool)) -> (Result Http.Error ((List Book)) -> msg) -> Cmd msg
13getBooks query_published query_sort query_year query_category query_filters toMsg =
13getBooks query_published query_sort query_year query_category query_filters toMsg =
14 let
14 let
15 params =
15 params =
test/elm-sources/getNothingSource.elm+2−2
@@ -4,7 +4,7 @@ import Http
4import Url.Builder
4import Url.Builder
5
5
6
6
7−getNothing : (Result Http.Error (()) -> msg) -> Cmd msg
7+getNothing : (Result Http.Error (()) -> msg) -> Cmd msg
8getNothing toMsg =
8getNothing toMsg =
9 let
9 let
10 params =
10 params =
@@ -25,7 +25,7 @@ getNothing toMsg =
25 , body =
25 , body =
26 Http.emptyBody
26 Http.emptyBody
27 , expect =
27 , expect =
28− Http.expectString
28+ Http.expectString
29 (\x -> case x of
29 (\x -> case x of
30 Err e -> toMsg (Err e)
30 Err e -> toMsg (Err e)
31 Ok _ -> toMsg (Ok ()))
31 Ok _ -> toMsg (Ok ()))
test/elm-sources/getOneSource.elm+1−1
@@ -5,7 +5,7 @@ import Json.Decode exposing (..)
5import Url.Builder
5import Url.Builder
6
6
7
7
8−getOne : (Result Http.Error (Int) -> msg) -> Cmd msg
8+getOne : (Result Http.Error (Int) -> msg) -> Cmd msg
9getOne toMsg =
9getOne toMsg =
10 let
10 let
11 params =
11 params =
test/elm-sources/getOneWithDynamicUrlSource.elm+1−1
@@ -5,7 +5,7 @@ import Url.Builder
5import Json.Decode exposing (..)
5import Json.Decode exposing (..)
6
6
7
7
8−getOne : String -> (Result Http.Error (Int) -> msg) -> Cmd msg
8+getOne : String -> (Result Http.Error (Int) -> msg) -> Cmd msg
9getOne urlBase toMsg =
9getOne urlBase toMsg =
10 let
10 let
11 params =
11 params =
test/elm-sources/getPolymorphicData.elm+1−1
@@ -14,7 +14,7 @@ jsonDecSomeRecord : Json.Decode.Decoder SomeRecord
14jsonDecSomeRecord = Debug.todo "finish"
14jsonDecSomeRecord = Debug.todo "finish"
15
15
16
16
17−getPolymorphicData : (Result Http.Error ((PolymorphicData (List String) SomeRecord)) -> msg) -> Cmd msg
17+getPolymorphicData : (Result Http.Error ((PolymorphicData (List String) SomeRecord)) -> msg) -> Cmd msg
18getPolymorphicData toMsg =
18getPolymorphicData toMsg =
19 let
19 let
20 params =
20 params =
test/elm-sources/getWithaheaderSource.elm+1−1
@@ -5,7 +5,7 @@ import Url.Builder
5import Json.Decode exposing (..)
5import Json.Decode exposing (..)
6
6
7
7
8−getWithaheader : (Maybe String) -> (Maybe Int) -> String -> Int -> (Result Http.Error (String) -> msg) -> Cmd msg
8+getWithaheader : (Maybe String) -> (Maybe Int) -> String -> Int -> (Result Http.Error (String) -> msg) -> Cmd msg
9getWithaheader header_myStringHeader header_MyIntHeader header_MyRequiredStringHeader header_MyRequiredIntHeader toMsg =
9getWithaheader header_myStringHeader header_MyIntHeader header_MyRequiredStringHeader header_MyRequiredIntHeader toMsg =
10 let
10 let
11 params =
11 params =
test/elm-sources/getWitharesponseheaderSource.elm+1−1
@@ -5,7 +5,7 @@ import Url.Builder
5import Json.Decode exposing (..)
5import Json.Decode exposing (..)
6
6
7
7
8−getWitharesponseheader : (Result Http.Error (String) -> msg) -> Cmd msg
8+getWitharesponseheader : (Result Http.Error (String) -> msg) -> Cmd msg
9getWitharesponseheader toMsg =
9getWitharesponseheader toMsg =
10 let
10 let
11 params =
11 params =
test/elm-sources/postBooksSource.elm+2−2
@@ -7,7 +7,7 @@ import Json.Encode as Enc
7type alias Book = {}
7type alias Book = {}
8jsonEncBook = \b -> Enc.object []
8jsonEncBook = \b -> Enc.object []
9
9
10−postBooks : Book -> (Result Http.Error (()) -> msg) -> Cmd msg
10+postBooks : Book -> (Result Http.Error (()) -> msg) -> Cmd msg
11postBooks body toMsg =
11postBooks body toMsg =
12 let
12 let
13 params =
13 params =
@@ -28,7 +28,7 @@ postBooks body toMsg =
28 , body =
28 , body =
29 Http.jsonBody (jsonEncBook body)
29 Http.jsonBody (jsonEncBook body)
30 , expect =
30 , expect =
31− Http.expectString
31+ Http.expectString
32 (\x -> case x of
32 (\x -> case x of
33 Err e -> toMsg (Err e)
33 Err e -> toMsg (Err e)
34 Ok _ -> toMsg (Ok ()))
34 Ok _ -> toMsg (Ok ()))
test/elm-sources/postTwoSource.elm+1−1
@@ -6,7 +6,7 @@ import Json.Encode
6import Url.Builder
6import Url.Builder
7
7
8
8
9−postTwo : String -> (Result Http.Error ((Maybe Int)) -> msg) -> Cmd msg
9+postTwo : String -> (Result Http.Error ((Maybe Int)) -> msg) -> Cmd msg
10postTwo body toMsg =
10postTwo body toMsg =
11 let
11 let
12 params =
12 params =
test/elm-sources/putNothingSource.elm+2−2
@@ -4,7 +4,7 @@ import Http
4import Url.Builder
4import Url.Builder
5
5
6
6
7−putNothing : (Result Http.Error (()) -> msg) -> Cmd msg
7+putNothing : (Result Http.Error (()) -> msg) -> Cmd msg
8putNothing toMsg =
8putNothing toMsg =
9 let
9 let
10 params =
10 params =
@@ -25,7 +25,7 @@ putNothing toMsg =
25 , body =
25 , body =
26 Http.emptyBody
26 Http.emptyBody
27 , expect =
27 , expect =
28− Http.expectString
28+ Http.expectString
29 (\x -> case x of
29 (\x -> case x of
30 Err e -> toMsg (Err e)
30 Err e -> toMsg (Err e)
31 Ok _ -> toMsg (Ok ()))
31 Ok _ -> toMsg (Ok ()))