git.iko.soy/typeable/openapi3
on master help sign in
Merge branch 'release-2.3'
f42c345Nickolay Kudasov
CHANGELOG.md+15
@@ -1,3 +1,18 @@
1+2.3
2+---
3+
4+Major changes:
5+
6+- Add support for `additionalProperties` with `Bool` value (see [#159](https://github.com/GetShopTV/swagger2/pull/159));
7+- Add `ToSchema` `Object` instance (for aeson's `Object`) (see [`d72466a`](https://github.com/GetShopTV/swagger2/commit/d72466a));
8+
9+Dependencies and CI:
10+
11+- Aeson 1.4 (see [#158](https://github.com/GetShopTV/swagger2/pull/158));
12+- Update .travis.yml (see [#160](https://github.com/GetShopTV/swagger2/pull/160));
13+- Allow network 2.7 (see [#155](https://github.com/GetShopTV/swagger2/pull/155));
14+- Allow lens-4.17 (see [#161](https://github.com/GetShopTV/swagger2/pull/161));
15+
12.2.2
162.2.2
2-----
17-----
3
18
src/Data/Swagger/Internal/Schema.hs+7−1
@@ -32,7 +32,7 @@ import Data.Data.Lens (template)
32
32
33import Control.Monad
33import Control.Monad
34import Control.Monad.Writer
34import Control.Monad.Writer
35−import Data.Aeson (ToJSON (..), ToJSONKey (..), ToJSONKeyFunction (..), Value (..))
35+import Data.Aeson (ToJSON (..), ToJSONKey (..), ToJSONKeyFunction (..), Value (..), Object(..))
36import Data.Char
36import Data.Char
37import Data.Data (Data)
37import Data.Data (Data)
38import Data.Foldable (traverse_)
38import Data.Foldable (traverse_)
@@ -552,6 +552,12 @@ instance ToSchema a => ToSchema (HashMap TL.Text a) where declareNamedSchema _ =
552
552
553#endif
553#endif
554
554
555+instance OVERLAPPING_ ToSchema Object where
556+ declareNamedSchema _ = pure $ NamedSchema (Just "Object") $ mempty
557+ & type_ .~ SwaggerObject
558+ & description ?~ "Arbitrary JSON object."
559+ & additionalProperties ?~ AdditionalPropertiesAllowed True
560+
555instance ToSchema a => ToSchema (V.Vector a) where declareNamedSchema _ = declareNamedSchema (Proxy :: Proxy [a])
561instance ToSchema a => ToSchema (V.Vector a) where declareNamedSchema _ = declareNamedSchema (Proxy :: Proxy [a])
556instance ToSchema a => ToSchema (VU.Vector a) where declareNamedSchema _ = declareNamedSchema (Proxy :: Proxy [a])
562instance ToSchema a => ToSchema (VU.Vector a) where declareNamedSchema _ = declareNamedSchema (Proxy :: Proxy [a])
557instance ToSchema a => ToSchema (VS.Vector a) where declareNamedSchema _ = declareNamedSchema (Proxy :: Proxy [a])
563instance ToSchema a => ToSchema (VS.Vector a) where declareNamedSchema _ = declareNamedSchema (Proxy :: Proxy [a])
stack.yaml+1−2
@@ -1,8 +1,7 @@
1−resolver: lts-11.4
1+resolver: lts-11.14
2packages:
2packages:
3- '.'
3- '.'
4extra-deps:
4extra-deps:
5- aeson-1.3.1.0
5- aeson-1.3.1.0
6- base-compat-0.10.1
6- base-compat-0.10.1
7- base-compat-batteries-0.10.1
7- base-compat-batteries-0.10.1
8−- insert-ordered-containers-0.2.1.0
swagger2.cabal+1−2
@@ -1,7 +1,6 @@
1cabal-version: >=1.10
1cabal-version: >=1.10
2name: swagger2
2name: swagger2
3−version: 2.2.2
3+version: 2.3
4−x-revision: 3
5
4
6synopsis: Swagger 2.0 data model
5synopsis: Swagger 2.0 data model
7description:
6description:
test/Data/Swagger/CommonTestTypes.hs+18−18
@@ -1,25 +1,25 @@
1−{-# LANGUAGE DeriveGeneric #-}
1+{-# LANGUAGE DeriveGeneric #-}
2+{-# LANGUAGE QuasiQuotes #-}
2{-# LANGUAGE ScopedTypeVariables #-}
3{-# LANGUAGE ScopedTypeVariables #-}
3−{-# LANGUAGE QuasiQuotes #-}
4
4
5module Data.Swagger.CommonTestTypes where
5module Data.Swagger.CommonTestTypes where
6
6
7−import Prelude ()
7+import Prelude ()
8−import Prelude.Compat
8+import Prelude.Compat
9−
9+
10−import Data.Aeson (Value, ToJSON(..), ToJSONKey(..))
10+import Data.Aeson (ToJSON (..), ToJSONKey (..), Value)
11+import Data.Aeson.QQ
11−import Data.Aeson.Types (toJSONKeyText)
12+import Data.Aeson.Types (toJSONKeyText)
12−import Data.Aeson.QQ
13−import Data.Char
13+import Data.Char
14+import Data.Map (Map)
14−import Data.Proxy
15+import Data.Proxy
15−import Data.Set (Set)
16+import Data.Set (Set)
16−import Data.Map (Map)
17−import qualified Data.Text as Text
17+import qualified Data.Text as Text
18−import GHC.Generics
18+import GHC.Generics
19−
19+
20−import Data.Swagger
20+import Data.Swagger
21−import Data.Swagger.Declare
21+import Data.Swagger.Declare
22−import Data.Swagger.Internal (SwaggerKind(..))
22+import Data.Swagger.Internal (SwaggerKind (..))
23
23
24-- ========================================================================
24-- ========================================================================
25-- Unit type
25-- Unit type
test/Data/Swagger/Schema/ValidationSpec.hs+51−36
@@ -1,41 +1,41 @@
1−{-# LANGUAGE CPP #-}
1+{-# LANGUAGE CPP #-}
2−{-# LANGUAGE DeriveGeneric #-}
2+{-# LANGUAGE DeriveGeneric #-}
3−{-# LANGUAGE PackageImports #-}
3+{-# LANGUAGE PackageImports #-}
4−{-# LANGUAGE RecordWildCards #-}
4+{-# LANGUAGE RecordWildCards #-}
5{-# LANGUAGE ScopedTypeVariables #-}
5{-# LANGUAGE ScopedTypeVariables #-}
6{-# OPTIONS_GHC -fno-warn-orphans #-}
6{-# OPTIONS_GHC -fno-warn-orphans #-}
7module Data.Swagger.Schema.ValidationSpec where
7module Data.Swagger.Schema.ValidationSpec where
8
8
9−import Control.Applicative
9+import Control.Applicative
10−import Control.Lens ((&), (.~), (?~))
10+import Control.Lens ((&), (.~), (?~))
11−import Data.Aeson
11+import Data.Aeson
12−import Data.Aeson.Types
12+import Data.Aeson.Types
13−import Data.Int
13+import Data.Hashable (Hashable)
14−import Data.IntMap (IntMap)
14+import Data.HashMap.Strict (HashMap)
15−import Data.Hashable (Hashable)
15+import qualified Data.HashMap.Strict as HashMap
16−import "unordered-containers" Data.HashSet (HashSet)
16+import "unordered-containers" Data.HashSet (HashSet)
17import qualified "unordered-containers" Data.HashSet as HashSet
17import qualified "unordered-containers" Data.HashSet as HashSet
18−import Data.HashMap.Strict (HashMap)
18+import Data.Int
19−import qualified Data.HashMap.Strict as HashMap
19+import Data.IntMap (IntMap)
20−import Data.List.NonEmpty.Compat (NonEmpty(..), nonEmpty)
20+import Data.List.NonEmpty.Compat (NonEmpty (..), nonEmpty)
21−import Data.Map (Map, fromList)
21+import Data.Map (Map, fromList)
22−import Data.Monoid (mempty)
22+import Data.Monoid (mempty)
23−import Data.Proxy
23+import Data.Proxy
24−import Data.Time
24+import Data.Set (Set)
25−import qualified Data.Text as T
25+import qualified Data.Text as T
26−import qualified Data.Text.Lazy as TL
26+import qualified Data.Text.Lazy as TL
27−import Data.Version (Version)
27+import Data.Time
28−import Data.Set (Set)
28+import Data.Version (Version)
29−import Data.Word
29+import Data.Word
30−import GHC.Generics
30+import GHC.Generics
31−
31+
32−import Data.Swagger
32+import Data.Swagger
33−import Data.Swagger.Declare
33+import Data.Swagger.Declare
34−
34+
35−import Test.Hspec
35+import Test.Hspec
36−import Test.Hspec.QuickCheck
36+import Test.Hspec.QuickCheck
37−import Test.QuickCheck
37+import Test.QuickCheck
38−import Test.QuickCheck.Instances ()
38+import Test.QuickCheck.Instances ()
39
39
40shouldValidate :: (ToJSON a, ToSchema a) => Proxy a -> a -> Bool
40shouldValidate :: (ToJSON a, ToSchema a) => Proxy a -> a -> Bool
41shouldValidate _ x = validateToJSON x == []
41shouldValidate _ x = validateToJSON x == []
@@ -83,6 +83,7 @@ spec = do
83 prop "(HashMap String Int)" $ shouldValidate (Proxy :: Proxy (HashMap String Int))
83 prop "(HashMap String Int)" $ shouldValidate (Proxy :: Proxy (HashMap String Int))
84 prop "(HashMap T.Text Int)" $ shouldValidate (Proxy :: Proxy (HashMap T.Text Int))
84 prop "(HashMap T.Text Int)" $ shouldValidate (Proxy :: Proxy (HashMap T.Text Int))
85 prop "(HashMap TL.Text Bool)" $ shouldValidate (Proxy :: Proxy (HashMap TL.Text Bool))
85 prop "(HashMap TL.Text Bool)" $ shouldValidate (Proxy :: Proxy (HashMap TL.Text Bool))
86+ prop "Object" $ shouldValidate (Proxy :: Proxy Object)
86 prop "(Int, String, Double)" $ shouldValidate (Proxy :: Proxy (Int, String, Double))
87 prop "(Int, String, Double)" $ shouldValidate (Proxy :: Proxy (Int, String, Double))
87 prop "(Int, String, Double, [Int])" $ shouldValidate (Proxy :: Proxy (Int, String, Double, [Int]))
88 prop "(Int, String, Double, [Int])" $ shouldValidate (Proxy :: Proxy (Int, String, Double, [Int]))
88 prop "(Int, String, Double, [Int], Int)" $ shouldValidate (Proxy :: Proxy (Int, String, Double, [Int], Int))
89 prop "(Int, String, Double, [Int], Int)" $ shouldValidate (Proxy :: Proxy (Int, String, Double, [Int], Int))
@@ -139,9 +140,9 @@ instance Arbitrary Color where
139 arbitrary = arbitraryBoundedEnum
140 arbitrary = arbitraryBoundedEnum
140
141
141invalidColorToJSON :: Color -> Value
142invalidColorToJSON :: Color -> Value
142−invalidColorToJSON Red = toJSON "red"
143+invalidColorToJSON Red = toJSON "red"
143−invalidColorToJSON Green = toJSON "green"
144+invalidColorToJSON Green = toJSON "green"
144−invalidColorToJSON Blue = toJSON "blue"
145+invalidColorToJSON Blue = toJSON "blue"
145
146
146-- ========================================================================
147-- ========================================================================
147-- Paint (record with bounded enum property)
148-- Paint (record with bounded enum property)
@@ -261,3 +262,17 @@ instance Arbitrary FreeForm where
261instance Eq ZonedTime where
262instance Eq ZonedTime where
262 ZonedTime t (TimeZone x _ _) == ZonedTime t' (TimeZone y _ _) = t == t' && x == y
263 ZonedTime t (TimeZone x _ _) == ZonedTime t' (TimeZone y _ _) = t == t' && x == y
263
264
265+-- ========================================================================
266+-- Arbitrary instance for Data.Aeson.Value
267+-- ========================================================================
268+
269+instance Arbitrary Value where
270+ -- Weights are almost random
271+ -- Uniform oneof tends not to build complex objects cause of recursive call.
272+ arbitrary = resize 4 $ frequency
273+ [ (3, Object <$> arbitrary)
274+ , (3, Array <$> arbitrary)
275+ , (3, String <$> arbitrary)
276+ , (3, Number <$> arbitrary)
277+ , (3, Bool <$> arbitrary)
278+ , (1, return Null) ]