git.iko.soy/typeable/swagger2
on master help sign in
Add ToSchema & ToParamSchema instance for Fixed
commit6d0b53c2cb31fca24e00effb32c6b48c5efe2924 authorGregor Kleen <rmpvqzvcjxvlhbkb@141.li> dateTue 19 Sep 2017, 15:18 (9 years ago) parent057d6b2
2 files changed+9
src/Data/Swagger/Internal/ParamSchema.hs+6 src/Data/Swagger/Internal/Schema.hs+3
src/Data/Swagger/Internal/ParamSchema.hs+6
@@ -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)
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
src/Data/Swagger/Internal/Schema.hs+3
@@ -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)
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