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 97761251e..b198d282a 100644 --- a/modules/http4s-swagger/src-jvm/smithy4s/http4s/swagger/Docs.scala +++ b/modules/http4s-swagger/src-jvm/smithy4s/http4s/swagger/Docs.scala @@ -48,7 +48,7 @@ private[smithy4s] abstract class Docs[F[_]]( } } def routes: HttpRoutes[F] = HttpRoutes.of[F] { - case GET -> DocPath() => + case r @ GET -> DocPath() if r.uri.query.isEmpty => PermanentRedirect( Location(Uri.unsafeFromString(s"/$path/index.html?url=/$jsonSpec")) ) diff --git a/modules/http4s-swagger/test/resources/swaggerui/index.html b/modules/http4s-swagger/test/resources/swaggerui/index.html new file mode 100644 index 000000000..157317d64 --- /dev/null +++ b/modules/http4s-swagger/test/resources/swaggerui/index.html @@ -0,0 +1,6 @@ + + + + + + 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 ebd7e2061..e14fdf5a8 100644 --- a/modules/http4s-swagger/test/src/smithy4s/http4s/swagger/DocsSpec.scala +++ b/modules/http4s-swagger/test/src/smithy4s/http4s/swagger/DocsSpec.scala @@ -78,6 +78,20 @@ object DocsSpec extends SimpleIOSuite with TestCompat { ) } } + test( + s"GET /$path/index.html?url=/test-file.json does not redirect" + ) { + val request = + Request[IO]( + method = Method.GET, + uri = Uri.unsafeFromString( + s"/$path/index.html?url=/test-file.json" + ) + ) + app.run(request).map { response => + expect(response.status == Status.Ok) + } + } test(s"GET $path/test-file.json fetches requested file") { val filePath = s"/$path/test-file.json" val request =