Skip to content

Commit de9ff55

Browse files
authored
Merge pull request #103 from haskell-servant/swagger2-2.4
Support swagger2-2.4
2 parents d9b8c49 + 8314f67 commit de9ff55

File tree

5 files changed

+137
-110
lines changed

5 files changed

+137
-110
lines changed

.travis.yml

Lines changed: 102 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,23 @@
11
# This Travis job script has been generated by a script via
22
#
3-
# haskell-ci '--branches' 'master' '--output' '.travis.yml' 'servant-swagger.cabal'
3+
# haskell-ci '--config=cabal.haskell-ci' 'servant-swagger.cabal'
44
#
55
# For more information, see https://github.com/haskell-CI/haskell-ci
66
#
7+
# version: 0.3.20190521
8+
#
79
language: c
810
dist: xenial
9-
1011
git:
11-
submodules: false # whether to recursively clone submodules
12-
12+
# whether to recursively clone submodules
13+
submodules: false
1314
branches:
1415
only:
1516
- master
16-
1717
cache:
1818
directories:
1919
- $HOME/.cabal/packages
2020
- $HOME/.cabal/store
21-
2221
before_cache:
2322
- rm -fv $CABALHOME/packages/hackage.haskell.org/build-reports.log
2423
# remove files that are regenerated by 'cabal update'
@@ -27,93 +26,131 @@ before_cache:
2726
- rm -fv $CABALHOME/packages/hackage.haskell.org/01-index.cache
2827
- rm -fv $CABALHOME/packages/hackage.haskell.org/01-index.tar
2928
- rm -fv $CABALHOME/packages/hackage.haskell.org/01-index.tar.idx
30-
3129
- rm -rfv $CABALHOME/packages/head.hackage
32-
3330
matrix:
3431
include:
35-
- compiler: "ghc-8.6.1"
36-
addons: {apt: {packages: [ghc-ppa-tools,cabal-install-2.4,ghc-8.6.1], sources: [hvr-ghc]}}
37-
- compiler: "ghc-8.4.4"
38-
addons: {apt: {packages: [ghc-ppa-tools,cabal-install-2.4,ghc-8.4.4], sources: [hvr-ghc]}}
39-
- compiler: "ghc-8.2.2"
40-
addons: {apt: {packages: [ghc-ppa-tools,cabal-install-2.4,ghc-8.2.2], sources: [hvr-ghc]}}
41-
- compiler: "ghc-8.0.2"
42-
addons: {apt: {packages: [ghc-ppa-tools,cabal-install-2.4,ghc-8.0.2], sources: [hvr-ghc]}}
43-
32+
- compiler: ghc-8.6.5
33+
addons: {"apt":{"sources":["hvr-ghc"],"packages":["ghc-8.6.5","cabal-install-2.4"]}}
34+
- compiler: ghc-8.4.4
35+
addons: {"apt":{"sources":["hvr-ghc"],"packages":["ghc-8.4.4","cabal-install-2.4"]}}
36+
- compiler: ghc-8.2.2
37+
addons: {"apt":{"sources":["hvr-ghc"],"packages":["ghc-8.2.2","cabal-install-2.4"]}}
38+
- compiler: ghc-8.0.2
39+
addons: {"apt":{"sources":["hvr-ghc"],"packages":["ghc-8.0.2","cabal-install-2.4"]}}
4440
before_install:
45-
- HC=/opt/ghc/bin/${CC}
46-
- HCVER=$(echo "$TRAVIS_COMPILER" | sed 's/ghc-//')
47-
- echo $HCVER
48-
- HCPKG=${HC/ghc/ghc-pkg}
41+
- HC=$(echo "/opt/$CC/bin/ghc" | sed 's/-/\//')
42+
- HCPKG="$HC-pkg"
4943
- unset CC
5044
- CABAL=/opt/ghc/bin/cabal
5145
- CABALHOME=$HOME/.cabal
5246
- export PATH="$CABALHOME/bin:$PATH"
53-
- ROOTDIR=$(pwd)
47+
- TOP=$(pwd)
5448
- HCNUMVER=$(( $(${HC} --numeric-version|sed -E 's/([0-9]+)\.([0-9]+)\.([0-9]+).*/\1 * 10000 + \2 * 100 + \3/') ))
5549
- echo $HCNUMVER
56-
50+
- CABAL="$CABAL -vnormal+nowrap+markoutput"
51+
- set -o pipefail
52+
- |
53+
echo 'function blue(s) { printf "\033[0;34m" s "\033[0m " }' >> .colorful.awk
54+
echo 'BEGIN { state = "output"; }' >> .colorful.awk
55+
echo '/^-----BEGIN CABAL OUTPUT-----$/ { state = "cabal" }' >> .colorful.awk
56+
echo '/^-----END CABAL OUTPUT-----$/ { state = "output" }' >> .colorful.awk
57+
echo '!/^(-----BEGIN CABAL OUTPUT-----|-----END CABAL OUTPUT-----)/ {' >> .colorful.awk
58+
echo ' if (state == "cabal") {' >> .colorful.awk
59+
echo ' print blue($0)' >> .colorful.awk
60+
echo ' } else {' >> .colorful.awk
61+
echo ' print $0' >> .colorful.awk
62+
echo ' }' >> .colorful.awk
63+
echo '}' >> .colorful.awk
64+
- cat .colorful.awk
65+
- |
66+
color_cabal_output () {
67+
awk -f $TOP/.colorful.awk
68+
}
69+
- echo text | color_cabal_output
5770
install:
5871
- ${CABAL} --version
5972
- echo "$(${HC} --version) [$(${HC} --print-project-git-commit-id 2> /dev/null || echo '?')]"
6073
- TEST=--enable-tests
6174
- BENCH=--enable-benchmarks
6275
- GHCHEAD=${GHCHEAD-false}
63-
- if [ "$TRAVIS_OS_NAME" = "windows" ]; then export CABALHOME=$APPDATA/cabal; else export CABALHOME=$HOME/.cabal; fi
64-
- travis_retry ${CABAL} update -v
65-
- sed -i.bak 's/^jobs:/-- jobs:/' $CABALHOME/config
66-
- rm -fv cabal.project cabal.project.local
67-
- grep -Ev -- '^\s*--' $CABALHOME/config | grep -Ev '^\s*$'
68-
- rm -f cabal.project
76+
- rm -f $CABALHOME/config
77+
- |
78+
echo "verbose: normal +nowrap +markoutput" >> $CABALHOME/config
79+
echo "remote-build-reporting: anonymous" >> $CABALHOME/config
80+
echo "remote-repo-cache: $CABALHOME/packages" >> $CABALHOME/config
81+
echo "logs-dir: $CABALHOME/logs" >> $CABALHOME/config
82+
echo "world-file: $CABALHOME/world" >> $CABALHOME/config
83+
echo "extra-prog-path: $CABALHOME/bin" >> $CABALHOME/config
84+
echo "symlink-bindir: $CABALHOME/bin" >> $CABALHOME/config
85+
echo "installdir: $CABALHOME/bin" >> $CABALHOME/config
86+
echo "build-summary: $CABALHOME/logs/build.log" >> $CABALHOME/config
87+
echo "store-dir: $CABALHOME/store" >> $CABALHOME/config
88+
echo "install-dirs user" >> $CABALHOME/config
89+
echo " prefix: $CABALHOME" >> $CABALHOME/config
90+
echo "repository hackage.haskell.org" >> $CABALHOME/config
91+
echo " url: http://hackage.haskell.org/" >> $CABALHOME/config
92+
- cat $CABALHOME/config
93+
- rm -fv cabal.project cabal.project.local cabal.project.freeze
94+
- travis_retry ${CABAL} v2-update -v
95+
# Generate cabal.project
96+
- rm -rf cabal.project cabal.project.local cabal.project.freeze
6997
- touch cabal.project
70-
- "printf 'packages: \".\"\\n' >> cabal.project"
71-
- "printf 'write-ghc-environment-files: always\\n' >> cabal.project"
72-
- touch cabal.project.local
73-
- "for pkg in $($HCPKG list --simple-output); do echo $pkg | sed 's/-[^-]*$//' | grep -vE -- '^(servant-swagger)$' | sed 's/^/constraints: /' | sed 's/$/ installed/' >> cabal.project.local; done"
98+
- |
99+
echo 'packages: "."' >> cabal.project
100+
- |
101+
echo "write-ghc-environment-files: always" >> cabal.project
102+
- "for pkg in $($HCPKG list --simple-output); do echo $pkg | sed 's/-[^-]*$//' | (grep -vE -- '^(servant-swagger)$' || true) | sed 's/^/constraints: /' | sed 's/$/ installed/' >> cabal.project.local; done"
74103
- cat cabal.project || true
75104
- cat cabal.project.local || true
76105
- if [ -f "./configure.ac" ]; then (cd "." && autoreconf -i); fi
77-
- rm -f cabal.project.freeze
78-
- ${CABAL} new-freeze -w ${HC} ${TEST} ${BENCH} --project-file="cabal.project" --dry
79-
- "cat \"cabal.project.freeze\" | sed -E 's/^(constraints: *| *)//' | sed 's/any.//'"
80-
- rm "cabal.project.freeze"
81-
- ${CABAL} new-build -w ${HC} ${TEST} ${BENCH} --project-file="cabal.project" --dep -j2 all
82-
- ${CABAL} new-build -w ${HC} --disable-tests --disable-benchmarks --project-file="cabal.project" --dep -j2 all
83-
- rm -rf .ghc.environment.* "."/dist
84-
- DISTDIR=$(mktemp -d /tmp/dist-test.XXXX)
85-
86-
# Here starts the actual work to be performed for the package under test;
87-
# any command which exits with a non-zero exit code causes the build to fail.
106+
- ${CABAL} v2-freeze -w ${HC} ${TEST} ${BENCH} | color_cabal_output
107+
- "cat cabal.project.freeze | sed -E 's/^(constraints: *| *)//' | sed 's/any.//'"
108+
- rm cabal.project.freeze
109+
- ${CABAL} v2-build -w ${HC} ${TEST} ${BENCH} --dep -j2 all | color_cabal_output
110+
- ${CABAL} v2-build -w ${HC} --disable-tests --disable-benchmarks --dep -j2 all | color_cabal_output
88111
script:
89-
# test that source-distributions can be generated
90-
- ${CABAL} new-sdist all
112+
- DISTDIR=$(mktemp -d /tmp/dist-test.XXXX)
113+
# Packaging...
114+
- ${CABAL} v2-sdist all | color_cabal_output
115+
# Unpacking...
91116
- mv dist-newstyle/sdist/*.tar.gz ${DISTDIR}/
92117
- cd ${DISTDIR} || false
93118
- find . -maxdepth 1 -name '*.tar.gz' -exec tar -xvf '{}' \;
94-
- rm -f cabal.project
119+
# Generate cabal.project
120+
- rm -rf cabal.project cabal.project.local cabal.project.freeze
95121
- touch cabal.project
96-
- "printf 'packages: \"servant-swagger-*/*.cabal\"\\n' >> cabal.project"
97-
- "printf 'write-ghc-environment-files: always\\n' >> cabal.project"
98-
- touch cabal.project.local
99-
- "for pkg in $($HCPKG list --simple-output); do echo $pkg | sed 's/-[^-]*$//' | grep -vE -- '^(servant-swagger)$' | sed 's/^/constraints: /' | sed 's/$/ installed/' >> cabal.project.local; done"
122+
- |
123+
echo 'packages: "servant-swagger-*/*.cabal"' >> cabal.project
124+
- |
125+
echo "write-ghc-environment-files: always" >> cabal.project
126+
- "for pkg in $($HCPKG list --simple-output); do echo $pkg | sed 's/-[^-]*$//' | (grep -vE -- '^(servant-swagger)$' || true) | sed 's/^/constraints: /' | sed 's/$/ installed/' >> cabal.project.local; done"
100127
- cat cabal.project || true
101128
- cat cabal.project.local || true
129+
# Building...
102130
# this builds all libraries and executables (without tests/benchmarks)
103-
- ${CABAL} new-build -w ${HC} --disable-tests --disable-benchmarks all
104-
131+
- ${CABAL} v2-build -w ${HC} --disable-tests --disable-benchmarks all | color_cabal_output
132+
# Building with tests and benchmarks...
105133
# build & run tests, build benchmarks
106-
- ${CABAL} new-build -w ${HC} ${TEST} ${BENCH} all
107-
- if [ "x$TEST" = "x--enable-tests" ]; then ${CABAL} new-test -w ${HC} ${TEST} ${BENCH} all; fi
108-
109-
# cabal check
110-
- (cd servant-swagger-* && ${CABAL} check)
111-
112-
# haddock
113-
- ${CABAL} new-haddock -w ${HC} ${TEST} ${BENCH} all
114-
115-
# Build without installed constraints for packages in global-db
116-
- rm -f cabal.project.local; ${CABAL} new-build -w ${HC} --disable-tests --disable-benchmarks all;
134+
- ${CABAL} v2-build -w ${HC} ${TEST} ${BENCH} all | color_cabal_output
135+
# Testing...
136+
- ${CABAL} v2-test -w ${HC} ${TEST} ${BENCH} all | color_cabal_output
137+
# cabal check...
138+
- (cd servant-swagger-* && ${CABAL} -vnormal check)
139+
# haddock...
140+
- ${CABAL} v2-haddock -w ${HC} ${TEST} ${BENCH} all | color_cabal_output
141+
# Building without installed constraints for packages in global-db...
142+
- rm -f cabal.project.local
143+
- ${CABAL} v2-build -w ${HC} --disable-tests --disable-benchmarks all | color_cabal_output
144+
# Constraint sets
145+
- rm -rf cabal.project.local
146+
# Constraint set swagger2-2.3
147+
- ${CABAL} v2-build -w ${HC} --disable-tests --disable-benchmarks --constraint='swagger2 ==2.3.*' all | color_cabal_output
148+
# Constraint set swagger2-2.4
149+
- ${CABAL} v2-build -w ${HC} --disable-tests --disable-benchmarks --constraint='swagger2 ==2.4.*' all | color_cabal_output
150+
# Constraint set servant-0.15
151+
- ${CABAL} v2-build -w ${HC} --disable-tests --disable-benchmarks --constraint='servant == 0.15.*' all | color_cabal_output
152+
# Constraint set servant-0.16
153+
- ${CABAL} v2-build -w ${HC} --disable-tests --disable-benchmarks --constraint='servant == 0.16.*' all | color_cabal_output
117154

