git.iko.soy/typeable/openapi3
on master help sign in
Add "format" field for uint32 and uint64 (#215)
023e2acPaul Young
src/Data/Swagger/Internal/ParamSchema.hs+6−2
@@ -147,8 +147,12 @@ instance ToParamSchema Int64 where
147instance ToParamSchema Word where toParamSchema = toParamSchemaBoundedIntegral
147instance ToParamSchema Word where toParamSchema = toParamSchemaBoundedIntegral
148instance ToParamSchema Word8 where toParamSchema = toParamSchemaBoundedIntegral
148instance ToParamSchema Word8 where toParamSchema = toParamSchemaBoundedIntegral
149instance ToParamSchema Word16 where toParamSchema = toParamSchemaBoundedIntegral
149instance ToParamSchema Word16 where toParamSchema = toParamSchemaBoundedIntegral
150+
150−instance ToParamSchema Word32 where toParamSchema = toParamSchemaBoundedIntegral
151+instance ToParamSchema Word32 where
152+ toParamSchema proxy = toParamSchemaBoundedIntegral proxy & format ?~ "int32"
153+
151−instance ToParamSchema Word64 where toParamSchema = toParamSchemaBoundedIntegral
154+instance ToParamSchema Word64 where
155+ toParamSchema proxy = toParamSchemaBoundedIntegral proxy & format ?~ "int64"
152
156
153-- | Default plain schema for @'Bounded'@, @'Integral'@ types.
157-- | Default plain schema for @'Bounded'@, @'Integral'@ types.
154--
158--
test/Data/Swagger/CommonTestTypes.hs+28−1
@@ -15,6 +15,7 @@ import Data.Map (Map)
15import Data.Proxy
15import Data.Proxy
16import Data.Set (Set)
16import Data.Set (Set)
17import qualified Data.Text as Text
17import qualified Data.Text as Text
18+import Data.Word
18import GHC.Generics
19import GHC.Generics
19
20
20import Data.Swagger
21import Data.Swagger
@@ -676,4 +677,30 @@ timeOfDayParamSchemaJSON = [aesonQQ|
676 "type": "string",
677 "type": "string",
677 "format": "hh:MM:ss"
678 "format": "hh:MM:ss"
678}
679}
679−|]
680+|]
681+
682+
683+-- ========================================================================
684+-- UnsignedInts
685+-- ========================================================================
686+data UnsignedInts = UnsignedInts
687+ { unsignedIntsUint32 :: Word32
688+ , unsignedIntsUint64 :: Word64
689+ } deriving (Generic)
690+
691+instance ToSchema UnsignedInts where
692+ declareNamedSchema = genericDeclareNamedSchema defaultSchemaOptions
693+ { fieldLabelModifier = map toLower . drop (length "unsignedInts") }
694+
695+unsignedIntsSchemaJSON :: Value
696+unsignedIntsSchemaJSON = [aesonQQ|
697+{
698+ "type": "object",
699+ "properties":
700+ {
701+ "uint32": { "type": "integer", "format": "int32", "minimum": 0, "maximum": 4294967295 },
702+ "uint64": { "type": "integer", "format": "int64", "minimum": 0, "maximum": 18446744073709551615 }
703+ },
704+ "required": ["uint32", "uint64"]
705+}
706+|]
test/Data/Swagger/SchemaSpec.hs+1
@@ -85,6 +85,7 @@ spec = do
85 context "Status (sum of unary constructors)" $ checkToSchema (Proxy :: Proxy Status) statusSchemaJSON
85 context "Status (sum of unary constructors)" $ checkToSchema (Proxy :: Proxy Status) statusSchemaJSON
86 context "Character (ref and record sum)" $ checkToSchema (Proxy :: Proxy Character) characterSchemaJSON
86 context "Character (ref and record sum)" $ checkToSchema (Proxy :: Proxy Character) characterSchemaJSON
87 context "Light (sum with unwrapUnaryRecords)" $ checkToSchema (Proxy :: Proxy Light) lightSchemaJSON
87 context "Light (sum with unwrapUnaryRecords)" $ checkToSchema (Proxy :: Proxy Light) lightSchemaJSON
88+ context "UnsignedInts" $ checkToSchema (Proxy :: Proxy UnsignedInts) unsignedIntsSchemaJSON
88 context "Schema name" $ do
89 context "Schema name" $ do
89 context "String" $ checkSchemaName Nothing (Proxy :: Proxy String)
90 context "String" $ checkSchemaName Nothing (Proxy :: Proxy String)
90 context "(Int, Float)" $ checkSchemaName Nothing (Proxy :: Proxy (Int, Float))
91 context "(Int, Float)" $ checkSchemaName Nothing (Proxy :: Proxy (Int, Float))