Skip to content

Commit e55a0d0

Browse files
committed
Support servant-0.13
1 parent edb1330 commit e55a0d0

File tree

5 files changed

+119
-85
lines changed

5 files changed

+119
-85
lines changed

.travis.yml

Lines changed: 56 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This Travis job script has been generated by a script via
22
#
3-
# make_travis_yml_2.hs '--branch' 'master' 'servant-swagger.cabal'
3+
# runghc make_travis_yml_2.hs '--branch' 'master' '--output' '.travis.yml' 'servant-swagger.cabal'
44
#
55
# For more information, see https://github.com/hvr/multi-ghc-travis
66
#
@@ -18,7 +18,6 @@ cache:
1818
directories:
1919
- $HOME/.cabal/packages
2020
- $HOME/.cabal/store
21-
- $HOME/.local/bin
2221

2322
before_cache:
2423
- rm -fv $HOME/.cabal/packages/hackage.haskell.org/build-reports.log
@@ -29,6 +28,8 @@ before_cache:
2928
- rm -fv $HOME/.cabal/packages/hackage.haskell.org/01-index.tar
3029
- rm -fv $HOME/.cabal/packages/hackage.haskell.org/01-index.tar.idx
3130

31+
- rm -rfv $HOME/.cabal/packages/head.hackage
32+
3233
matrix:
3334
include:
3435
- compiler: "ghc-7.8.4"
@@ -40,55 +41,69 @@ matrix:
4041
- compiler: "ghc-8.0.2"
4142
# env: TEST=--disable-tests BENCH=--disable-benchmarks
4243
addons: {apt: {packages: [ghc-ppa-tools,cabal-install-head,ghc-8.0.2], sources: [hvr-ghc]}}
43-
- compiler: "ghc-8.2.1"
44+
- compiler: "ghc-8.2.2"
4445
# env: TEST=--disable-tests BENCH=--disable-benchmarks
45-
addons: {apt: {packages: [ghc-ppa-tools,cabal-install-head,ghc-8.2.1], sources: [hvr-ghc]}}
46+
addons: {apt: {packages: [ghc-ppa-tools,cabal-install-head,ghc-8.2.2], sources: [hvr-ghc]}}
4647

4748
before_install:
48-
- HC=${CC}
49-
- unset CC
50-
- PATH=/opt/ghc/bin:/opt/ghc-ppa-tools/bin:$HOME/.local/bin:$PATH
51-
- PKGNAME='servant-swagger'
49+
- HC=${CC}
50+
- HCPKG=${HC/ghc/ghc-pkg}
51+
- unset CC
52+
- ROOTDIR=$(pwd)
53+
- mkdir -p $HOME/.local/bin
54+
- "PATH=/opt/ghc/bin:/opt/ghc-ppa-tools/bin:$HOME/local/bin:$PATH"
55+
- HCNUMVER=$(( $(${HC} --numeric-version|sed -E 's/([0-9]+)\.([0-9]+)\.([0-9]+).*/\1 * 10000 + \2 * 100 + \3/') ))
56+
- echo $HCNUMVER
5257

