Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions servant-swagger-ui-core/Changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
# 0.3.6

- Generalize to support arbitrary type instead of hardcoded `Value`.

`SwaggerSchemaUI` now needs one more parameter which typically is
either `Swagger` or `OpenApi`.

To migrate from older version, alter your API type from
`SwaggerSchemaUI "swagger-ui" "swagger.json"`
to
`SwaggerSchemaUI "swagger-ui" "swagger.json" Swagger`

Or in case of the more generic variant, old
`SwaggerSchemaUI' "foo-ui" ("foo" :> "swagger.json" :> Get '[JSON] Value)`
becomes
`SwaggerSchemaUI' "foo-ui" ("foo" :> "swagger.json" :> Get '[JSON] Swagger)`

# 0.3.5

- Generalize `SwaggerSchemaUI` and `swaggerSchemaUIServerImpl` to support arbitrary `Value` instead
Expand Down
2 changes: 1 addition & 1 deletion servant-swagger-ui-core/servant-swagger-ui-core.cabal
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cabal-version: 1.12
name: servant-swagger-ui-core
version: 0.3.5
version: 0.3.6
synopsis: Servant swagger ui core components
category: Web, Servant, Swagger
description:
Expand Down
17 changes: 9 additions & 8 deletions servant-swagger-ui-core/src/Servant/Swagger/UI/Core.hs
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,19 @@ module Servant.Swagger.UI.Core (
Handler,
) where

import Data.Aeson (ToJSON (..), Value)
import Data.ByteString (ByteString)
import GHC.TypeLits (KnownSymbol, Symbol, symbolVal)
import Network.Wai.Application.Static (embeddedSettings, staticApp)
import Servant
import Servant.HTML.Blaze (HTML)
import Text.Blaze (ToMarkup (..))
import Data.Kind (Type)

import qualified Data.Text as T

-- | Swagger schema + ui api.
--
-- @SwaggerSchemaUI "swagger-ui" "swagger.json"@ will result into following hierarchy:
-- @SwaggerSchemaUI "swagger-ui" "swagger.json" Swagger@ will result into following hierarchy:
--
-- @
-- \/swagger.json
Expand All @@ -67,10 +67,11 @@ import qualified Data.Text as T
-- \/swagger-ui\/...
-- @
--
-- This type does not actually force served type to be @Swagger@ from @swagger2@ package,
-- it could be arbitrary @aeson@ 'Value'.
type SwaggerSchemaUI (dir :: Symbol) (schema :: Symbol) =
SwaggerSchemaUI' dir (schema :> Get '[JSON] Value)
-- The third type parameter specifies which Haskell datatype contains the Swagger
-- description. Typical instantiations are @Swagger@ from the @swagger2@ package,
-- and @OpenApi@ from the @openapi3@ package.
type SwaggerSchemaUI (dir :: Symbol) (schema :: Symbol) (ctype :: Type) =
SwaggerSchemaUI' dir (schema :> Get '[JSON] ctype)

-- | Use 'SwaggerSchemaUI'' when you need even more control over
-- where @swagger.json@ is served (e.g. subdirectory).
Expand Down Expand Up @@ -103,11 +104,11 @@ instance (KnownSymbol dir, HasLink api, Link ~ MkLink api Link, IsElem api api)
proxyApi = Proxy :: Proxy api

swaggerSchemaUIServerImpl
:: (Monad m, ServerT api m ~ m Value, ToJSON a)
:: (Monad m, ServerT api m ~ m a)
=> T.Text -> [(FilePath, ByteString)]
-> a -> ServerT (SwaggerSchemaUI' dir api) m
swaggerSchemaUIServerImpl indexTemplate files swagger
= swaggerSchemaUIServerImpl' indexTemplate files $ return $ toJSON swagger
= swaggerSchemaUIServerImpl' indexTemplate files $ return swagger

-- | Use a custom server to serve the Swagger spec source.
swaggerSchemaUIServerImpl'
Expand Down
6 changes: 3 additions & 3 deletions servant-swagger-ui-example/src/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,13 @@ type BasicAPI = Get '[PlainText, JSON] Text

type API =
-- this serves both: swagger.json and swagger-ui
SwaggerSchemaUI "swagger-ui" "swagger.json"
SwaggerSchemaUI "swagger-ui" "swagger.json" Swagger
:<|> BasicAPI

-- To test nested case
type API' = API
:<|> "nested" :> API
:<|> SwaggerSchemaUI' "foo-ui" ("foo" :> "swagger.json" :> Get '[JSON] Value)
:<|> SwaggerSchemaUI' "foo-ui" ("foo" :> "swagger.json" :> Get '[JSON] Swagger)

