Skip to content

Commit

Permalink
Merge pull request #955 from vbouzon/master
Browse files Browse the repository at this point in the history
Add redocVersion parameter for RedocHttp4s
  • Loading branch information
adamw authored Jan 20, 2021
2 parents f722c9d + 56a22c3 commit 4387865
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion docs/redoc-http4s/src/main/resources/redoc.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@
</head>
<body>
<redoc spec-url='{{docsPath}}' expand-responses="200,201"></redoc>
<script src="https://cdn.jsdelivr.net/npm/redoc@2.0.0-rc.22/bundles/redoc.standalone.js"></script>
<script src="https://cdn.jsdelivr.net/npm/redoc@{{redocVersion}}/bundles/redoc.standalone.js"></script>
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,16 @@ import scala.io.Source
* @param title The title of the HTML page.
* @param yaml The yaml with the OpenAPI documentation.
* @param yamlName The name of the file, through which the yaml documentation will be served. Defaults to `docs.yaml`.
* @param redocVersion The semver version of Redoc to use. Defaults to `2.0.0-rc.23`.
*/
class RedocHttp4s(title: String, yaml: String, yamlName: String = "docs.yaml") {
class RedocHttp4s(title: String, yaml: String, yamlName: String = "docs.yaml", redocVersion: String = "2.0.0-rc.23") {
private lazy val html = {
val fileName = "redoc.html"
val is = getClass.getClassLoader.getResourceAsStream(fileName)
assert(Option(is).nonEmpty, s"Could not find file ${fileName} on classpath.")
val rawHtml = Source.fromInputStream(is).mkString
// very poor man's templating engine
rawHtml.replace("{{docsPath}}", yamlName).replace("{{title}}", title)
rawHtml.replace("{{docsPath}}", yamlName).replace("{{title}}", title).replace("{{redocVersion}}", redocVersion)
}

def routes[F[_]: ContextShift: Sync]: HttpRoutes[F] = {
Expand Down

0 comments on commit 4387865

Please sign in to comment.