@@ -9,19 +9,35 @@ import Data.Swagger
9import Test.Hspec
9import Test.Hspec
10import Test.Hspec.HUnit
10import Test.Hspec.HUnit
12+(<=>) :: (Eq a, Show a, ToJSON a, FromJSON a) => a -> Value -> Spec
14+ it "encodes correctly" $ do
15+ toJSON x `shouldBe` json
16+ it "decodes correctly" $ do
17+ fromJSON json `shouldBe` Success x
21+ describe "License Object" $ licenseExample <=> licenseExampleJSON
22+ describe "Contact Object" $ contactExample <=> contactExampleJSON
23+ describe "Info Object" $ infoExample <=> infoExampleJSON
28+-- =======================================================================
30+-- =======================================================================
12infoExample :: SwaggerInfo
32infoExample :: SwaggerInfo
13infoExample = SwaggerInfo
33infoExample = SwaggerInfo
14 { swaggerInfoTitle = "Swagger Sample App"
34 { swaggerInfoTitle = "Swagger Sample App"
15 , swaggerInfoDescription = Just "This is a sample server Petstore server."
35 , swaggerInfoDescription = Just "This is a sample server Petstore server."
16 , swaggerInfoTermsOfService = Just "http://swagger.io/terms/"
36 , swaggerInfoTermsOfService = Just "http://swagger.io/terms/"
17− , swaggerInfoContact = Just contact
37+ , swaggerInfoContact = Just contactExample
18− , swaggerInfoLicense = Just license
38+ , swaggerInfoLicense = Just licenseExample
19 , swaggerInfoVersion = "1.0.1" }
39 , swaggerInfoVersion = "1.0.1" }
21− contact = SwaggerContact
22− { swaggerContactName = Just "API Support"
23− , swaggerContactUrl = Just (URL "http://www.swagger.io/support")
24− , swaggerContactEmail = Just "support@swagger.io" }
25 license = SwaggerLicense
41 license = SwaggerLicense
26 { swaggerLicenseName = "Apache 2.0"
42 { swaggerLicenseName = "Apache 2.0"
27 , swaggerLicenseUrl = Just (URL "http://www.apache.org/licenses/LICENSE-2.0.html") }
43 , swaggerLicenseUrl = Just (URL "http://www.apache.org/licenses/LICENSE-2.0.html") }
@@ -45,14 +61,38 @@ infoExampleJSON = [aesonQQ|
48−spec :: Spec
64+-- =======================================================================
49−spec = do
65+-- Contact object
50− describe "Info Object" $ do
66+-- =======================================================================
51− it "encodes correctly" $ do
52− toJSON infoExample `shouldBe` infoExampleJSON
53− it "decodes correctly" $ do
54− fromJSON infoExampleJSON `shouldBe` Success infoExample
56−main :: IO ()
68+contactExample :: SwaggerContact
57−main = hspec spec
69+contactExample = SwaggerContact
70+ { swaggerContactName = Just "API Support"
71+ , swaggerContactUrl = Just (URL "http://www.swagger.io/support")
72+ , swaggerContactEmail = Just "support@swagger.io" }
74+contactExampleJSON :: Value
75+contactExampleJSON = [aesonQQ|
77+ "name": "API Support",
78+ "url": "http://www.swagger.io/support",
79+ "email": "support@swagger.io"
83+-- =======================================================================
85+-- =======================================================================
87+licenseExample :: SwaggerLicense
88+licenseExample = SwaggerLicense
89+ { swaggerLicenseName = "Apache 2.0"
90+ , swaggerLicenseUrl = Just (URL "http://www.apache.org/licenses/LICENSE-2.0.html") }
92+licenseExampleJSON :: Value
93+licenseExampleJSON = [aesonQQ|
95+ "name": "Apache 2.0",
96+ "url": "http://www.apache.org/licenses/LICENSE-2.0.html"