-- Implementation

Expand Down Expand Up @@ -174,7 +174,7 @@ server' uiFlavour = server Normal
-- Unfortunately we have to specify the basePath manually atm.

schemaUiServer
:: (Server api ~ Handler Value)
:: (Server api ~ Handler Swagger)
=> Swagger -> Server (SwaggerSchemaUI' dir api)
schemaUiServer = case uiFlavour of
Original -> swaggerSchemaUIServer
Expand Down
4 changes: 2 additions & 2 deletions servant-swagger-ui-jensoleg/servant-swagger-ui-jensoleg.cabal
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cabal-version: 1.12
name: servant-swagger-ui-jensoleg
version: 0.3.5
version: 0.3.6
synopsis: Servant swagger ui: Jens-Ole Graulund theme
category: Web, Servant, Swagger
description:
Expand Down Expand Up @@ -86,7 +86,7 @@ source-repository head
library
hs-source-dirs: src
ghc-options: -Wall
build-depends: servant-swagger-ui-core >=0.3.5 && <0.4
build-depends: servant-swagger-ui-core >=0.3.6 && <0.4
build-depends:
base >=4.7 && <4.22
, aeson >=0.8.0.2 && <2.3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ module Servant.Swagger.UI.JensOleG (

import Servant.Swagger.UI.Core

import Data.Aeson (ToJSON, Value)
import Data.ByteString (ByteString)
import Data.Text (Text)
#if MIN_VERSION_file_embed_lzma(0,1,0)
Expand All @@ -71,7 +70,7 @@ import Servant
--
-- See <https://github.com/jensoleg/swagger-ui>
jensolegSwaggerSchemaUIServer
:: (Server api ~ Handler Value, ToJSON a)
:: (Server api ~ Handler a)
=> a -> Server (SwaggerSchemaUI' dir api)
jensolegSwaggerSchemaUIServer =
swaggerSchemaUIServerImpl jensolegIndexTemplate jensolegFiles
Expand Down
16 changes: 16 additions & 0 deletions servant-swagger-ui-redoc/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
- 0.3.6.1.22.3
- Generalize to support arbitrary type instead of hardcoded `Value`.

`SwaggerSchemaUI` now needs one more parameter which typically is
either `Swagger` or `OpenApi`.

To migrate from older version, alter your API type from
`SwaggerSchemaUI "swagger-ui" "swagger.json"`
to
`SwaggerSchemaUI "swagger-ui" "swagger.json" Swagger`

Or in case of the more generic variant, old
`SwaggerSchemaUI' "foo-ui" ("foo" :> "swagger.json" :> Get '[JSON] Value)`
becomes
`SwaggerSchemaUI' "foo-ui" ("foo" :> "swagger.json" :> Get '[JSON] Swagger)`

- 0.3.2.1.22.3
- Update to ReDoc-1.22.3

Expand Down
4 changes: 2 additions & 2 deletions servant-swagger-ui-redoc/servant-swagger-ui-redoc.cabal
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cabal-version: 1.12
name: servant-swagger-ui-redoc
version: 0.3.5
version: 0.3.6
synopsis: Servant swagger ui: ReDoc theme
category: Web, Servant, Swagger
description:
Expand Down Expand Up @@ -40,7 +40,7 @@ source-repository head
library
hs-source-dirs: src
ghc-options: -Wall
build-depends: servant-swagger-ui-core >=0.3.5 && <0.4
build-depends: servant-swagger-ui-core >=0.3.6 && <0.4
build-depends:
base >=4.7 && <4.22
, aeson >=0.8.0.2 && <2.3
Expand Down
5 changes: 2 additions & 3 deletions servant-swagger-ui-redoc/src/Servant/Swagger/UI/ReDoc.hs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ module Servant.Swagger.UI.ReDoc (

import Servant.Swagger.UI.Core

import Data.Aeson (ToJSON, Value)
import Data.ByteString (ByteString)
import Data.Text (Text)
#if MIN_VERSION_file_embed_lzma(0,1,0)
Expand All @@ -71,7 +70,7 @@ import Servant
--
-- See <https://github.com/Rebilly/ReDoc/tree/v1.x>
redocSchemaUIServer
:: (Server api ~ Handler Value, ToJSON a)
:: (Server api ~ Handler a)
=> a -> Server (SwaggerSchemaUI' dir api)
redocSchemaUIServer =
swaggerSchemaUIServerImpl redocIndexTemplate redocFiles
Expand All @@ -84,7 +83,7 @@ redocSchemaUIServer =
-- redocSchemaUIServerT :: Swagger -> ServerT (SwaggerSchemaUI schema dir) m
-- @
redocSchemaUIServerT
:: (Monad m, ServerT api m ~ m Value, ToJSON a)
:: (Monad m, ServerT api m ~ m a)
=> a -> ServerT (SwaggerSchemaUI' dir api) m
redocSchemaUIServerT =
swaggerSchemaUIServerImpl redocIndexTemplate redocFiles
Expand Down
16 changes: 16 additions & 0 deletions servant-swagger-ui/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
- 0.3.6.5.0.1
- Generalize to support arbitrary type instead of hardcoded `Value`.

`SwaggerSchemaUI` now needs one more parameter which typically is
either `Swagger` or `OpenApi`.

To migrate from older version, alter your API type from
`SwaggerSchemaUI "swagger-ui" "swagger.json"`
to
`SwaggerSchemaUI "swagger-ui" "swagger.json" Swagger`

Or in case of the more generic variant, old
`SwaggerSchemaUI' "foo-ui" ("foo" :> "swagger.json" :> Get '[JSON] Value)`
becomes
`SwaggerSchemaUI' "foo-ui" ("foo" :> "swagger.json" :> Get '[JSON] Swagger)`

- 0.3.5.4.14.0
- Update to `swagger-ui-4.14.0`

Expand Down
4 changes: 2 additions & 2 deletions servant-swagger-ui/servant-swagger-ui.cabal
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cabal-version: 1.12
name: servant-swagger-ui
version: 0.3.5.5.0.1
version: 0.3.6.5.0.1
synopsis: Servant swagger ui
category: Web, Servant, Swagger
description:
Expand Down Expand Up @@ -50,7 +50,7 @@ source-repository head
library
hs-source-dirs: src
ghc-options: -Wall
build-depends: servant-swagger-ui-core >=0.3.5 && <0.4
build-depends: servant-swagger-ui-core >=0.3.6 && <0.4
build-depends:
base >=4.7 && <4.22
, aeson >=0.8.0.2 && <2.3
Expand Down
5 changes: 2 additions & 3 deletions servant-swagger-ui/src/Servant/Swagger/UI.hs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ module Servant.Swagger.UI (

import Servant.Swagger.UI.Core

import Data.Aeson (ToJSON, Value)
import Data.ByteString (ByteString)
import Data.Text (Text)
#if MIN_VERSION_file_embed_lzma(0,1,0)
Expand All @@ -79,7 +78,7 @@ import Servant
-- swaggerSchemaUIServer :: OpenApi -> Server (SwaggerSchemaUI schema dir)
-- @
swaggerSchemaUIServer
:: (Server api ~ Handler Value, ToJSON a)
:: (Server api ~ Handler a)
=> a -> Server (SwaggerSchemaUI' dir api)
swaggerSchemaUIServer =
swaggerSchemaUIServerImpl swaggerUiIndexTemplate swaggerUiFiles
Expand All @@ -93,7 +92,7 @@ swaggerSchemaUIServer =
-- swaggerSchemaUIServerT :: OpenApi -> ServerT (SwaggerSchemaUI schema dir) m
-- @
swaggerSchemaUIServerT
:: (Monad m, ServerT api m ~ m Value, ToJSON a)
:: (Monad m, ServerT api m ~ m a)
=> a -> ServerT (SwaggerSchemaUI' dir api) m
swaggerSchemaUIServerT =
swaggerSchemaUIServerImpl swaggerUiIndexTemplate swaggerUiFiles
Expand Down