Skip to content

Commit

Permalink
Merge pull request #81 from phadej/uuid
Browse files Browse the repository at this point in the history
Add UUID instances
  • Loading branch information
fizruk committed Sep 26, 2016
2 parents 1d892fb + 12dbb51 commit 2c26881
Show file tree
Hide file tree
Showing 4 changed files with 19 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 (see [#81](https://github.com/GetShopTV/swagger2/pull/81)).

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.Types (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
6 changes: 6 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 qualified Data.UUID.Types as UUID

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

-- | For 'ToJSON' instance, see <http://hackage.haskell.org/package/uuid-aeson uuid-aeson> package.
instance ToSchema UUID.UUID where
declareNamedSchema p = pure $ named "UUID" $ paramSchemaToSchema p
& example ?~ toJSON (UUID.toText UUID.nil)

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-types >=1.0.2 && <1.1
default-language: Haskell2010

test-suite spec
Expand Down

0 comments on commit 2c26881

Please sign in to comment.