118-
# REGENDATA ["--branches","master","--output",".travis.yml","servant-swagger.cabal"]
155+
# REGENDATA ["--config=cabal.haskell-ci","servant-swagger.cabal"]
119156
# EOF

servant-swagger.cabal

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
name: servant-swagger
2-
version: 1.1.7
3-
x-revision: 2
2+
version: 1.1.7.1
43
synopsis: Generate a Swagger/OpenAPI/OAS 2.0 specification for your servant API.
54
description:
65
Swagger is a project used to describe and document RESTful APIs. The core of the
@@ -33,7 +32,7 @@ tested-with:
3332
GHC ==8.0.2
3433
|| ==8.2.2
3534
|| ==8.4.4
36-
|| ==8.6.1
35+
|| ==8.6.5
3736

3837
extra-source-files:
3938
README.md
@@ -56,7 +55,7 @@ custom-setup
5655
setup-depends:
5756
base >=4.9 && <4.13,
5857
Cabal >= 1.24 && <2.5,
59-
cabal-doctest >=1.0.2 && <1.1
58+
cabal-doctest >=1.0.6 && <1.1
6059

6160
library
6261
ghc-options: -Wall
@@ -74,7 +73,7 @@ library
7473
Servant.Swagger.Internal.TypeLevel.Every
7574
Servant.Swagger.Internal.TypeLevel.TMap
7675
hs-source-dirs: src
77-
build-depends: aeson >=1.4.1.0 && <1.5
76+
build-depends: aeson >=1.4.2.0 && <1.5
7877
, aeson-pretty >=0.8.7 && <0.9
7978
, base >=4.9.1.0 && <4.13
8079
, base-compat >=0.10.5 && <0.11
@@ -84,7 +83,7 @@ library
8483
, lens >=4.17 && <4.18
8584
, servant >=0.15 && <0.17
8685
, singleton-bool >=0.1.4 && <0.2
87-
, swagger2 >=2.3.0.1 && <2.4
86+
, swagger2 >=2.3.0.1 && <2.5
8887
, text >=1.2.3.0 && <1.3
8988
, unordered-containers >=0.2.9.0 && <0.3
9089

