Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add DayOfWeek ToSchema instance. #250

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
---

Expand Down
19 changes: 15 additions & 4 deletions src/Data/Swagger/Internal/Schema.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion swagger2.cabal
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Loading