Skip to content

Commit

Permalink
Merge pull request #123 from pngwjpgh/feature/Natural
Browse files Browse the repository at this point in the history
Add ParamSchema & Schema for Numeric.Natural
  • Loading branch information
phadej authored Sep 21, 2017
2 parents 482a9ab + bf9c2e5 commit 5ec8bd7
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
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

0 comments on commit 5ec8bd7

Please sign in to comment.