@@ -6,13 +6,15 @@ module App.Fossa.Report.Attribution (
6
6
Dependency (.. ),
7
7
License (.. ),
8
8
LicenseContents (.. ),
9
+ LicenseCopyright (.. ),
10
+ LicenseDetails (.. ),
9
11
LicenseName (.. ),
10
12
Project (.. ),
11
13
) where
12
14
13
15
import Data.Aeson
14
16
import Data.Map.Strict (Map )
15
- import Data.Maybe (catMaybes )
17
+ import Data.Maybe (catMaybes , isNothing )
16
18
import Data.Text (Text )
17
19
18
20
newtype LicenseName = LicenseName { rawName :: Text }
@@ -21,11 +23,21 @@ newtype LicenseName = LicenseName {rawName :: Text}
21
23
newtype LicenseContents = LicenseContents { rawContents :: Text }
22
24
deriving (Eq , Ord , Show , FromJSON , ToJSON )
23
25
26
+ newtype LicenseCopyright = LicenseCopyright { rawCopyright :: Text }
27
+ deriving (Eq , Ord , Show , FromJSON , ToJSON )
28
+
29
+ data LicenseDetails = LicenseDetails
30
+ { licenseText :: LicenseContents
31
+ , licenseCopyrights :: [LicenseCopyright ]
32
+ }
33
+ deriving (Eq , Ord , Show )
34
+
24
35
data Attribution = Attribution
25
36
{ attribProject :: Project
26
37
, attribDirectDeps :: [Dependency ]
27
38
, attribDeepDeps :: [Dependency ]
28
39
, attribLicenses :: Map LicenseName LicenseContents
40
+ , attribLicenseDetails :: Maybe (Map LicenseName LicenseDetails )
29
41
}
30
42
deriving (Eq , Show , Ord )
31
43
@@ -66,15 +78,19 @@ instance FromJSON Attribution where
66
78
<*> obj .:? " directDependencies" .!= []
67
79
<*> obj .:? " deepDependencies" .!= []
68
80
<*> obj .: " licenses"
81
+ <*> obj .:? " licenseDetails"
69
82
70
83
instance ToJSON Attribution where
71
84
toJSON Attribution {.. } =
72
- object
85
+ object $
73
86
[ " project" .= attribProject
74
87
, " directDependencies" .= attribDirectDeps
75
88
, " deepDependencies" .= attribDeepDeps
76
89
, " licenses" .= attribLicenses
77
90
]
91
+ ++ if isNothing attribLicenseDetails
92
+ then []
93
+ else [" licenseDetails" .= attribLicenseDetails]
78
94
79
95
instance FromJSON Dependency where
80
96
parseJSON = withObject " Dependency" $ \ obj ->
@@ -138,3 +154,16 @@ instance ToJSON Project where
138
154
[ " name" .= projectName
139
155
, " revision" .= projectRevision
140
156
]
157
+
158
+ instance FromJSON LicenseDetails where
159
+ parseJSON = withObject " LicenseDetails" $ \ obj ->
160
+ LicenseDetails
161
+ <$> obj .: " text"
162
+ <*> obj .: " copyrights"
163
+
164
+ instance ToJSON LicenseDetails where
165
+ toJSON LicenseDetails {.. } =
166
+ object
167
+ [ " text" .= licenseText
168
+ , " copyrights" .= licenseCopyrights
169
+ ]
0 commit comments