5358
install:
54-
- cabal --version
55-
- echo "$(${HC} --version) [$(${HC} --print-project-git-commit-id 2> /dev/null || echo '?')]"
56-
- BENCH=${BENCH---enable-benchmarks}
57-
- TEST=${TEST---enable-tests}
58-
- travis_retry cabal update -v
59-
- sed -i 's/^jobs:/-- jobs:/' ${HOME}/.cabal/config
60-
- sh install-hspec-discover.sh # TEMP: we should use build-tools-depends
61-
- rm -fv cabal.project.local
62-
- "echo 'packages: .' > cabal.project"
63-
- rm -f cabal.project.freeze
64-
- cabal new-build -w ${HC} ${TEST} ${BENCH} --dep -j2 all
65-
- cabal new-build -w ${HC} --disable-tests --disable-benchmarks --dep -j2 all
59+
- cabal --version
60+
- echo "$(${HC} --version) [$(${HC} --print-project-git-commit-id 2> /dev/null || echo '?')]"
61+
- BENCH=${BENCH---enable-benchmarks}
62+
- TEST=${TEST---enable-tests}
63+
- HADDOCK=${HADDOCK-true}
64+
- INSTALLED=${INSTALLED-true}
65+
- GHCHEAD=${GHCHEAD-false}
66+
- travis_retry cabal update -v
67+
- "sed -i.bak 's/^jobs:/-- jobs:/' ${HOME}/.cabal/config"
68+
- rm -fv cabal.project cabal.project.local
69+
- grep -Ev -- '^\s*--' ${HOME}/.cabal/config | grep -Ev '^\s*$'
70+
- "printf 'packages: \".\"\\n' > cabal.project"
71+
- cat cabal.project
72+
- if [ -f "./configure.ac" ]; then
73+
(cd "." && autoreconf -i);
74+
fi
75+
- rm -f cabal.project.freeze
76+
- cabal new-build -w ${HC} ${TEST} ${BENCH} --project-file="cabal.project" --dep -j2 all
77+
- cabal new-build -w ${HC} --disable-tests --disable-benchmarks --project-file="cabal.project" --dep -j2 all
78+
- rm -rf "."/.ghc.environment.* "."/dist
79+
- DISTDIR=$(mktemp -d /tmp/dist-test.XXXX)
6680

6781
# Here starts the actual work to be performed for the package under test;
6882
# any command which exits with a non-zero exit code causes the build to fail.
6983
script:
70-
- if [ -f configure.ac ]; then autoreconf -i; fi
71-
- rm -rf .ghc.environment.* dist/
72-
- cabal sdist # test that a source-distribution can be generated
73-
- cd dist/
74-
- SRCTAR=(${PKGNAME}-*.tar.gz)
75-
- SRC_BASENAME="${SRCTAR/%.tar.gz}"
76-
- tar -xvf "./$SRC_BASENAME.tar.gz"
77-
- cd "$SRC_BASENAME/"
78-
## from here on, CWD is inside the extracted source-tarball
79-
- rm -fv cabal.project.local
80-
- "echo 'packages: .' > cabal.project"
81-
# this builds all libraries and executables (without tests/benchmarks)
82-
- rm -f cabal.project.freeze
83-
- cabal new-build -w ${HC} --disable-tests --disable-benchmarks all
84-
# this builds all libraries and executables (including tests/benchmarks)
85-
# - rm -rf ./dist-newstyle
84+
# test that source-distributions can be generated
85+
- (cd "." && cabal sdist)
86+
- mv "."/dist/servant-swagger-*.tar.gz ${DISTDIR}/
87+
- cd ${DISTDIR} || false
88+
- find . -maxdepth 1 -name '*.tar.gz' -exec tar -xvf '{}' \;
89+
- "printf 'packages: servant-swagger-*/*.cabal\\n' > cabal.project"
90+
- cat cabal.project
91+
# this builds all libraries and executables (without tests/benchmarks)
92+
- cabal new-build -w ${HC} --disable-tests --disable-benchmarks all
93+
94+
# Build with installed constraints for packages in global-db
95+
- if $INSTALLED; then echo cabal new-build -w ${HC} --disable-tests --disable-benchmarks $(${HCPKG} list --global --simple-output --names-only | sed 's/\([a-zA-Z0-9-]\{1,\}\) */--constraint="\1 installed" /g') all | sh; else echo "Not building with installed constraints"; fi
96+
97+
# build & run tests, build benchmarks
98+
- cabal new-build -w ${HC} ${TEST} ${BENCH} all
99+
- if [ "x$TEST" = "x--enable-tests" ]; then cabal new-test -w ${HC} ${TEST} ${BENCH} all; fi
86100

87-
# build & run tests, build benchmarks
88-
- cabal new-build -w ${HC} ${TEST} ${BENCH} all
89-
- if [ "x$TEST" = "x--enable-tests" ]; then cabal new-test -w ${HC} ${TEST} all; fi
101+
# cabal check
102+
- (cd servant-swagger-* && cabal check)
90103

