Skip to content

Commit

Permalink
Reformat with scalafmt 3.8.0
Browse files Browse the repository at this point in the history
Executed command: scalafmt --non-interactive
  • Loading branch information
scala-steward committed Feb 20, 2024
1 parent 1a2c5d5 commit 4561e31
Show file tree
Hide file tree
Showing 45 changed files with 149 additions and 162 deletions.
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
8 changes: 4 additions & 4 deletions perf-tests/src/main/scala/sttp/tapir/perf/Common.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ object Common {
val Port = 8080
val TmpDir: File = new java.io.File(System.getProperty("java.io.tmpdir")).getAbsoluteFile
def newTempFilePath(): Path = TmpDir.toPath.resolve(s"tapir-${new Date().getTime}-${Random.nextLong()}")
def buildOptions[F[_], O](customiseInterceptors: CustomiseInterceptors[F, O], withServerLog: Boolean): O =
def buildOptions[F[_], O](customiseInterceptors: CustomiseInterceptors[F, O], withServerLog: Boolean): O =
(if (withServerLog == false)
customiseInterceptors.serverLog(None)
else
customiseInterceptors).options
customiseInterceptors.serverLog(None)
else
customiseInterceptors).options
}
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 @@ -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 @@ -186,8 +186,7 @@ object DecodeBasicInputs {
val newDecodedPathInputs = decodedPathInputs :+ ((idxInput, i.codec.decode(seg)))
matchPathInner(restInputs, newCtx, decodeValues, newDecodedPathInputs, 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 @@ -203,8 +202,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(decodedPathInputs, decodeValues), ctx)
}
Expand Down Expand Up @@ -298,8 +297,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

0 comments on commit 4561e31

Please sign in to comment.