Skip to content

Commit a8c9704

Browse files
authored
Merge pull request #46 from phadej/separate-packages
Split servant-swagger-ui into many packages
2 parents a75c1cd + 3a373fb commit a8c9704

File tree

80 files changed

+667
-413
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+667
-413
lines changed

.travis.yml

Lines changed: 31 additions & 12 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-
# runghc make_travis_yml_2.hs '--branch' 'master' '--output' '.travis.yml' '--config' 'servant-swagger-ui.cabal'
3+
# runghc make_travis_yml_2.hs '--branch' 'master' '--output' '.travis.yml' '--config' 'cabal.project'
44
#
55
# For more information, see https://github.com/hvr/multi-ghc-travis
66
#
@@ -44,9 +44,9 @@ matrix:
4444
- compiler: "ghc-8.2.2"
4545
# env: TEST=--disable-tests BENCH=--disable-benchmarks
4646
addons: {apt: {packages: [ghc-ppa-tools,cabal-install-head,ghc-8.2.2], sources: [hvr-ghc]}}
47-
- compiler: "ghc-8.4.1"
47+
- compiler: "ghc-8.4.2"
4848
# env: TEST=--disable-tests BENCH=--disable-benchmarks
49-
addons: {apt: {packages: [ghc-ppa-tools,cabal-install-head,ghc-8.4.1], sources: [hvr-ghc]}}
49+
addons: {apt: {packages: [ghc-ppa-tools,cabal-install-head,ghc-8.4.2], sources: [hvr-ghc]}}
5050

5151
before_install:
5252
- HC=${CC}
@@ -70,26 +70,42 @@ install:
7070
- "sed -i.bak 's/^jobs:/-- jobs:/' ${HOME}/.cabal/config"
7171
- rm -fv cabal.project cabal.project.local
7272
- grep -Ev -- '^\s*--' ${HOME}/.cabal/config | grep -Ev '^\s*$'
73-
- "printf 'packages: \".\"\\n' > cabal.project"
73+
- "printf 'packages: \"servant-swagger-ui\" \"servant-swagger-ui-core\" \"servant-swagger-ui-example\" \"servant-swagger-ui-jensoleg\" \"servant-swagger-ui-redoc\"\\n' > cabal.project"
7474
- cat cabal.project
75-
- if [ -f "./configure.ac" ]; then
76-
(cd "." && autoreconf -i);
75+
- if [ -f "servant-swagger-ui/configure.ac" ]; then
76+
(cd "servant-swagger-ui" && autoreconf -i);
77+
fi
78+
- if [ -f "servant-swagger-ui-core/configure.ac" ]; then
79+
(cd "servant-swagger-ui-core" && autoreconf -i);
80+
fi
81+
- if [ -f "servant-swagger-ui-example/configure.ac" ]; then
82+
(cd "servant-swagger-ui-example" && autoreconf -i);
83+
fi
84+
- if [ -f "servant-swagger-ui-jensoleg/configure.ac" ]; then
85+
(cd "servant-swagger-ui-jensoleg" && autoreconf -i);
86+
fi
87+
- if [ -f "servant-swagger-ui-redoc/configure.ac" ]; then
88+
(cd "servant-swagger-ui-redoc" && autoreconf -i);
7789
fi
7890
- rm -f cabal.project.freeze
7991
- cabal new-build -w ${HC} ${TEST} ${BENCH} --project-file="cabal.project" --dep -j2 all
8092
- cabal new-build -w ${HC} --disable-tests --disable-benchmarks --project-file="cabal.project" --dep -j2 all
81-
- rm -rf .ghc.environment.* "."/dist
93+
- rm -rf .ghc.environment.* "servant-swagger-ui"/dist "servant-swagger-ui-core"/dist "servant-swagger-ui-example"/dist "servant-swagger-ui-jensoleg"/dist "servant-swagger-ui-redoc"/dist
8294
- DISTDIR=$(mktemp -d /tmp/dist-test.XXXX)
8395

