@@ -1,34 +1,58 @@
11module OpenAPI.Checker.Report where
22
3+import Data.Aeson
4+import Data.Aeson.Types
5+import qualified Data.Attoparsec.Text as A
6+import Data.Functor
37import Data.Map.Strict as M
8+import Data.Maybe
49import Data.Monoid.Generic
510import Data.OpenApi.Internal
6−import Data.Semigroup.Generic
711import Data.Text (Text)
8−import GHC.Generics (Generic)
12+import Deriving.Aeson.Stock
913import OpenAPI.Checker.Validate.Monad
14+import Prelude as P
1015
1116printReport :: Report -> IO ()
1217printReport = error "FIXME: printReport not implemented"
1318
19+class HasUnsupportedFeature x where
20+ hasUnsupportedFeature :: x -> Bool
21+
1422data Report = Report
1523 { status :: Status
1624 , tree :: ReportTree
17− } deriving (Eq, Ord, Show, Generic)
25+ }
26+ deriving stock (Eq, Ord, Show, Generic)
27+ deriving (ToJSON, FromJSON) via Snake Report
28+
29+instance HasUnsupportedFeature Report
30+
31+instance HasUnsupportedFeature x => HasUnsupportedFeature (Either e x) where
32+ hasUnsupportedFeature (Left _) = False
33+ hasUnsupportedFeature (Right x) = hasUnsupportedFeature x
1834
1935data Status = Success | Fail Text
20− deriving (Eq, Ord, Show, Generic)
36+ deriving stock (Eq, Ord, Show, Generic)
37+ deriving (ToJSON, FromJSON) via Snake Status
2138
2239type Path = FilePath -- From the library
2340
2441newtype ReportTree = ReportTree
2542 { paths :: Map Path (Errorable PathItemTree)
26− } deriving (Eq, Ord, Show, Generic, Semigroup, Monoid)
43+ }
44+ deriving stock (Show, Generic)
45+ deriving newtype (Eq, Ord, Semigroup, Monoid)
46+ deriving (ToJSON, FromJSON) via Snake ReportTree
47+
48+instance HasUnsupportedFeature ReportTree
2749
2850data PathItemTree = PathItemTree
2951 { operations :: Map OperationName (Errorable OperationTree)
3052 , server :: Maybe (Errorable ServerTree)
31− } deriving (Eq, Ord, Show, Generic)
53+ }
54+ deriving stock (Eq, Ord, Show, Generic)
55+ deriving (ToJSON, FromJSON) via Snake PathItemTree
3256
3357instance Semigroup PathItemTree where
3458 (<>) = genericMappend
@@ -44,10 +68,14 @@ instance Nested PathItemTree where
4468data OperationName
4569 = Get | Put | Post | Delete | Options | Head | Patch | Trace
4670 deriving (Eq, Ord, Show, Generic)
71+ deriving (ToJSON, FromJSON) via Snake OperationName
72+ deriving anyclass (ToJSONKey, FromJSONKey)
4773
4874newtype OperationTree = OperationTree
4975 { parameters :: Map ParamKey (Errorable ParamTree)
50− } deriving (Eq, Ord, Show, Generic, Semigroup, Monoid)
76+ }
77+ deriving stock (Show, Generic)
78+ deriving newtype (Eq, Ord, Semigroup, Monoid, FromJSON, ToJSON)
5179
5280instance Nested OperationTree where
5381 type Parent OperationTree = PathItemTree
@@ -55,10 +83,12 @@ instance Nested OperationTree where
5583 nest key p = PathItemTree (M.singleton key p) mempty
5684
5785data ServerTree = ServerTree
58− deriving (Eq, Ord, Show, Generic)
86+ deriving stock (Eq, Ord, Show, Generic)
87+ deriving (ToJSON, FromJSON) via Snake ServerTree
5988
6089data ParamTree = ParamTree
61− deriving (Eq, Ord, Show, Generic)
90+ deriving stock (Eq, Ord, Show, Generic)
91+ deriving (ToJSON, FromJSON) via Snake ParamTree
6292
6393instance Semigroup ParamTree where
6494 (<>) = error "Not implemented"
@@ -76,7 +106,10 @@ deriving instance Ord ParamLocation
76106data ParamKey = ParamKey
77107 { name :: Text
78108 , paramIn :: ParamLocation
79− } deriving (Eq, Ord, Show, Generic)
109+ }
110+ deriving stock (Eq, Ord, Show, Generic)
111+ deriving (FromJSON, ToJSON) via Snake ParamKey
112+ deriving anyclass (ToJSONKey, FromJSONKey)
80113
81114getParamKey :: Param -> ParamKey
82115getParamKey p = ParamKey