git.iko.soy/typeable/openapi3
on master help sign in
Merge pull request #121 from pngwjpgh/bugfix/99
482a9abOleg Grenrus
src/Data/Swagger/Internal/ParamSchema.hs+7−1
@@ -31,6 +31,7 @@ import "unordered-containers" Data.HashSet (HashSet)
31import Data.Monoid
31import Data.Monoid
32import Data.Set (Set)
32import Data.Set (Set)
33import Data.Scientific
33import Data.Scientific
34+import Data.Fixed (HasResolution(..), Fixed, Pico)
34import qualified Data.Text as T
35import qualified Data.Text as T
35import qualified Data.Text.Lazy as TL
36import qualified Data.Text.Lazy as TL
36import Data.Time
37import Data.Time
@@ -159,6 +160,11 @@ instance ToParamSchema Char where
159instance ToParamSchema Scientific where
160instance ToParamSchema Scientific where
160 toParamSchema _ = mempty & type_ .~ SwaggerNumber
161 toParamSchema _ = mempty & type_ .~ SwaggerNumber
161
162
163+instance HasResolution a => ToParamSchema (Fixed a) where
164+ toParamSchema _ = mempty
165+ & type_ .~ SwaggerNumber
166+ & multipleOf ?~ (recip . fromInteger $ resolution (Proxy :: Proxy a))
167+
162instance ToParamSchema Double where
168instance ToParamSchema Double where
163 toParamSchema _ = mempty
169 toParamSchema _ = mempty
164 & type_ .~ SwaggerNumber
170 & type_ .~ SwaggerNumber
@@ -197,7 +203,7 @@ instance ToParamSchema UTCTime where
197 toParamSchema _ = timeParamSchema "yyyy-mm-ddThh:MM:ssZ"
203 toParamSchema _ = timeParamSchema "yyyy-mm-ddThh:MM:ssZ"
198
204
199instance ToParamSchema NominalDiffTime where
205instance ToParamSchema NominalDiffTime where
200− toParamSchema _ = toParamSchema (Proxy :: Proxy Integer)
206+ toParamSchema _ = toParamSchema (Proxy :: Proxy Pico)
201
207
202instance ToParamSchema T.Text where
208instance ToParamSchema T.Text where
203 toParamSchema _ = toParamSchema (Proxy :: Proxy String)
209 toParamSchema _ = toParamSchema (Proxy :: Proxy String)
src/Data/Swagger/Internal/Schema.hs+4−1
@@ -47,6 +47,7 @@ import Data.IntMap (IntMap)
47import Data.Map (Map)
47import Data.Map (Map)
48import Data.Proxy
48import Data.Proxy
49import Data.Scientific (Scientific)
49import Data.Scientific (Scientific)
50+import Data.Fixed (Fixed, HasResolution, Pico)
50import Data.Set (Set)
51import Data.Set (Set)
51import qualified Data.Text as T
52import qualified Data.Text as T
52import qualified Data.Text.Lazy as TL
53import qualified Data.Text.Lazy as TL
@@ -437,6 +438,8 @@ instance ToSchema Scientific where declareNamedSchema = plain . paramSchemaToSc
437instance ToSchema Double where declareNamedSchema = plain . paramSchemaToSchema
438instance ToSchema Double where declareNamedSchema = plain . paramSchemaToSchema
438instance ToSchema Float where declareNamedSchema = plain . paramSchemaToSchema
439instance ToSchema Float where declareNamedSchema = plain . paramSchemaToSchema
439
440
441+instance HasResolution a => ToSchema (Fixed a) where declareNamedSchema = plain . paramSchemaToSchema
442+
440instance ToSchema a => ToSchema (Maybe a) where
443instance ToSchema a => ToSchema (Maybe a) where
441 declareNamedSchema _ = declareNamedSchema (Proxy :: Proxy a)
444 declareNamedSchema _ = declareNamedSchema (Proxy :: Proxy a)
442
445
@@ -480,7 +483,7 @@ instance ToSchema ZonedTime where
480 & example ?~ toJSON (ZonedTime (LocalTime (fromGregorian 2016 7 22) (TimeOfDay 7 40 0)) (hoursToTimeZone 3))
483 & example ?~ toJSON (ZonedTime (LocalTime (fromGregorian 2016 7 22) (TimeOfDay 7 40 0)) (hoursToTimeZone 3))
481
484
482instance ToSchema NominalDiffTime where
485instance ToSchema NominalDiffTime where
483− declareNamedSchema _ = declareNamedSchema (Proxy :: Proxy Integer)
486+ declareNamedSchema _ = declareNamedSchema (Proxy :: Proxy Pico)
484
487
485-- |
488-- |
486-- >>> toSchema (Proxy :: Proxy UTCTime) ^. format
489-- >>> toSchema (Proxy :: Proxy UTCTime) ^. format