8496
# Here starts the actual work to be performed for the package under test;
8597
# any command which exits with a non-zero exit code causes the build to fail.
8698
script:
8799
# test that source-distributions can be generated
88-
- (cd "." && cabal sdist)
89-
- mv "."/dist/servant-swagger-ui-*.tar.gz ${DISTDIR}/
100+
- (cd "servant-swagger-ui" && cabal sdist)
101+
- (cd "servant-swagger-ui-core" && cabal sdist)
102+
- (cd "servant-swagger-ui-example" && cabal sdist)
103+
- (cd "servant-swagger-ui-jensoleg" && cabal sdist)
104+
- (cd "servant-swagger-ui-redoc" && cabal sdist)
105+
- mv "servant-swagger-ui"/dist/servant-swagger-ui-*.tar.gz "servant-swagger-ui-core"/dist/servant-swagger-ui-core-*.tar.gz "servant-swagger-ui-example"/dist/servant-swagger-ui-example-*.tar.gz "servant-swagger-ui-jensoleg"/dist/servant-swagger-ui-jensoleg-*.tar.gz "servant-swagger-ui-redoc"/dist/servant-swagger-ui-redoc-*.tar.gz ${DISTDIR}/
90106
- cd ${DISTDIR} || false
91107
- find . -maxdepth 1 -name '*.tar.gz' -exec tar -xvf '{}' \;
92-
- "printf 'packages: servant-swagger-ui-*/*.cabal\\n' > cabal.project"
108+
- "printf 'packages: servant-swagger-ui-*/*.cabal servant-swagger-ui-core-*/*.cabal servant-swagger-ui-example-*/*.cabal servant-swagger-ui-jensoleg-*/*.cabal servant-swagger-ui-redoc-*/*.cabal\\n' > cabal.project"
93109
- cat cabal.project
94110
# this builds all libraries and executables (without tests/benchmarks)
95111
- cabal new-build -w ${HC} --disable-tests --disable-benchmarks all
@@ -99,10 +115,13 @@ script:
99115

100116
# build & run tests, build benchmarks
101117
- cabal new-build -w ${HC} ${TEST} ${BENCH} all
102-
- if [ "x$TEST" = "x--enable-tests" ]; then cabal new-test -w ${HC} ${TEST} ${BENCH} all; fi
103118

104119
# cabal check
105120
- (cd servant-swagger-ui-* && cabal check)
121+
- (cd servant-swagger-ui-core-* && cabal check)
122+
- (cd servant-swagger-ui-example-* && cabal check)
123+
- (cd servant-swagger-ui-jensoleg-* && cabal check)
124+
- (cd servant-swagger-ui-redoc-* && cabal check)
106125

107126
# haddock
108127
- rm -rf ./dist-newstyle
@@ -122,5 +141,5 @@ script:
122141

123142
- if [ $HCNUMVER -ge 70800 ] && [ $HCNUMVER -lt 80600 ]; then cabal new-build -w ${HC} --disable-tests --disable-benchmarks --constraint='servant ==0.13.*' all; else echo skipping...; fi
124143

125-
# REGENDATA ["--branch","master","--output",".travis.yml","--config","servant-swagger-ui.cabal"]
144+
# REGENDATA ["--branch","master","--output",".travis.yml","--config","cabal.project"]
126145
# EOF

cabal.project

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
packages:
2+
servant-swagger-ui/
3+
servant-swagger-ui-core/
4+
servant-swagger-ui-example/
5+
servant-swagger-ui-jensoleg/
6+
servant-swagger-ui-redoc/

hackage-docs.sh

