@@ -1,34 +1,58 @@
1module OpenAPI.Checker.Report where
1module OpenAPI.Checker.Report where
4+import Data.Aeson.Types
5+import qualified Data.Attoparsec.Text as A
3import Data.Map.Strict as M
7import Data.Map.Strict as M
4import Data.Monoid.Generic
9import Data.Monoid.Generic
5import Data.OpenApi.Internal
10import Data.OpenApi.Internal
6−import Data.Semigroup.Generic
7import Data.Text (Text)
11import Data.Text (Text)
8−import GHC.Generics (Generic)
12+import Deriving.Aeson.Stock
9import OpenAPI.Checker.Validate.Monad
13import OpenAPI.Checker.Validate.Monad
11printReport :: Report -> IO ()
16printReport :: Report -> IO ()
12printReport = error "FIXME: printReport not implemented"
17printReport = error "FIXME: printReport not implemented"
19+class HasUnsupportedFeature x where
20+ hasUnsupportedFeature :: x -> Bool
14data Report = Report
22data Report = Report
15 { status :: Status
23 { status :: Status
16 , tree :: ReportTree
24 , tree :: ReportTree
17− } deriving (Eq, Ord, Show, Generic)
26+ deriving stock (Eq, Ord, Show, Generic)
27+ deriving (ToJSON, FromJSON) via Snake Report
29+instance HasUnsupportedFeature Report
31+instance HasUnsupportedFeature x => HasUnsupportedFeature (Either e x) where
32+ hasUnsupportedFeature (Left _) = False
33+ hasUnsupportedFeature (Right x) = hasUnsupportedFeature x
19data Status = Success | Fail Text
35data Status = Success | Fail Text
20− deriving (Eq, Ord, Show, Generic)
36+ deriving stock (Eq, Ord, Show, Generic)
37+ deriving (ToJSON, FromJSON) via Snake Status
22type Path = FilePath -- From the library
39type Path = FilePath -- From the library
24newtype ReportTree = ReportTree
41newtype ReportTree = ReportTree
25 { paths :: Map Path (Errorable PathItemTree)
42 { paths :: Map Path (Errorable PathItemTree)
44+ deriving stock (Show, Generic)
26− } deriving (Eq, Ord, Show, Generic, Semigroup, Monoid)
45+ deriving newtype (Eq, Ord, Semigroup, Monoid)
46+ deriving (ToJSON, FromJSON) via Snake ReportTree
48+instance HasUnsupportedFeature ReportTree
28data PathItemTree = PathItemTree
50data PathItemTree = PathItemTree
29 { operations :: Map OperationName (Errorable OperationTree)
51 { operations :: Map OperationName (Errorable OperationTree)
30 , server :: Maybe (Errorable ServerTree)
52 , server :: Maybe (Errorable ServerTree)
31− } deriving (Eq, Ord, Show, Generic)
54+ deriving stock (Eq, Ord, Show, Generic)
55+ deriving (ToJSON, FromJSON) via Snake PathItemTree
33instance Semigroup PathItemTree where
57instance Semigroup PathItemTree where
34 (<>) = genericMappend
58 (<>) = genericMappend
@@ -44,10 +68,14 @@ instance Nested PathItemTree where
44data OperationName
68data OperationName
45 = Get | Put | Post | Delete | Options | Head | Patch | Trace
69 = Get | Put | Post | Delete | Options | Head | Patch | Trace
46 deriving (Eq, Ord, Show, Generic)
70 deriving (Eq, Ord, Show, Generic)
71+ deriving (ToJSON, FromJSON) via Snake OperationName
72+ deriving anyclass (ToJSONKey, FromJSONKey)
48newtype OperationTree = OperationTree
74newtype OperationTree = OperationTree
49 { parameters :: Map ParamKey (Errorable ParamTree)
75 { parameters :: Map ParamKey (Errorable ParamTree)
77+ deriving stock (Show, Generic)
50− } deriving (Eq, Ord, Show, Generic, Semigroup, Monoid)
78+ deriving newtype (Eq, Ord, Semigroup, Monoid, FromJSON, ToJSON)
52instance Nested OperationTree where
80instance Nested OperationTree where
53 type Parent OperationTree = PathItemTree
81 type Parent OperationTree = PathItemTree
@@ -55,10 +83,12 @@ instance Nested OperationTree where
55 nest key p = PathItemTree (M.singleton key p) mempty
83 nest key p = PathItemTree (M.singleton key p) mempty
57data ServerTree = ServerTree
85data ServerTree = ServerTree
58− deriving (Eq, Ord, Show, Generic)
86+ deriving stock (Eq, Ord, Show, Generic)
87+ deriving (ToJSON, FromJSON) via Snake ServerTree
60data ParamTree = ParamTree
89data ParamTree = ParamTree
61− deriving (Eq, Ord, Show, Generic)
90+ deriving stock (Eq, Ord, Show, Generic)
91+ deriving (ToJSON, FromJSON) via Snake ParamTree
63instance Semigroup ParamTree where
93instance Semigroup ParamTree where
64 (<>) = error "Not implemented"
94 (<>) = error "Not implemented"
@@ -76,7 +106,10 @@ deriving instance Ord ParamLocation
76data ParamKey = ParamKey
106data ParamKey = ParamKey
77 { name :: Text
107 { name :: Text
78 , paramIn :: ParamLocation
108 , paramIn :: ParamLocation
79− } deriving (Eq, Ord, Show, Generic)
110+ deriving stock (Eq, Ord, Show, Generic)
111+ deriving (FromJSON, ToJSON) via Snake ParamKey
112+ deriving anyclass (ToJSONKey, FromJSONKey)
81getParamKey :: Param -> ParamKey
114getParamKey :: Param -> ParamKey
82getParamKey p = ParamKey
115getParamKey p = ParamKey