From 529edac0c8f5ca5bb3e57ffd54aa77f68e22d375 Mon Sep 17 00:00:00 2001 From: Ivan Yablochkin Date: Fri, 9 Feb 2024 00:20:28 +0300 Subject: [PATCH 1/3] Add DayOfWeek ToSchema instance. Move all time related ToSchema instances to the same place. --- src/Data/Swagger/Internal/Schema.hs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/Data/Swagger/Internal/Schema.hs b/src/Data/Swagger/Internal/Schema.hs index b15c6d7..e93c0ef 100644 --- a/src/Data/Swagger/Internal/Schema.hs +++ b/src/Data/Swagger/Internal/Schema.hs @@ -74,6 +74,7 @@ import qualified Data.ByteString.Lazy as BSL import GHC.TypeLits (TypeError, ErrorMessage(..)) import qualified Data.Aeson.KeyMap as KM import Data.Aeson.Key (toText) +import Data.Time (DayOfWeek(Monday, Sunday)) unnamed :: Schema -> NamedSchema unnamed schema = NamedSchema Nothing schema @@ -144,10 +145,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 +494,16 @@ 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) + +instance ToSchema DayOfWeek where + declareNamedSchema _ = pure $ named "DayOfWeek" $ + mempty + & type_ ?~ SwaggerString + & enum_ ?~ map toJSON [Monday .. Sunday] + instance ToSchema NominalDiffTime where declareNamedSchema _ = declareNamedSchema (Proxy :: Proxy Pico) From c0f7d559c849aa2cb3fa39e4289a374eb055180b Mon Sep 17 00:00:00 2001 From: Ivan Yablochkin Date: Fri, 9 Feb 2024 00:40:56 +0300 Subject: [PATCH 2/3] No DayOfWeek instance for GHC prior to 8.8.4 --- src/Data/Swagger/Internal/Schema.hs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Data/Swagger/Internal/Schema.hs b/src/Data/Swagger/Internal/Schema.hs index e93c0ef..9aa7b18 100644 --- a/src/Data/Swagger/Internal/Schema.hs +++ b/src/Data/Swagger/Internal/Schema.hs @@ -74,7 +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 @@ -498,11 +500,13 @@ 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) From 607f23bc5a57f068bf09c4e4530215da71776838 Mon Sep 17 00:00:00 2001 From: Ivan Yablochkin Date: Wed, 21 Feb 2024 15:41:56 +0300 Subject: [PATCH 3/3] bump version --- CHANGELOG.md | 5 +++++ swagger2.cabal | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) 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/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