diff --git a/server/sttp-stub-server/src/main/scala/sttp/tapir/server/stub/SttpRequest.scala b/server/sttp-stub-server/src/main/scala/sttp/tapir/server/stub/SttpRequest.scala index 44949a21fc..c6d0277e53 100644 --- a/server/sttp-stub-server/src/main/scala/sttp/tapir/server/stub/SttpRequest.scala +++ b/server/sttp-stub-server/src/main/scala/sttp/tapir/server/stub/SttpRequest.scala @@ -14,7 +14,10 @@ case class SttpRequest(r: Request[_, _], attributes: AttributeMap = AttributeMap override def protocol: String = "HTTP/1.1" override def connectionInfo: ConnectionInfo = ConnectionInfo(None, None, None) override def underlying: Any = r - override def pathSegments: List[String] = r.uri.pathSegments.segments.map(_.v).toList + override def pathSegments: List[String] = (r.uri.pathSegments.segments.map(_.v) match { + case other :+ "" => other + case s => s + }).toList override def uri: Uri = r.uri override def attribute[T](k: AttributeKey[T]): Option[T] = attributes.get(k) override def attribute[T](k: AttributeKey[T], v: T): SttpRequest = copy(attributes = attributes.put(k, v)) diff --git a/server/sttp-stub-server/src/test/scala/sttp/tapir/server/stub/TapirStubInterpreterTest.scala b/server/sttp-stub-server/src/test/scala/sttp/tapir/server/stub/TapirStubInterpreterTest.scala index b64d1d6da9..fae8a3a35e 100644 --- a/server/sttp-stub-server/src/test/scala/sttp/tapir/server/stub/TapirStubInterpreterTest.scala +++ b/server/sttp-stub-server/src/test/scala/sttp/tapir/server/stub/TapirStubInterpreterTest.scala @@ -42,6 +42,20 @@ class TapirStubInterpreterTest extends AnyFlatSpec with Matchers { response.body shouldBe Right("computer") } + it should "stub endpoint logic with trailing slash with success response" in { + // given + val server = TapirStubInterpreter(options, SttpBackendStub(IdMonad)) + .whenEndpoint(getProduct) + .thenRespond("computer") + .backend() + + // when + val response = sttp.client3.basicRequest.get(uri"http://test.com/api/products/").send(server) + + // then + response.body shouldBe Right("computer") + } + it should "stub endpoint logic with error response" in { // given val server = TapirStubInterpreter[Identity, Nothing, ServerOptions](options, SttpBackendStub(IdMonad))