Skip to content

Commit 13b7e5d

Browse files
authored
Merge pull request #94 from phadej/servant-0.15
Support servant-0.15
2 parents 6da28ea + 2b428e6 commit 13b7e5d

File tree

7 files changed

+76
-32
lines changed

7 files changed

+76
-32
lines changed

.travis.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,6 @@ matrix:
4444
- compiler: "ghc-8.0.2"
4545
# env: TEST=--disable-tests BENCH=--disable-benchmarks
4646
addons: {apt: {packages: [ghc-ppa-tools,cabal-install-2.4,ghc-8.0.2], sources: [hvr-ghc]}}
47-
- compiler: "ghc-7.10.3"
48-
# env: TEST=--disable-tests BENCH=--disable-benchmarks
49-
addons: {apt: {packages: [ghc-ppa-tools,cabal-install-2.4,ghc-7.10.3], sources: [hvr-ghc]}}
50-
- compiler: "ghc-7.8.4"
51-
# env: TEST=--disable-tests BENCH=--disable-benchmarks
52-
addons: {apt: {packages: [ghc-ppa-tools,cabal-install-2.4,ghc-7.8.4], sources: [hvr-ghc]}}
5347

5448
before_install:
5549
- HC=${CC}

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
1.1.7
2+
-----
3+
4+
* Support servant-0.15
5+
- support for 'Stream' and 'StreamBody' combinators
6+
- orphan 'ToSchema (SourceT m a)' instance
7+
* Fix BodyTypes to work with generalized ReqBody'
8+
[#88](https://github.com/haskell-servant/servant-swagger/pull/88)
9+
110
1.1.6
211
-----
312

servant-swagger.cabal

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: servant-swagger
2-
version: 1.1.6
2+
version: 1.1.7
33
synopsis: Generate Swagger specification for your servant API.
44
description:
55
Swagger is a project used to describe and document RESTful APIs.
@@ -27,9 +27,7 @@ category: Web, Servant, Swagger
2727
build-type: Custom
2828
cabal-version: 1.18
2929
tested-with:
30-
GHC ==7.8.4
31-
|| ==7.10.3
32-
|| ==8.0.2
30+
GHC ==8.0.2
3331
|| ==8.2.2
3432
|| ==8.4.4
3533
|| ==8.6.1
@@ -53,8 +51,8 @@ source-repository head
5351

5452
custom-setup
5553
setup-depends:
56-
base >=4.7 && <4.13,
57-
Cabal >= 1.18 && <2.5,
54+
base >=4.9 && <4.13,
55+
Cabal >= 1.24 && <2.5,
5856
cabal-doctest >=1.0.2 && <1.1
5957

6058
library
@@ -66,24 +64,26 @@ library
6664

6765
-- Internal modules
6866
Servant.Swagger.Internal
67+
Servant.Swagger.Internal.Orphans
6968
Servant.Swagger.Internal.Test
7069
Servant.Swagger.Internal.TypeLevel
7170
Servant.Swagger.Internal.TypeLevel.API
7271
Servant.Swagger.Internal.TypeLevel.Every
7372
Servant.Swagger.Internal.TypeLevel.TMap
7473
hs-source-dirs: src
75-
build-depends: aeson >=0.11.2.0 && <1.5
76-
, aeson-pretty >=0.4 && <0.9
77-
, base >=4.7.0.0 && <4.13
78-
, bytestring >=0.10.4.0 && <0.11
79-
, http-media >=0.6.3 && <0.8
80-
, insert-ordered-containers >=0.1.0.0 && <0.3
81-
, lens >=4.7.0.1 && <4.18
82-
, servant >=0.13 && <0.15
83-
, singleton-bool >=0.1.3 && <0.2
84-
, swagger2 >=2.1 && <2.4
85-
, text >=1.2.0.6 && <1.3
86-
, unordered-containers >=0.2.5.1 && <0.3
74+
build-depends: aeson >=1.4.1.0 && <1.5
75+
, aeson-pretty >=0.8.7 && <0.9
76+
, base >=4.9.1.0 && <4.13
77+
, base-compat >=0.10.5 && <0.11
78+
, bytestring >=0.10.8.1 && <0.11
79+
, http-media >=0.7.1.3 && <0.8
80+
, insert-ordered-containers >=0.2.1.0 && <0.3
81+
, lens >=4.17 && <4.18
82+
, servant >=0.15 && <0.16
83+
, singleton-bool >=0.1.4 && <0.2
84+
, swagger2 >=2.3.0.1 && <2.4
85+
, text >=1.2.3.0 && <1.3
86+
, unordered-containers >=0.2.9.0 && <0.3
8787

8888
, hspec
8989
, QuickCheck
@@ -108,11 +108,11 @@ test-suite spec
108108
type: exitcode-stdio-1.0
109109
hs-source-dirs: test
110110
main-is: Spec.hs
111-
build-tool-depends: hspec-discover:hspec-discover
111+
build-tool-depends: hspec-discover:hspec-discover >=2.6.0 && <2.7
112112
build-depends: base
113-
, base-compat >= 0.10.4 && <0.11
113+
, base-compat
114114
, aeson
115-
, hspec
115+
, hspec >=2.6.0 && <2.7
116116
, QuickCheck
117117
, lens
118118
, servant

src/Servant/Swagger.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ module Servant.Swagger (
4444

4545
import Servant.Swagger.Internal
4646
import Servant.Swagger.Test
47+
import Servant.Swagger.Internal.Orphans ()
4748

4849
-- $setup
4950
-- >>> import Control.Applicative

src/Servant/Swagger/Internal.hs

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,14 @@
1919
#endif
2020
module Servant.Swagger.Internal where
2121

22+
import Prelude ()
23+
import Prelude.Compat
24+
2225
import Control.Lens
2326
import Data.Aeson
2427
import Data.HashMap.Strict.InsOrd (InsOrdHashMap)
2528
import qualified Data.HashMap.Strict.InsOrd as InsOrdHashMap
26-
import Data.Monoid
29+
import Data.Foldable (toList)
2730
import Data.Proxy
2831
import Data.Singletons.Bool
2932
import Data.Swagger hiding (Header)
@@ -176,6 +179,10 @@ instance SwaggerMethod 'PATCH where swaggerMethod _ = patch
176179
instance OVERLAPPABLE_ (ToSchema a, AllAccept cs, KnownNat status, SwaggerMethod method) => HasSwagger (Verb method status cs a) where
177180
toSwagger _ = toSwagger (Proxy :: Proxy (Verb method status cs (Headers '[] a)))
178181

182+
-- | @since 1.1.7
183+
instance (ToSchema a, Accept ct, KnownNat status, SwaggerMethod method) => HasSwagger (Stream method status fr ct a) where
184+
toSwagger _ = toSwagger (Proxy :: Proxy (Verb method status '[ct] (Headers '[] a)))
185+
179186
instance OVERLAPPABLE_ (ToSchema a, AllAccept cs, AllToResponseHeader hs, KnownNat status, SwaggerMethod method)
180187
=> HasSwagger (Verb method status cs (Headers hs a)) where
181188
toSwagger = mkEndpoint "/"
@@ -330,6 +337,26 @@ instance (ToSchema a, AllAccept cs, HasSwagger sub, KnownSymbol (FoldDescription
330337
& required ?~ True
331338
& schema .~ ParamBody ref
332339

340+
-- | This instance is an approximation.
341+
--
342+
-- @since 1.1.7
343+
instance (ToSchema a, Accept ct, HasSwagger sub, KnownSymbol (FoldDescription mods)) => HasSwagger (StreamBody' mods fr ct a :> sub) where
344+
toSwagger _ = toSwagger (Proxy :: Proxy sub)
345+
& addParam param
346+
& addConsumes (toList (contentTypes (Proxy :: Proxy ct)))
347+
& addDefaultResponse400 tname
348+
& definitions %~ (<> defs)
349+
where
350+
tname = "body"
351+
transDesc "" = Nothing
352+
transDesc desc = Just (Text.pack desc)
353+
(defs, ref) = runDeclare (declareSchemaRef (Proxy :: Proxy a)) mempty
354+
param = mempty
355+
& name .~ tname
356+
& description .~ transDesc (reflectDescription (Proxy :: Proxy mods))
357+
& required ?~ True
358+
& schema .~ ParamBody ref
359+
333360
-- =======================================================================
334361
-- Below are the definitions that should be in Servant.API.ContentTypes
335362
-- =======================================================================
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{-# LANGUAGE ScopedTypeVariables #-}
2+
{-# OPTIONS_GHC -fno-warn-orphans #-}
3+
module Servant.Swagger.Internal.Orphans where
4+
5+
import Data.Proxy
6+
(Proxy (..))
7+
import Data.Swagger
8+
import Servant.Types.SourceT
9+
(SourceT)
10+
11+
-- | Pretend that 'SourceT m a' is '[a]'.
12+
--
13+
-- @since 1.1.7
14+
--
15+
instance ToSchema a => ToSchema (SourceT m a) where
16+
declareNamedSchema _ = declareNamedSchema (Proxy :: Proxy [a])

test/Servant/SwaggerSpec.hs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@
66
{-# LANGUAGE QuasiQuotes #-}
77
{-# LANGUAGE TypeOperators #-}
88
{-# LANGUAGE PackageImports #-}
9-
#if __GLASGOW_HASKELL__ == 708
10-
{-# OPTIONS_GHC -fcontext-stack=31 #-}
11-
#endif
129
module Servant.SwaggerSpec where
1310

1411
import Control.Lens
@@ -24,7 +21,7 @@ import Data.Time
2421
import GHC.Generics
2522
import Servant.API
2623
import Servant.Swagger
27-
import Servant.API.Internal.Test.ComprehensiveAPI (comprehensiveAPI)
24+
import Servant.Test.ComprehensiveAPI (comprehensiveAPI)
2825
import Test.Hspec hiding (example)
2926

3027
checkAPI :: HasSwagger api => Proxy api -> Value -> IO ()

0 commit comments

Comments
 (0)