Skip to content

Commit

Permalink
implement some useful functions for api
Browse files Browse the repository at this point in the history
  • Loading branch information
Anton Kholomiov committed Oct 19, 2023
1 parent a019c2b commit 7b2a9c5
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
2 changes: 2 additions & 0 deletions mig-extra/src/Mig/Extra/Server/Common.hs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ module Mig.Extra.Server.Common (
mapServerFun,
mapResponse,
atPath,
filterPath,
getServerPaths,
addPathLink,

-- ** OpenApi
Expand Down
2 changes: 2 additions & 0 deletions mig-server/src/Mig.hs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ module Mig (
mapServerFun,
mapResponse,
atPath,
filterPath,
getServerPaths,
addPathLink,

-- ** OpenApi
Expand Down
9 changes: 9 additions & 0 deletions mig/src/Mig/Core/Server.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ module Mig.Core.Server (
staticFiles,
describeInputs,
atPath,
filterPath,
getServerPaths,
addPathLink,
) where

Expand Down Expand Up @@ -355,6 +357,13 @@ atPath rootPath rootServer = maybe mempty Server $ find rootPath rootServer.unSe
guard (prefixHead == pathHead)
matchPath prefixTail pathTail

filterPath :: (Api.Path -> Bool) -> Server m -> Server m
filterPath cond (Server a) =
Server (Api.fromFlatApi $ filter (cond . fst) $ Api.flatApi a)

getServerPaths :: Server m -> [Api.Path]
getServerPaths (Server a) = fmap fst $ Api.flatApi a

{-| Links one route of the server to another
so that every call to first path is redirected to the second path
-}
Expand Down

0 comments on commit 7b2a9c5

Please sign in to comment.