Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: GetShopTV/swagger2
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 40ddbceb9b7911bf1da5ef9481dc7966e606461d
Choose a base ref
..
head repository: GetShopTV/swagger2
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: c3b14a64864dea6136d2b60b23274542046a99b1
Choose a head ref
Showing with 11 additions and 2 deletions.
  1. +7 −1 src/Data/Swagger/Internal/ParamSchema.hs
  2. +4 −1 src/Data/Swagger/Internal/Schema.hs
8 changes: 7 additions & 1 deletion src/Data/Swagger/Internal/ParamSchema.hs
Original file line number Diff line number Diff line change
@@ -31,6 +31,7 @@ import "unordered-containers" Data.HashSet (HashSet)
import Data.Monoid
import Data.Set (Set)
import Data.Scientific
import Data.Fixed (HasResolution(..), Fixed, Pico)
import qualified Data.Text as T
import qualified Data.Text.Lazy as TL
import Data.Time
@@ -166,6 +167,11 @@ instance ToParamSchema Char where
instance ToParamSchema Scientific where
toParamSchema _ = mempty & type_ .~ SwaggerNumber

instance HasResolution a => ToParamSchema (Fixed a) where
toParamSchema _ = mempty
& type_ .~ SwaggerNumber
& multipleOf ?~ (recip . fromInteger $ resolution (Proxy :: Proxy a))

instance ToParamSchema Double where
toParamSchema _ = mempty
& type_ .~ SwaggerNumber
@@ -204,7 +210,7 @@ instance ToParamSchema UTCTime where
toParamSchema _ = timeParamSchema "yyyy-mm-ddThh:MM:ssZ"

instance ToParamSchema NominalDiffTime where
toParamSchema _ = toParamSchema (Proxy :: Proxy Integer)
toParamSchema _ = toParamSchema (Proxy :: Proxy Pico)

instance ToParamSchema T.Text where
toParamSchema _ = toParamSchema (Proxy :: Proxy String)
5 changes: 4 additions & 1 deletion src/Data/Swagger/Internal/Schema.hs
Original file line number Diff line number Diff line change
@@ -47,6 +47,7 @@ import Data.IntMap (IntMap)
import Data.Map (Map)
import Data.Proxy
import Data.Scientific (Scientific)
import Data.Fixed (Fixed, HasResolution, Pico)
import Data.Set (Set)
import qualified Data.Text as T
import qualified Data.Text.Lazy as TL
@@ -439,6 +440,8 @@ instance ToSchema Scientific where declareNamedSchema = plain . paramSchemaToSc
instance ToSchema Double where declareNamedSchema = plain . paramSchemaToSchema
instance ToSchema Float where declareNamedSchema = plain . paramSchemaToSchema

instance HasResolution a => ToSchema (Fixed a) where declareNamedSchema = plain . paramSchemaToSchema

instance ToSchema a => ToSchema (Maybe a) where
declareNamedSchema _ = declareNamedSchema (Proxy :: Proxy a)

@@ -482,7 +485,7 @@ instance ToSchema ZonedTime where
& example ?~ toJSON (ZonedTime (LocalTime (fromGregorian 2016 7 22) (TimeOfDay 7 40 0)) (hoursToTimeZone 3))

instance ToSchema NominalDiffTime where
declareNamedSchema _ = declareNamedSchema (Proxy :: Proxy Integer)
declareNamedSchema _ = declareNamedSchema (Proxy :: Proxy Pico)

-- |
-- >>> toSchema (Proxy :: Proxy UTCTime) ^. format