on master help sign in
skel
0d56e15Aleksey Uymanov
app/Main.hs+2−2
@@ -1,7 +1,7 @@
1module Main (main) where
1module Main (main) where
2
2
3−import Compa4ek (someFunc)
3+import OpenAPI.Checker.Run (runChecker)
4
4
5
5
6main :: IO ()
6main :: IO ()
7−main = someFunc
7+main = runChecker
compa4ek.cabal+40−5
@@ -16,8 +16,6 @@ tested-with: GHC == 8.6.5
16 GHC == 8.8.3
16 GHC == 8.8.3
17
17
18common common-options
18common common-options
19− build-depends: base >= 4.12.0.0 && < 4.14
20−
21 ghc-options: -Wall
19 ghc-options: -Wall
22 -Wcompat
20 -Wcompat
23 -Widentities
21 -Widentities
@@ -30,15 +28,52 @@ common common-options
30 if impl(ghc >= 8.4)
28 if impl(ghc >= 8.4)
31 ghc-options: -Wmissing-export-lists
29 ghc-options: -Wmissing-export-lists
32 -Wpartial-fields
30 -Wpartial-fields
33− if impl(ghc >= 8.8)
34− ghc-options: -Wmissing-deriving-strategies
35
31
36 default-language: Haskell2010
32 default-language: Haskell2010
33+ build-depends: base >= 4.12.0.0 && < 4.14
34+ , aeson
35+ , insert-ordered-containers
36+ , openapi3
37+ , text
38+ default-extensions: ConstraintKinds
39+ , DataKinds
40+ , DeriveFoldable
41+ , DeriveFunctor
42+ , DeriveGeneric
43+ , DeriveTraversable
44+ , DuplicateRecordFields
45+ , FlexibleContexts
46+ , FlexibleInstances
47+ , FunctionalDependencies
48+ , GADTs
49+ , GeneralizedNewtypeDeriving
50+ , LambdaCase
51+ , MultiParamTypeClasses
52+ , MultiWayIf
53+ , NamedFieldPuns
54+ , NumDecimals
55+ , OverloadedStrings
56+ , PolyKinds
57+ , QuasiQuotes
58+ , RankNTypes
59+ , RecordWildCards
60+ , ScopedTypeVariables
61+ , StandaloneDeriving
62+ , TemplateHaskell
63+ , TupleSections
64+ , TypeApplications
65+ , TypeFamilies
66+ , TypeOperators
67+ , UndecidableInstances
68+ , ViewPatterns
37
69
38library
70library
39 import: common-options
71 import: common-options
40 hs-source-dirs: src
72 hs-source-dirs: src
41− exposed-modules: Compa4ek
73+ exposed-modules: OpenAPI.Checker.Report
74+ , OpenAPI.Checker.Run
75+ , OpenAPI.Checker.Validate
76+ , OpenAPI.Checker.Validate.Monad
42
77
43executable compa4ek
78executable compa4ek
44 import: common-options
79 import: common-options
src/Compa4ek.hsdeleted−15
@@ -1,15 +0,0 @@
1−{- |
2−Copyright: (c) 2021 Aleksey Uymanov
3−SPDX-License-Identifier: MIT
4−Maintainer: Aleksey Uymanov <s9gf4ult@gmail.com>
5−
6−Compatibility checker for OpenAPI
7−-}
8−
9−module Compa4ek
10− ( someFunc
11− ) where
12−
13−
14−someFunc :: IO ()
15−someFunc = putStrLn ("someFunc" :: String)
src/OpenAPI/Checker/Report.hsnew file+31
@@ -0,0 +1,31 @@
1+module OpenAPI.Checker.Report where
2+
3+import Data.Text (Text)
4+import GHC.Generics (Generic)
5+
6+data Report = Report
7+ { status :: Status
8+ , tree :: ReportTree
9+ } deriving (Eq, Ord, Show, Generic)
10+
11+data Status = Success | Fail Text
12+ deriving (Eq, Ord, Show, Generic)
13+
14+type Errorable = Either Text
15+
16+type Path = FilePath -- From the library
17+
18+data ReportTree = ReportTree
19+ { paths :: [PathTree]
20+ } deriving (Eq, Ord, Show, Generic)
21+
22+data PathTree = PathTree
23+ { path :: Path
24+ , pathItem :: Errorable PathItemTree
25+ } deriving (Eq, Ord, Show, Generic)
26+
27+data PathItemTree = PathItemTree
28+ deriving (Eq, Ord, Show, Generic)
29+
30+printReport :: Report -> IO ()
31+printReport = error "FIXME: printReport not implemented"
src/OpenAPI/Checker/Run.hsnew file+25
@@ -0,0 +1,25 @@
1+module OpenAPI.Checker.Run (runChecker) where
2+
3+import Data.Aeson
4+import Data.OpenApi
5+import OpenAPI.Checker.Report
6+import OpenAPI.Checker.Validate
7+
8+
9+runChecker :: IO ()
10+runChecker = do
11+ let
12+ schemaA = (error "FIXME: not implemented")
13+ schemaB = (error "FIXME: not implemented")
14+ a <- eitherDecodeFileStrict schemaA >>= \case
15+ Left e -> do
16+ putStrLn $ "Failed to parse: " ++ schemaA
17+ fail e
18+ Right s -> pure s
19+ b <- eitherDecodeFileStrict schemaB >>= \case
20+ Left e -> do
21+ putStrLn $ "Failed to parse: " ++ schemaB
22+ fail e
23+ Right s -> pure s
24+ let report = reportCompat a b
25+ printReport report
src/OpenAPI/Checker/Validate.hsnew file+29
@@ -0,0 +1,29 @@
1+module OpenAPI.Checker.Validate where
2+
3+import Control.Monad
4+import Data.Functor
5+import Data.HashMap.Strict.InsOrd as InsMap
6+import Data.HashSet.InsOrd as InsSet
7+import Data.OpenApi
8+import Data.Traversable
9+import OpenAPI.Checker.Report
10+import OpenAPI.Checker.Validate.Monad
11+
12+reportCompat :: OpenApi -> OpenApi -> Report
13+reportCompat = error "FIXME: reportCompat not implemented"
14+
15+forwardCompatible :: OpenApi -> OpenApi -> ReportTree
16+forwardCompatible dec enc = fst $ runReportTreeT $ openApiCompatible dec enc
17+
18+openApiCompatible :: OpenApi -> OpenApi -> ReportTreeT ()
19+openApiCompatible dec enc = void $ follow $
20+ (InsMap.toList $ _openApiPaths dec) <&> \(path, encItem) ->
21+ (path, checkItem path encItem)
22+ where
23+ checkItem path encItem = do
24+ case (InsMap.lookup path $ _openApiPaths enc) of
25+ Nothing -> pathError $ "Path deleted"
26+ Just decItem -> pathItemsCompatible encItem decItem
27+
28+pathItemsCompatible :: PathItem -> PathItem -> ReportTreeT ()
29+pathItemsCompatible = error "FIXME: pathItemsCompatible not implemented"
src/OpenAPI/Checker/Validate/Monad.hsnew file+23
@@ -0,0 +1,23 @@
1+module OpenAPI.Checker.Validate.Monad where
2+
3+import Data.Text (Text)
4+import OpenAPI.Checker.Report
5+
6+data ReportTreeT a = ReportTreeT
7+
8+instance Functor ReportTreeT
9+instance Applicative ReportTreeT
10+instance Monad ReportTreeT
11+
12+
13+runReportTreeT :: ReportTreeT a -> (ReportTree, a)
14+runReportTreeT = error "FIXME: runReportTree not implemented"
15+
16+pathError :: Text -> ReportTreeT a
17+pathError = error "FIXME: pathError not implemented"
18+
19+follow
20+ :: (Traversable f)
21+ => f (Path, ReportTreeT a)
22+ -> ReportTreeT (f a)
23+follow = error "FIXME: follow not implemented"
stack.yaml+3
@@ -1 +1,4 @@
1resolver: lts-15.5
1resolver: lts-15.5
2+extra-deps:
3+ - openapi3-3.0.1.0
4+ - generics-sop-0.5.1.0
stack.yaml.lock+15−1
@@ -3,7 +3,21 @@
3# For more information, please see the documentation at:
3# For more information, please see the documentation at:
4# https://docs.haskellstack.org/en/stable/lock_files
4# https://docs.haskellstack.org/en/stable/lock_files
5
5
6−packages: []
6+packages:
7+- completed:
8+ hackage: openapi3-3.0.1.0@sha256:6d97aaf074d70c79f43dd6cc923c1f3830daa5e8b54d11d0302676d536f38011,4641
9+ pantry-tree:
10+ size: 2191
11+ sha256: 2b3c61a5efd9595940cfdb9877ac009e853e79093ca3f2c4dc2204effddfce78
12+ original:
13+ hackage: openapi3-3.0.1.0
14+- completed:
15+ hackage: generics-sop-0.5.1.0@sha256:e27ea888daaa96d2acdba7d3e9fc5c35e1ab9b03b65f3858d6cb9b34cd5ac1d4,5806
16+ pantry-tree:
17+ size: 1571
18+ sha256: 19ccba2cfd129c390c34514fd655a60617911fae20eed3a30f12a574fffea69c
19+ original:
20+ hackage: generics-sop-0.5.1.0
7snapshots:
21snapshots:
8- completed:
22- completed:
9 size: 491372
23 size: 491372