git.iko.soy/typeable/compaREST
on master help sign in
Added basic options (#13)
1660766iko
openapi-diff.cabal+2
@@ -42,6 +42,7 @@ common common-options
42 , transformers
42 , transformers
43 , yaml
43 , yaml
44 , attoparsec
44 , attoparsec
45+ , optparse-applicative
45
46
46 default-extensions: ConstraintKinds
47 default-extensions: ConstraintKinds
47 , DataKinds
48 , DataKinds
@@ -87,6 +88,7 @@ library
87 , OpenAPI.Checker.Validate
88 , OpenAPI.Checker.Validate
88 , OpenAPI.Checker.Validate.Dereference
89 , OpenAPI.Checker.Validate.Dereference
89 , OpenAPI.Checker.Validate.Monad
90 , OpenAPI.Checker.Validate.Monad
91+ , OpenAPI.Checker.Options
90
92
91executable openapi-diff
93executable openapi-diff
92 import: common-options
94 import: common-options
src/OpenAPI/Checker/Options.hsnew file+61
@@ -0,0 +1,61 @@
1+module OpenAPI.Checker.Options
2+ ( Options (..),
3+ Mode (..),
4+ optionsParserInfo,
5+ execParser,
6+ )
7+where
8+
9+import GHC.Generics (Generic)
10+import Options.Applicative
11+
12+data Options = Options
13+ { clientFile :: FilePath,
14+ serverFile :: FilePath,
15+ mode :: Mode
16+ }
17+ deriving stock (Generic)
18+
19+data Mode = Silent | OnlyErrors | All
20+
21+optionsParserInfo :: ParserInfo Options
22+optionsParserInfo =
23+ info
24+ (helper <*> optionsParser)
25+ ( fullDesc
26+ <> header "openapi-diff"
27+ <> progDesc "A tool to check compatibility between two OpenApi specifications."
28+ )
29+
30+optionsParser :: Parser Options
31+optionsParser =
32+ Options
33+ <$> strOption
34+ ( short 'c'
35+ <> long "client"
36+ <> help "The specification that will be used for the client of the API."
37+ )
38+ <*> strOption
39+ ( short 's'
40+ <> long "server"
41+ <> help "The specification that will be used for the server of the API."
42+ )
43+ <*> ( flag'
44+ Silent
45+ ( long "silent"
46+ <> help "Silence all output."
47+ )
48+ <|> flag'
49+ OnlyErrors
50+ ( long "only-errors"
51+ <> help "Only report incompatibility errors in the output."
52+ )
53+ <|> flag'
54+ All
55+ ( long "all"
56+ <> help
57+ "Report both incompatible and compatible changes. \
58+ \Compatible changes will not trigger a failure exit code."
59+ )
60+ <|> pure All
61+ )
src/OpenAPI/Checker/Run.hs+13−18
@@ -1,25 +1,20 @@
1module OpenAPI.Checker.Run (runChecker) where
1module OpenAPI.Checker.Run (runChecker) where
2
2
3−import Data.Aeson
3+import Data.Aeson
4−import Data.OpenApi
4+import OpenAPI.Checker.Options
5−import OpenAPI.Checker.Report
5+import OpenAPI.Checker.Report
6−import OpenAPI.Checker.Validate
6+import OpenAPI.Checker.Validate
7−
8
7
9runChecker :: IO ()
8runChecker :: IO ()
10runChecker = do
9runChecker = do
11− let
10+ opts <- execParser optionsParserInfo
12− schemaA = (error "FIXME: not implemented")
11+ let parseSchema path =
13− schemaB = (error "FIXME: not implemented")
12+ eitherDecodeFileStrict path >>= \case
14− a <- eitherDecodeFileStrict schemaA >>= \case
13+ Left e -> do
15− Left e -> do
14+ putStrLn $ "Failed to parse: " ++ path
16− putStrLn $ "Failed to parse: " ++ schemaA
15+ fail e
17− fail e
16+ Right s -> pure s
18− Right s -> pure s
17+ a <- parseSchema (clientFile opts)
19− b <- eitherDecodeFileStrict schemaB >>= \case
18+ b <- parseSchema (serverFile opts)
20− Left e -> do
21− putStrLn $ "Failed to parse: " ++ schemaB
22− fail e
23− Right s -> pure s
24 let report = reportCompat a b
19 let report = reportCompat a b
25 printReport report
20 printReport report