This commit is contained in:
Aleksey Uymanov 2021-02-25 10:13:20 +05:00
parent db6b2a0724
commit 0d56e1542f
9 changed files with 168 additions and 23 deletions

View File

@ -1,7 +1,7 @@
module Main (main) where
import Compa4ek (someFunc)
import OpenAPI.Checker.Run (runChecker)
main :: IO ()
main = someFunc
main = runChecker

View File

@ -16,8 +16,6 @@ tested-with: GHC == 8.6.5
GHC == 8.8.3
common common-options
build-depends: base >= 4.12.0.0 && < 4.14
ghc-options: -Wall
-Wcompat
-Widentities
@ -30,15 +28,52 @@ common common-options
if impl(ghc >= 8.4)
ghc-options: -Wmissing-export-lists
-Wpartial-fields
if impl(ghc >= 8.8)
ghc-options: -Wmissing-deriving-strategies
default-language: Haskell2010
build-depends: base >= 4.12.0.0 && < 4.14
, aeson
, insert-ordered-containers
, openapi3
, text
default-extensions: ConstraintKinds
, DataKinds
, DeriveFoldable
, DeriveFunctor
, DeriveGeneric
, DeriveTraversable
, DuplicateRecordFields
, FlexibleContexts
, FlexibleInstances
, FunctionalDependencies
, GADTs
, GeneralizedNewtypeDeriving
, LambdaCase
, MultiParamTypeClasses
, MultiWayIf
, NamedFieldPuns
, NumDecimals
, OverloadedStrings
, PolyKinds
, QuasiQuotes
, RankNTypes
, RecordWildCards
, ScopedTypeVariables
, StandaloneDeriving
, TemplateHaskell
, TupleSections
, TypeApplications
, TypeFamilies
, TypeOperators
, UndecidableInstances
, ViewPatterns
library
import: common-options
hs-source-dirs: src
exposed-modules: Compa4ek
exposed-modules: OpenAPI.Checker.Report
, OpenAPI.Checker.Run
, OpenAPI.Checker.Validate
, OpenAPI.Checker.Validate.Monad
executable compa4ek
import: common-options

View File

@ -1,15 +0,0 @@
{- |
Copyright: (c) 2021 Aleksey Uymanov
SPDX-License-Identifier: MIT
Maintainer: Aleksey Uymanov <s9gf4ult@gmail.com>
Compatibility checker for OpenAPI
-}
module Compa4ek
( someFunc
) where
someFunc :: IO ()
someFunc = putStrLn ("someFunc" :: String)

View File

@ -0,0 +1,31 @@
module OpenAPI.Checker.Report where
import Data.Text (Text)
import GHC.Generics (Generic)
data Report = Report
{ status :: Status
, tree :: ReportTree
} deriving (Eq, Ord, Show, Generic)
data Status = Success | Fail Text
deriving (Eq, Ord, Show, Generic)
type Errorable = Either Text
type Path = FilePath -- From the library
data ReportTree = ReportTree
{ paths :: [PathTree]
} deriving (Eq, Ord, Show, Generic)
data PathTree = PathTree
{ path :: Path
, pathItem :: Errorable PathItemTree
} deriving (Eq, Ord, Show, Generic)
data PathItemTree = PathItemTree
deriving (Eq, Ord, Show, Generic)
printReport :: Report -> IO ()
printReport = error "FIXME: printReport not implemented"

View File

@ -0,0 +1,25 @@
module OpenAPI.Checker.Run (runChecker) where
import Data.Aeson
import Data.OpenApi
import OpenAPI.Checker.Report
import OpenAPI.Checker.Validate
runChecker :: IO ()
runChecker = do
let
schemaA = (error "FIXME: not implemented")
schemaB = (error "FIXME: not implemented")
a <- eitherDecodeFileStrict schemaA >>= \case
Left e -> do
putStrLn $ "Failed to parse: " ++ schemaA
fail e
Right s -> pure s
b <- eitherDecodeFileStrict schemaB >>= \case
Left e -> do
putStrLn $ "Failed to parse: " ++ schemaB
fail e
Right s -> pure s
let report = reportCompat a b
printReport report

View File

@ -0,0 +1,29 @@
module OpenAPI.Checker.Validate where
import Control.Monad
import Data.Functor
import Data.HashMap.Strict.InsOrd as InsMap
import Data.HashSet.InsOrd as InsSet
import Data.OpenApi
import Data.Traversable
import OpenAPI.Checker.Report
import OpenAPI.Checker.Validate.Monad
reportCompat :: OpenApi -> OpenApi -> Report
reportCompat = error "FIXME: reportCompat not implemented"
forwardCompatible :: OpenApi -> OpenApi -> ReportTree
forwardCompatible dec enc = fst $ runReportTreeT $ openApiCompatible dec enc
openApiCompatible :: OpenApi -> OpenApi -> ReportTreeT ()
openApiCompatible dec enc = void $ follow $
(InsMap.toList $ _openApiPaths dec) <&> \(path, encItem) ->
(path, checkItem path encItem)
where
checkItem path encItem = do
case (InsMap.lookup path $ _openApiPaths enc) of
Nothing -> pathError $ "Path deleted"
Just decItem -> pathItemsCompatible encItem decItem
pathItemsCompatible :: PathItem -> PathItem -> ReportTreeT ()
pathItemsCompatible = error "FIXME: pathItemsCompatible not implemented"

View File

@ -0,0 +1,23 @@
module OpenAPI.Checker.Validate.Monad where
import Data.Text (Text)
import OpenAPI.Checker.Report
data ReportTreeT a = ReportTreeT
instance Functor ReportTreeT
instance Applicative ReportTreeT
instance Monad ReportTreeT
runReportTreeT :: ReportTreeT a -> (ReportTree, a)
runReportTreeT = error "FIXME: runReportTree not implemented"
pathError :: Text -> ReportTreeT a
pathError = error "FIXME: pathError not implemented"
follow
:: (Traversable f)
=> f (Path, ReportTreeT a)
-> ReportTreeT (f a)
follow = error "FIXME: follow not implemented"

View File

@ -1 +1,4 @@
resolver: lts-15.5
extra-deps:
- openapi3-3.0.1.0
- generics-sop-0.5.1.0

View File

@ -3,7 +3,21 @@
# For more information, please see the documentation at:
# https://docs.haskellstack.org/en/stable/lock_files
packages: []
packages:
- completed:
hackage: openapi3-3.0.1.0@sha256:6d97aaf074d70c79f43dd6cc923c1f3830daa5e8b54d11d0302676d536f38011,4641
pantry-tree:
size: 2191
sha256: 2b3c61a5efd9595940cfdb9877ac009e853e79093ca3f2c4dc2204effddfce78
original:
hackage: openapi3-3.0.1.0
- completed:
hackage: generics-sop-0.5.1.0@sha256:e27ea888daaa96d2acdba7d3e9fc5c35e1ab9b03b65f3858d6cb9b34cd5ac1d4,5806
pantry-tree:
size: 1571
sha256: 19ccba2cfd129c390c34514fd655a60617911fae20eed3a30f12a574fffea69c
original:
hackage: generics-sop-0.5.1.0
snapshots:
- completed:
size: 491372