@@ -118,14 +117,15 @@ test-suite spec
118117
, hspec >=2.6.0 && <2.8
119118
, QuickCheck
120119
, lens
120+
, lens-aeson >=1.0.2 && <1.1
121121
, servant
122122
, servant-swagger
123123
, swagger2
124124
, text
125125
, template-haskell
126126
, utf8-string >=1.0.1.1 && <1.1
127127
, time
128+
, vector
128129
other-modules:
129130
Servant.SwaggerSpec
130-
Data.Aeson.QQ.Simple2
131131
default-language: Haskell2010

src/Servant/Swagger/Internal.hs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,6 @@
88
{-# LANGUAGE RankNTypes #-}
99
{-# LANGUAGE ScopedTypeVariables #-}
1010
{-# LANGUAGE TypeOperators #-}
11-
#if __GLASGOW_HASKELL__ >= 710
12-
#define OVERLAPPABLE_ {-# OVERLAPPABLE #-}
13-
#else
14-
{-# LANGUAGE OverlappingInstances #-}
15-
#define OVERLAPPABLE_
16-
#endif
1711
#if __GLASGOW_HASKELL__ >= 806
1812
{-# LANGUAGE UndecidableInstances #-}
1913
#endif
@@ -176,14 +170,14 @@ instance SwaggerMethod 'OPTIONS where swaggerMethod _ = options
176170
instance SwaggerMethod 'HEAD where swaggerMethod _ = head_
177171
instance SwaggerMethod 'PATCH where swaggerMethod _ = patch
178172

179-
instance OVERLAPPABLE_ (ToSchema a, AllAccept cs, KnownNat status, SwaggerMethod method) => HasSwagger (Verb method status cs a) where
173+
instance {-# OVERLAPPABLE #-} (ToSchema a, AllAccept cs, KnownNat status, SwaggerMethod method) => HasSwagger (Verb method status cs a) where
180174
toSwagger _ = toSwagger (Proxy :: Proxy (Verb method status cs (Headers '[] a)))
181175

182176
-- | @since 1.1.7
183177
instance (ToSchema a, Accept ct, KnownNat status, SwaggerMethod method) => HasSwagger (Stream method status fr ct a) where
184178
toSwagger _ = toSwagger (Proxy :: Proxy (Verb method status '[ct] (Headers '[] a)))
185179

186-
instance OVERLAPPABLE_ (ToSchema a, AllAccept cs, AllToResponseHeader hs, KnownNat status, SwaggerMethod method)
180+
instance {-# OVERLAPPABLE #-} (ToSchema a, AllAccept cs, AllToResponseHeader hs, KnownNat status, SwaggerMethod method)
187181
=> HasSwagger (Verb method status cs (Headers hs a)) where
188182
toSwagger = mkEndpoint "/"
189183

@@ -287,7 +281,11 @@ instance (KnownSymbol sym, ToParamSchema a, HasSwagger sub) => HasSwagger (Query
287281
& in_ .~ ParamQuery
288282
& paramSchema .~ pschema
289283
pschema = mempty
284+
#if MIN_VERSION_swagger2(2,4,0)
285+
& type_ ?~ SwaggerArray
286+
#else
290287
& type_ .~ SwaggerArray
288+
#endif
291289
& items ?~ SwaggerItemsPrimitive (Just CollectionMulti) (toParamSchema (Proxy :: Proxy a))
292290

293291
instance (KnownSymbol sym, HasSwagger sub) => HasSwagger (QueryFlag sym :> sub) where

test/Data/Aeson/QQ/Simple2.hs

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

0 commit comments

Comments
 (0)