From 1de97d1a503fbcaac5459fa1268fd5476c1d40d0 Mon Sep 17 00:00:00 2001 From: yisraelu Date: Fri, 11 Mar 2022 09:59:13 -0500 Subject: [PATCH] fixed bug , plus tests and formatting applied --- .../src-jvm/smithy4s/http4s/swagger/Docs.scala | 9 +++++---- .../test/src/smithy4s/http4s/swagger/DocsSpec.scala | 5 ++++- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/modules/http4s-swagger/src-jvm/smithy4s/http4s/swagger/Docs.scala b/modules/http4s-swagger/src-jvm/smithy4s/http4s/swagger/Docs.scala index 3a4cd31e4..97761251e 100644 --- a/modules/http4s-swagger/src-jvm/smithy4s/http4s/swagger/Docs.scala +++ b/modules/http4s-swagger/src-jvm/smithy4s/http4s/swagger/Docs.scala @@ -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 } } } @@ -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()) @@ -61,7 +63,6 @@ private[smithy4s] abstract class Docs[F[_]]( } } - object Docs extends Compat.DocsCompanion {} trait SwaggerUiInit { diff --git a/modules/http4s-swagger/test/src/smithy4s/http4s/swagger/DocsSpec.scala b/modules/http4s-swagger/test/src/smithy4s/http4s/swagger/DocsSpec.scala index 18388a656..ebd7e2061 100644 --- a/modules/http4s-swagger/test/src/smithy4s/http4s/swagger/DocsSpec.scala +++ b/modules/http4s-swagger/test/src/smithy4s/http4s/swagger/DocsSpec.scala @@ -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"))