91-
# haddock
92-
- cabal new-haddock -w ${HC} --disable-tests --disable-benchmarks all
104+
# haddock
105+
- rm -rf ./dist-newstyle
106+
- if $HADDOCK; then cabal new-haddock -w ${HC} ${TEST} ${BENCH} all; else echo "Skipping haddock generation";fi
93107

108+
# REGENDATA ["--branch","master","--output",".travis.yml","servant-swagger.cabal"]
94109
# EOF

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
1.1.5
2+
-----
3+
4+
* Notes:
5+
* `servant-0.13` compatible release
6+
* Drops compatibility with previous `servant` versions.
7+
18
1.1.4
29
-----
310

install-hspec-discover.sh

Lines changed: 0 additions & 19 deletions
This file was deleted.

servant-swagger.cabal

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,37 @@
11
name: servant-swagger
2-
version: 1.1.4
2+
version: 1.1.5
33
synopsis: Generate Swagger specification for your servant API.
4-
description: Please see README.md
4+
description:
5+
Swagger™ is a project used to describe and document RESTful APIs.
6+
Unlike Servant it is language-agnostic and thus is quite popular among developers
7+
in different languages. It also exists for a longer time and has more tools to work with.
8+
.
9+
This package provides means to generate Swagger specification for a Servant API
10+
and also to partially test whether API conforms with its specification.
11+
.
12+
Generated Swagger specification then can be used for many things such as
13+
.
14+
* displaying interactive documentation using [Swagger UI](http://swagger.io/swagger-ui/);
15+
.
16+
* generating clients and servers in many languages using [Swagger Codegen](http://swagger.io/swagger-codegen/);
17+
.
18+
* and [many others](http://swagger.io/open-source-integrations/).
519
homepage: https://github.com/haskell-servant/servant-swagger
620
bug-reports: https://github.com/haskell-servant/servant-swagger/issues
721
license: BSD3
822
license-file: LICENSE
923
author: David Johnson, Nickolay Kudasov
1024
maintainer: [email protected]
11-
copyright: (c) 2015-2016, Servant contributors
25+
copyright: (c) 2015-2018, Servant contributors
1226
category: Web, Servant, Swagger
1327
build-type: Custom
14-
cabal-version: >=1.10
28+
cabal-version: 1.18
1529
tested-with:
1630
GHC==7.8.4,
1731
GHC==7.10.3,
1832
GHC==8.0.2,
19-
GHC==8.2.1
33+
GHC==8.2.2
34+
2035
extra-source-files:
2136
README.md
2237
, CHANGELOG.md
@@ -60,8 +75,9 @@ library
6075
, bytestring >=0.10.4.0 && <0.11
6176
, http-media >=0.6.3 && <0.8
6277
, insert-ordered-containers >=0.1.0.0 && <0.3
63-
, lens >=4.7.0.1 && <4.16
64-
, servant >=0.5 && <0.13
78+
, lens >=4.7.0.1 && <4.17
79+
, servant >=0.13 && <0.14
80+
, singleton-bool >=0.1.3 && <0.2
6581
, swagger2 >=2.1 && <2.3
6682
, text >=1.2.0.6 && <1.3
6783
, unordered-containers >=0.2.5.1 && <0.3
@@ -89,6 +105,7 @@ test-suite spec
89105
type: exitcode-stdio-1.0
90106
hs-source-dirs: test
91107
main-is: Spec.hs
108+
build-tool-depends: hspec-discover:hspec-discover
92109
build-depends: base
93110
, aeson
94111
, aeson-qq >=0.8.1

src/Servant/Swagger/Internal.hs

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ import qualified Data.Text as Text
3030
import GHC.TypeLits
3131
import Network.HTTP.Media (MediaType)
3232
import Servant.API
33+
import Servant.API.Description (FoldDescription, reflectDescription)
34+
import Servant.API.Modifiers (FoldRequired)
35+
import Data.Singletons.Bool
3336

3437
import Servant.Swagger.Internal.TypeLevel.API
3538

@@ -71,10 +74,8 @@ class HasSwagger api where
7174
instance HasSwagger Raw where
7275
toSwagger _ = mempty & paths . at "/" ?~ mempty
7376

74-
#if MIN_VERSION_servant(0,11,0)
7577
instance HasSwagger EmptyAPI where
7678
toSwagger _ = mempty
77-
#endif
7879

7980
-- | All operations of sub API.
8081
-- This is similar to @'operationsOf'@ but ensures that operations
@@ -214,49 +215,53 @@ instance (KnownSymbol sym, HasSwagger sub) => HasSwagger (sym :> sub) where
214215
where
215216
piece = symbolVal (Proxy :: Proxy sym)
216217

217-
instance (KnownSymbol sym, ToParamSchema a, HasSwagger sub) => HasSwagger (Capture sym a :> sub) where
218+
instance (KnownSymbol sym, ToParamSchema a, HasSwagger sub, KnownSymbol (FoldDescription mods)) => HasSwagger (Capture' mods sym a :> sub) where
218219
toSwagger _ = toSwagger (Proxy :: Proxy sub)
219220
& addParam param
220221
& prependPath capture
221222
& addDefaultResponse404 tname
222223
where
223224
pname = symbolVal (Proxy :: Proxy sym)
224225
tname = Text.pack pname
226+
transDesc "" = Nothing
227+
transDesc desc = Just (Text.pack desc)
225228
capture = "{" <> pname <> "}"
226229
param = mempty
227230
& name .~ tname
231+
& description .~ transDesc (reflectDescription (Proxy :: Proxy mods))
228232
& required ?~ True
229233
& schema .~ ParamOther (mempty
230234
& in_ .~ ParamPath
231235
& paramSchema .~ toParamSchema (Proxy :: Proxy a))
232236

233-
#if MIN_VERSION_servant(0,8,1)
234237
-- | Swagger Spec doesn't have a notion of CaptureAll, this instance is the best effort.
235238
instance (KnownSymbol sym, ToParamSchema a, HasSwagger sub) => HasSwagger (CaptureAll sym a :> sub) where
236239
toSwagger _ = toSwagger (Proxy :: Proxy (Capture sym a :> sub))
237-
#endif
238240

239-
#if MIN_VERSION_servant(0,12,0)
240241
instance (KnownSymbol desc, HasSwagger api) => HasSwagger (Description desc :> api) where
241242
toSwagger _ = toSwagger (Proxy :: Proxy api)
242243
& allOperations.description %~ (Just (Text.pack (symbolVal (Proxy :: Proxy desc))) <>)
243244

244245
instance (KnownSymbol desc, HasSwagger api) => HasSwagger (Summary desc :> api) where
245246
toSwagger _ = toSwagger (Proxy :: Proxy api)
246247
& allOperations.summary %~ (Just (Text.pack (symbolVal (Proxy :: Proxy desc))) <>)
247-
#endif
248248

249-
instance (KnownSymbol sym, ToParamSchema a, HasSwagger sub) => HasSwagger (QueryParam sym a :> sub) where
249+
instance (KnownSymbol sym, ToParamSchema a, HasSwagger sub, SBoolI (FoldRequired mods), KnownSymbol (FoldDescription mods)) => HasSwagger (QueryParam' mods sym a :> sub) where
250250
toSwagger _ = toSwagger (Proxy :: Proxy sub)
251251
& addParam param
252252
& addDefaultResponse400 tname
253253
where
254254
tname = Text.pack (symbolVal (Proxy :: Proxy sym))
255+
transDesc "" = Nothing
256+
transDesc desc = Just (Text.pack desc)
255257
param = mempty
256258
& name .~ tname
257-
& schema .~ ParamOther (mempty
258-
& in_ .~ ParamQuery
259-
& paramSchema .~ toParamSchema (Proxy :: Proxy a))
259+
& description .~ transDesc (reflectDescription (Proxy :: Proxy mods))
260+
& required ?~ reflectBool (Proxy :: Proxy (FoldRequired mods))
261+
& schema .~ ParamOther sch
262+
sch = mempty
263+
& in_ .~ ParamQuery
264+
& paramSchema .~ toParamSchema (Proxy :: Proxy a)
260265

261266
instance (KnownSymbol sym, ToParamSchema a, HasSwagger sub) => HasSwagger (QueryParams sym a :> sub) where
262267
toSwagger _ = toSwagger (Proxy :: Proxy sub)
@@ -266,11 +271,13 @@ instance (KnownSymbol sym, ToParamSchema a, HasSwagger sub) => HasSwagger (Query
266271
tname = Text.pack (symbolVal (Proxy :: Proxy sym))
267272
param = mempty
268273
& name .~ tname
269-
& schema .~ ParamOther (mempty
270-
& in_ .~ ParamQuery
271-
& paramSchema .~ (mempty
272-
& type_ .~ SwaggerArray
273-
& items ?~ SwaggerItemsPrimitive (Just CollectionMulti) (toParamSchema (Proxy :: Proxy a))))
274+
& schema .~ ParamOther sch
275+
sch = mempty
276+
& in_ .~ ParamQuery
277+
& paramSchema .~ pschema
278+
pschema = mempty
279+
& type_ .~ SwaggerArray
280+
& items ?~ SwaggerItemsPrimitive (Just CollectionMulti) (toParamSchema (Proxy :: Proxy a))
274281

275282
instance (KnownSymbol sym, HasSwagger sub) => HasSwagger (QueryFlag sym :> sub) where
276283
toSwagger _ = toSwagger (Proxy :: Proxy sub)
@@ -286,29 +293,36 @@ instance (KnownSymbol sym, HasSwagger sub) => HasSwagger (QueryFlag sym :> sub)
286293
& paramSchema .~ (toParamSchema (Proxy :: Proxy Bool)
287294
& default_ ?~ toJSON False))
288295

289-
instance (KnownSymbol sym, ToParamSchema a, HasSwagger sub) => HasSwagger (Header sym a :> sub) where
296+
instance (KnownSymbol sym, ToParamSchema a, HasSwagger sub, SBoolI (FoldRequired mods), KnownSymbol (FoldDescription mods)) => HasSwagger (Header' mods sym a :> sub) where
290297
toSwagger _ = toSwagger (Proxy :: Proxy sub)
291298
& addParam param
292299
& addDefaultResponse400 tname
293300
where
294301
tname = Text.pack (symbolVal (Proxy :: Proxy sym))
302+
transDesc "" = Nothing
303+
transDesc desc = Just (Text.pack desc)
295304
param = mempty
296305
& name .~ tname
306+
& description .~ transDesc (reflectDescription (Proxy :: Proxy mods))
307+
& required ?~ reflectBool (Proxy :: Proxy (FoldRequired mods))
297308
& schema .~ ParamOther (mempty
298309
& in_ .~ ParamHeader
299310
& paramSchema .~ toParamSchema (Proxy :: Proxy a))
300311

301-
instance (ToSchema a, AllAccept cs, HasSwagger sub) => HasSwagger (ReqBody cs a :> sub) where
312+
instance (ToSchema a, AllAccept cs, HasSwagger sub, KnownSymbol (FoldDescription mods)) => HasSwagger (ReqBody' mods cs a :> sub) where
302313
toSwagger _ = toSwagger (Proxy :: Proxy sub)
303314
& addParam param
304315
& addConsumes (allContentType (Proxy :: Proxy cs))
305316
& addDefaultResponse400 tname
306317
& definitions %~ (<> defs)
307318
where
308319
tname = "body"
320+
transDesc "" = Nothing
321+
transDesc desc = Just (Text.pack desc)
309322
(defs, ref) = runDeclare (declareSchemaRef (Proxy :: Proxy a)) mempty
310323
param = mempty
311324
& name .~ tname
325+
& description .~ transDesc (reflectDescription (Proxy :: Proxy mods))
312326
& required ?~ True
313327
& schema .~ ParamBody ref
314328

0 commit comments

Comments
 (0)