File tree Expand file tree Collapse file tree 2 files changed +7
-4
lines changed Expand file tree Collapse file tree 2 files changed +7
-4
lines changed Original file line number Diff line number Diff line change
1
+ synopsis: Use newtype deriving for ToHttpApiData in the type Range
2
+ packages: servant
3
+ prs: #1813
4
+ description: {
5
+ Use newtype deriving for ToHttpApiData in the type Range
6
+ }
Original file line number Diff line number Diff line change @@ -39,7 +39,7 @@ import Servant.API
39
39
-- Nothing
40
40
newtype Range (min :: Nat ) (max :: Nat ) = MkRange { unRange :: Natural }
41
41
deriving stock (Eq , Ord , Show , Generic )
42
- deriving newtype (Ix , ToJSON )
42
+ deriving newtype (Ix , ToJSON , ToHttpApiData )
43
43
44
44
unsafeRange :: Natural -> Range min max
45
45
unsafeRange = MkRange
@@ -62,9 +62,6 @@ instance (KnownNat min, KnownNat max) => FromJSON (Range min max) where
62
62
n <- modifyFailure (const $ parseErrorMsg @ min @ max Proxy ) $ parseJSON v
63
63
maybe (fail $ parseErrorMsg @ min @ max Proxy ) pure $ mkRange n
64
64
65
- instance (KnownNat min , KnownNat max ) => ToHttpApiData (Range min max ) where
66
- toQueryParam = T. pack . show . unRange
67
-
68
65
instance (KnownNat min , KnownNat max ) => FromHttpApiData (Range min max ) where
69
66
parseQueryParam v = do
70
67
n <- first (const . T. pack $ parseErrorMsg @ min @ max Proxy ) $ parseQueryParam v
You can’t perform that action at this time.
0 commit comments