servant-xml-conduit 0.1.0.2 → 0.1.0.4
raw patch · 3 files changed
+52/−6 lines, 3 files
Files
- CHANGELOG.md +13/−0
- servant-xml-conduit.cabal +1/−1
- src/Servant/XML/Conduit.hs +38/−5
CHANGELOG.md view
@@ -1,5 +1,18 @@ # Revision history for servant-xml-conduit +## [0.1.0.4] - 2023-11-23++### Fixed++- version bump because haddock didn't refresh candidate properly++## [0.1.0.3] - 2023-11-23++### Fixed++- documentation generation (add `cabal.project` with `allow-newer` for `base`)+- fix overlapping instances+ ## [0.1.0.2] - 2023-11-23 ### Added
servant-xml-conduit.cabal view
@@ -20,7 +20,7 @@ -- PVP summary: +-+------- breaking API changes -- | | +----- non-breaking API additions -- | | | +--- code changes with no API change-version: 0.1.0.2+version: 0.1.0.4 -- A short (one-line) description of the package. synopsis: Servant XML content-type with support for xml-conduit
src/Servant/XML/Conduit.hs view
@@ -1,6 +1,3 @@-{-# LANGUAGE FlexibleContexts #-}-{-# LANGUAGE UndecidableInstances #-}- {-| Module : Servant.XML.Conduit Description : Servant bindings for XML using xml-conduit@@ -14,6 +11,7 @@ module Servant.XML.Conduit where import Data.Bifunctor (first)+import Data.ByteString.Lazy qualified as BSL import Network.HTTP.Media qualified as M import Servant.API import Text.XML qualified as XML@@ -24,7 +22,42 @@ instance Accept XML where contentType _ = "application" M.// "xml" M./: ("charset", "utf-8") -instance {-# OVERLAPPING #-} MimeUnrender XML XML.Document where- mimeUnrender _ bs = first show $ XML.parseLBS XML.def bs instance MimeRender XML XML.Document where mimeRender _ doc = XML.renderLBS XML.def doc++{-| Function to decode a lazy `ByteString' into 'XML.Document'. The+ reason we don't privde a @'MimeUnrender' 'XML' 'XML.Document'@ instance is+ that we don't want to force users with a predefined 'FromXML'+ typeclass.++ If we added++ @+ instance 'MimeUnrender' 'XML' 'XML.Document' where+ mimeUnrender _ bs = first show $ 'XML.parseLBS' 'XML.def' bs+ @++ we immediately arrive at overlapping instances problem when we try to define++ @+ instance FromXML a => 'MimeUnrender' 'XML' a ...+ @++ So, just define this in your code:++ @+ data ParseError =+ ErrorNoElementFound Text+ | ...++ class FromXML a where+ fromXML :: (Functor m, Applicative m, MonadError ParseError m) => 'Text.XML.Cursor.Cursor' -> m a++ instance (FromXML a) => 'MimeUnrender' 'XML' a where+ mimeUnrender _ctype bs = case 'mimeUnrenderXML' bs of+ Left err -> Left err+ Right doc -> first show $ fromXML ('Text.XML.Cursor.fromDocument' doc)+ @+-}+mimeUnrenderXML :: BSL.ByteString -> Either String XML.Document+mimeUnrenderXML bs = first show $ XML.parseLBS XML.def bs