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 ParamSchema & Schema for Numeric.Natural #123

Merged
merged 4 commits into from
Sep 21, 2017
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
7 changes: 7 additions & 0 deletions src/Data/Swagger/Internal/ParamSchema.hs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import qualified Data.Vector as V
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)

Expand Down Expand Up @@ -125,6 +126,12 @@ instance ToParamSchema Bool where
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
Expand Down
2 changes: 2 additions & 0 deletions src/Data/Swagger/Internal/Schema.hs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ import qualified Data.Vector as V
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
Expand Down Expand Up @@ -419,6 +420,7 @@ instance OVERLAPPABLE_ ToSchema a => ToSchema [a] where
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
Expand Down
2 changes: 2 additions & 0 deletions swagger2.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ library
, 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
Expand Down