Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update scalafmt-core to 3.8.0 #3524

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,6 @@ c40dbf3aafd72299a21b38125140249337c83e0f

# Scala Steward: Reformat with scalafmt 3.7.17
ab79cadbb13aac7c32015ce5caf24d57290ee59b

# Scala Steward: Reformat with scalafmt 3.8.0
bd7dd1f0cdee5a05ceb65215832463139d534a1e
2 changes: 1 addition & 1 deletion .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version = 3.7.17
version = 3.8.0
maxColumn = 140
runner.dialect = scala3
fileOverride {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/scala/sttp/tapir/Endpoint.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand All @@ -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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ object HelloWorldPekkoServer extends App {
println("Got result: " + result)

assert(result == "Hello, Frodo!")

binding
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
)

Expand All @@ -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 = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ object BasicAuthenticationPekkoServer extends App {
println("Got result: " + result)
assert(result.code == StatusCode.Ok)
assert(result.body == Right("Hello, user!"))

binding
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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!")))
Expand All @@ -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")))
Expand All @@ -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)
Expand All @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ object ServerSecurityLogicRefreshCookiesPekko extends App {

assert(response.body == "Welcome, Steve!")
assert(response.unsafeCookies.map(_.value).toList == List("new token"))

binding
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ object StaticContentSecurePekkoServer extends App {

assert(response2.code == StatusCode.Ok)
assert(response2.body == "f1 content")

binding
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ object StreamingPekkoServer extends App {
println("Got result: " + result)

assert(result == "Hello!" * 10)

binding
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,3 @@ case class GatlingSimulationResult(
latencyP75: Double,
latencyP50: Double
)

Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
}
Expand Down Expand Up @@ -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)
Expand Down
Loading
Loading