diff --git a/CHANGELOG.md b/CHANGELOG.md index 297c53d..2e85e25 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +2.8.9 +--- + +- Add DayOfWeek instance for GHC >= 8.8.4 (see [#250](https://github.com/GetShopTV/swagger2/pull/250)); + 2.8.8 --- diff --git a/src/Data/Swagger/Internal/Schema.hs b/src/Data/Swagger/Internal/Schema.hs index b15c6d7..9aa7b18 100644 --- a/src/Data/Swagger/Internal/Schema.hs +++ b/src/Data/Swagger/Internal/Schema.hs @@ -74,6 +74,9 @@ import qualified Data.ByteString.Lazy as BSL import GHC.TypeLits (TypeError, ErrorMessage(..)) import qualified Data.Aeson.KeyMap as KM import Data.Aeson.Key (toText) +#if ( __GLASGOW_HASKELL__ > 884 ) +import Data.Time (DayOfWeek(Monday, Sunday)) +#endif unnamed :: Schema -> NamedSchema unnamed schema = NamedSchema Nothing schema @@ -144,10 +147,6 @@ class ToSchema a where Proxy a -> Declare (Definitions Schema) NamedSchema declareNamedSchema = genericDeclareNamedSchema defaultSchemaOptions -instance ToSchema TimeOfDay where - declareNamedSchema _ = pure $ named "TimeOfDay" $ timeSchema "hh:MM:ss" - & example ?~ toJSON (TimeOfDay 12 33 15) - -- | Convert a type into a schema and declare all used schema definitions. declareSchema :: ToSchema a => Proxy a -> Declare (Definitions Schema) Schema declareSchema = fmap _namedSchemaSchema . declareNamedSchema @@ -497,6 +496,18 @@ instance ToSchema ZonedTime where declareNamedSchema _ = pure $ named "ZonedTime" $ timeSchema "date-time" & example ?~ toJSON (ZonedTime (LocalTime (fromGregorian 2016 7 22) (TimeOfDay 7 40 0)) (hoursToTimeZone 3)) +instance ToSchema TimeOfDay where + declareNamedSchema _ = pure $ named "TimeOfDay" $ timeSchema "hh:MM:ss" + & example ?~ toJSON (TimeOfDay 12 33 15) + +#if ( __GLASGOW_HASKELL__ > 884 ) +instance ToSchema DayOfWeek where + declareNamedSchema _ = pure $ named "DayOfWeek" $ + mempty + & type_ ?~ SwaggerString + & enum_ ?~ map toJSON [Monday .. Sunday] +#endif + instance ToSchema NominalDiffTime where declareNamedSchema _ = declareNamedSchema (Proxy :: Proxy Pico) diff --git a/swagger2.cabal b/swagger2.cabal index 3166a5d..5452b49 100644 --- a/swagger2.cabal +++ b/swagger2.cabal @@ -1,6 +1,6 @@ cabal-version: >=1.10 name: swagger2 -version: 2.8.8 +version: 2.8.9 synopsis: Swagger 2.0 data model category: Web, Swagger