git.iko.soy/typeable/openapi3
on master help sign in
Fix all warnings
commit9016212eb17ea1cf55371bbc1a1077f77143795d authorNickolay Kudasov <nickolay.kudasov@gmail.com> dateSat 28 Nov 2015, 02:07 (11 years ago) parent2600c20
8 files changed+37−59
src/Data/Swagger.hs+4−4 src/Data/Swagger/Internal.hs+16−19 src/Data/Swagger/Internal/Utils.hs+3−4 src/Data/Swagger/Lens.hs−1 src/Data/Swagger/Schema/Internal.hs+4−4 test/Data/Swagger/SchemaSpec.hs+4−5 test/Data/SwaggerSpec.hs−9 test/SpecCommon.hs+6−13
src/Data/Swagger.hs+4−4
@@ -30,7 +30,7 @@ module Data.Swagger (
3030 ParameterType(..),
3131 ItemsType(..),
3232 SchemaType(..),
33− Format(..),
33+ Format,
3434 CollectionFormat(..),
3535 ItemsCollectionFormat(..),
3636
@@ -39,7 +39,7 @@ module Data.Swagger (
3939 ParameterSchema(..),
4040 ParameterOtherSchema(..),
4141 ParameterLocation(..),
42− ParamName(..),
42+ ParamName,
4343 Items(..),
4444 Header(..),
4545 Example(..),
@@ -66,8 +66,8 @@ module Data.Swagger (
6666 -- ** OAuth2
6767 OAuth2Params(..),
6868 OAuth2Flow(..),
69− AuthorizationURL(..),
70− TokenURL(..),
69+ AuthorizationURL,
70+ TokenURL,
7171
7272 -- * External documentation
7373 ExternalDocs(..),
src/Data/Swagger/Internal.hs+16−19
@@ -13,7 +13,6 @@ import Control.Applicative
1313import Control.Monad
1414import Data.Aeson
1515import Data.Aeson.TH (deriveJSON)
16−import Data.Foldable (Foldable)
1716import Data.HashMap.Strict (HashMap)
1817import qualified Data.HashMap.Strict as HashMap
1918import Data.Map (Map)
@@ -23,8 +22,6 @@ import Data.Scientific (Scientific)
2322import Data.String (fromString)
2423import Data.Text (Text)
2524import qualified Data.Text as Text
26−import Data.Traversable (Traversable)
27−import Data.Hashable (Hashable)
2825import GHC.Generics (Generic)
2926import Network (HostName, PortNumber)
3027import Network.HTTP.Media (MediaType)
@@ -897,17 +894,17 @@ instance FromJSON OAuth2Params where
897894 parseJSON = genericParseJSONWithSub "flow" (jsonPrefix "oauth2")
898895
899896instance FromJSON SecuritySchemeType where
900− parseJSON json@(Object o) = do
897+ parseJSON js@(Object o) = do
901898 (t :: Text) <- o .: "type"
902899 case t of
903900 "basic" -> pure SecuritySchemeBasic
904− "apiKey" -> SecuritySchemeApiKey <$> parseJSON json
905− "oauth2" -> SecuritySchemeOAuth2 <$> parseJSON json
901+ "apiKey" -> SecuritySchemeApiKey <$> parseJSON js
902+ "oauth2" -> SecuritySchemeOAuth2 <$> parseJSON js
906903 _ -> empty
907904 parseJSON _ = empty
908905
909906instance FromJSON Swagger where
910− parseJSON json@(Object o) = do
907+ parseJSON js@(Object o) = do
911908 (version :: Text) <- o .: "swagger"
912909 when (version /= "2.0") empty
913910 (genericParseJSON (jsonPrefix "")
@@ -919,7 +916,7 @@ instance FromJSON Swagger where
919916 , "parameters" .= (mempty :: HashMap Text Parameter)
920917 , "responses" .= (mempty :: HashMap Text Response)
921918 , "securityDefinitions" .= (mempty :: HashMap Text SecurityScheme)
922− ] ) json
919+ ] ) js
923920 parseJSON _ = empty
924921
925922instance FromJSON SecurityScheme where
@@ -947,30 +944,30 @@ instance FromJSON Host where
947944 parseJSON _ = empty
948945
949946instance FromJSON Paths where
950− parseJSON json = Paths <$> parseJSON json
947+ parseJSON js = Paths <$> parseJSON js
951948
952949instance FromJSON MimeList where
953− parseJSON json = (MimeList . map fromString) <$> parseJSON json
950+ parseJSON js = (MimeList . map fromString) <$> parseJSON js
954951
955952instance FromJSON Parameter where
956953 parseJSON = genericParseJSONWithSub "schema" (jsonPrefix "parameter")
957954
958955instance FromJSON ParameterSchema where
959− parseJSON json@(Object o) = do
956+ parseJSON js@(Object o) = do
960957 (i :: Text) <- o .: "in"
961958 case i of
962959 "body" -> do
963960 schema <- o .: "schema"
964961 ParameterBody <$> parseJSON schema
965− _ -> ParameterOther <$> parseJSON json
962+ _ -> ParameterOther <$> parseJSON js
966963 parseJSON _ = empty
967964
968965instance FromJSON ParameterOtherSchema where
969966 parseJSON = genericParseJSONWithSub "common" (jsonPrefix "parameterOtherSchema")
970967
971968instance FromJSON SchemaItems where
972− parseJSON json@(Object _) = SchemaItemsObject <$> parseJSON json
973− parseJSON json@(Array _) = SchemaItemsArray <$> parseJSON json
969+ parseJSON js@(Object _) = SchemaItemsObject <$> parseJSON js
970+ parseJSON js@(Array _) = SchemaItemsArray <$> parseJSON js
974971 parseJSON _ = empty
975972
976973instance FromJSON Responses where
@@ -980,8 +977,8 @@ instance FromJSON Responses where
980977 parseJSON _ = empty
981978
982979instance FromJSON Example where
983− parseJSON json = do
984− m <- parseJSON json
980+ parseJSON js = do
981+ m <- parseJSON js
985982 pure $ Example (Map.mapKeys fromString m)
986983
987984instance FromJSON Response where
@@ -1001,9 +998,9 @@ instance FromJSON Reference where
1001998 parseJSON _ = empty
1002999
10031000instance FromJSON a => FromJSON (Referenced a) where
1004− parseJSON json
1005− = Ref <$> parseJSON json
1006− <|> Inline <$> parseJSON json
1001+ parseJSON js
1002+ = Ref <$> parseJSON js
1003+ <|> Inline <$> parseJSON js
10071004
10081005instance FromJSON Xml where
10091006 parseJSON = genericParseJSON (jsonPrefix "xml")
src/Data/Swagger/Internal/Utils.hs+3−4
@@ -15,7 +15,6 @@ import Data.HashMap.Strict (HashMap)
1515import qualified Data.HashMap.Strict as HashMap
1616import Data.Monoid
1717import Data.Text (Text)
18−import Data.Traversable
1918import GHC.Generics
2019import Language.Haskell.TH
2120import Text.Read (readMaybe)
@@ -62,9 +61,9 @@ genericToJSONWithSub sub opts x =
6261 _ -> error "genericToJSONWithSub: subjson is not an object"
6362
6463genericParseJSONWithSub :: (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
6665 where
67− json = Object (HashMap.insert sub (Object o) o)
66+ js = Object (HashMap.insert sub (Object o) o)
6867genericParseJSONWithSub _ _ _ = error "genericParseJSONWithSub: given json is not an object"
6968
7069(<+>) :: Value -> Value -> Value
@@ -72,7 +71,7 @@ Object x <+> Object y = Object (x <> y)
7271_ <+> _ = error "<+>: merging non-objects"
7372
7473withDefaults :: (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)
7675withDefaults _ _ _ = empty
7776
7877genericMempty :: (Generic a, GMonoid (Rep a)) => a
src/Data/Swagger/Lens.hs−1
@@ -5,7 +5,6 @@
55module Data.Swagger.Lens where
66
77import Control.Lens
8−import Control.Lens.TH
98import Data.Aeson (Value)
109import Data.Scientific (Scientific)
1110import Data.Swagger.Internal
src/Data/Swagger/Schema/Internal.hs+4−4
@@ -336,9 +336,9 @@ instance (GToSchema f, GToSchema g) => GToSchema (f :*: g) where
336336 gtoNamedSchema opts _ = unnamed . gtoSchema opts (Proxy :: Proxy f) . gtoSchema opts (Proxy :: Proxy g)
337337
338338instance (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)
340340 where
341− schemaName = gdatatypeSchemaName opts (Proxy :: Proxy d)
341+ name = gdatatypeSchemaName opts (Proxy :: Proxy d)
342342
343343instance {-# OVERLAPPABLE #-} GToSchema f => GToSchema (C1 c f) where
344344 gtoNamedSchema opts _ = unnamed . gtoSchema opts (Proxy :: Proxy f)
@@ -409,9 +409,9 @@ class GSumToSchema f where
409409 gsumToSchema :: SchemaOptions -> proxy f -> Schema -> (AllNullary, Schema)
410410
411411instance (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)
413413 where
414− (f <.> g) s = (a <> b, s'')
414+ (f `after` g) s = (a <> b, s'')
415415 where
416416 (a, s') = f s
417417 (b, s'') = g s'
test/Data/Swagger/SchemaSpec.hs+4−5
@@ -3,7 +3,7 @@
33{-# LANGUAGE ScopedTypeVariables #-}
44{-# LANGUAGE TemplateHaskell #-}
55{-# LANGUAGE QuasiQuotes #-}
6−module Data.Swagger.SchemaSpec (main, spec) where
6+module Data.Swagger.SchemaSpec where
77
88import Data.Aeson
99import Data.Aeson.QQ
@@ -13,7 +13,6 @@ import Data.Set (Set)
1313import GHC.Generics
1414
1515import Data.Swagger
16−import Data.Swagger.Schema
1716
1817import SpecCommon
1918import Test.Hspec
@@ -22,9 +21,9 @@ checkToSchema :: ToSchema a => Proxy a -> Value -> Spec
2221checkToSchema proxy js = toSchema proxy <~> js
2322
2423checkSchemaName :: ToSchema a => Maybe String -> Proxy a -> Spec
25−checkSchemaName name proxy =
26− it ("schema name is " ++ show name) $
27− schemaName proxy `shouldBe` name
24+checkSchemaName sname proxy =
25+ it ("schema name is " ++ show sname) $
26+ schemaName proxy `shouldBe` sname
2827
2928spec :: Spec
3029spec = do
test/Data/SwaggerSpec.hs−9
@@ -6,12 +6,7 @@ module Data.SwaggerSpec where
66
77import Data.Aeson
88import Data.Aeson.QQ
9−import qualified Data.Foldable as F
109import 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
1510import Data.Text (Text)
1611
1712import Data.Swagger
@@ -54,10 +49,6 @@ infoExample = Info
5449 , _infoContact = Just contactExample
5550 , _infoLicense = Just licenseExample
5651 , _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") }
6152
6253infoExampleJSON :: Value
6354infoExampleJSON = [aesonQQ|
test/SpecCommon.hs+6−13
@@ -1,16 +1,9 @@
11module SpecCommon where
22
33import Data.Aeson
4−import Data.Aeson.QQ
54import qualified Data.Foldable as F
6−import Data.HashMap.Strict (HashMap)
75import qualified Data.HashMap.Strict as HashMap
8−import Data.Maybe
9−import Data.Monoid
106import qualified Data.Vector as Vector
11−import Data.Text (Text)
12−
13−import Data.Swagger
147
158import Test.Hspec
169
@@ -23,17 +16,17 @@ isSubJSON (Array xs) (Array ys) = Vector.length xs == Vector.length ys && F.and
2316isSubJSON x y = x == y
2417
2518(<~>) :: (Eq a, Show a, ToJSON a, FromJSON a) => a -> Value -> Spec
26−x <~> json = do
19+x <~> js = do
2720 it "encodes correctly (probably with extra properties)" $ do
28− toJSON x `shouldSatisfy` (json `isSubJSON`)
21+ toJSON x `shouldSatisfy` (js `isSubJSON`)
2922 it "decodes correctly" $ do
30− fromJSON json `shouldBe` Success x
23+ fromJSON js `shouldBe` Success x
3124
3225(<=>) :: (Eq a, Show a, ToJSON a, FromJSON a) => a -> Value -> Spec
33−x <=> json = do
26+x <=> js = do
3427 it "encodes correctly" $ do
35− toJSON x `shouldBe` json
28+ toJSON x `shouldBe` js
3629 it "decodes correctly" $ do
37− fromJSON json `shouldBe` Success x
30+ fromJSON js `shouldBe` Success x
3831
3932