Skip to content
This repository was archived by the owner on Aug 18, 2020. It is now read-only.

Commit 503e3a8

Browse files
committed
[CO-351] Re-introduce custom template for rendering swagger
There's actually a bug in the current template which serves the swagger specs on an absolute url , completely ignoring any sub-path in the URL. A PR has been submitted to the upstream library (servant-swagger-ui-redoc) haskell-servant/servant-swagger-ui#53 but until it gets accepted, we need a way to serve our documentation
1 parent 8636de3 commit 503e3a8

File tree

1 file changed

+30
-2
lines changed

1 file changed

+30
-2
lines changed

src/Cardano/Wallet/API/V1/Swagger.hs

+30-2
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ import Servant (Handler, ServantErr (..), Server)
4646
import Servant.API.Sub
4747
import Servant.Swagger
4848
import Servant.Swagger.UI (SwaggerSchemaUI')
49-
import Servant.Swagger.UI.ReDoc (redocSchemaUIServer)
49+
import Servant.Swagger.UI.Core (swaggerSchemaUIServerImpl)
50+
import Servant.Swagger.UI.ReDoc (redocFiles)
5051
import Test.QuickCheck
5152
import Test.QuickCheck.Gen
5253
import Test.QuickCheck.Random
@@ -822,7 +823,34 @@ leverage the API capabilities.
822823
swaggerSchemaUIServer
823824
:: (Server api ~ Handler Swagger)
824825
=> Swagger -> Server (SwaggerSchemaUI' dir api)
825-
swaggerSchemaUIServer = redocSchemaUIServer
826+
swaggerSchemaUIServer =
827+
swaggerSchemaUIServerImpl redocIndexTemplate redocFiles
828+
where
829+
redocIndexTemplate :: Text
830+
redocIndexTemplate = [text|
831+
<!doctype html>
832+
<html lang="en">
833+
<head>
834+
<title>ReDoc</title>
835+
<meta charset="utf-8"/>
836+
<meta name="viewport" content="width=device-width, initial-scale=1">
837+
<style>
838+
body { margin: 0; padding: 0; }
839+
</style>
840+
<script>
841+
// Force Strict-URL Routing for assets relative paths
842+
(function onload() {
843+
if (!window.location.href.endsWith("/")) {
844+
window.location.href += "/";
845+
}
846+
}());
847+
</script>
848+
</head>
849+
<body>
850+
<redoc spec-url="../SERVANT_SWAGGER_UI_SCHEMA"></redoc>
851+
<script src="redoc.min.js"> </script>
852+
</body>
853+
</html>|]
826854

827855
--
828856
-- The API

0 commit comments

Comments
 (0)