Skip to content

Commit

Permalink
fixed bug , plus tests and formatting applied
Browse files Browse the repository at this point in the history
  • Loading branch information
yisraelU committed Mar 11, 2022
1 parent c8168d0 commit 1de97d1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,14 @@ private[smithy4s] abstract class Docs[F[_]](
val jsonSpec = hasId.id.namespace + '.' + hasId.id.name + ".json"

val actualPath: Path = Uri.Path.unsafeFromString("/" + path)

object DocPath {
def unapply(p: Path): Boolean = {
p match {
case `actualPath` => true
case `actualPath` / "" => true
case `actualPath` => true
case `actualPath` / "" => true
case `actualPath` / file if file.equalsIgnoreCase("index.html") => true
case _ => false
case _ => false
}
}
}
Expand All @@ -51,6 +52,7 @@ private[smithy4s] abstract class Docs[F[_]](
PermanentRedirect(
Location(Uri.unsafeFromString(s"/$path/index.html?url=/$jsonSpec"))
)

case request @ GET -> `actualPath` / filePath =>
val resource = s"$swaggerUiPath/$filePath"
staticResource(resource, Some(request)).getOrElseF(NotFound())
Expand All @@ -61,7 +63,6 @@ private[smithy4s] abstract class Docs[F[_]](
}
}


object Docs extends Compat.DocsCompanion {}

trait SwaggerUiInit {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ object DocsSpec extends SimpleIOSuite with TestCompat {

test(s"GET /$path redirects to expected location") {
val request =
Request[IO](method = Method.GET, uri = Uri.unsafeFromString(s"/$path"))
Request[IO](
method = Method.GET,
uri = Uri.unsafeFromString(s"/$path/index.html")
)
app.run(request).map { response =>
val redirectUri = response.headers
.get(CIString("Location"))
Expand Down

0 comments on commit 1de97d1

Please sign in to comment.