mirror of
https://github.com/scarf-sh/tie.git
synced 2024-11-23 02:56:59 +03:00
Streamline api call generation
This commit is contained in:
parent
8d43265515
commit
014652191f
@ -187,14 +187,17 @@ codegenCallApiMember operationName path queryParams headerParams requestBody =
|
||||
"run" <+> "request" <+> "(" <> "do" <> PP.line
|
||||
<> PP.indent
|
||||
4
|
||||
( "response" <+> "<-" <+> "Control.Monad.Catch.handle" <+> "pure" <+> "(" <> toApiMemberName operationName
|
||||
<+> "api"
|
||||
<+> PP.hsep
|
||||
( [toParamBinder name | VariableSegment Param {name} <- path]
|
||||
++ [toParamBinder name | Param {name} <- queryParams]
|
||||
++ [toParamBinder name | Param {name} <- headerParams]
|
||||
)
|
||||
<+> (maybe mempty (\_ -> "body") requestBody)
|
||||
( "response" <+> "<-" <+> "Control.Monad.Catch.handle" <+> "pure"
|
||||
<+> "("
|
||||
<> PP.hsep
|
||||
( concat
|
||||
[ [toApiMemberName operationName, "api"],
|
||||
[toParamBinder name | VariableSegment Param {name} <- path],
|
||||
[toParamBinder name | Param {name} <- queryParams],
|
||||
[toParamBinder name | Param {name} <- headerParams],
|
||||
["body" | Just {} <- [requestBody]]
|
||||
]
|
||||
)
|
||||
<> ")"
|
||||
<> PP.line
|
||||
<> "Control.Monad.IO.Class.liftIO"
|
||||
|
@ -49,7 +49,7 @@ application run api notFound request respond =
|
||||
case Network.Wai.requestMethod request of
|
||||
"GET" ->
|
||||
run request (do
|
||||
response <- Control.Monad.Catch.handle pure (test api )
|
||||
response <- Control.Monad.Catch.handle pure (test api)
|
||||
Control.Monad.IO.Class.liftIO (respond $! (toResponse response))
|
||||
)
|
||||
x ->
|
||||
|
@ -52,7 +52,7 @@ application run api notFound request respond =
|
||||
case Network.Wai.requestMethod request of
|
||||
"GET" ->
|
||||
run request (do
|
||||
response <- Control.Monad.Catch.handle pure (dummy api __entity )
|
||||
response <- Control.Monad.Catch.handle pure (dummy api __entity)
|
||||
Control.Monad.IO.Class.liftIO (respond $! (toResponse response))
|
||||
)
|
||||
x ->
|
||||
|
@ -66,7 +66,7 @@ application run api notFound request respond =
|
||||
case Network.Wai.requestMethod request of
|
||||
"GET" ->
|
||||
run request (do
|
||||
response <- Control.Monad.Catch.handle pure (listPackages api )
|
||||
response <- Control.Monad.Catch.handle pure (listPackages api)
|
||||
Control.Monad.IO.Class.liftIO (respond $! (toResponse response))
|
||||
)
|
||||
x ->
|
||||
@ -76,7 +76,7 @@ application run api notFound request respond =
|
||||
case Network.Wai.requestMethod request of
|
||||
"GET" ->
|
||||
run request (do
|
||||
response <- Control.Monad.Catch.handle pure (listPackages2 api )
|
||||
response <- Control.Monad.Catch.handle pure (listPackages2 api)
|
||||
Control.Monad.IO.Class.liftIO (respond $! (toResponse response))
|
||||
)
|
||||
x ->
|
||||
@ -87,7 +87,7 @@ application run api notFound request respond =
|
||||
"GET" ->
|
||||
optionalQueryParameter "order" False (\__order request respond ->
|
||||
run request (do
|
||||
response <- Control.Monad.Catch.handle pure (listPackages3 api __order )
|
||||
response <- Control.Monad.Catch.handle pure (listPackages3 api __order)
|
||||
Control.Monad.IO.Class.liftIO (respond $! (toResponse response))
|
||||
)) request respond
|
||||
x ->
|
||||
@ -98,7 +98,7 @@ application run api notFound request respond =
|
||||
"GET" ->
|
||||
optionalQueryParameter "order" False (\__order request respond ->
|
||||
run request (do
|
||||
response <- Control.Monad.Catch.handle pure (listPackages4 api __order )
|
||||
response <- Control.Monad.Catch.handle pure (listPackages4 api __order)
|
||||
Control.Monad.IO.Class.liftIO (respond $! (toResponse response))
|
||||
)) request respond
|
||||
x ->
|
||||
|
@ -60,7 +60,7 @@ application run api notFound request respond =
|
||||
"GET" ->
|
||||
optionalHeader "x-next" (\__x_next request respond ->
|
||||
run request (do
|
||||
response <- Control.Monad.Catch.handle pure (test api __x_next )
|
||||
response <- Control.Monad.Catch.handle pure (test api __x_next)
|
||||
Control.Monad.IO.Class.liftIO (respond $! (toResponse response))
|
||||
)) request respond
|
||||
x ->
|
||||
@ -70,7 +70,7 @@ application run api notFound request respond =
|
||||
case Network.Wai.requestMethod request of
|
||||
"GET" ->
|
||||
run request (do
|
||||
response <- Control.Monad.Catch.handle pure (test1 api )
|
||||
response <- Control.Monad.Catch.handle pure (test1 api)
|
||||
Control.Monad.IO.Class.liftIO (respond $! (toResponse response))
|
||||
)
|
||||
x ->
|
||||
@ -80,7 +80,7 @@ application run api notFound request respond =
|
||||
case Network.Wai.requestMethod request of
|
||||
"GET" ->
|
||||
run request (do
|
||||
response <- Control.Monad.Catch.handle pure (test2 api )
|
||||
response <- Control.Monad.Catch.handle pure (test2 api)
|
||||
Control.Monad.IO.Class.liftIO (respond $! (toResponse response))
|
||||
)
|
||||
x ->
|
||||
|
@ -59,7 +59,7 @@ application run api notFound request respond =
|
||||
case Network.Wai.requestMethod request of
|
||||
"GET" ->
|
||||
run request (do
|
||||
response <- Control.Monad.Catch.handle pure (listPackages api )
|
||||
response <- Control.Monad.Catch.handle pure (listPackages api)
|
||||
Control.Monad.IO.Class.liftIO (respond $! (toResponse response))
|
||||
)
|
||||
x ->
|
||||
@ -69,7 +69,7 @@ application run api notFound request respond =
|
||||
case Network.Wai.requestMethod request of
|
||||
"GET" ->
|
||||
run request (do
|
||||
response <- Control.Monad.Catch.handle pure (listPackages2 api )
|
||||
response <- Control.Monad.Catch.handle pure (listPackages2 api)
|
||||
Control.Monad.IO.Class.liftIO (respond $! (toResponse response))
|
||||
)
|
||||
x ->
|
||||
@ -79,7 +79,7 @@ application run api notFound request respond =
|
||||
case Network.Wai.requestMethod request of
|
||||
"GET" ->
|
||||
run request (do
|
||||
response <- Control.Monad.Catch.handle pure (listPackages3 api )
|
||||
response <- Control.Monad.Catch.handle pure (listPackages3 api)
|
||||
Control.Monad.IO.Class.liftIO (respond $! (toResponse response))
|
||||
)
|
||||
x ->
|
||||
|
@ -49,7 +49,7 @@ application run api notFound request respond =
|
||||
case Network.Wai.requestMethod request of
|
||||
"GET" ->
|
||||
run request (do
|
||||
response <- Control.Monad.Catch.handle pure (test api )
|
||||
response <- Control.Monad.Catch.handle pure (test api)
|
||||
Control.Monad.IO.Class.liftIO (respond $! (toResponse response))
|
||||
)
|
||||
x ->
|
||||
|
@ -59,7 +59,7 @@ application run api notFound request respond =
|
||||
case Network.Wai.requestMethod request of
|
||||
"GET" ->
|
||||
run request (do
|
||||
response <- Control.Monad.Catch.handle pure (listPackages api )
|
||||
response <- Control.Monad.Catch.handle pure (listPackages api)
|
||||
Control.Monad.IO.Class.liftIO (respond $! (toResponse response))
|
||||
)
|
||||
x ->
|
||||
@ -69,7 +69,7 @@ application run api notFound request respond =
|
||||
case Network.Wai.requestMethod request of
|
||||
"GET" ->
|
||||
run request (do
|
||||
response <- Control.Monad.Catch.handle pure (listPackages2 api )
|
||||
response <- Control.Monad.Catch.handle pure (listPackages2 api)
|
||||
Control.Monad.IO.Class.liftIO (respond $! (toResponse response))
|
||||
)
|
||||
x ->
|
||||
@ -79,7 +79,7 @@ application run api notFound request respond =
|
||||
case Network.Wai.requestMethod request of
|
||||
"GET" ->
|
||||
run request (do
|
||||
response <- Control.Monad.Catch.handle pure (listPackages3 api )
|
||||
response <- Control.Monad.Catch.handle pure (listPackages3 api)
|
||||
Control.Monad.IO.Class.liftIO (respond $! (toResponse response))
|
||||
)
|
||||
x ->
|
||||
|
@ -64,12 +64,12 @@ application run api notFound request respond =
|
||||
"GET" ->
|
||||
optionalQueryParameter "limit" False (\__limit request respond ->
|
||||
run request (do
|
||||
response <- Control.Monad.Catch.handle pure (listPets api __limit )
|
||||
response <- Control.Monad.Catch.handle pure (listPets api __limit)
|
||||
Control.Monad.IO.Class.liftIO (respond $! (toResponse response))
|
||||
)) request respond
|
||||
"POST" ->
|
||||
run request (do
|
||||
response <- Control.Monad.Catch.handle pure (createPets api )
|
||||
response <- Control.Monad.Catch.handle pure (createPets api)
|
||||
Control.Monad.IO.Class.liftIO (respond $! (toResponse response))
|
||||
)
|
||||
x ->
|
||||
@ -80,7 +80,7 @@ application run api notFound request respond =
|
||||
case Network.Wai.requestMethod request of
|
||||
"GET" ->
|
||||
run request (do
|
||||
response <- Control.Monad.Catch.handle pure (showPetById api __petId )
|
||||
response <- Control.Monad.Catch.handle pure (showPetById api __petId)
|
||||
Control.Monad.IO.Class.liftIO (respond $! (toResponse response))
|
||||
)
|
||||
x ->
|
||||
|
@ -75,7 +75,7 @@ application run api notFound request respond =
|
||||
requiredQueryParameter "page" (\__page request respond ->
|
||||
optionalQueryParameter "offset" False (\__offset request respond ->
|
||||
run request (do
|
||||
response <- Control.Monad.Catch.handle pure (getUser api __id __name __page __offset )
|
||||
response <- Control.Monad.Catch.handle pure (getUser api __id __name __page __offset)
|
||||
Control.Monad.IO.Class.liftIO (respond $! (toResponse response))
|
||||
)) request respond) request respond
|
||||
"POST" ->
|
||||
|
Loading…
Reference in New Issue
Block a user