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 UUID instances #81

Merged
merged 1 commit into from
Sep 26, 2016
Merged
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.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