mirror of
https://github.com/aelve/guide.git
synced 2024-12-23 04:42:24 +03:00
Fix decoding ItemKind
issue (#204)
This commit is contained in:
parent
bb510a9f1d
commit
7d6aa64d4b
@ -3,9 +3,8 @@ module Guide.Common.Api where
|
||||
import Prelude
|
||||
|
||||
import Control.Monad.Aff (Aff)
|
||||
import Data.Argonaut.Generic.Aeson (userDecoding, userEncoding)
|
||||
import Data.Argonaut.Generic.Decode (Options(..), SumEncoding(..), genericDecodeJson)
|
||||
import Data.Argonaut.Generic.Util (stripModulePath)
|
||||
import Data.Argonaut.Generic.Aeson (options)
|
||||
import Data.Argonaut.Generic.Decode (genericDecodeJson)
|
||||
import Data.Bifunctor (bimap)
|
||||
import Data.Either (Either(..), either)
|
||||
import Data.Foreign (Foreign, unsafeFromForeign)
|
||||
@ -29,27 +28,6 @@ instance showEndpointError :: Show EndpointError where
|
||||
show (ServerError e) =
|
||||
"[ServerError]: " <> show e
|
||||
|
||||
-- custom encode options (because `unpackRecords` should be `false`)
|
||||
sumEncoding :: SumEncoding
|
||||
sumEncoding = TaggedObject
|
||||
{ tagFieldName: "tag"
|
||||
, contentsFieldName: "contents"
|
||||
, unpackRecords: false
|
||||
}
|
||||
|
||||
options :: Options
|
||||
options = Options
|
||||
{ constructorTagModifier: stripModulePath
|
||||
, allNullaryToStringTag: true
|
||||
, sumEncoding
|
||||
, flattenContentsArray: true
|
||||
, encodeSingleConstructors: false
|
||||
, userEncoding
|
||||
, userDecoding
|
||||
, fieldLabelModifier: id
|
||||
, omitNothingFields: false
|
||||
}
|
||||
|
||||
-- | Decoder for json data
|
||||
decodeJson :: forall a. (Generic a) => Foreign -> Either String a
|
||||
decodeJson = genericDecodeJson options <<< unsafeFromForeign
|
||||
|
@ -128,10 +128,10 @@ hackageName _ Other = pure Other
|
||||
instance A.ToJSON ItemKind where
|
||||
toJSON (Library x) = A.object [
|
||||
"tag" A..= ("Library" :: Text),
|
||||
"hackageName" A..= x ]
|
||||
"contents" A..= x ]
|
||||
toJSON (Tool x) = A.object [
|
||||
"tag" A..= ("Tool" :: Text),
|
||||
"hackageName" A..= x ]
|
||||
"contents" A..= x ]
|
||||
toJSON Other = A.object [
|
||||
"tag" A..= ("Other" :: Text) ]
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user