Lines changed: 0 additions & 78 deletions
This file was deleted.
File renamed without changes.
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
cabal-version: 1.12
2+
name: servant-swagger-ui-core
3+
version: 0.3
4+
5+
synopsis: Servant swagger ui core components
6+
category: Web, Servant, Swagger
7+
description:
8+
Provide embedded swagger UI for servant and swagger (i.e. servant-swagger)
9+
.
10+
See servant-swagger-ui, servant-swagger-ui-jensoleg or
11+
servant-swagger-ui-redoc for "concrete" implementations.
12+
13+
homepage: https://github.com/phadej/servant-swagger-ui
14+
bug-reports: https://github.com/phadej/servant-swagger-ui/issues
15+
author: Oleg Grenrus <[email protected]>
16+
maintainer: Oleg Grenrus <[email protected]>
17+
license: BSD3
18+
license-file: LICENSE
19+
build-type: Simple
20+
tested-with: GHC ==7.8.4 || ==7.10.3 || ==8.0.2 || ==8.2.2 || ==8.4.2
21+
22+
source-repository head
23+
type: git
24+
location: https://github.com/phadej/servant-swagger-ui
25+
26+
flag servant-0-5
27+
description: Whether use servant >= 0.5
28+
manual: False
29+
default: True
30+
31+
library
32+
hs-source-dirs:
33+
src
34+
ghc-options: -Wall
35+
36+
build-depends:
37+
base >=4.7 && <4.12
38+
, blaze-markup >=0.7.0.2 && <0.9
39+
, bytestring >=0.10.4.0 && <0.11
40+
, http-media >=0.6.2 && <0.8
41+
, servant >=0.4.4.5 && <0.14
42+
, servant-blaze >=0.4.4.5 && <0.9
43+
, servant-server >=0.4.4.5 && <0.14
44+
, swagger2 >=2.0.1 && <2.3
45+
, text >=1.2.0.6 && <1.3
46+
, wai-app-static >=3.0.1.1 && <3.2
47+
if flag(servant-0-5)
48+
build-depends:
49+
servant >=0.5
50+
, transformers >=0.3 && <0.6
51+
, transformers-compat >=0.3 && <0.6
52+
else
53+
build-depends:
54+
servant <0.5
55+
, either
56+
exposed-modules:
57+
Servant.Swagger.UI.Core
58+
default-language: Haskell2010

src/Servant/Swagger/UI.hs renamed to servant-swagger-ui-core/src/Servant/Swagger/UI/Core.hs

