git.iko.soy/typeable/compaREST
on master help sign in
Added support for modes (#101)
commitff54497e2409688e88de80868550506368bfc58d authoriko <ilyakooo0@gmail.com> dateFri 2 Jul 2021, 16:17 (5 years ago) parent3f2c95f
3 files changed+61−36
app/Main.hs+10−2 app/OpenAPI/Checker/Options.hs+23−26 src/OpenAPI/Checker/Report.hs+28−8
app/Main.hs+10−2
@@ -5,6 +5,7 @@ import Control.Monad.Except
55import Data.Aeson
66import qualified Data.ByteString.Lazy as BSL
77import Data.Default
8+import Data.Maybe
89import qualified Data.Text.IO as T
910import qualified Data.Yaml as Yaml
1011import FormatHeuristic
@@ -39,8 +40,15 @@ main = do
3940 FileMode f -> case formatFromFilePath f of
4041 Nothing -> \_ -> throwError UnknownOutputFormat
4142 Just (writer, f') -> lift . BSL.writeFile f' <=< runPandocIO . writer
42− (report, status) = runReport (reportConfig opts) (a, b)
43− either handler pure <=< runExceptT $ write report
43+ reportConfig =
44+ ReportConfig
45+ { treeStyle = reportTreeStyle opts
46+ , reportMode = fromMaybe All $ mode opts
47+ }
48+ (report, status) = runReport reportConfig (a, b)
49+ case mode opts of
50+ Just _ -> either handler pure <=< runExceptT $ write report
51+ Nothing -> pure ()
4452 case status of
4553 NoBreakingChanges -> exitSuccess
4654 BreakingChanges -> exitWith $ ExitFailure 1
app/OpenAPI/Checker/Options.hs+23−26
@@ -1,6 +1,5 @@
11module OpenAPI.Checker.Options
22 ( Options (..)
3− , Mode (..)
43 , OutputMode (..)
54 , optionsParserInfo
65 , execParser
@@ -14,14 +13,13 @@ import Options.Applicative
1413data Options = Options
1514 { clientFile :: FilePath
1615 , serverFile :: FilePath
17− , mode :: Mode
16+ , -- | 'Nothing' means "don't produce any output"
17+ mode :: Maybe ReportMode
1818 , outputMode :: OutputMode
19− , reportConfig :: ReportConfig
19+ , reportTreeStyle :: ReportTreeStyle
2020 }
2121 deriving stock (Generic)
2222
23−data Mode = Silent | OnlyErrors | All
24−
2523data OutputMode = StdoutMode | FileMode FilePath
2624
2725optionsParserInfo :: ParserInfo Options
@@ -44,20 +42,20 @@ optionsParser =
4442 <> long "server"
4543 <> help "The specification that will be used for the server of the API.")
4644 <*> (flag'
47− Silent
45+ Nothing
4846 (long "silent"
4947 <> help "Silence all output.")
5048 <|> flag'
51− OnlyErrors
49+ (Just OnlyErrors)
5250 (long "only-errors"
5351 <> help "Only report incompatibility errors in the output.")
5452 <|> flag'
55− All
53+ (Just All)
5654 (long "all"
5755 <> help
5856 "Report both incompatible and compatible changes. \
5957 \Compatible changes will not trigger a failure exit code.")
60− <|> pure All)
58+ <|> pure (Just All))
6159 <*> ((FileMode
6260 <$> strOption
6361 (short 'o' <> long "output"
@@ -65,20 +63,19 @@ optionsParser =
6563 "The file path where the output should be writtrn. \
6664 \Leave blank to output result to stdout."))
6765 <|> pure StdoutMode)
68− <*> (ReportConfig
69− <$> (flag'
70− FoldingBlockquotesTreeStyle
71− (long "folding-block-quotes-style"
72− <> help
73− "The report tree is structured using \
74− \summary/detail HTML elements and indented using \
75− \block quotes. This style renders well on GitHub.\
76− \Intended for HTML output format. Markdown has rendering \
77− \bugs on GitHub.")
78− <|> flag'
79− HeadersTreeStyle
80− (long "header-style"
81− <> help
82− "The report tree is structured using \
83− \increasing levels of headers.")
84− <|> pure HeadersTreeStyle))
66+ <*> (flag'
67+ FoldingBlockquotesTreeStyle
68+ (long "folding-block-quotes-style"
69+ <> help
70+ "The report tree is structured using \
71+ \summary/detail HTML elements and indented using \
72+ \block quotes. This style renders well on GitHub.\
73+ \Intended for HTML output format. Markdown has rendering \
74+ \bugs on GitHub.")
75+ <|> flag'
76+ HeadersTreeStyle
77+ (long "header-style"
78+ <> help
79+ "The report tree is structured using \
80+ \increasing levels of headers.")
81+ <|> pure HeadersTreeStyle)
src/OpenAPI/Checker/Report.hs+28−8
@@ -5,6 +5,7 @@ module OpenAPI.Checker.Report
55 , Pandoc
66 , ReportConfig (..)
77 , ReportTreeStyle (..)
8+ , ReportMode (..)
89 )
910where
1011
@@ -56,18 +57,26 @@ data ReportStatus
5657 -- there actually are any breaking changes.
5758 OnlyUnsupportedChanges
5859
60+data ReportMode = OnlyErrors | All
61+ deriving stock (Eq)
62+
5963data ReportConfig = ReportConfig
6064 { treeStyle :: ReportTreeStyle
65+ , reportMode :: ReportMode
6166 }
6267
6368instance Default ReportConfig where
6469 def =
6570 ReportConfig
6671 { treeStyle = HeadersTreeStyle
72+ , reportMode = All
6773 }
6874
6975data ReportTreeStyle = HeadersTreeStyle | FoldingBlockquotesTreeStyle
7076
77+twoRowTable :: [(Inlines, Inlines)] -> Blocks
78+twoRowTable x = simpleTable (para . fst <$> x) [para . snd <$> x]
79+
7180generateReport :: ReportConfig -> ReportInput -> (Pandoc, ReportStatus)
7281generateReport cfg inp =
7382 let partitionUnsupported = P.partition (\(AnIssue _ i) -> issueIsUnsupported i)
@@ -77,23 +86,34 @@ generateReport cfg inp =
7786 breakingChangesPresent = not $ P.null breaking
7887 nonBreakingChangesPresent = not $ P.null nonBreaking
7988 unsupportedChangesPresent = not $ P.null unsupported
89+ nonBreakingChangesShown = case reportMode cfg of
90+ All -> True
91+ OnlyErrors -> False
8092 builder = buildReport cfg
8193 report =
8294 doc $
8395 header 1 "Summary"
84− <> simpleTable
85− (para
86− <$> [ refOpt breakingChangesPresent breakingChangesId "⚠️ Breaking changes"
87− , refOpt nonBreakingChangesPresent nonBreakingChangesId "🙆 Non-breaking changes"
88− , refOpt unsupportedChangesPresent unsupportedChangesId "🤷 Unsupported feature changes"
89− ])
90− [para . show' <$> [P.size breaking, P.size nonBreaking, P.size unsupported]]
96+ <> twoRowTable
97+ ([ ( refOpt breakingChangesPresent breakingChangesId "⚠️ Breaking changes"
98+ , show' $ P.size breaking
99+ )
100+ ]
101+ ++ when'
102+ nonBreakingChangesShown
103+ [ ( refOpt nonBreakingChangesPresent nonBreakingChangesId "🙆 Non-breaking changes"
104+ , show' $ P.size nonBreaking
105+ )
106+ ]
107+ ++ [ ( refOpt unsupportedChangesPresent unsupportedChangesId "🤷 Unsupported feature changes"
108+ , show' $ P.size unsupported
109+ )
110+ ])
91111 <> when'
92112 breakingChangesPresent
93113 (header 1 (anchor breakingChangesId <> "⚠️ Breaking changes")
94114 <> builder (showErrs breaking))
95115 <> when'
96− nonBreakingChangesPresent
116+ (nonBreakingChangesPresent && nonBreakingChangesShown)
97117 (header 1 (anchor nonBreakingChangesId <> "🙆 Non-breaking changes")
98118 <> builder (showErrs nonBreaking))
99119 <> when'