git.iko.soy/typeable/compaREST
on master help sign in
fix
614ef52Aleksey Uymanov
compa4ek.cabal+2
@@ -32,9 +32,11 @@ common common-options
32 default-language: Haskell2010
32 default-language: Haskell2010
33 build-depends: base >= 4.12.0.0 && < 4.14
33 build-depends: base >= 4.12.0.0 && < 4.14
34 , aeson
34 , aeson
35+ , containers
35 , insert-ordered-containers
36 , insert-ordered-containers
36 , openapi3
37 , openapi3
37 , text
38 , text
39+
38 default-extensions: ConstraintKinds
40 default-extensions: ConstraintKinds
39 , DataKinds
41 , DataKinds
40 , DeriveFoldable
42 , DeriveFoldable
src/OpenAPI/Checker/Report.hs+25−12
@@ -1,7 +1,12 @@
1module OpenAPI.Checker.Report where
1module OpenAPI.Checker.Report where
2
2
3−import Data.Text (Text)
3+import Data.Map.Strict as M
4+import Data.Text (Text)
4−import GHC.Generics (Generic)
5+import GHC.Generics (Generic)
6+import OpenAPI.Checker.Validate.Monad
7+
8+printReport :: Report -> IO ()
9+printReport = error "FIXME: printReport not implemented"
5
10
6data Report = Report
11data Report = Report
7 { status :: Status
12 { status :: Status
@@ -11,21 +16,29 @@ data Report = Report
11data Status = Success | Fail Text
16data Status = Success | Fail Text
12 deriving (Eq, Ord, Show, Generic)
17 deriving (Eq, Ord, Show, Generic)
13
18
14−type Errorable = Either Text
15−
16type Path = FilePath -- From the library
19type Path = FilePath -- From the library
17
20
18data ReportTree = ReportTree
21data ReportTree = ReportTree
19− { paths :: [PathTree]
22+ { paths :: Map Path (Errorable PathItemTree)
20 } deriving (Eq, Ord, Show, Generic)
23 } deriving (Eq, Ord, Show, Generic)
21
24
22−data PathTree = PathTree
25+newtype PathItemTree = PathItemTree
23− { path :: Path
26+ { operations :: Map OperationName (Errorable OperationTree)
24− , pathItem :: Errorable PathItemTree
25− } deriving (Eq, Ord, Show, Generic)
27+ } deriving (Eq, Ord, Show, Generic, Semigroup, Monoid)
26
28
27−data PathItemTree = PathItemTree
29+instance Nested PathItemTree where
30+ type Parent PathItemTree = ReportTree
31+ type Key PathItemTree = Path
32+ nest key p = ReportTree $ M.singleton key p
33+
34+data OperationName
35+ = Get | Put | Post | Delete | Options | Head | Patch | Trace
28 deriving (Eq, Ord, Show, Generic)
36 deriving (Eq, Ord, Show, Generic)
29
37
30−printReport :: Report -> IO ()
38+data OperationTree = OperationTree
31−printReport = error "FIXME: printReport not implemented"
39+ deriving (Eq, Ord, Show, Generic)
40+
41+instance Nested OperationTree where
42+ type Parent OperationTree = PathItemTree
43+ type Key OperationTree = OperationName
44+ nest key p = PathItemTree $ M.singleton key p
src/OpenAPI/Checker/Validate.hs+17−4
@@ -5,6 +5,7 @@ import Data.Functor
5import Data.HashMap.Strict.InsOrd as InsMap
5import Data.HashMap.Strict.InsOrd as InsMap
6import Data.HashSet.InsOrd as InsSet
6import Data.HashSet.InsOrd as InsSet
7import Data.OpenApi
7import Data.OpenApi
8+import Data.OpenApi.Internal
8import Data.Traversable
9import Data.Traversable
9import OpenAPI.Checker.Report
10import OpenAPI.Checker.Report
10import OpenAPI.Checker.Validate.Monad
11import OpenAPI.Checker.Validate.Monad
@@ -13,17 +14,29 @@ reportCompat :: OpenApi -> OpenApi -> Report
13reportCompat = error "FIXME: reportCompat not implemented"
14reportCompat = error "FIXME: reportCompat not implemented"
14
15
15forwardCompatible :: OpenApi -> OpenApi -> ReportTree
16forwardCompatible :: OpenApi -> OpenApi -> ReportTree
16−forwardCompatible dec enc = fst $ runReportTreeT $ openApiCompatible dec enc
17+forwardCompatible dec enc = fst $ runTreeM $ openApiCompatible dec enc
17
18
18−openApiCompatible :: OpenApi -> OpenApi -> ReportTreeT ()
19+openApiCompatible :: OpenApi -> OpenApi -> TreeM ReportTree ()
19openApiCompatible dec enc = void $ follow $
20openApiCompatible dec enc = void $ follow $
20 (InsMap.toList $ _openApiPaths dec) <&> \(path, encItem) ->
21 (InsMap.toList $ _openApiPaths dec) <&> \(path, encItem) ->
21 (path, checkItem path encItem)
22 (path, checkItem path encItem)
22 where
23 where
24+ -- checkItem :: Path -> PathItem -> TreeM PathItemTree ()
23 checkItem path encItem = do
25 checkItem path encItem = do
24 case (InsMap.lookup path $ _openApiPaths enc) of
26 case (InsMap.lookup path $ _openApiPaths enc) of
25 Nothing -> pathError $ "Path deleted"
27 Nothing -> pathError $ "Path deleted"
26 Just decItem -> pathItemsCompatible encItem decItem
28 Just decItem -> pathItemsCompatible encItem decItem
27
29
28−pathItemsCompatible :: PathItem -> PathItem -> ReportTreeT ()
30+pathItemsCompatible :: PathItem -> PathItem -> TreeM PathItemTree ()
31+pathItemsCompatible dec enc = void $ follow
32+ [ (Get, go _pathItemGet)
33+ , (Put, go _pathItemPut)
34+ , (Post, go _pathItemPost)
35+ , (Delete, go _pathItemDelete)
36+ , (Options, go _pathItemOptions)
37+ , (Head, go _pathItemHead)
38+ , (Patch, go _pathItemPatch)
39+ , (Trace, go _pathItemTrace) ]
40+ where
41+ go :: (PathItem -> Maybe Operation) -> TreeM OperationTree ()
29−pathItemsCompatible = error "FIXME: pathItemsCompatible not implemented"
42+ go getOp = (error "FIXME: not implemented")
src/OpenAPI/Checker/Validate/Monad.hs+19−12
@@ -1,23 +1,30 @@
1module OpenAPI.Checker.Validate.Monad where
1module OpenAPI.Checker.Validate.Monad where
2
2
3−import Data.Text (Text)
3+import Data.Text (Text)
4−import OpenAPI.Checker.Report
5
4
6−data ReportTreeT a = ReportTreeT
7
5
6+data TreeM t a = TreeM
8−instance Functor ReportTreeT
7+instance Functor (TreeM t)
9−instance Applicative ReportTreeT
8+instance Applicative (TreeM t)
10−instance Monad ReportTreeT
9+instance Monad (TreeM t)
11
10
11+type Errorable = Either Text
12
12
13−runReportTreeT :: ReportTreeT a -> (ReportTree, a)
13+-- | Class of trees nested into another trees
14−runReportTreeT = error "FIXME: runReportTree not implemented"
14+class Nested t where
15+ type Parent t
16+ type Key t
17+ nest :: Key t -> Errorable t -> Parent t
15
18
19+runTreeM :: TreeM t a -> (t, a)
20+runTreeM = error "FIXME: runReportTree not implemented"
21+
16−pathError :: Text -> ReportTreeT a
22+pathError :: Text -> TreeM t a
17pathError = error "FIXME: pathError not implemented"
23pathError = error "FIXME: pathError not implemented"
18
24
25+-- | Runs several computations in different paths
19follow
26follow
20− :: (Traversable f)
27+ :: (Traversable f, Nested t)
21− => f (Path, ReportTreeT a)
28+ => f (Key t, TreeM t a)
22− -> ReportTreeT (f a)
29+ -> TreeM (Parent t) (f a)
23follow = error "FIXME: follow not implemented"
30follow = error "FIXME: follow not implemented"