swagger2 2.1.5 → 2.1.6
raw patch · 6 files changed
+37/−7 lines, 6 filesdep +natsdep ~aeson
Dependencies added: nats
Dependency ranges changed: aeson
Files
- CHANGELOG.md +7/−0
- src/Data/Swagger/Internal/ParamSchema.hs +17/−2
- src/Data/Swagger/Internal/Schema.hs +8/−2
- swagger2.cabal +3/−1
- test/Data/Swagger/ParamSchemaSpec.hs +1/−1
- test/Data/Swagger/SchemaSpec.hs +1/−1
CHANGELOG.md view
@@ -1,3 +1,10 @@+2.1.6+-----++* Add `ToParamSchema` and `ToSchema` instances for `Fixed` (see [#121](https://github.com/GetShopTV/swagger2/pull/121)) and `Natural` (see [#123](https://github.com/GetShopTV/swagger2/pull/123));+* Fix instance for `NominalDiffTime` (see [#121](https://github.com/GetShopTV/swagger2/pull/121));+* Fix build for `aeson-1.2.2.0` (see [#125](https://github.com/GetShopTV/swagger2/pull/125)).+ 2.1.5 -----
src/Data/Swagger/Internal/ParamSchema.hs view
@@ -22,7 +22,7 @@ module Data.Swagger.Internal.ParamSchema where import Control.Lens-import Data.Aeson+import Data.Aeson (ToJSON (..)) import Data.Proxy import GHC.Generics @@ -31,6 +31,7 @@ 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@@ -38,6 +39,7 @@ import qualified Data.Vector.Primitive as VP import qualified Data.Vector.Storable as VS import qualified Data.Vector.Unboxed as VU+import Numeric.Natural import Data.Word import Data.UUID.Types (UUID) @@ -124,6 +126,12 @@ instance ToParamSchema Integer where toParamSchema _ = mempty & type_ .~ SwaggerInteger +instance ToParamSchema Natural where+ toParamSchema _ = mempty+ & type_ .~ SwaggerInteger+ & minimum_ ?~ 0+ & exclusiveMinimum ?~ False+ instance ToParamSchema Int where toParamSchema = toParamSchemaBoundedIntegral instance ToParamSchema Int8 where toParamSchema = toParamSchemaBoundedIntegral instance ToParamSchema Int16 where toParamSchema = toParamSchemaBoundedIntegral@@ -159,6 +167,11 @@ 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@@ -197,7 +210,7 @@ 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)@@ -302,3 +315,5 @@ data Proxy3 a b c = Proxy3 +-- $setup+-- >>> import Data.Aeson (encode)
src/Data/Swagger/Internal/Schema.hs view
@@ -32,7 +32,7 @@ import Control.Monad import Control.Monad.Writer-import Data.Aeson+import Data.Aeson (ToJSON (..), ToJSONKey (..), ToJSONKeyFunction (..), Value (..)) import Data.Char import Data.Data (Data) import Data.Foldable (traverse_)@@ -47,6 +47,7 @@ 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@@ -55,6 +56,7 @@ import qualified Data.Vector.Primitive as VP import qualified Data.Vector.Storable as VS import qualified Data.Vector.Unboxed as VU+import Numeric.Natural import Data.Word import GHC.Generics import qualified Data.UUID.Types as UUID@@ -418,6 +420,7 @@ instance OVERLAPPING_ ToSchema String where declareNamedSchema = plain . paramSchemaToSchema instance ToSchema Bool where declareNamedSchema = plain . paramSchemaToSchema instance ToSchema Integer where declareNamedSchema = plain . paramSchemaToSchema+instance ToSchema Natural where declareNamedSchema = plain . paramSchemaToSchema instance ToSchema Int where declareNamedSchema = plain . paramSchemaToSchema instance ToSchema Int8 where declareNamedSchema = plain . paramSchemaToSchema instance ToSchema Int16 where declareNamedSchema = plain . paramSchemaToSchema@@ -437,6 +440,8 @@ 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) @@ -480,7 +485,7 @@ & 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@@ -791,3 +796,4 @@ -- $setup -- >>> import Data.Swagger+-- >>> import Data.Aeson (encode)
swagger2.cabal view
@@ -1,5 +1,5 @@ name: swagger2-version: 2.1.5+version: 2.1.6 synopsis: Swagger 2.0 data model description: This library is inteded to be used for decoding and encoding Swagger 2.0 API@@ -69,6 +69,8 @@ , unordered-containers , vector , uuid-types >=1.0.2 && <1.1+ if !impl(ghc >= 7.10)+ build-depends: nats >=1.1.1 && <1.2 default-language: Haskell2010 test-suite spec
test/Data/Swagger/ParamSchemaSpec.hs view
@@ -5,7 +5,7 @@ {-# LANGUAGE QuasiQuotes #-} module Data.Swagger.ParamSchemaSpec where -import Data.Aeson+import Data.Aeson (Value) import Data.Aeson.QQ import Data.Char import Data.Proxy
test/Data/Swagger/SchemaSpec.hs view
@@ -8,7 +8,7 @@ import Prelude.Compat import Control.Lens ((^.))-import Data.Aeson+import Data.Aeson (Value) import Data.Aeson.QQ import Data.Char import qualified Data.HashMap.Strict.InsOrd as InsOrdHashMap