Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add redocVersion parameter for RedocHttp4s #955

Merged
merged 1 commit into from
Jan 20, 2021
Merged
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
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