Lines changed: 5 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,10 @@
66
{-# LANGUAGE MultiParamTypeClasses #-}
77
{-# LANGUAGE OverloadedStrings #-}
88
{-# LANGUAGE ScopedTypeVariables #-}
9-
{-# LANGUAGE TemplateHaskell #-}
109
{-# LANGUAGE TypeFamilies #-}
1110
{-# LANGUAGE TypeOperators #-}
1211
{-# LANGUAGE UndecidableInstances #-}
1312
-----------------------------------------------------------------------------
14-
-- |
15-
-- Module : Servant.Swagger.UI
16-
-- Copyright : (C) 2016 Oleg Grenrus
17-
-- License : BSD3
18-
-- Maintainer : Oleg Grenrus <[email protected]>
1913
--
2014
-- Provides 'SwaggerUI' and corresponding 'swaggerUIServer' to embed
2115
-- <http://swagger.io/swagger-ui/ swagger ui> into the application.
@@ -41,37 +35,19 @@
4135
-- catEndpoint name = pure $ Cat name False
4236
-- @
4337

44-
module Servant.Swagger.UI (
38+
module Servant.Swagger.UI.Core (
4539
-- * Swagger UI API
4640
SwaggerSchemaUI,
4741
SwaggerSchemaUI',
48-
swaggerSchemaUIServer,
49-
jensolegSwaggerSchemaUIServer,
50-
redocSchemaUIServer,
5142

52-
-- * Internals
53-
--
54-
-- /Note:/ in next major version, these will be moved to separate module.
43+
-- * Implementation details
5544
SwaggerUiHtml(..),
5645
swaggerSchemaUIServerImpl,
57-
-- ** Official swagger ui
58-
swaggerUiIndexTemplate,
59-
swaggerUiFiles,
60-
-- ** jensoleg theme
61-
--
62-
-- Current version: @79f3bba07b070cfab1d8c245c4f9229052e20a1a@
63-
jensolegIndexTemplate,
64-
jensolegFiles,
65-
-- ** ReDoc theme
66-
--
67-
-- Current Version: v1.21.2 https://rebilly.github.io/ReDoc/releases/v1.21.2/redoc.min.js
68-
redocIndexTemplate,
69-
redocFiles
46+
Handler,
7047
) where
7148

7249
import Data.ByteString (ByteString)
7350
import Data.Swagger (Swagger)
74-
import FileEmbedLzma
7551
import GHC.TypeLits (KnownSymbol, Symbol, symbolVal)
7652
import Network.Wai.Application.Static (embeddedSettings, staticApp)
7753
import Servant
@@ -85,10 +61,10 @@ import qualified Data.Text as T
8561
#else
8662
#if MIN_VERSION_servant(0,5,0)
8763
import Control.Monad.Trans.Except (ExceptT)
88-
#define Handler ExceptT ServantErr IO
64+
type Handler = ExceptT ServantErr IO
8965
#else
9066
import Control.Monad.Trans.Either (EitherT)
91-
#define Handler EitherT ServantErr IO
67+
type Handler = EitherT ServantErr IO
9268
#endif
9369
#endif
9470

@@ -144,35 +120,6 @@ instance (KnownSymbol dir, HasLink api, LINK ~ MkLink api, IsElem api api)
144120
dir = T.pack $ symbolVal (Proxy :: Proxy dir)
145121
proxyApi = Proxy :: Proxy api
146122

147-
-- | Serve Swagger UI on @/dir@ using @api@ as a Swagger spec source.
148-
--
149-
-- @
150-
-- swaggerSchemaUIServer :: Swagger -> Server (SwaggerSchemaUI schema dir)
151-
-- @
152-
swaggerSchemaUIServer
153-
:: (Server api ~ Handler Swagger)
154-
=> Swagger -> Server (SwaggerSchemaUI' dir api)
155-
swaggerSchemaUIServer =
156-
swaggerSchemaUIServerImpl swaggerUiIndexTemplate swaggerUiFiles
157-
158-
-- | Serve alternative Swagger UI.
159-
--
160-
-- See <https://github.com/jensoleg/swagger-ui>
161-
jensolegSwaggerSchemaUIServer
162-
:: (Server api ~ Handler Swagger)
163-
=> Swagger -> Server (SwaggerSchemaUI' dir api)
164-
jensolegSwaggerSchemaUIServer =
165-
swaggerSchemaUIServerImpl jensolegIndexTemplate jensolegFiles
166-
167-
-- | Serve alternative Swagger UI.
168-
--
169-
-- See <https://github.com/Rebilly/ReDoc/tree/v1.x>
170-
redocSchemaUIServer
171-
:: (Server api ~ Handler Swagger)
172-
=> Swagger -> Server (SwaggerSchemaUI' dir api)
173-
redocSchemaUIServer =
174-
swaggerSchemaUIServerImpl redocIndexTemplate redocFiles
175-
176123
swaggerSchemaUIServerImpl
177124
:: (Server api ~ Handler Swagger)
178125
=> T.Text -> [(FilePath, ByteString)]
@@ -187,21 +134,3 @@ swaggerSchemaUIServerImpl indexTemplate files swagger = return swagger
187134
Tagged $
188135
#endif
189136
staticApp $ embeddedSettings files
190-
191-
swaggerUiIndexTemplate :: T.Text
192-
swaggerUiIndexTemplate = $(embedText "index.html.tmpl")
193-
194-
swaggerUiFiles :: [(FilePath, ByteString)]
195-
swaggerUiFiles = $(embedRecursiveDir "swagger-ui-dist-3.9.1")
196-
197-
jensolegIndexTemplate :: T.Text
198-
jensolegIndexTemplate = $(embedText "jensoleg.index.html.tmpl")
199-
200-
jensolegFiles :: [(FilePath, ByteString)]
201-
jensolegFiles = $(embedRecursiveDir "jensoleg-dist")
202-
203-
redocIndexTemplate :: T.Text
204-
redocIndexTemplate = $(embedText "redoc.index.html.tmpl")
205-
206-
redocFiles :: [(FilePath, ByteString)]
207-
redocFiles = $(embedRecursiveDir "redoc-dist")

servant-swagger-ui-example/LICENSE

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
Copyright (c) 2018, Oleg Grenrus
2+
3+
All rights reserved.
4+
5+
Redistribution and use in source and binary forms, with or without
6+
modification, are permitted provided that the following conditions are met:
7+
8+
* Redistributions of source code must retain the above copyright
9+
notice, this list of conditions and the following disclaimer.
10+
11+
* Redistributions in binary form must reproduce the above
12+
copyright notice, this list of conditions and the following
13+
disclaimer in the documentation and/or other materials provided
14+
with the distribution.
15+
16+
* Neither the name of Oleg Grenrus nor the names of other
17+
contributors may be used to endorse or promote products derived
18+
from this software without specific prior written permission.
19+
20+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24+
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

0 commit comments

Comments
 (0)