Skip to content

Commit

Permalink
Add UUID instances
Browse files Browse the repository at this point in the history
  • Loading branch information
phadej committed Sep 23, 2016
1 parent 1d892fb commit cf77585
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 1 deletion.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
2.1.3
-----

* Add UUID instances

2.1.2.1
-------

Expand Down
6 changes: 6 additions & 0 deletions src/Data/Swagger/Internal/ParamSchema.hs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import qualified Data.Vector.Primitive as VP
import qualified Data.Vector.Storable as VS
import qualified Data.Vector.Unboxed as VU
import Data.Word
import Data.UUID (UUID)

import Data.Swagger.Internal
import Data.Swagger.Lens
Expand Down Expand Up @@ -221,6 +222,11 @@ instance ToParamSchema () where
& type_ .~ SwaggerString
& enum_ ?~ ["_"]

instance ToParamSchema UUID where
toParamSchema _ = mempty
& type_ .~ SwaggerString
& format ?~ "uuid"

-- | A configurable generic @'ParamSchema'@ creator.
--
-- >>> :set -XDeriveGeneric
Expand Down
3 changes: 3 additions & 0 deletions src/Data/Swagger/Internal/Schema.hs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ import qualified Data.Vector.Storable as VS
import qualified Data.Vector.Unboxed as VU
import Data.Word
import GHC.Generics
import Data.UUID (UUID)

import Data.Swagger.Declare
import Data.Swagger.Internal
Expand Down Expand Up @@ -433,6 +434,8 @@ instance (ToSchema a, ToSchema b) => ToSchema (Either a b)
instance ToSchema () where
declareNamedSchema _ = pure (NamedSchema Nothing nullarySchema)

instance ToSchema UUID where declareNamedSchema = plain . paramSchemaToSchema

instance (ToSchema a, ToSchema b) => ToSchema (a, b)
instance (ToSchema a, ToSchema b, ToSchema c) => ToSchema (a, b, c)
instance (ToSchema a, ToSchema b, ToSchema c, ToSchema d) => ToSchema (a, b, c, d)
Expand Down
3 changes: 2 additions & 1 deletion swagger2.cabal
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: swagger2
version: 2.1.2.1
version: 2.1.3
synopsis: Swagger 2.0 data model
description: Please see README.md
homepage: https://github.com/GetShopTV/swagger2
Expand Down Expand Up @@ -57,6 +57,7 @@ library
, transformers
, unordered-containers
, vector
, uuid >=1.3.12 && <1.4
default-language: Haskell2010

test-suite spec
Expand Down

0 comments on commit cf77585

Please sign in to comment.