[aeson] fix incomplete pattern matches in ISTEX.Client parsing

parent 5f1f42e3
......@@ -44,7 +44,7 @@ common defaults
, servant >= 0.20 && < 0.21
, servant-client >= 0.20 && < 0.21
, text >= 2.0.2 && < 2.2
ghc-options: -Wall -Wunused-imports -Wunused-binds -Wmissing-signatures -Werror
ghc-options: -Wall -Wincomplete-uni-patterns -Wmissing-signatures -Wunused-imports -Wunused-binds -Werror
library
import:
......
......@@ -3,16 +3,14 @@
module ISTEX.Client where
import Control.Applicative ((<|>))
import Control.Lens qualified as L
import Data.Aeson
import Data.Proxy (Proxy(..))
import Data.Text qualified as T
import GHC.Generics
import Text.Read (readEither)
import Servant.API
import Servant.Client
import Data.Proxy (Proxy(..))
import qualified Data.Text as T
import qualified Control.Lens as L
import Text.Read (readEither)
data Author = Author
{ _author_name :: T.Text
......@@ -21,8 +19,10 @@ data Author = Author
L.makeLenses ''Author
instance FromJSON Author where
parseJSON (Object o) =
Author <$> (o .: "name") <*> (o .: "affiliations" <|> pure [])
parseJSON = withObject "Author" $ \o -> do
_author_name <- o .: "name"
_author_affiliations <- o .: "affiliations" <|> pure []
pure $ Author { .. }
data Source = Source
{ _source_title :: Maybe T.Text
......@@ -41,7 +41,7 @@ parsePubDate (Just pubDate) =
ePubDate = readEither (T.unpack pubDate) :: Either String Int
instance FromJSON Source where
parseJSON (Object o) = do
parseJSON = withObject "Source" $ \o -> do
_source_title <- o .:? "title"
-- _source_authors <- o .:? "author"
mPubDate <- o .:? "publicationDate"
......@@ -60,7 +60,7 @@ data Document = Document
L.makeLenses ''Document
instance FromJSON Document where
parseJSON (Object o) = do
parseJSON = withObject "Document" $ \o -> do
_document_id <- o .: "id" <|> o .: "_id"
_document_title <- o .:? "title"
_document_authors <- o .: "author" <|> pure []
......@@ -76,8 +76,10 @@ data Documents = Documents
} deriving (Show, Generic)
L.makeLenses ''Documents
instance FromJSON Documents where
parseJSON (Object o) =
Documents <$> (o .: "total") <*> (o .: "hits")
parseJSON = withObject "Documents" $ \o -> do
_documents_total <- o .: "total"
_documents_hits <- o .: "hits"
pure $ Documents { .. }
instance Semigroup Documents where
(<>) (Documents { _documents_total
, _documents_hits = d1 })
......@@ -96,7 +98,7 @@ data ScrollResponse = ScrollResponse
L.makeLenses ''ScrollResponse
instance FromJSON ScrollResponse where
parseJSON (Object o) = do
parseJSON = withObject "ScrollResponse" $ \o -> do
_documents_total <- o .: "total"
_documents_hits <- o .: "hits"
_scroll_noMoreScrollResults <- o .:? "noMoreScrollResults"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment