git.iko.soy/typeable/swagger2
on master help sign in
extract schema and paramSchema's JSON Value into CommonTestTypes
commitbd00ca59051d1a1a0833b17397201c649c02d9d9 authoranneloreegger <annelore.e@hotmail.com> dateSat 20 Jul 2019, 14:14 (7 years ago) parent1c3de74
3 files changed+32−3
test/Data/Swagger/CommonTestTypes.hs+29 test/Data/Swagger/ParamSchemaSpec.hs+1−1 test/Data/Swagger/SchemaSpec.hs+2−2
test/Data/Swagger/CommonTestTypes.hs+29
@@ -650,3 +650,32 @@ singleMaybeFieldSchemaJSON = [aesonQQ|
650650 }
651651}
652652|]
653+
654+
655+-- ========================================================================
656+-- TimeOfDay
657+-- ========================================================================
658+data TimeOfDay
659+ = Int
660+ | Pico
661+ deriving (Generic)
662+instance ToSchema TimeOfDay
663+instance ToParamSchema TimeOfDay
664+
665+
666+timeOfDaySchemaJSON :: Value
667+timeOfDaySchemaJSON = [aesonQQ|
668+{
669+ "example": "12:33:15",
670+ "type": "string",
671+ "format": "hh:MM:ss"
672+}
673+|]
674+
675+timeOfDayParamSchemaJSON :: Value
676+timeOfDayParamSchemaJSON = [aesonQQ|
677+{
678+ "type": "string",
679+ "format": "hh:MM:ss"
680+}
681+|]
test/Data/Swagger/ParamSchemaSpec.hs+1−1
@@ -34,7 +34,7 @@ spec = do
3434 context "Unary records" $ do
3535 context "Email (unary record)" $ checkToParamSchema (Proxy :: Proxy Email) emailSchemaJSON
3636 context "UserId (non-record newtype)" $ checkToParamSchema (Proxy :: Proxy UserId) userIdSchemaJSON
37− context "TimeOfDay" $ checkToParamSchema (Proxy :: Proxy TimeOfDay) (Object (HM.fromList [("format",String "hh:MM:ss"),("type",String "string")]))
37+ context "TimeOfDay" $ checkToParamSchema (Proxy :: Proxy Data.Time.LocalTime.TimeOfDay) timeOfDayParamSchemaJSON
3838
3939main :: IO ()
4040main = hspec spec
test/Data/Swagger/SchemaSpec.hs+2−2
@@ -29,7 +29,7 @@ import SpecCommon
2929import Test.Hspec
3030
3131import qualified Data.HashMap.Strict as HM
32−import Data.Time
32+import Data.Time.LocalTime
3333
3434checkToSchema :: ToSchema a => Proxy a -> Value -> Spec
3535checkToSchema proxy js = toSchema proxy <=> js
@@ -115,7 +115,7 @@ spec = do
115115 context "MyRoseTree' (inlineNonRecursiveSchemas)" $ checkInlinedRecSchema (Proxy :: Proxy MyRoseTree') myRoseTreeSchemaJSON'
116116 describe "Bounded Enum key mapping" $ do
117117 context "ButtonImages" $ checkToSchema (Proxy :: Proxy ButtonImages) buttonImagesSchemaJSON
118− context "TimeOfDay" $ checkToSchema (Proxy :: Proxy TimeOfDay ) (Object (HM.fromList [("example",String "12:33:15"),("format",String "hh:MM:ss"),("type",String "string")]))
118+ context "TimeOfDay" $ checkToSchema (Proxy :: Proxy Data.Time.LocalTime.TimeOfDay ) timeOfDaySchemaJSON
119119
120120main :: IO ()
121121main = hspec spec