From 9170c934dfcb60804fa35286a260d25699d9a20c Mon Sep 17 00:00:00 2001 From: scala-steward Date: Thu, 7 Mar 2024 00:09:43 +0000 Subject: [PATCH 1/3] Update scalafmt-core to 3.8.0 --- .scalafmt.conf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.scalafmt.conf b/.scalafmt.conf index 6f22285747..9508cfbb48 100644 --- a/.scalafmt.conf +++ b/.scalafmt.conf @@ -1,4 +1,4 @@ -version = 3.7.17 +version = 3.8.0 maxColumn = 140 runner.dialect = scala3 fileOverride { From bd7dd1f0cdee5a05ceb65215832463139d534a1e Mon Sep 17 00:00:00 2001 From: scala-steward Date: Thu, 7 Mar 2024 00:10:05 +0000 Subject: [PATCH 2/3] Reformat with scalafmt 3.8.0 Executed command: scalafmt --non-interactive --- .../client/sttp/EndpointToSttpClient.scala | 33 ++++------- core/src/main/scala/sttp/tapir/Endpoint.scala | 4 +- .../docs/apispec/EndpointInputMapper.scala | 12 ++-- .../EndpointToAsyncAPIWebSocketChannel.scala | 3 +- .../examples/HelloWorldPekkoServer.scala | 2 +- ...stomErrorsOnDecodeFailurePekkoServer.scala | 3 +- .../IronRefinementErrorsNettyServer.scala | 6 +- .../sttp/tapir/examples/logging/Logging.scala | 15 ++--- .../BasicAuthenticationPekkoServer.scala | 2 +- .../security/CorsInterceptorPekkoServer.scala | 32 +++++++---- .../security/ServerSecurityLogicPekko.scala | 2 +- ...rverSecurityLogicRefreshCookiesPekko.scala | 2 +- .../StaticContentSecurePekkoServer.scala | 2 +- .../streaming/StreamingPekkoServer.scala | 2 +- .../grpc/protobuf/ProtoSchemaGenerator.scala | 2 +- .../CreateDerivedEnumerationPickler.scala | 3 +- .../tapir/perf/netty/future/NettyFuture.scala | 4 +- .../sttp/tapir/perf/PerfTestSuiteParams.scala | 3 +- .../sttp/tapir/perf/PerfTestSuiteResult.scala | 1 - .../server/akkahttp/AkkaServerRequest.scala | 3 +- .../server/armeria/ArmeriaRequestBody.scala | 5 +- .../interpreter/DecodeBasicInputs.scala | 10 ++-- .../server/http4s/Http4sToResponseBody.scala | 12 ++-- .../server/http4s/Http4sWebSockets.scala | 55 ++++++++++--------- .../jdkhttp/internal/JdkHttpRequestBody.scala | 7 ++- .../internal/JdkHttpToResponseBody.scala | 10 +--- .../cats/internal/NettyCatsRequestBody.scala | 3 +- .../server/netty/internal/NettyDefaults.scala | 2 +- .../internal/NettyFutureRequestBody.scala | 4 +- .../netty/internal/NettyServerHandler.scala | 7 +-- .../netty/internal/StreamCompatible.scala | 7 +-- .../netty/zio/NettyZioServerOptions.scala | 2 +- .../server/nima/NimaServerInterpreter.scala | 3 +- .../tapir/server/nima/NimaServerOptions.scala | 2 +- .../tapir/server/play/PlayRequestBody.scala | 2 +- .../tapir/server/tests/CreateServerTest.scala | 2 +- .../tapir/server/tests/ServerBasicTests.scala | 1 - .../vertx/streams/LimitedReadStream.scala | 9 ++- .../tapir/server/vertx/streams/package.scala | 2 +- .../tapir/server/vertx/VertxServerTest.scala | 2 +- .../server/ziohttp/ZioHttpRequestBody.scala | 1 - .../tapir/server/ziohttp/ZioWebSockets.scala | 6 +- .../server/ziohttp/ZioHttpServerTest.scala | 3 +- .../aws/lambda/AwsToResponseBody.scala | 3 +- .../aws/lambda/AwsToResponseBody.scala | 12 ++-- 45 files changed, 147 insertions(+), 161 deletions(-) diff --git a/client/sttp-client/src/main/scala/sttp/tapir/client/sttp/EndpointToSttpClient.scala b/client/sttp-client/src/main/scala/sttp/tapir/client/sttp/EndpointToSttpClient.scala index ab1191b122..7cc8775b33 100644 --- a/client/sttp-client/src/main/scala/sttp/tapir/client/sttp/EndpointToSttpClient.scala +++ b/client/sttp-client/src/main/scala/sttp/tapir/client/sttp/EndpointToSttpClient.scala @@ -73,53 +73,42 @@ private[sttp] class EndpointToSttpClient[R](clientOptions: SttpClientOptions, ws case EndpointInput.FixedMethod(_, _, _) => (uri, req) case EndpointInput.FixedPath(p, _, _) => (uri.addPath(p), req) case EndpointInput.PathCapture(_, codec, _) => - val v = codec.asInstanceOf[PlainCodec[Any]].encode(value: Any) - (uri.addPath(v), req) + val v = codec.asInstanceOf[PlainCodec[Any]].encode(value: Any)(uri.addPath(v), req) case EndpointInput.PathsCapture(codec, _) => - val ps = codec.encode(value) - (uri.addPath(ps), req) + val ps = codec.encode(value)(uri.addPath(ps), req) case EndpointInput.Query(name, Some(flagValue), _, _) if value == flagValue => (uri.withParams(uri.params.param(name, Nil)), req) case EndpointInput.Query(name, _, codec, _) => - val uri2 = codec.encode(value).foldLeft(uri) { case (u, v) => u.addParam(name, v) } - (uri2, req) + val uri2 = codec.encode(value).foldLeft(uri) { case (u, v) => u.addParam(name, v) }(uri2, req) case EndpointInput.Cookie(name, codec, _) => - val req2 = codec.encode(value).foldLeft(req) { case (r, v) => r.cookie(name, v) } - (uri, req2) + val req2 = codec.encode(value).foldLeft(req) { case (r, v) => r.cookie(name, v) }(uri, req2) case EndpointInput.QueryParams(codec, _) => val mqp = codec.encode(value) - val uri2 = uri.addParams(mqp.toSeq: _*) - (uri2, req) + val uri2 = uri.addParams(mqp.toSeq: _*)(uri2, req) case EndpointIO.Empty(_, _) => (uri, req) case EndpointIO.Body(bodyType, codec, _) => - val req2 = setBody(value, bodyType, codec, req) - (uri, req2) + val req2 = setBody(value, bodyType, codec, req)(uri, req2) case EndpointIO.OneOfBody(EndpointIO.OneOfBodyVariant(_, Left(body)) :: _, _) => setInputParams(body, params, uri, req) case EndpointIO.OneOfBody( EndpointIO.OneOfBodyVariant(_, Right(EndpointIO.StreamBodyWrapper(StreamBodyIO(streams, _, _, _, _)))) :: _, _ ) => - val req2 = req.streamBody(streams)(value.asInstanceOf[streams.BinaryStream]) - (uri, req2) + val req2 = req.streamBody(streams)(value.asInstanceOf[streams.BinaryStream])(uri, req2) case EndpointIO.OneOfBody(Nil, _) => throw new RuntimeException("One of body without variants") case EndpointIO.StreamBodyWrapper(StreamBodyIO(streams, _, _, _, _)) => - val req2 = req.streamBody(streams)(value.asInstanceOf[streams.BinaryStream]) - (uri, req2) + val req2 = req.streamBody(streams)(value.asInstanceOf[streams.BinaryStream])(uri, req2) case EndpointIO.Header(name, codec, _) => val req2 = codec .encode(value) - .foldLeft(req) { case (r, v) => r.header(name, v) } - (uri, req2) + .foldLeft(req) { case (r, v) => r.header(name, v) }(uri, req2) case EndpointIO.Headers(codec, _) => val headers = codec.encode(value) val req2 = headers.foldLeft(req) { case (r, h) => val replaceExisting = HeaderNames.ContentType.equalsIgnoreCase(h.name) || HeaderNames.ContentLength.equalsIgnoreCase(h.name) r.header(h, replaceExisting) - } - (uri, req2) + }(uri, req2) case EndpointIO.FixedHeader(h, _, _) => - val req2 = req.header(h) - (uri, req2) + val req2 = req.header(h)(uri, req2) case EndpointInput.ExtractFromRequest(_, _) => // ignoring (uri, req) diff --git a/core/src/main/scala/sttp/tapir/Endpoint.scala b/core/src/main/scala/sttp/tapir/Endpoint.scala index 02a372b544..9a78991104 100644 --- a/core/src/main/scala/sttp/tapir/Endpoint.scala +++ b/core/src/main/scala/sttp/tapir/Endpoint.scala @@ -220,10 +220,10 @@ trait EndpointErrorOutputVariantsOps[A, I, E, O, -R] { def errorOutVariantPrepend[E2 >: E](o: OneOfVariant[_ <: E2]): EndpointType[A, I, E2, O, R] = withErrorOutputVariant(oneOf[E2](o, oneOfDefaultVariant(errorOutput)), identity) - /** Same as [[errorOutVariantPrepend]], but allows appending multiple variants in one go. */ + /** Same as [[errorOutVariantPrepend]], but allows appending multiple variants in one go. */ def errorOutVariantsPrepend[E2 >: E](first: OneOfVariant[_ <: E2], other: OneOfVariant[_ <: E2]*): EndpointType[A, I, E2, O, R] = withErrorOutputVariant(oneOf[E2](oneOfDefaultVariant(errorOutput), first +: other: _*), identity) - + /** Same as [[errorOutVariant]], but allows appending multiple variants in one go. */ def errorOutVariants[E2 >: E](first: OneOfVariant[_ <: E2], other: OneOfVariant[_ <: E2]*)(implicit ct: ClassTag[E], diff --git a/docs/apispec-docs/src/main/scala/sttp/tapir/docs/apispec/EndpointInputMapper.scala b/docs/apispec-docs/src/main/scala/sttp/tapir/docs/apispec/EndpointInputMapper.scala index 06218debd6..19af42b811 100644 --- a/docs/apispec-docs/src/main/scala/sttp/tapir/docs/apispec/EndpointInputMapper.scala +++ b/docs/apispec-docs/src/main/scala/sttp/tapir/docs/apispec/EndpointInputMapper.scala @@ -22,8 +22,10 @@ private[docs] class EndpointInputMapper[S]( ei match { case _ if inputMapping.isDefinedAt((ei, s)) => inputMapping((ei, s)) case EndpointInput.MappedPair(wrapped, c) => - val (wrapped2, s2) = mapInput(wrapped, s) - (EndpointInput.MappedPair(wrapped2.asInstanceOf[EndpointInput.Pair[Any, Any, Any]], c.asInstanceOf[Mapping[Any, Any]]), s2) + val (wrapped2, s2) = mapInput(wrapped, s)( + EndpointInput.MappedPair(wrapped2.asInstanceOf[EndpointInput.Pair[Any, Any, Any]], c.asInstanceOf[Mapping[Any, Any]]), + s2 + ) case _ => (ei, s) } @@ -41,8 +43,10 @@ private[docs] class EndpointInputMapper[S]( ei match { case _ if ioMapping.isDefinedAt((ei, s)) => ioMapping((ei, s)) case EndpointIO.MappedPair(wrapped, c) => - val (wrapped2, s2) = mapIO(wrapped, s) - (EndpointIO.MappedPair(wrapped2.asInstanceOf[EndpointIO.Pair[Any, Any, Any]], c.asInstanceOf[Mapping[Any, Any]]), s2) + val (wrapped2, s2) = mapIO(wrapped, s)( + EndpointIO.MappedPair(wrapped2.asInstanceOf[EndpointIO.Pair[Any, Any, Any]], c.asInstanceOf[Mapping[Any, Any]]), + s2 + ) case _ => (ei, s) } } diff --git a/docs/asyncapi-docs/src/main/scala/sttp/tapir/docs/asyncapi/EndpointToAsyncAPIWebSocketChannel.scala b/docs/asyncapi-docs/src/main/scala/sttp/tapir/docs/asyncapi/EndpointToAsyncAPIWebSocketChannel.scala index c4bed5ebe8..b2fe34cbac 100644 --- a/docs/asyncapi-docs/src/main/scala/sttp/tapir/docs/asyncapi/EndpointToAsyncAPIWebSocketChannel.scala +++ b/docs/asyncapi-docs/src/main/scala/sttp/tapir/docs/asyncapi/EndpointToAsyncAPIWebSocketChannel.scala @@ -55,8 +55,7 @@ private[asyncapi] class EndpointToAsyncAPIWebSocketChannel( val schemaWithDescription = if (schema.description.isEmpty) schemaRef.copy(description = info.description) else schemaRef val schemaWithDeprecation = if (schema.deprecated.isEmpty && info.deprecated) schemaWithDescription.copy(deprecated = Some(info.deprecated)) - else schemaWithDescription - (name, codec) -> schemaWithDeprecation + else schemaWithDescription(name, codec) -> schemaWithDeprecation case _ => (name, codec) -> schemaRef } } diff --git a/examples/src/main/scala/sttp/tapir/examples/HelloWorldPekkoServer.scala b/examples/src/main/scala/sttp/tapir/examples/HelloWorldPekkoServer.scala index ab22daf4d3..f8bcc3e382 100644 --- a/examples/src/main/scala/sttp/tapir/examples/HelloWorldPekkoServer.scala +++ b/examples/src/main/scala/sttp/tapir/examples/HelloWorldPekkoServer.scala @@ -31,7 +31,7 @@ object HelloWorldPekkoServer extends App { println("Got result: " + result) assert(result == "Hello, Frodo!") - + binding } diff --git a/examples/src/main/scala/sttp/tapir/examples/errors/CustomErrorsOnDecodeFailurePekkoServer.scala b/examples/src/main/scala/sttp/tapir/examples/errors/CustomErrorsOnDecodeFailurePekkoServer.scala index 782efd7469..11351c1476 100644 --- a/examples/src/main/scala/sttp/tapir/examples/errors/CustomErrorsOnDecodeFailurePekkoServer.scala +++ b/examples/src/main/scala/sttp/tapir/examples/errors/CustomErrorsOnDecodeFailurePekkoServer.scala @@ -41,7 +41,8 @@ object CustomErrorsOnDecodeFailurePekkoServer extends App { ) .options - val amountRoute: Route = PekkoHttpServerInterpreter(customServerOptions).toRoute(amountEndpoint.serverLogicSuccess(_ => Future.successful(()))) + val amountRoute: Route = + PekkoHttpServerInterpreter(customServerOptions).toRoute(amountEndpoint.serverLogicSuccess(_ => Future.successful(()))) // starting the server val bindAndCheck = Http().newServerAt("localhost", 8080).bindFlow(amountRoute).map { binding => diff --git a/examples/src/main/scala/sttp/tapir/examples/errors/IronRefinementErrorsNettyServer.scala b/examples/src/main/scala/sttp/tapir/examples/errors/IronRefinementErrorsNettyServer.scala index 9b0019156b..7997c1c8d0 100644 --- a/examples/src/main/scala/sttp/tapir/examples/errors/IronRefinementErrorsNettyServer.scala +++ b/examples/src/main/scala/sttp/tapir/examples/errors/IronRefinementErrorsNettyServer.scala @@ -37,7 +37,7 @@ object IronRefinementErrorsNettyServer extends IOApp.Simple { // Decoder throwing custom exception when refinement fails inline given (using inline constraint: Constraint[Int, Positive]): Decoder[Age] = summon[Decoder[Int]].map(unrefinedValue => unrefinedValue.refineEither[Positive] match - case Right(value) => value + case Right(value) => value case Left(errorMessage) => throw IronException(s"Could not refine value $unrefinedValue: $errorMessage") ) @@ -58,8 +58,8 @@ object IronRefinementErrorsNettyServer extends IOApp.Simple { // and we can add the failure details to the error message. private def failureDetailMessage(failure: DecodeResult.Failure): Option[String] = failure match { case Error(_, JsonDecodeException(_, IronException(errorMessage))) => Some(errorMessage) - case Error(_, IronException(errorMessage)) => Some(errorMessage) - case other => FailureMessages.failureDetailMessage(other) + case Error(_, IronException(errorMessage)) => Some(errorMessage) + case other => FailureMessages.failureDetailMessage(other) } private def failureMessage(ctx: DecodeFailureContext): String = { diff --git a/examples/src/main/scala/sttp/tapir/examples/logging/Logging.scala b/examples/src/main/scala/sttp/tapir/examples/logging/Logging.scala index af18df84a6..fe33bf4dc4 100644 --- a/examples/src/main/scala/sttp/tapir/examples/logging/Logging.scala +++ b/examples/src/main/scala/sttp/tapir/examples/logging/Logging.scala @@ -2,14 +2,11 @@ package sttp.tapir.examples.logging import org.slf4j.{Logger, LoggerFactory} -/** - * Defines a [[org.slf4j.Logger]] instance `logger` named according to the class - * into which this trait is mixed. - * - * In a real-life project, you might rather want to use a macros-based SLF4J wrapper - * or logging backend. - */ +/** Defines a [[org.slf4j.Logger]] instance `logger` named according to the class into which this trait is mixed. + * + * In a real-life project, you might rather want to use a macros-based SLF4J wrapper or logging backend. + */ trait Logging { - - protected val logger: Logger = LoggerFactory.getLogger(getClass.getName) + + protected val logger: Logger = LoggerFactory.getLogger(getClass.getName) } diff --git a/examples/src/main/scala/sttp/tapir/examples/security/BasicAuthenticationPekkoServer.scala b/examples/src/main/scala/sttp/tapir/examples/security/BasicAuthenticationPekkoServer.scala index 504f74cb1f..a8aa347ba9 100644 --- a/examples/src/main/scala/sttp/tapir/examples/security/BasicAuthenticationPekkoServer.scala +++ b/examples/src/main/scala/sttp/tapir/examples/security/BasicAuthenticationPekkoServer.scala @@ -40,7 +40,7 @@ object BasicAuthenticationPekkoServer extends App { println("Got result: " + result) assert(result.code == StatusCode.Ok) assert(result.body == Right("Hello, user!")) - + binding } diff --git a/examples/src/main/scala/sttp/tapir/examples/security/CorsInterceptorPekkoServer.scala b/examples/src/main/scala/sttp/tapir/examples/security/CorsInterceptorPekkoServer.scala index dc3dbeb9c5..b761bfe3ba 100644 --- a/examples/src/main/scala/sttp/tapir/examples/security/CorsInterceptorPekkoServer.scala +++ b/examples/src/main/scala/sttp/tapir/examples/security/CorsInterceptorPekkoServer.scala @@ -24,13 +24,17 @@ object CorsInterceptorPekkoServer extends App { // Add CORSInterceptor to ServerOptions. Allow http://example.com origin, GET methods, credentials and some custom // headers. val customServerOptions: PekkoHttpServerOptions = PekkoHttpServerOptions.customiseInterceptors - .corsInterceptor(CORSInterceptor.customOrThrow(CORSConfig.default - .allowOrigin(Origin.Host("http", "example.com")) - .allowMethods(Method.GET) - .allowHeaders("X-Foo", "X-Bar") - .allowCredentials - .maxAge(42.seconds) - )).options + .corsInterceptor( + CORSInterceptor.customOrThrow( + CORSConfig.default + .allowOrigin(Origin.Host("http", "example.com")) + .allowMethods(Method.GET) + .allowHeaders("X-Foo", "X-Bar") + .allowCredentials + .maxAge(42.seconds) + ) + ) + .options val helloCorsRoute: Route = PekkoHttpServerInterpreter(customServerOptions).toRoute(helloCors.serverLogicSuccess(name => Future.successful(s"Hello!"))) @@ -44,8 +48,9 @@ object CorsInterceptorPekkoServer extends App { .options(uri"http://localhost:8080/hello") .headers( Header.origin(Origin.Host("http", "example.com")), - Header.accessControlRequestMethod(Method.GET), - ).send(backend) + Header.accessControlRequestMethod(Method.GET) + ) + .send(backend) assert(preflightResponse.code == StatusCode.NoContent) assert(preflightResponse.headers.contains(Header.accessControlAllowOrigin("http://example.com"))) @@ -60,8 +65,9 @@ object CorsInterceptorPekkoServer extends App { .options(uri"http://localhost:8080/hello") .headers( Header.origin(Origin.Host("http", "unallowed.com")), - Header.accessControlRequestMethod(Method.GET), - ).send(backend) + Header.accessControlRequestMethod(Method.GET) + ) + .send(backend) // Check response does not contain allowed origin header assert(preflightResponseForUnallowedOrigin.code == StatusCode.NoContent) @@ -70,7 +76,9 @@ object CorsInterceptorPekkoServer extends App { println("Got expected response for preflight request for wrong origin. No allowed origin header in response") // Sending regular request from allowed origin - val requestResponse = basicRequest.response(asStringAlways).get(uri"http://localhost:8080/hello") + val requestResponse = basicRequest + .response(asStringAlways) + .get(uri"http://localhost:8080/hello") .headers(Header.origin(Origin.Host("http", "example.com")), Header.authorization("Bearer", "dummy-credentials")) .send(backend) diff --git a/examples/src/main/scala/sttp/tapir/examples/security/ServerSecurityLogicPekko.scala b/examples/src/main/scala/sttp/tapir/examples/security/ServerSecurityLogicPekko.scala index 0b8ab743ff..f231477c3c 100644 --- a/examples/src/main/scala/sttp/tapir/examples/security/ServerSecurityLogicPekko.scala +++ b/examples/src/main/scala/sttp/tapir/examples/security/ServerSecurityLogicPekko.scala @@ -83,7 +83,7 @@ object ServerSecurityLogicPekko extends App { assert(testWith("hello", "Cześć", "berries") == "Cześć, Papa Smurf!") assert(testWith("hello", "Hello", "apple") == "1001") assert(testWith("hello", "Hello", "smurf") == "Not saying hello to Gargamel!") - + binding } diff --git a/examples/src/main/scala/sttp/tapir/examples/security/ServerSecurityLogicRefreshCookiesPekko.scala b/examples/src/main/scala/sttp/tapir/examples/security/ServerSecurityLogicRefreshCookiesPekko.scala index 7581fc8246..9b55a6da57 100644 --- a/examples/src/main/scala/sttp/tapir/examples/security/ServerSecurityLogicRefreshCookiesPekko.scala +++ b/examples/src/main/scala/sttp/tapir/examples/security/ServerSecurityLogicRefreshCookiesPekko.scala @@ -64,7 +64,7 @@ object ServerSecurityLogicRefreshCookiesPekko extends App { assert(response.body == "Welcome, Steve!") assert(response.unsafeCookies.map(_.value).toList == List("new token")) - + binding } diff --git a/examples/src/main/scala/sttp/tapir/examples/static_content/StaticContentSecurePekkoServer.scala b/examples/src/main/scala/sttp/tapir/examples/static_content/StaticContentSecurePekkoServer.scala index a476671ce9..77eda683ac 100644 --- a/examples/src/main/scala/sttp/tapir/examples/static_content/StaticContentSecurePekkoServer.scala +++ b/examples/src/main/scala/sttp/tapir/examples/static_content/StaticContentSecurePekkoServer.scala @@ -52,7 +52,7 @@ object StaticContentSecurePekkoServer extends App { assert(response2.code == StatusCode.Ok) assert(response2.body == "f1 content") - + binding } diff --git a/examples/src/main/scala/sttp/tapir/examples/streaming/StreamingPekkoServer.scala b/examples/src/main/scala/sttp/tapir/examples/streaming/StreamingPekkoServer.scala index da83fd8d77..d0461858c1 100644 --- a/examples/src/main/scala/sttp/tapir/examples/streaming/StreamingPekkoServer.scala +++ b/examples/src/main/scala/sttp/tapir/examples/streaming/StreamingPekkoServer.scala @@ -35,7 +35,7 @@ object StreamingPekkoServer extends App { println("Got result: " + result) assert(result == "Hello!" * 10) - + binding } diff --git a/grpc/protobuf/src/main/scala/sttp/tapir/grpc/protobuf/ProtoSchemaGenerator.scala b/grpc/protobuf/src/main/scala/sttp/tapir/grpc/protobuf/ProtoSchemaGenerator.scala index c8069693c3..bca6107c47 100644 --- a/grpc/protobuf/src/main/scala/sttp/tapir/grpc/protobuf/ProtoSchemaGenerator.scala +++ b/grpc/protobuf/src/main/scala/sttp/tapir/grpc/protobuf/ProtoSchemaGenerator.scala @@ -9,7 +9,7 @@ import sttp.tapir.AnyEndpoint import sttp.tapir.grpc.protobuf.model._ object ProtoSchemaGenerator { - + private val logger = LoggerFactory.getLogger(getClass.getName) def renderToFile(path: String, packageName: PackageName, endpoints: Iterable[AnyEndpoint]): Unit = { logger.info("Generating proto file") diff --git a/json/pickler/src/main/scala/sttp/tapir/json/pickler/CreateDerivedEnumerationPickler.scala b/json/pickler/src/main/scala/sttp/tapir/json/pickler/CreateDerivedEnumerationPickler.scala index f36bc01c46..7563ba8cd6 100644 --- a/json/pickler/src/main/scala/sttp/tapir/json/pickler/CreateDerivedEnumerationPickler.scala +++ b/json/pickler/src/main/scala/sttp/tapir/json/pickler/CreateDerivedEnumerationPickler.scala @@ -61,8 +61,7 @@ class CreateDerivedEnumerationPickler[T: ClassTag]( inline erasedValue[Cases] match { case _: (enumerationCase *: enumerationCasesTail) => val processedHead = readWriterForEnumerationCase[enumerationCase] - val processedTail = buildEnumerationReadWriters[T, enumerationCasesTail] - (processedHead +: processedTail) + val processedTail = buildEnumerationReadWriters[T, enumerationCasesTail](processedHead +: processedTail) case _: EmptyTuple.type => Nil } diff --git a/perf-tests/src/main/scala/sttp/tapir/perf/netty/future/NettyFuture.scala b/perf-tests/src/main/scala/sttp/tapir/perf/netty/future/NettyFuture.scala index 8cfe1c67f1..97c1fef7dc 100644 --- a/perf-tests/src/main/scala/sttp/tapir/perf/netty/future/NettyFuture.scala +++ b/perf-tests/src/main/scala/sttp/tapir/perf/netty/future/NettyFuture.scala @@ -36,4 +36,6 @@ object NettyFuture { object TapirServer extends ServerRunner { override def start = NettyFuture.runServer(Tapir.genEndpointsFuture(1)) } object TapirMultiServer extends ServerRunner { override def start = NettyFuture.runServer(Tapir.genEndpointsFuture(128)) } -object TapirInterceptorMultiServer extends ServerRunner { override def start = NettyFuture.runServer(Tapir.genEndpointsFuture(128), withServerLog = true) } +object TapirInterceptorMultiServer extends ServerRunner { + override def start = NettyFuture.runServer(Tapir.genEndpointsFuture(128), withServerLog = true) +} diff --git a/perf-tests/src/test/scala/sttp/tapir/perf/PerfTestSuiteParams.scala b/perf-tests/src/test/scala/sttp/tapir/perf/PerfTestSuiteParams.scala index f0ba4b20c7..7724fddb95 100644 --- a/perf-tests/src/test/scala/sttp/tapir/perf/PerfTestSuiteParams.scala +++ b/perf-tests/src/test/scala/sttp/tapir/perf/PerfTestSuiteParams.scala @@ -44,7 +44,8 @@ case class PerfTestSuiteParams( /** Returns list of server names */ - def serverNames: List[ServerName] = if (shortServerNames.nonEmpty) shortServerNames.map(ServerName.fromShort).distinct else List(ExternalServerName) + def serverNames: List[ServerName] = + if (shortServerNames.nonEmpty) shortServerNames.map(ServerName.fromShort).distinct else List(ExternalServerName) /** Returns pairs of (fullSimulationName, shortSimulationName), for example: (sttp.tapir.perf.SimpleGetSimulation, SimpleGet) */ diff --git a/perf-tests/src/test/scala/sttp/tapir/perf/PerfTestSuiteResult.scala b/perf-tests/src/test/scala/sttp/tapir/perf/PerfTestSuiteResult.scala index 2c6cdaeee9..9d2b0d032b 100644 --- a/perf-tests/src/test/scala/sttp/tapir/perf/PerfTestSuiteResult.scala +++ b/perf-tests/src/test/scala/sttp/tapir/perf/PerfTestSuiteResult.scala @@ -12,4 +12,3 @@ case class GatlingSimulationResult( latencyP75: Double, latencyP50: Double ) - diff --git a/server/akka-http-server/src/main/scala/sttp/tapir/server/akkahttp/AkkaServerRequest.scala b/server/akka-http-server/src/main/scala/sttp/tapir/server/akkahttp/AkkaServerRequest.scala index 2cb8da5a35..29491a4046 100644 --- a/server/akka-http-server/src/main/scala/sttp/tapir/server/akkahttp/AkkaServerRequest.scala +++ b/server/akka-http-server/src/main/scala/sttp/tapir/server/akkahttp/AkkaServerRequest.scala @@ -28,7 +28,7 @@ private[akkahttp] case class AkkaServerRequest(ctx: RequestContext, attributes: } override lazy val queryParameters: QueryParams = QueryParams.fromMultiMap(ctx.request.uri.query().toMultiMap) override lazy val method: Method = Method(ctx.request.method.value.toUpperCase) - + private def queryToSegments(query: AkkaUri.Query): List[QuerySegment] = { @tailrec def run(q: AkkaUri.Query, acc: List[QuerySegment]): List[QuerySegment] = q match { @@ -57,7 +57,6 @@ private[akkahttp] case class AkkaServerRequest(ctx: RequestContext, attributes: ) } - private val EmptyContentType = "none/none" // Add low-level headers that have been removed by akka-http. diff --git a/server/armeria-server/src/main/scala/sttp/tapir/server/armeria/ArmeriaRequestBody.scala b/server/armeria-server/src/main/scala/sttp/tapir/server/armeria/ArmeriaRequestBody.scala index 637513d4a5..bfefeb5da6 100644 --- a/server/armeria-server/src/main/scala/sttp/tapir/server/armeria/ArmeriaRequestBody.scala +++ b/server/armeria-server/src/main/scala/sttp/tapir/server/armeria/ArmeriaRequestBody.scala @@ -25,7 +25,10 @@ private[armeria] final class ArmeriaRequestBody[F[_], S <: Streams[S]]( override def toStream(serverRequest: ServerRequest, maxBytes: Option[Long]): streams.BinaryStream = { streamCompatible - .fromArmeriaStream(armeriaCtx(serverRequest).request().filter(x => x.isInstanceOf[HttpData]).asInstanceOf[StreamMessage[HttpData]], maxBytes) + .fromArmeriaStream( + armeriaCtx(serverRequest).request().filter(x => x.isInstanceOf[HttpData]).asInstanceOf[StreamMessage[HttpData]], + maxBytes + ) .asInstanceOf[streams.BinaryStream] } diff --git a/server/core/src/main/scala/sttp/tapir/server/interpreter/DecodeBasicInputs.scala b/server/core/src/main/scala/sttp/tapir/server/interpreter/DecodeBasicInputs.scala index 2bc7892d7c..60eb9ce7e7 100644 --- a/server/core/src/main/scala/sttp/tapir/server/interpreter/DecodeBasicInputs.scala +++ b/server/core/src/main/scala/sttp/tapir/server/interpreter/DecodeBasicInputs.scala @@ -189,8 +189,7 @@ object DecodeBasicInputs { decodedPathInputs(index) = in.codec.decode(seg) matchPathInner(index + 1, pathInputs, newCtx, decodeValues, decodedPathInputs, idxInput.input, matchWholePath) case None => - val failure = DecodeBasicInputsResult.Failure(in, DecodeResult.Missing) - (failure, newCtx) + val failure = DecodeBasicInputsResult.Failure(in, DecodeResult.Missing)(failure, newCtx) } case i: EndpointInput.PathsCapture[_] => val (paths, newCtx) = collectRemainingPath(Vector.empty, ctx) @@ -206,8 +205,8 @@ object DecodeBasicInputs { // shape path mismatch - input path too long; there are more segments in the request path than expected by // that input. Reporting a failure on the last path input. val failure = - DecodeBasicInputsResult.Failure(lastPathInput, DecodeResult.Multiple(collectRemainingPath(Vector.empty, ctx)._1)) - (failure, newCtx) + DecodeBasicInputsResult + .Failure(lastPathInput, DecodeResult.Multiple(collectRemainingPath(Vector.empty, ctx)._1))(failure, newCtx) case _ => (foldDecodedPathInputs(0, pathInputs, decodedPathInputs, decodeValues), ctx) } @@ -307,8 +306,7 @@ object DecodeBasicInputs { ) ) .map(_.flatten) - val decodedCookieValue = allCookies.map(_.find(_.name == name).map(_.value)).flatMap(codec.decode) - (decodedCookieValue, ctx) + val decodedCookieValue = allCookies.map(_.find(_.name == name).map(_.value)).flatMap(codec.decode)(decodedCookieValue, ctx) case EndpointIO.Header(name, codec, _) => (codec.decode(ctx.header(name)), ctx) diff --git a/server/http4s-server/src/main/scala/sttp/tapir/server/http4s/Http4sToResponseBody.scala b/server/http4s-server/src/main/scala/sttp/tapir/server/http4s/Http4sToResponseBody.scala index 6ffe5d5193..a671cf7df8 100644 --- a/server/http4s-server/src/main/scala/sttp/tapir/server/http4s/Http4sToResponseBody.scala +++ b/server/http4s-server/src/main/scala/sttp/tapir/server/http4s/Http4sToResponseBody.scala @@ -41,26 +41,22 @@ private[http4s] class Http4sToResponseBody[F[_]: Async]( private def rawValueToEntity[CF <: CodecFormat, R](bodyType: RawBodyType[R], r: R): (EntityBody[F], Option[Long]) = { bodyType match { case RawBodyType.StringBody(charset) => - val bytes = r.toString.getBytes(charset) - (fs2.Stream.chunk(Chunk.array(bytes)), Some(bytes.length)) + val bytes = r.toString.getBytes(charset)(fs2.Stream.chunk(Chunk.array(bytes)), Some(bytes.length)) case RawBodyType.ByteArrayBody => (fs2.Stream.chunk(Chunk.array(r)), Some((r: Array[Byte]).length)) case RawBodyType.ByteBufferBody => (fs2.Stream.chunk(Chunk.byteBuffer(r)), None) case RawBodyType.InputStreamBody => (inputStreamToFs2(() => r), None) case RawBodyType.InputStreamRangeBody => val fs2Stream = r.range .map(range => inputStreamToFs2(r.inputStreamFromRangeStart).take(range.contentLength)) - .getOrElse(inputStreamToFs2(r.inputStream)) - (fs2Stream, None) + .getOrElse(inputStreamToFs2(r.inputStream))(fs2Stream, None) case RawBodyType.FileBody => val tapirFile = r val stream = tapirFile.range .flatMap(r => r.startAndEnd.map(s => Files[F].readRange(tapirFile.file.toPath, r.contentLength.toInt, s._1, s._2))) - .getOrElse(Files[F].readAll(tapirFile.file.toPath, serverOptions.ioChunkSize)) - (stream, Some(tapirFile.file.length)) + .getOrElse(Files[F].readAll(tapirFile.file.toPath, serverOptions.ioChunkSize))(stream, Some(tapirFile.file.length)) case m: RawBodyType.MultipartBody => val parts = (r: Seq[RawPart]).flatMap(rawPartToBodyPart(m, _)) - val body = implicitly[EntityEncoder[F, multipart.Multipart[F]]].toEntity(multipart.Multipart(parts.toVector)).body - (body, None) + val body = implicitly[EntityEncoder[F, multipart.Multipart[F]]].toEntity(multipart.Multipart(parts.toVector)).body(body, None) } } diff --git a/server/http4s-server/src/main/scala/sttp/tapir/server/http4s/Http4sWebSockets.scala b/server/http4s-server/src/main/scala/sttp/tapir/server/http4s/Http4sWebSockets.scala index f711117d1b..3a53cbc292 100644 --- a/server/http4s-server/src/main/scala/sttp/tapir/server/http4s/Http4sWebSockets.scala +++ b/server/http4s-server/src/main/scala/sttp/tapir/server/http4s/Http4sWebSockets.scala @@ -15,9 +15,9 @@ import cats.effect.implicits._ private[http4s] object Http4sWebSockets { def pipeToBody[F[_]: Temporal, REQ, RESP]( - pipe: Pipe[F, REQ, RESP], - o: WebSocketBodyOutput[Pipe[F, REQ, RESP], REQ, RESP, _, Fs2Streams[F]] - ): F[Pipe[F, Http4sWebSocketFrame, Http4sWebSocketFrame]] = { + pipe: Pipe[F, REQ, RESP], + o: WebSocketBodyOutput[Pipe[F, REQ, RESP], REQ, RESP, _, Fs2Streams[F]] + ): F[Pipe[F, Http4sWebSocketFrame, Http4sWebSocketFrame]] = { if ((!o.autoPongOnPing) && o.autoPing.isEmpty) { // fast track: lift Http4sWebSocketFrames into REQ, run through pipe, convert RESP back to Http4sWebSocketFrame @@ -36,7 +36,8 @@ private[http4s] object Http4sWebSockets { .through(pipe) .mapChunks(_.map(r => frameToHttp4sFrame(o.responses.encode(r)))) .append(Stream(frameToHttp4sFrame(WebSocketFrame.close))) - }.pure[F] else { + }.pure[F] + else { // concurrently merge business logic response, autoPings, autoPongOnPing // use fs2.Channel to perform the merge (more efficient than Stream#mergeHaltL / Stream#parJoin) @@ -75,20 +76,20 @@ private[http4s] object Http4sWebSockets { private def http4sFrameToFrame(f: Http4sWebSocketFrame): WebSocketFrame = f match { - case t: Http4sWebSocketFrame.Text => WebSocketFrame.Text(t.str, t.last, None) - case x: Http4sWebSocketFrame.Ping => WebSocketFrame.Ping(x.data.toArray) - case x: Http4sWebSocketFrame.Pong => WebSocketFrame.Pong(x.data.toArray) + case t: Http4sWebSocketFrame.Text => WebSocketFrame.Text(t.str, t.last, None) + case x: Http4sWebSocketFrame.Ping => WebSocketFrame.Ping(x.data.toArray) + case x: Http4sWebSocketFrame.Pong => WebSocketFrame.Pong(x.data.toArray) case c: Http4sWebSocketFrame.Close => WebSocketFrame.Close(c.closeCode, "") - case _ => WebSocketFrame.Binary(f.data.toArray, f.last, None) + case _ => WebSocketFrame.Binary(f.data.toArray, f.last, None) } private def frameToHttp4sFrame(w: WebSocketFrame): Http4sWebSocketFrame = w match { - case x: WebSocketFrame.Text => Http4sWebSocketFrame.Text(x.payload, x.finalFragment) + case x: WebSocketFrame.Text => Http4sWebSocketFrame.Text(x.payload, x.finalFragment) case x: WebSocketFrame.Binary => Http4sWebSocketFrame.Binary(ByteVector(x.payload), x.finalFragment) - case x: WebSocketFrame.Ping => Http4sWebSocketFrame.Ping(ByteVector(x.payload)) - case x: WebSocketFrame.Pong => Http4sWebSocketFrame.Pong(ByteVector(x.payload)) - case x: WebSocketFrame.Close => Http4sWebSocketFrame.Close(x.statusCode, x.reasonText).fold(throw _, identity) + case x: WebSocketFrame.Ping => Http4sWebSocketFrame.Ping(ByteVector(x.payload)) + case x: WebSocketFrame.Pong => Http4sWebSocketFrame.Pong(ByteVector(x.payload)) + case x: WebSocketFrame.Close => Http4sWebSocketFrame.Close(x.statusCode, x.reasonText).fold(throw _, identity) } private def optionallyConcatenateFrames[F[_]](s: Stream[F, WebSocketFrame], doConcatenate: Boolean): Stream[F, WebSocketFrame] = @@ -96,14 +97,14 @@ private[http4s] object Http4sWebSockets { type Accumulator = Option[Either[Array[Byte], String]] s.mapAccumulate(None: Accumulator) { - case (None, f: WebSocketFrame.Ping) => (None, Some(f)) - case (None, f: WebSocketFrame.Pong) => (None, Some(f)) - case (None, f: WebSocketFrame.Close) => (None, Some(f)) - case (None, f: WebSocketFrame.Data[_]) if f.finalFragment => (None, Some(f)) - case (Some(Left(acc)), f: WebSocketFrame.Binary) if f.finalFragment => (None, Some(f.copy(payload = acc ++ f.payload))) + case (None, f: WebSocketFrame.Ping) => (None, Some(f)) + case (None, f: WebSocketFrame.Pong) => (None, Some(f)) + case (None, f: WebSocketFrame.Close) => (None, Some(f)) + case (None, f: WebSocketFrame.Data[_]) if f.finalFragment => (None, Some(f)) + case (Some(Left(acc)), f: WebSocketFrame.Binary) if f.finalFragment => (None, Some(f.copy(payload = acc ++ f.payload))) case (Some(Left(acc)), f: WebSocketFrame.Binary) if !f.finalFragment => (Some(Left(acc ++ f.payload)), None) - case (Some(Right(acc)), f: WebSocketFrame.Text) if f.finalFragment => (None, Some(f.copy(payload = acc + f.payload))) - case (Some(Right(acc)), f: WebSocketFrame.Text) if !f.finalFragment => (Some(Right(acc + f.payload)), None) + case (Some(Right(acc)), f: WebSocketFrame.Text) if f.finalFragment => (None, Some(f.copy(payload = acc + f.payload))) + case (Some(Right(acc)), f: WebSocketFrame.Text) if !f.finalFragment => (Some(Right(acc + f.payload)), None) case (acc, f) => throw new IllegalStateException(s"Cannot accumulate web socket frames. Accumulator: $acc, frame: $f.") }.collect { case (_, Some(f)) => f } } else s @@ -112,21 +113,21 @@ private[http4s] object Http4sWebSockets { if (doIgnore) { s.filter { case _: WebSocketFrame.Pong => false - case _ => true + case _ => true } } else s } - private def optionallyAutoPong[F[_] : Monad]( - s: Stream[F, WebSocketFrame], - c: Channel[F, Chunk[Http4sWebSocketFrame]], - doAuto: Boolean - ): Stream[F, WebSocketFrame] = + private def optionallyAutoPong[F[_]: Monad]( + s: Stream[F, WebSocketFrame], + c: Channel[F, Chunk[Http4sWebSocketFrame]], + doAuto: Boolean + ): Stream[F, WebSocketFrame] = if (doAuto) { val trueF = true.pure[F] s.evalFilter { case ping: WebSocketFrame.Ping => c.send(Chunk.singleton(frameToHttp4sFrame(WebSocketFrame.Pong(ping.payload)))).map(_ => false) - case _ => trueF + case _ => trueF } } else s @@ -134,7 +135,7 @@ private[http4s] object Http4sWebSockets { if (!doDecodeClose) { s.takeWhile { case _: Http4sWebSocketFrame.Close => false - case _ => true + case _ => true } } else s } diff --git a/server/jdkhttp-server/src/main/scala/sttp/tapir/server/jdkhttp/internal/JdkHttpRequestBody.scala b/server/jdkhttp-server/src/main/scala/sttp/tapir/server/jdkhttp/internal/JdkHttpRequestBody.scala index 0cb5fe8528..51a27717b4 100644 --- a/server/jdkhttp-server/src/main/scala/sttp/tapir/server/jdkhttp/internal/JdkHttpRequestBody.scala +++ b/server/jdkhttp-server/src/main/scala/sttp/tapir/server/jdkhttp/internal/JdkHttpRequestBody.scala @@ -23,7 +23,12 @@ private[jdkhttp] class JdkHttpRequestBody(createFile: ServerRequest => TapirFile toRaw(serverRequest, bodyType, request.getRequestBody, maxBytes) } - private def toRaw[RAW](serverRequest: ServerRequest, bodyType: RawBodyType[RAW], body: InputStream, maxBytes: Option[Long]): RawValue[RAW] = { + private def toRaw[RAW]( + serverRequest: ServerRequest, + bodyType: RawBodyType[RAW], + body: InputStream, + maxBytes: Option[Long] + ): RawValue[RAW] = { def asInputStream: InputStream = maxBytes.map(limit => new FailingLimitedInputStream(body, limit)).getOrElse(body) def asByteArray: Array[Byte] = asInputStream.readAllBytes() diff --git a/server/jdkhttp-server/src/main/scala/sttp/tapir/server/jdkhttp/internal/JdkHttpToResponseBody.scala b/server/jdkhttp-server/src/main/scala/sttp/tapir/server/jdkhttp/internal/JdkHttpToResponseBody.scala index cd4cb3c297..9dfe4453b4 100644 --- a/server/jdkhttp-server/src/main/scala/sttp/tapir/server/jdkhttp/internal/JdkHttpToResponseBody.scala +++ b/server/jdkhttp-server/src/main/scala/sttp/tapir/server/jdkhttp/internal/JdkHttpToResponseBody.scala @@ -20,11 +20,9 @@ private[jdkhttp] class JdkHttpToResponseBody extends ToResponseBody[JdkHttpRespo override def fromRawValue[R](v: R, headers: HasHeaders, format: CodecFormat, bodyType: RawBodyType[R]): JdkHttpResponseBody = { bodyType match { case RawBodyType.StringBody(charset) => - val bytes = v.asInstanceOf[String].getBytes(charset) - (new ByteArrayInputStream(bytes), Some(bytes.length.toLong)) + val bytes = v.asInstanceOf[String].getBytes(charset)(new ByteArrayInputStream(bytes), Some(bytes.length.toLong)) case RawBodyType.ByteArrayBody => - val arr = v.asInstanceOf[Array[Byte]] - (new ByteArrayInputStream(arr), Some(arr.length.toLong)) + val arr = v.asInstanceOf[Array[Byte]](new ByteArrayInputStream(arr), Some(arr.length.toLong)) case RawBodyType.ByteBufferBody => (new ByteBufferBackedInputStream(v.asInstanceOf[ByteBuffer]), None) // TODO can't we provide the length? case RawBodyType.InputStreamBody => @@ -56,8 +54,7 @@ private[jdkhttp] class JdkHttpToResponseBody extends ToResponseBody[JdkHttpRespo val entity = MultipartEntityBuilder.create() v.flatMap(rawPartToFormBodyPart(m, _)).foreach { (formBodyPart: FormBodyPart) => entity.addPart(formBodyPart) } val builtEntity = entity.build() - val inputStream: InputStream = builtEntity.getContent - (inputStream, Some(builtEntity.getContentLength)) + val inputStream: InputStream = builtEntity.getContent(inputStream, Some(builtEntity.getContentLength)) } } @@ -132,4 +129,3 @@ private class ByteBufferBackedInputStream(buf: ByteBuffer) extends InputStream { len2 } } - diff --git a/server/netty-server/cats/src/main/scala/sttp/tapir/server/netty/cats/internal/NettyCatsRequestBody.scala b/server/netty-server/cats/src/main/scala/sttp/tapir/server/netty/cats/internal/NettyCatsRequestBody.scala index e1a762ae70..55c9d6e5d2 100644 --- a/server/netty-server/cats/src/main/scala/sttp/tapir/server/netty/cats/internal/NettyCatsRequestBody.scala +++ b/server/netty-server/cats/src/main/scala/sttp/tapir/server/netty/cats/internal/NettyCatsRequestBody.scala @@ -24,7 +24,8 @@ private[cats] class NettyCatsRequestBody[F[_]: Async]( streamCompatible.fromPublisher(publisher, maxBytes).compile.to(Chunk).map(_.toArray[Byte]) override def writeToFile(serverRequest: ServerRequest, file: TapirFile, maxBytes: Option[Long]): F[Unit] = - (toStream(serverRequest, maxBytes).asInstanceOf[streamCompatible.streams.BinaryStream]) + (toStream(serverRequest, maxBytes) + .asInstanceOf[streamCompatible.streams.BinaryStream]) .through( Files[F](Files.forAsync[F]).writeAll(Path.fromNioPath(file.toPath)) ) diff --git a/server/netty-server/src/main/scala/sttp/tapir/server/netty/internal/NettyDefaults.scala b/server/netty-server/src/main/scala/sttp/tapir/server/netty/internal/NettyDefaults.scala index 4f12013158..3a49ddbaca 100644 --- a/server/netty-server/src/main/scala/sttp/tapir/server/netty/internal/NettyDefaults.scala +++ b/server/netty-server/src/main/scala/sttp/tapir/server/netty/internal/NettyDefaults.scala @@ -6,7 +6,7 @@ object NettyDefaults { def debugLog(log: Logger, msg: String, exOpt: Option[Throwable]): Unit = if (log.isDebugEnabled) { exOpt match { - case None => log.debug(msg) + case None => log.debug(msg) case Some(ex) => log.debug(msg, ex) } } diff --git a/server/netty-server/src/main/scala/sttp/tapir/server/netty/internal/NettyFutureRequestBody.scala b/server/netty-server/src/main/scala/sttp/tapir/server/netty/internal/NettyFutureRequestBody.scala index c6dcbf0a9d..f9d67e67ba 100644 --- a/server/netty-server/src/main/scala/sttp/tapir/server/netty/internal/NettyFutureRequestBody.scala +++ b/server/netty-server/src/main/scala/sttp/tapir/server/netty/internal/NettyFutureRequestBody.scala @@ -26,7 +26,7 @@ private[netty] class NettyFutureRequestBody(val createFile: ServerRequest => Fut case r: StreamedHttpRequest => FileWriterSubscriber.processAll(r, file.toPath, maxBytes) case _ => monad.unit(()) // Empty request } - - override def toStream(serverRequest: ServerRequest, maxBytes: Option[Long]): streams.BinaryStream = + + override def toStream(serverRequest: ServerRequest, maxBytes: Option[Long]): streams.BinaryStream = throw new UnsupportedOperationException() } diff --git a/server/netty-server/src/main/scala/sttp/tapir/server/netty/internal/NettyServerHandler.scala b/server/netty-server/src/main/scala/sttp/tapir/server/netty/internal/NettyServerHandler.scala index 181ee68fad..eadf165c72 100644 --- a/server/netty-server/src/main/scala/sttp/tapir/server/netty/internal/NettyServerHandler.scala +++ b/server/netty-server/src/main/scala/sttp/tapir/server/netty/internal/NettyServerHandler.scala @@ -80,12 +80,9 @@ class NettyServerHandler[F[_]]( // Since the listener will be executed from the channels EventLoop everything is thread safe. val _ = ctx.channel.closeFuture.addListener { (_: ChannelFuture) => if (logger.isDebugEnabled) { - logger.debug("Http channel to {} closed. Cancelling {} responses.", - ctx.channel.remoteAddress, - pendingResponses.length - ) + logger.debug("Http channel to {} closed. Cancelling {} responses.", ctx.channel.remoteAddress, pendingResponses.length) } - while(pendingResponses.nonEmpty) { + while (pendingResponses.nonEmpty) { pendingResponses.dequeue().apply() } } diff --git a/server/netty-server/src/main/scala/sttp/tapir/server/netty/internal/StreamCompatible.scala b/server/netty-server/src/main/scala/sttp/tapir/server/netty/internal/StreamCompatible.scala index 6d5da177bd..6ffa3c8927 100644 --- a/server/netty-server/src/main/scala/sttp/tapir/server/netty/internal/StreamCompatible.scala +++ b/server/netty-server/src/main/scala/sttp/tapir/server/netty/internal/StreamCompatible.scala @@ -7,10 +7,9 @@ import sttp.tapir.FileRange import java.io.InputStream -/** - * Operations on streams that have to be implemented for each streaming integration (fs2, zio-streams, etc) used by Netty backends. - * This includes conversions like building a stream from a `File`, an `InputStream`, or a reactive `Publisher`. - * We also need implementation of a failed (errored) stream, as well as an empty stream (for handling empty requests). +/** Operations on streams that have to be implemented for each streaming integration (fs2, zio-streams, etc) used by Netty backends. This + * includes conversions like building a stream from a `File`, an `InputStream`, or a reactive `Publisher`. We also need implementation of a + * failed (errored) stream, as well as an empty stream (for handling empty requests). */ private[netty] trait StreamCompatible[S <: Streams[S]] { val streams: S diff --git a/server/netty-server/zio/src/main/scala/sttp/tapir/server/netty/zio/NettyZioServerOptions.scala b/server/netty-server/zio/src/main/scala/sttp/tapir/server/netty/zio/NettyZioServerOptions.scala index 2b25e067ef..4b1f0193ad 100644 --- a/server/netty-server/zio/src/main/scala/sttp/tapir/server/netty/zio/NettyZioServerOptions.scala +++ b/server/netty-server/zio/src/main/scala/sttp/tapir/server/netty/zio/NettyZioServerOptions.scala @@ -49,7 +49,7 @@ object NettyZioServerOptions { private def debugLog[R](msg: String, exOpt: Option[Throwable]): RIO[R, Unit] = exOpt match { - case None => ZIO.logDebug(msg) + case None => ZIO.logDebug(msg) case Some(ex) => ZIO.logDebugCause(msg, Cause.fail(ex)) } diff --git a/server/nima-server/src/main/scala/sttp/tapir/server/nima/NimaServerInterpreter.scala b/server/nima-server/src/main/scala/sttp/tapir/server/nima/NimaServerInterpreter.scala index 9a28839b32..5e10f6bbc1 100644 --- a/server/nima-server/src/main/scala/sttp/tapir/server/nima/NimaServerInterpreter.scala +++ b/server/nima-server/src/main/scala/sttp/tapir/server/nima/NimaServerInterpreter.scala @@ -49,8 +49,7 @@ trait NimaServerInterpreter { // If endpoint matching fails, we return control to Nima case RequestResult.Failure(_) => - helidonResponse.next() - () + helidonResponse.next()() } } } diff --git a/server/nima-server/src/main/scala/sttp/tapir/server/nima/NimaServerOptions.scala b/server/nima-server/src/main/scala/sttp/tapir/server/nima/NimaServerOptions.scala index 70f6a85f6d..e325920906 100644 --- a/server/nima-server/src/main/scala/sttp/tapir/server/nima/NimaServerOptions.scala +++ b/server/nima-server/src/main/scala/sttp/tapir/server/nima/NimaServerOptions.scala @@ -41,7 +41,7 @@ object NimaServerOptions { if (log.isDebugEnabled) { exOpt match { case Some(e) => log.debug(msg, e) - case None => log.debug(msg) + case None => log.debug(msg) } } } diff --git a/server/play-server/src/main/scala/sttp/tapir/server/play/PlayRequestBody.scala b/server/play-server/src/main/scala/sttp/tapir/server/play/PlayRequestBody.scala index 04383c35a8..cc8aa49af0 100644 --- a/server/play-server/src/main/scala/sttp/tapir/server/play/PlayRequestBody.scala +++ b/server/play-server/src/main/scala/sttp/tapir/server/play/PlayRequestBody.scala @@ -127,7 +127,7 @@ private[play] class PlayRequestBody(serverOptions: PlayServerOptions)(implicit charset(partType), () => FileIO.fromPath(f.ref.path), Some(f.ref.toFile), - maxBytes = None, + maxBytes = None ).map(body => Some( Part( diff --git a/server/tests/src/main/scala/sttp/tapir/server/tests/CreateServerTest.scala b/server/tests/src/main/scala/sttp/tapir/server/tests/CreateServerTest.scala index 2cbcfcb546..7bb8b83823 100644 --- a/server/tests/src/main/scala/sttp/tapir/server/tests/CreateServerTest.scala +++ b/server/tests/src/main/scala/sttp/tapir/server/tests/CreateServerTest.scala @@ -60,7 +60,7 @@ class DefaultCreateServerTest[F[_], +R, OPTIONS, ROUTE]( backend: SttpBackend[IO, Fs2Streams[IO] with WebSockets], interpreter: TestServerInterpreter[F, R, OPTIONS, ROUTE] ) extends CreateServerTest[F, R, OPTIONS, ROUTE] { - + private val logger = LoggerFactory.getLogger(getClass.getName) override def testServer[I, E, O]( diff --git a/server/tests/src/main/scala/sttp/tapir/server/tests/ServerBasicTests.scala b/server/tests/src/main/scala/sttp/tapir/server/tests/ServerBasicTests.scala index 000abfedb1..00e3efc0f8 100644 --- a/server/tests/src/main/scala/sttp/tapir/server/tests/ServerBasicTests.scala +++ b/server/tests/src/main/scala/sttp/tapir/server/tests/ServerBasicTests.scala @@ -787,7 +787,6 @@ class ServerBasicTests[F[_], OPTIONS, ROUTE]( r.code shouldBe StatusCode.PayloadTooLarge } }, - testPayloadTooLarge(in_byte_buffer_out_byte_buffer, maxLength), testPayloadWithinLimit(in_string_out_string, maxLength), testServer( diff --git a/server/vertx-server/src/main/scala/sttp/tapir/server/vertx/streams/LimitedReadStream.scala b/server/vertx-server/src/main/scala/sttp/tapir/server/vertx/streams/LimitedReadStream.scala index 79f6e83b80..b3535f2d90 100644 --- a/server/vertx-server/src/main/scala/sttp/tapir/server/vertx/streams/LimitedReadStream.scala +++ b/server/vertx-server/src/main/scala/sttp/tapir/server/vertx/streams/LimitedReadStream.scala @@ -5,14 +5,13 @@ import io.vertx.core.Handler import io.vertx.core.buffer.Buffer import sttp.capabilities.StreamMaxLengthExceededException -/** - * An adapter for Vertx ReadStream[Buffer], which passes bytes through, but fails with a [[sttp.capabilities.StreamMaxLengthExceededException]] if exceeds given limit. - * This exception should be handled by [[sttp.tapir.server.interceptor.exception.DefaultExceptionHandler]] in order to return a HTTP 413 Payload Too Large. - +/** An adapter for Vertx ReadStream[Buffer], which passes bytes through, but fails with a + * [[sttp.capabilities.StreamMaxLengthExceededException]] if exceeds given limit. This exception should be handled by + * [[sttp.tapir.server.interceptor.exception.DefaultExceptionHandler]] in order to return a HTTP 413 Payload Too Large. */ private[vertx] class LimitedReadStream(source: ReadStream[Buffer], maxBytes: Long) extends ReadStream[Buffer] { - // Safe, Vertx uses a single thread + // Safe, Vertx uses a single thread private var bytesReadSoFar: Long = 0 private var endHandler: Handler[Void] = _ private var exceptionHandler: Handler[Throwable] = _ diff --git a/server/vertx-server/src/main/scala/sttp/tapir/server/vertx/streams/package.scala b/server/vertx-server/src/main/scala/sttp/tapir/server/vertx/streams/package.scala index bbd928c0f5..8165d15bcb 100644 --- a/server/vertx-server/src/main/scala/sttp/tapir/server/vertx/streams/package.scala +++ b/server/vertx-server/src/main/scala/sttp/tapir/server/vertx/streams/package.scala @@ -18,7 +18,7 @@ package object streams { override def asReadStream(readStream: ReadStream[Buffer]): ReadStream[Buffer] = readStream - override def fromReadStream(readStream: ReadStream[Buffer], maxBytes: Option[Long]): ReadStream[Buffer] = + override def fromReadStream(readStream: ReadStream[Buffer], maxBytes: Option[Long]): ReadStream[Buffer] = maxBytes.map(new LimitedReadStream(readStream, _)).getOrElse(readStream) override def webSocketPipe[REQ, RESP]( diff --git a/server/vertx-server/src/test/scala/sttp/tapir/server/vertx/VertxServerTest.scala b/server/vertx-server/src/test/scala/sttp/tapir/server/vertx/VertxServerTest.scala index 8a7a8f57ce..9335edb79f 100644 --- a/server/vertx-server/src/test/scala/sttp/tapir/server/vertx/VertxServerTest.scala +++ b/server/vertx-server/src/test/scala/sttp/tapir/server/vertx/VertxServerTest.scala @@ -27,7 +27,7 @@ class VertxServerTest extends TestSuite { def drainVertx[T](source: ReadStream[T]): Future[Unit] = { val p = Promise[Unit]() // Handler for stream data - do nothing with the data - val dataHandler: Handler[T] = (_: T) => () + val dataHandler: Handler[T] = (_: T) => () // End handler - complete the promise when the stream ends val endHandler: Handler[Void] = (_: Void) => p.success(()) diff --git a/server/zio-http-server/src/main/scala/sttp/tapir/server/ziohttp/ZioHttpRequestBody.scala b/server/zio-http-server/src/main/scala/sttp/tapir/server/ziohttp/ZioHttpRequestBody.scala index 290b6e3736..fe9e503324 100644 --- a/server/zio-http-server/src/main/scala/sttp/tapir/server/ziohttp/ZioHttpRequestBody.scala +++ b/server/zio-http-server/src/main/scala/sttp/tapir/server/ziohttp/ZioHttpRequestBody.scala @@ -46,4 +46,3 @@ class ZioHttpRequestBody[R](serverOptions: ZioHttpServerOptions[R]) extends Requ private def zioHttpRequest(serverRequest: ServerRequest) = serverRequest.underlying.asInstanceOf[Request] } - diff --git a/server/zio-http-server/src/main/scala/sttp/tapir/server/ziohttp/ZioWebSockets.scala b/server/zio-http-server/src/main/scala/sttp/tapir/server/ziohttp/ZioWebSockets.scala index 1814d859b7..db889aa18c 100644 --- a/server/zio-http-server/src/main/scala/sttp/tapir/server/ziohttp/ZioWebSockets.scala +++ b/server/zio-http-server/src/main/scala/sttp/tapir/server/ziohttp/ZioWebSockets.scala @@ -128,12 +128,10 @@ object ZioWebSockets { case (Some(Left(acc)), f: SttpWebSocketFrame.Binary) if !f.finalFragment => (Some(Left(acc ++ f.payload)), None) case (Some(Right(acc)), f: SttpWebSocketFrame.Text) if f.finalFragment => println(s"final fragment: $f") - println(s"acc: $acc") - (None, Some(f.copy(payload = acc + f.payload))) + println(s"acc: $acc")(None, Some(f.copy(payload = acc + f.payload))) case (Some(Right(acc)), f: SttpWebSocketFrame.Text) if !f.finalFragment => println(s"final fragment: $f") - println(s"acc: $acc") - (Some(Right(acc + f.payload)), None) + println(s"acc: $acc")(Some(Right(acc + f.payload)), None) case (acc, f) => throw new IllegalStateException(s"Cannot accumulate web socket frames. Accumulator: $acc, frame: $f.") } diff --git a/server/zio-http-server/src/test/scala/sttp/tapir/server/ziohttp/ZioHttpServerTest.scala b/server/zio-http-server/src/test/scala/sttp/tapir/server/ziohttp/ZioHttpServerTest.scala index 828290d902..2b0dc5e720 100644 --- a/server/zio-http-server/src/test/scala/sttp/tapir/server/ziohttp/ZioHttpServerTest.scala +++ b/server/zio-http-server/src/test/scala/sttp/tapir/server/ziohttp/ZioHttpServerTest.scala @@ -65,8 +65,7 @@ class ZioHttpServerTest extends TestSuite { new FutureOutcome(outcome.toFuture.flatMap { case Exceptional(e) => println(s"Test ${test.name} failed, retrying.") - e.printStackTrace() - (if (count == 1) super.withFixture(test) else withFixture(test, count - 1)).toFuture + e.printStackTrace()(if (count == 1) super.withFixture(test) else withFixture(test, count - 1)).toFuture case other => Future.successful(other) }) } diff --git a/serverless/aws/lambda-core/src/main/scalajs/sttp/tapir/serverless/aws/lambda/AwsToResponseBody.scala b/serverless/aws/lambda-core/src/main/scalajs/sttp/tapir/serverless/aws/lambda/AwsToResponseBody.scala index adefe67bde..f502398f7e 100644 --- a/serverless/aws/lambda-core/src/main/scalajs/sttp/tapir/serverless/aws/lambda/AwsToResponseBody.scala +++ b/serverless/aws/lambda-core/src/main/scalajs/sttp/tapir/serverless/aws/lambda/AwsToResponseBody.scala @@ -16,8 +16,7 @@ private[lambda] class AwsToResponseBody[F[_]](options: AwsServerOptions[F]) exte bodyType match { case RawBodyType.StringBody(charset) => val str = v.asInstanceOf[String] - val r = if (options.encodeResponseBody) Base64.getEncoder.encodeToString(str.getBytes(charset)) else str - (r, Some(str.length.toLong)) + val r = if (options.encodeResponseBody) Base64.getEncoder.encodeToString(str.getBytes(charset)) else str(r, Some(str.length.toLong)) case RawBodyType.ByteArrayBody => val bytes = v.asInstanceOf[Array[Byte]] diff --git a/serverless/aws/lambda-core/src/main/scalajvm/sttp/tapir/serverless/aws/lambda/AwsToResponseBody.scala b/serverless/aws/lambda-core/src/main/scalajvm/sttp/tapir/serverless/aws/lambda/AwsToResponseBody.scala index b70debd682..a09a4e9896 100644 --- a/serverless/aws/lambda-core/src/main/scalajvm/sttp/tapir/serverless/aws/lambda/AwsToResponseBody.scala +++ b/serverless/aws/lambda-core/src/main/scalajvm/sttp/tapir/serverless/aws/lambda/AwsToResponseBody.scala @@ -18,8 +18,7 @@ private[lambda] class AwsToResponseBody[F[_]](options: AwsServerOptions[F]) exte bodyType match { case RawBodyType.StringBody(charset) => val str = v.asInstanceOf[String] - val r = if (options.encodeResponseBody) Base64.getEncoder.encodeToString(str.getBytes(charset)) else str - (r, Some(str.length.toLong)) + val r = if (options.encodeResponseBody) Base64.getEncoder.encodeToString(str.getBytes(charset)) else str(r, Some(str.length.toLong)) case RawBodyType.ByteArrayBody => val bytes = v.asInstanceOf[Array[Byte]] @@ -34,15 +33,16 @@ private[lambda] class AwsToResponseBody[F[_]](options: AwsServerOptions[F]) exte case RawBodyType.InputStreamBody => val stream = v.asInstanceOf[InputStream] val r = - if (options.encodeResponseBody) Base64.getEncoder.encodeToString(stream.readAllBytes()) else new String(stream.readAllBytes()) - (r, None) + if (options.encodeResponseBody) Base64.getEncoder.encodeToString(stream.readAllBytes()) else new String(stream.readAllBytes())( + r, + None + ) case RawBodyType.InputStreamRangeBody => val bytes: Array[Byte] = v.range .map(r => v.inputStreamFromRangeStart().readNBytes(r.contentLength.toInt)) .getOrElse(v.inputStream().readAllBytes()) val body = - if (options.encodeResponseBody) Base64.getEncoder.encodeToString(bytes) else new String(bytes) - (body, Some(bytes.length.toLong)) + if (options.encodeResponseBody) Base64.getEncoder.encodeToString(bytes) else new String(bytes)(body, Some(bytes.length.toLong)) case RawBodyType.FileBody => throw new UnsupportedOperationException case _: RawBodyType.MultipartBody => throw new UnsupportedOperationException From 6e86ff35e31b76272f8168b0c86d8344b24b06d4 Mon Sep 17 00:00:00 2001 From: scala-steward Date: Thu, 7 Mar 2024 00:10:05 +0000 Subject: [PATCH 3/3] Add 'Reformat with scalafmt 3.8.0' to .git-blame-ignore-revs --- .git-blame-ignore-revs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.git-blame-ignore-revs b/.git-blame-ignore-revs index 9f8e86bf95..404bad3e23 100644 --- a/.git-blame-ignore-revs +++ b/.git-blame-ignore-revs @@ -42,3 +42,6 @@ c40dbf3aafd72299a21b38125140249337c83e0f # Scala Steward: Reformat with scalafmt 3.7.17 ab79cadbb13aac7c32015ce5caf24d57290ee59b + +# Scala Steward: Reformat with scalafmt 3.8.0 +bd7dd1f0cdee5a05ceb65215832463139d534a1e