git.iko.soy/typeable/swagger2
on master help sign in
Fix all warnings
9016212Nickolay Kudasov
src/Data/Swagger.hs+4−4
@@ -30,7 +30,7 @@ module Data.Swagger (
30 ParameterType(..),
30 ParameterType(..),
31 ItemsType(..),
31 ItemsType(..),
32 SchemaType(..),
32 SchemaType(..),
33− Format(..),
33+ Format,
34 CollectionFormat(..),
34 CollectionFormat(..),
35 ItemsCollectionFormat(..),
35 ItemsCollectionFormat(..),
36
36
@@ -39,7 +39,7 @@ module Data.Swagger (
39 ParameterSchema(..),
39 ParameterSchema(..),
40 ParameterOtherSchema(..),
40 ParameterOtherSchema(..),
41 ParameterLocation(..),
41 ParameterLocation(..),
42− ParamName(..),
42+ ParamName,
43 Items(..),
43 Items(..),
44 Header(..),
44 Header(..),
45 Example(..),
45 Example(..),
@@ -66,8 +66,8 @@ module Data.Swagger (
66 -- ** OAuth2
66 -- ** OAuth2
67 OAuth2Params(..),
67 OAuth2Params(..),
68 OAuth2Flow(..),
68 OAuth2Flow(..),
69− AuthorizationURL(..),
69+ AuthorizationURL,
70− TokenURL(..),
70+ TokenURL,
71
71
72 -- * External documentation
72 -- * External documentation
73 ExternalDocs(..),
73 ExternalDocs(..),
src/Data/Swagger/Internal.hs+16−19
@@ -13,7 +13,6 @@ import Control.Applicative
13import Control.Monad
13import Control.Monad
14import Data.Aeson
14import Data.Aeson
15import Data.Aeson.TH (deriveJSON)
15import Data.Aeson.TH (deriveJSON)
16−import Data.Foldable (Foldable)
17import Data.HashMap.Strict (HashMap)
16import Data.HashMap.Strict (HashMap)
18import qualified Data.HashMap.Strict as HashMap
17import qualified Data.HashMap.Strict as HashMap
19import Data.Map (Map)
18import Data.Map (Map)
@@ -23,8 +22,6 @@ import Data.Scientific (Scientific)
23import Data.String (fromString)
22import Data.String (fromString)
24import Data.Text (Text)
23import Data.Text (Text)
25import qualified Data.Text as Text
24import qualified Data.Text as Text
26−import Data.Traversable (Traversable)
27−import Data.Hashable (Hashable)
28import GHC.Generics (Generic)
25import GHC.Generics (Generic)
29import Network (HostName, PortNumber)
26import Network (HostName, PortNumber)
30import Network.HTTP.Media (MediaType)
27import Network.HTTP.Media (MediaType)
@@ -897,17 +894,17 @@ instance FromJSON OAuth2Params where
897 parseJSON = genericParseJSONWithSub "flow" (jsonPrefix "oauth2")
894 parseJSON = genericParseJSONWithSub "flow" (jsonPrefix "oauth2")
898
895
899instance FromJSON SecuritySchemeType where
896instance FromJSON SecuritySchemeType where
900− parseJSON json@(Object o) = do
897+ parseJSON js@(Object o) = do
901 (t :: Text) <- o .: "type"
898 (t :: Text) <- o .: "type"
902 case t of
899 case t of
903 "basic" -> pure SecuritySchemeBasic
900 "basic" -> pure SecuritySchemeBasic
904− "apiKey" -> SecuritySchemeApiKey <$> parseJSON json
901+ "apiKey" -> SecuritySchemeApiKey <$> parseJSON js
905− "oauth2" -> SecuritySchemeOAuth2 <$> parseJSON json
902+ "oauth2" -> SecuritySchemeOAuth2 <$> parseJSON js
906 _ -> empty
903 _ -> empty
907 parseJSON _ = empty
904 parseJSON _ = empty
908
905
909instance FromJSON Swagger where
906instance FromJSON Swagger where
910− parseJSON json@(Object o) = do
907+ parseJSON js@(Object o) = do
911 (version :: Text) <- o .: "swagger"
908 (version :: Text) <- o .: "swagger"
912 when (version /= "2.0") empty
909 when (version /= "2.0") empty
913 (genericParseJSON (jsonPrefix "")
910 (genericParseJSON (jsonPrefix "")
@@ -919,7 +916,7 @@ instance FromJSON Swagger where
919 , "parameters" .= (mempty :: HashMap Text Parameter)
916 , "parameters" .= (mempty :: HashMap Text Parameter)
920 , "responses" .= (mempty :: HashMap Text Response)
917 , "responses" .= (mempty :: HashMap Text Response)
921 , "securityDefinitions" .= (mempty :: HashMap Text SecurityScheme)
918 , "securityDefinitions" .= (mempty :: HashMap Text SecurityScheme)
922− ] ) json
919+ ] ) js
923 parseJSON _ = empty
920 parseJSON _ = empty
924
921
925instance FromJSON SecurityScheme where
922instance FromJSON SecurityScheme where
@@ -947,30 +944,30 @@ instance FromJSON Host where
947 parseJSON _ = empty
944 parseJSON _ = empty
948
945
949instance FromJSON Paths where
946instance FromJSON Paths where
950− parseJSON json = Paths <$> parseJSON json
947+ parseJSON js = Paths <$> parseJSON js
951
948
952instance FromJSON MimeList where
949instance FromJSON MimeList where
953− parseJSON json = (MimeList . map fromString) <$> parseJSON json
950+ parseJSON js = (MimeList . map fromString) <$> parseJSON js
954
951
955instance FromJSON Parameter where
952instance FromJSON Parameter where
956 parseJSON = genericParseJSONWithSub "schema" (jsonPrefix "parameter")
953 parseJSON = genericParseJSONWithSub "schema" (jsonPrefix "parameter")
957
954
958instance FromJSON ParameterSchema where
955instance FromJSON ParameterSchema where
959− parseJSON json@(Object o) = do
956+ parseJSON js@(Object o) = do
960 (i :: Text) <- o .: "in"
957 (i :: Text) <- o .: "in"
961 case i of
958 case i of
962 "body" -> do
959 "body" -> do
963 schema <- o .: "schema"
960 schema <- o .: "schema"
964 ParameterBody <$> parseJSON schema
961 ParameterBody <$> parseJSON schema
965− _ -> ParameterOther <$> parseJSON json
962+ _ -> ParameterOther <$> parseJSON js
966 parseJSON _ = empty
963 parseJSON _ = empty
967
964
968instance FromJSON ParameterOtherSchema where
965instance FromJSON ParameterOtherSchema where
969 parseJSON = genericParseJSONWithSub "common" (jsonPrefix "parameterOtherSchema")
966 parseJSON = genericParseJSONWithSub "common" (jsonPrefix "parameterOtherSchema")
970
967
971instance FromJSON SchemaItems where
968instance FromJSON SchemaItems where
972− parseJSON json@(Object _) = SchemaItemsObject <$> parseJSON json
969+ parseJSON js@(Object _) = SchemaItemsObject <$> parseJSON js
973− parseJSON json@(Array _) = SchemaItemsArray <$> parseJSON json
970+ parseJSON js@(Array _) = SchemaItemsArray <$> parseJSON js
974 parseJSON _ = empty
971 parseJSON _ = empty
975
972
976instance FromJSON Responses where
973instance FromJSON Responses where
@@ -980,8 +977,8 @@ instance FromJSON Responses where
980 parseJSON _ = empty
977 parseJSON _ = empty
981
978
982instance FromJSON Example where
979instance FromJSON Example where
983− parseJSON json = do
980+ parseJSON js = do
984− m <- parseJSON json
981+ m <- parseJSON js
985 pure $ Example (Map.mapKeys fromString m)
982 pure $ Example (Map.mapKeys fromString m)
986
983
987instance FromJSON Response where
984instance FromJSON Response where
@@ -1001,9 +998,9 @@ instance FromJSON Reference where
1001 parseJSON _ = empty
998 parseJSON _ = empty
1002
999
1003instance FromJSON a => FromJSON (Referenced a) where
1000instance FromJSON a => FromJSON (Referenced a) where
1004− parseJSON json
1001+ parseJSON js
1005− = Ref <$> parseJSON json
1002+ = Ref <$> parseJSON js
1006− <|> Inline <$> parseJSON json
1003+ <|> Inline <$> parseJSON js
1007
1004
1008instance FromJSON Xml where
1005instance FromJSON Xml where
1009 parseJSON = genericParseJSON (jsonPrefix "xml")
1006 parseJSON = genericParseJSON (jsonPrefix "xml")
src/Data/Swagger/Internal/Utils.hs+3−4
@@ -15,7 +15,6 @@ import Data.HashMap.Strict (HashMap)
15import qualified Data.HashMap.Strict as HashMap
15import qualified Data.HashMap.Strict as HashMap
16import Data.Monoid
16import Data.Monoid
17import Data.Text (Text)
17import Data.Text (Text)
18−import Data.Traversable
19import GHC.Generics
18import GHC.Generics
20import Language.Haskell.TH
19import Language.Haskell.TH
21import Text.Read (readMaybe)
20import Text.Read (readMaybe)
@@ -62,9 +61,9 @@ genericToJSONWithSub sub opts x =
62 _ -> error "genericToJSONWithSub: subjson is not an object"
61 _ -> error "genericToJSONWithSub: subjson is not an object"
63
62
64genericParseJSONWithSub :: (Generic a, GFromJSON (Rep a)) => Text -> Options -> Value -> Parser a
63genericParseJSONWithSub :: (Generic a, GFromJSON (Rep a)) => Text -> Options -> Value -> Parser a
65−genericParseJSONWithSub sub opts (Object o) = genericParseJSON opts json
64+genericParseJSONWithSub sub opts (Object o) = genericParseJSON opts js
66 where
65 where
67− json = Object (HashMap.insert sub (Object o) o)
66+ js = Object (HashMap.insert sub (Object o) o)
68genericParseJSONWithSub _ _ _ = error "genericParseJSONWithSub: given json is not an object"
67genericParseJSONWithSub _ _ _ = error "genericParseJSONWithSub: given json is not an object"
69
68
70(<+>) :: Value -> Value -> Value
69(<+>) :: Value -> Value -> Value
@@ -72,7 +71,7 @@ Object x <+> Object y = Object (x <> y)
72_ <+> _ = error "<+>: merging non-objects"
71_ <+> _ = error "<+>: merging non-objects"
73
72
74withDefaults :: (Value -> Parser a) -> [Pair] -> Value -> Parser a
73withDefaults :: (Value -> Parser a) -> [Pair] -> Value -> Parser a
75−withDefaults parser defs json@(Object _) = parser (json <+> object defs)
74+withDefaults parser defs js@(Object _) = parser (js <+> object defs)
76withDefaults _ _ _ = empty
75withDefaults _ _ _ = empty
77
76
78genericMempty :: (Generic a, GMonoid (Rep a)) => a
77genericMempty :: (Generic a, GMonoid (Rep a)) => a
src/Data/Swagger/Lens.hs−1
@@ -5,7 +5,6 @@
5module Data.Swagger.Lens where
5module Data.Swagger.Lens where
6
6
7import Control.Lens
7import Control.Lens
8−import Control.Lens.TH
9import Data.Aeson (Value)
8import Data.Aeson (Value)
10import Data.Scientific (Scientific)
9import Data.Scientific (Scientific)
11import Data.Swagger.Internal
10import Data.Swagger.Internal
src/Data/Swagger/Schema/Internal.hs+4−4
@@ -336,9 +336,9 @@ instance (GToSchema f, GToSchema g) => GToSchema (f :*: g) where
336 gtoNamedSchema opts _ = unnamed . gtoSchema opts (Proxy :: Proxy f) . gtoSchema opts (Proxy :: Proxy g)
336 gtoNamedSchema opts _ = unnamed . gtoSchema opts (Proxy :: Proxy f) . gtoSchema opts (Proxy :: Proxy g)
337
337
338instance (Datatype d, GToSchema f) => GToSchema (D1 d f) where
338instance (Datatype d, GToSchema f) => GToSchema (D1 d f) where
339− gtoNamedSchema opts _ s = (schemaName, gtoSchema opts (Proxy :: Proxy f) s)
339+ gtoNamedSchema opts _ s = (name, gtoSchema opts (Proxy :: Proxy f) s)
340 where
340 where
341− schemaName = gdatatypeSchemaName opts (Proxy :: Proxy d)
341+ name = gdatatypeSchemaName opts (Proxy :: Proxy d)
342
342
343instance {-# OVERLAPPABLE #-} GToSchema f => GToSchema (C1 c f) where
343instance {-# OVERLAPPABLE #-} GToSchema f => GToSchema (C1 c f) where
344 gtoNamedSchema opts _ = unnamed . gtoSchema opts (Proxy :: Proxy f)
344 gtoNamedSchema opts _ = unnamed . gtoSchema opts (Proxy :: Proxy f)
@@ -409,9 +409,9 @@ class GSumToSchema f where
409 gsumToSchema :: SchemaOptions -> proxy f -> Schema -> (AllNullary, Schema)
409 gsumToSchema :: SchemaOptions -> proxy f -> Schema -> (AllNullary, Schema)
410
410
411instance (GSumToSchema f, GSumToSchema g) => GSumToSchema (f :+: g) where
411instance (GSumToSchema f, GSumToSchema g) => GSumToSchema (f :+: g) where
412− gsumToSchema opts _ = gsumToSchema opts (Proxy :: Proxy f) <.> gsumToSchema opts (Proxy :: Proxy g)
412+ gsumToSchema opts _ = gsumToSchema opts (Proxy :: Proxy f) `after` gsumToSchema opts (Proxy :: Proxy g)
413 where
413 where
414− (f <.> g) s = (a <> b, s'')
414+ (f `after` g) s = (a <> b, s'')
415 where
415 where
416 (a, s') = f s
416 (a, s') = f s
417 (b, s'') = g s'
417 (b, s'') = g s'
test/Data/Swagger/SchemaSpec.hs+4−5
@@ -3,7 +3,7 @@
3{-# LANGUAGE ScopedTypeVariables #-}
3{-# LANGUAGE ScopedTypeVariables #-}
4{-# LANGUAGE TemplateHaskell #-}
4{-# LANGUAGE TemplateHaskell #-}
5{-# LANGUAGE QuasiQuotes #-}
5{-# LANGUAGE QuasiQuotes #-}
6−module Data.Swagger.SchemaSpec (main, spec) where
6+module Data.Swagger.SchemaSpec where
7
7
8import Data.Aeson
8import Data.Aeson
9import Data.Aeson.QQ
9import Data.Aeson.QQ
@@ -13,7 +13,6 @@ import Data.Set (Set)
13import GHC.Generics
13import GHC.Generics
14
14
15import Data.Swagger
15import Data.Swagger
16−import Data.Swagger.Schema
17
16
18import SpecCommon
17import SpecCommon
19import Test.Hspec
18import Test.Hspec
@@ -22,9 +21,9 @@ checkToSchema :: ToSchema a => Proxy a -> Value -> Spec
22checkToSchema proxy js = toSchema proxy <~> js
21checkToSchema proxy js = toSchema proxy <~> js
23
22
24checkSchemaName :: ToSchema a => Maybe String -> Proxy a -> Spec
23checkSchemaName :: ToSchema a => Maybe String -> Proxy a -> Spec
25−checkSchemaName name proxy =
24+checkSchemaName sname proxy =
26− it ("schema name is " ++ show name) $
25+ it ("schema name is " ++ show sname) $
27− schemaName proxy `shouldBe` name
26+ schemaName proxy `shouldBe` sname
28
27
29spec :: Spec
28spec :: Spec
30spec = do
29spec = do
test/Data/SwaggerSpec.hs−9
@@ -6,12 +6,7 @@ module Data.SwaggerSpec where
6
6
7import Data.Aeson
7import Data.Aeson
8import Data.Aeson.QQ
8import Data.Aeson.QQ
9−import qualified Data.Foldable as F
10import Data.HashMap.Strict (HashMap)
9import Data.HashMap.Strict (HashMap)
11−import qualified Data.HashMap.Strict as HashMap
12−import Data.Maybe
13−import Data.Monoid
14−import qualified Data.Vector as Vector
15import Data.Text (Text)
10import Data.Text (Text)
16
11
17import Data.Swagger
12import Data.Swagger
@@ -54,10 +49,6 @@ infoExample = Info
54 , _infoContact = Just contactExample
49 , _infoContact = Just contactExample
55 , _infoLicense = Just licenseExample
50 , _infoLicense = Just licenseExample
56 , _infoVersion = "1.0.1" }
51 , _infoVersion = "1.0.1" }
57− where
58− license = License
59− { _licenseName = "Apache 2.0"
60− , _licenseUrl = Just (URL "http://www.apache.org/licenses/LICENSE-2.0.html") }
61
52
62infoExampleJSON :: Value
53infoExampleJSON :: Value
63infoExampleJSON = [aesonQQ|
54infoExampleJSON = [aesonQQ|
test/SpecCommon.hs+6−13
@@ -1,16 +1,9 @@
1module SpecCommon where
1module SpecCommon where
2
2
3import Data.Aeson
3import Data.Aeson
4−import Data.Aeson.QQ
5import qualified Data.Foldable as F
4import qualified Data.Foldable as F
6−import Data.HashMap.Strict (HashMap)
7import qualified Data.HashMap.Strict as HashMap
5import qualified Data.HashMap.Strict as HashMap
8−import Data.Maybe
9−import Data.Monoid
10import qualified Data.Vector as Vector
6import qualified Data.Vector as Vector
11−import Data.Text (Text)
12−
13−import Data.Swagger
14
7
15import Test.Hspec
8import Test.Hspec
16
9
@@ -23,17 +16,17 @@ isSubJSON (Array xs) (Array ys) = Vector.length xs == Vector.length ys && F.and
23isSubJSON x y = x == y
16isSubJSON x y = x == y
24
17
25(<~>) :: (Eq a, Show a, ToJSON a, FromJSON a) => a -> Value -> Spec
18(<~>) :: (Eq a, Show a, ToJSON a, FromJSON a) => a -> Value -> Spec
26−x <~> json = do
19+x <~> js = do
27 it "encodes correctly (probably with extra properties)" $ do
20 it "encodes correctly (probably with extra properties)" $ do
28− toJSON x `shouldSatisfy` (json `isSubJSON`)
21+ toJSON x `shouldSatisfy` (js `isSubJSON`)
29 it "decodes correctly" $ do
22 it "decodes correctly" $ do
30− fromJSON json `shouldBe` Success x
23+ fromJSON js `shouldBe` Success x
31
24
32(<=>) :: (Eq a, Show a, ToJSON a, FromJSON a) => a -> Value -> Spec
25(<=>) :: (Eq a, Show a, ToJSON a, FromJSON a) => a -> Value -> Spec
33−x <=> json = do
26+x <=> js = do
34 it "encodes correctly" $ do
27 it "encodes correctly" $ do
35− toJSON x `shouldBe` json
28+ toJSON x `shouldBe` js
36 it "decodes correctly" $ do
29 it "decodes correctly" $ do
37− fromJSON json `shouldBe` Success x
30+ fromJSON js `shouldBe` Success x
38
31
39
32