git.iko.soy/typeable/swagger2
on master help sign in
Merge pull request #121 from pngwjpgh/bugfix/99

Add instances for Fixed && Fix instances for NominalDiffTime

commit482a9ab2ae4ea0b0407e822c591a9f20afbd33b6 authorOleg Grenrus <oleg.grenrus@iki.fi> dateWed 20 Sep 2017, 14:37 (9 years ago) parent057d6b288b35bf
2 files changed+11−2
src/Data/Swagger/Internal/ParamSchema.hs+7−1 src/Data/Swagger/Internal/Schema.hs+4−1
src/Data/Swagger/Internal/ParamSchema.hs+7−1
@@ -31,6 +31,7 @@ import "unordered-containers" Data.HashSet (HashSet)
3131import Data.Monoid
3232import Data.Set (Set)
3333import Data.Scientific
34+import Data.Fixed (HasResolution(..), Fixed, Pico)
3435import qualified Data.Text as T
3536import qualified Data.Text.Lazy as TL
3637import Data.Time
@@ -159,6 +160,11 @@ instance ToParamSchema Char where
159160instance ToParamSchema Scientific where
160161 toParamSchema _ = mempty & type_ .~ SwaggerNumber
161162
163+instance HasResolution a => ToParamSchema (Fixed a) where
164+ toParamSchema _ = mempty
165+ & type_ .~ SwaggerNumber
166+ & multipleOf ?~ (recip . fromInteger $ resolution (Proxy :: Proxy a))
167+
162168instance ToParamSchema Double where
163169 toParamSchema _ = mempty
164170 & type_ .~ SwaggerNumber
@@ -197,7 +203,7 @@ instance ToParamSchema UTCTime where
197203 toParamSchema _ = timeParamSchema "yyyy-mm-ddThh:MM:ssZ"
198204
199205instance ToParamSchema NominalDiffTime where
200− toParamSchema _ = toParamSchema (Proxy :: Proxy Integer)
206+ toParamSchema _ = toParamSchema (Proxy :: Proxy Pico)
201207
202208instance ToParamSchema T.Text where
203209 toParamSchema _ = toParamSchema (Proxy :: Proxy String)
src/Data/Swagger/Internal/Schema.hs+4−1
@@ -47,6 +47,7 @@ import Data.IntMap (IntMap)
4747import Data.Map (Map)
4848import Data.Proxy
4949import Data.Scientific (Scientific)
50+import Data.Fixed (Fixed, HasResolution, Pico)
5051import Data.Set (Set)
5152import qualified Data.Text as T
5253import qualified Data.Text.Lazy as TL
@@ -437,6 +438,8 @@ instance ToSchema Scientific where declareNamedSchema = plain . paramSchemaToSc
437438instance ToSchema Double where declareNamedSchema = plain . paramSchemaToSchema
438439instance ToSchema Float where declareNamedSchema = plain . paramSchemaToSchema
439440
441+instance HasResolution a => ToSchema (Fixed a) where declareNamedSchema = plain . paramSchemaToSchema
442+
440443instance ToSchema a => ToSchema (Maybe a) where
441444 declareNamedSchema _ = declareNamedSchema (Proxy :: Proxy a)
442445
@@ -480,7 +483,7 @@ instance ToSchema ZonedTime where
480483 & example ?~ toJSON (ZonedTime (LocalTime (fromGregorian 2016 7 22) (TimeOfDay 7 40 0)) (hoursToTimeZone 3))
481484
482485instance ToSchema NominalDiffTime where
483− declareNamedSchema _ = declareNamedSchema (Proxy :: Proxy Integer)
486+ declareNamedSchema _ = declareNamedSchema (Proxy :: Proxy Pico)
484487
485488-- |
486489-- >>> toSchema (Proxy :: Proxy UTCTime) ^. format