git.iko.soy/typeable/openapi3
on master help sign in
Add proper examples for Char, Day, LocalTime, ZonedTime and UTCTime
commit0f43d15da74f571314e29c273fa4a4672382432d authorNickolay Kudasov <nickolay.kudasov@gmail.com> dateFri 22 Jul 2016, 01:00 (10 years ago) parent81635e3
1 file changed+12−4
src/Data/Swagger/Internal/Schema.hs+12−4
src/Data/Swagger/Internal/Schema.hs+12−4
@@ -58,6 +58,7 @@ import Data.Swagger.Declare
5858import Data.Swagger.Internal
5959import Data.Swagger.Internal.ParamSchema (ToParamSchema(..))
6060import Data.Swagger.Lens hiding (name, schema)
61+import qualified Data.Swagger.Lens as Swagger
6162import Data.Swagger.SchemaOptions
6263
6364#ifdef __DOCTEST__
@@ -416,7 +417,10 @@ instance ToSchema Word16 where declareNamedSchema = plain . paramSchemaToSchema
416417instance ToSchema Word32 where declareNamedSchema = plain . paramSchemaToSchema
417418instance ToSchema Word64 where declareNamedSchema = plain . paramSchemaToSchema
418419
419−instance ToSchema Char where declareNamedSchema = plain . paramSchemaToSchema
420+instance ToSchema Char where
421+ declareNamedSchema proxy = plain (paramSchemaToSchema proxy)
422+ & mapped.Swagger.schema.example ?~ toJSON '?'
423+
420424instance ToSchema Scientific where declareNamedSchema = plain . paramSchemaToSchema
421425instance ToSchema Double where declareNamedSchema = plain . paramSchemaToSchema
422426instance ToSchema Float where declareNamedSchema = plain . paramSchemaToSchema
@@ -443,17 +447,20 @@ timeSchema fmt = mempty
443447
444448-- | Format @"date"@ corresponds to @yyyy-mm-dd@ format.
445449instance ToSchema Day where
446− declareNamedSchema _ = pure $ named "Day" (timeSchema "date")
450+ declareNamedSchema _ = pure $ named "Day" $ timeSchema "date"
451+ & example ?~ toJSON (fromGregorian 2016 7 22)
447452
448453-- |
449454-- >>> toSchema (Proxy :: Proxy LocalTime) ^. format
450455-- Just "yyyy-mm-ddThh:MM:ss"
451456instance ToSchema LocalTime where
452− declareNamedSchema _ = pure $ named "LocalTime" (timeSchema "yyyy-mm-ddThh:MM:ss")
457+ declareNamedSchema _ = pure $ named "LocalTime" $ timeSchema "yyyy-mm-ddThh:MM:ss"
458+ & example ?~ toJSON (LocalTime (fromGregorian 2016 7 22) (TimeOfDay 7 40 0))
453459
454460-- | Format @"date"@ corresponds to @yyyy-mm-ddThh:MM:ss(Z|+hh:MM)@ format.
455461instance ToSchema ZonedTime where
456462 declareNamedSchema _ = pure $ named "ZonedTime" $ timeSchema "date-time"
463+ & example ?~ toJSON (ZonedTime (LocalTime (fromGregorian 2016 7 22) (TimeOfDay 7 40 0)) (hoursToTimeZone 3))
457464
458465instance ToSchema NominalDiffTime where
459466 declareNamedSchema _ = declareNamedSchema (Proxy :: Proxy Integer)
@@ -462,7 +469,8 @@ instance ToSchema NominalDiffTime where
462469-- >>> toSchema (Proxy :: Proxy UTCTime) ^. format
463470-- Just "yyyy-mm-ddThh:MM:ssZ"
464471instance ToSchema UTCTime where
465− declareNamedSchema _ = pure $ named "UTCTime" (timeSchema "yyyy-mm-ddThh:MM:ssZ")
472+ declareNamedSchema _ = pure $ named "UTCTime" $ timeSchema "yyyy-mm-ddThh:MM:ssZ"
473+ & example ?~ toJSON (UTCTime (fromGregorian 2016 7 22) 0)
466474
467475instance ToSchema T.Text where declareNamedSchema = plain . paramSchemaToSchema
468476instance ToSchema TL.Text where declareNamedSchema = plain . paramSchemaToSchema