Skip to content

Commit cc36eb2

Browse files
committed
Update scalafmt configuration
1 parent 15c2a99 commit cc36eb2

File tree

8 files changed

+158
-162
lines changed

8 files changed

+158
-162
lines changed

.scalafmt.conf

+15-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
11
version = 3.8.4
22
maxColumn = 140
3-
runner.dialect = scala3
3+
runner.dialect = scala213
44
fileOverride {
5-
"glob:**/scala-2/**" {
6-
runner.dialect = scala213
5+
"glob:**/scala-3/**" {
6+
runner.dialect = scala3
77
}
8-
"glob:**/enumeratum/**" {
9-
runner.dialect = scala213
10-
}
8+
"glob:**/examples/**" {
9+
runner.dialect = scala3
10+
}
11+
"glob:**/integrations/iron/**" {
12+
runner.dialect = scala3
13+
}
14+
"glob:**/json/pickler/**" {
15+
runner.dialect = scala3
16+
}
17+
"glob:**/server/netty-server/sync/**" {
18+
runner.dialect = scala3
19+
}
1120
}

examples/src/main/scala/sttp/tapir/examples/errors/optionalValueExample.scala

+12-12
Original file line numberDiff line numberDiff line change
@@ -25,24 +25,24 @@ import scala.concurrent.duration.*
2525

2626
case class Beer(name: String, volumeInLiters: Double)
2727

28-
val bartenderEndpoint = endpoint
29-
.get
28+
val bartenderEndpoint = endpoint.get
3029
.in("beer" / query[Int]("age"))
3130
// Optional value from serverLogic, responding with 404 "Not Found" when logic returns None
32-
.out(oneOf(
33-
oneOfVariantExactMatcher(StatusCode.NotFound, jsonBody[Option[Beer]])(None),
34-
oneOfVariantValueMatcher(StatusCode.Ok, jsonBody[Option[Beer]]) {
35-
case Some(_) => true
36-
}
37-
))
31+
.out(
32+
oneOf(
33+
oneOfVariantExactMatcher(StatusCode.NotFound, jsonBody[Option[Beer]])(None),
34+
oneOfVariantValueMatcher(StatusCode.Ok, jsonBody[Option[Beer]]) { case Some(_) =>
35+
true
36+
}
37+
)
38+
)
3839

3940
//
4041

4142
val bartenderServerEndpoint = bartenderEndpoint.serverLogic {
42-
case a if a < 18 => Future.successful(Right(None))
43-
case _ => Future.successful(Right(Some(Beer("IPA", 0.5))))
44-
}
45-
43+
case a if a < 18 => Future.successful(Right(None))
44+
case _ => Future.successful(Right(Some(Beer("IPA", 0.5))))
45+
}
4646

4747
given actorSystem: ActorSystem = ActorSystem()
4848
import actorSystem.dispatcher

examples/src/main/scala/sttp/tapir/examples/openapi/swaggerUIOAuth2PekkoServer.scala

-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import scala.concurrent.{Await, Future, Promise}
2121
/** Preliminary steps (!!! DO NOT USE ON PRODUCTION :) !!!):
2222
* 1. Start keycloak
2323
* {{{docker run -p 8080:8080 -e KEYCLOAK_ADMIN=admin -e KEYCLOAK_ADMIN_PASSWORD=admin quay.io/keycloak/keycloak:17.0.1 start-dev}}}
24-
*
2524
* 2. Based on page: [[https://www.keycloak.org/getting-started/getting-started-docker]]
2625
*
2726
* - create realm `myrealm`

perf-tests/src/main/scala/sttp/tapir/perf/apis/Endpoints.scala

+6-9
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,8 @@ trait Endpoints {
3131
.in(stringBody)
3232
.maxRequestBodyLength(LargeInputSize + 1024L)
3333
.out(stringBody)
34-
.serverLogicSuccess {
35-
body: String =>
36-
reply(s"Ok [$n], string length = ${body.length}")
34+
.serverLogicSuccess { body: String =>
35+
reply(s"Ok [$n], string length = ${body.length}")
3736
}
3837
},
3938
{ (n: Int) =>
@@ -52,9 +51,8 @@ trait Endpoints {
5251
.in(fileBody)
5352
.maxRequestBodyLength(LargeInputSize + 1024L)
5453
.out(stringBody)
55-
.serverLogicSuccess {
56-
body: File =>
57-
reply(s"Ok [$n], file saved to ${body.toPath}")
54+
.serverLogicSuccess { body: File =>
55+
reply(s"Ok [$n], file saved to ${body.toPath}")
5856
}
5957
},
6058
{ (n: Int) =>
@@ -63,9 +61,8 @@ trait Endpoints {
6361
.in(jsonBody[Json])
6462
.maxRequestBodyLength(LargeInputSize + 1024L)
6563
.out(stringBody)
66-
.serverLogicSuccess {
67-
body: Json =>
68-
reply(s"Ok [$n], file saved to ${body}")
64+
.serverLogicSuccess { body: Json =>
65+
reply(s"Ok [$n], file saved to ${body}")
6966
}
7067
}
7168
)

perf-tests/src/main/scala/sttp/tapir/perf/vertx/Vertx.scala

+99-105
Original file line numberDiff line numberDiff line change
@@ -16,74 +16,73 @@ import scala.concurrent.Future
1616

1717
object Tapir extends Endpoints {
1818
import sttp.tapir._
19-
def route(nRoutes: Int, withServerLog: Boolean = false): Vertx => Router => Route = { vertx =>
20-
router =>
21-
val serverOptions = buildOptions(VertxFutureServerOptions.customiseInterceptors, withServerLog)
22-
val interpreter = VertxFutureServerInterpreter(serverOptions)
23-
val wsEndpoint = wsBaseEndpoint
24-
.out(
25-
webSocketBody[Long, CodecFormat.TextPlain, Long, CodecFormat.TextPlain](VertxStreams)
26-
.concatenateFragmentedFrames(false)
27-
)
28-
29-
val laggedTimestampPipe: ReadStream[Long] => ReadStream[Long] = { inputStream =>
30-
new ReadStream[Long] {
31-
32-
override def fetch(amount: Long): ReadStream[Long] = this
33-
34-
private var dataHandler: Handler[Long] = _
35-
private var endHandler: Handler[Void] = _
36-
private var exceptionHandler: Handler[Throwable] = _
37-
38-
inputStream.handler(new Handler[Long] {
39-
override def handle(event: Long): Unit = {
40-
vertx.setTimer(
41-
WebSocketSingleResponseLag.toMillis,
42-
_ => {
43-
if (dataHandler != null) dataHandler.handle(System.currentTimeMillis())
44-
}
45-
): Unit
46-
}
47-
})
48-
49-
inputStream.endHandler(new Handler[Void] {
50-
override def handle(e: Void): Unit = {
51-
if (endHandler != null) endHandler.handle(e)
52-
}
53-
})
54-
55-
inputStream.exceptionHandler(new Handler[Throwable] {
56-
override def handle(e: Throwable): Unit = {
57-
if (exceptionHandler != null) exceptionHandler.handle(e)
58-
}
59-
})
60-
61-
override def handler(handler: Handler[Long]): ReadStream[Long] = {
62-
this.dataHandler = handler
63-
this
19+
def route(nRoutes: Int, withServerLog: Boolean = false): Vertx => Router => Route = { vertx => router =>
20+
val serverOptions = buildOptions(VertxFutureServerOptions.customiseInterceptors, withServerLog)
21+
val interpreter = VertxFutureServerInterpreter(serverOptions)
22+
val wsEndpoint = wsBaseEndpoint
23+
.out(
24+
webSocketBody[Long, CodecFormat.TextPlain, Long, CodecFormat.TextPlain](VertxStreams)
25+
.concatenateFragmentedFrames(false)
26+
)
27+
28+
val laggedTimestampPipe: ReadStream[Long] => ReadStream[Long] = { inputStream =>
29+
new ReadStream[Long] {
30+
31+
override def fetch(amount: Long): ReadStream[Long] = this
32+
33+
private var dataHandler: Handler[Long] = _
34+
private var endHandler: Handler[Void] = _
35+
private var exceptionHandler: Handler[Throwable] = _
36+
37+
inputStream.handler(new Handler[Long] {
38+
override def handle(event: Long): Unit = {
39+
vertx.setTimer(
40+
WebSocketSingleResponseLag.toMillis,
41+
_ => {
42+
if (dataHandler != null) dataHandler.handle(System.currentTimeMillis())
43+
}
44+
): Unit
6445
}
46+
})
6547

66-
override def pause(): ReadStream[Long] = this
67-
override def resume(): ReadStream[Long] = this
68-
69-
override def endHandler(endHandler: Handler[Void]): ReadStream[Long] = {
70-
this.endHandler = endHandler
71-
this
48+
inputStream.endHandler(new Handler[Void] {
49+
override def handle(e: Void): Unit = {
50+
if (endHandler != null) endHandler.handle(e)
7251
}
52+
})
7353

74-
override def exceptionHandler(exceptionHandler: Handler[Throwable]): ReadStream[Long] = {
75-
this.exceptionHandler = exceptionHandler
76-
this
54+
inputStream.exceptionHandler(new Handler[Throwable] {
55+
override def handle(e: Throwable): Unit = {
56+
if (exceptionHandler != null) exceptionHandler.handle(e)
7757
}
58+
})
59+
60+
override def handler(handler: Handler[Long]): ReadStream[Long] = {
61+
this.dataHandler = handler
62+
this
7863
}
7964

80-
}
65+
override def pause(): ReadStream[Long] = this
66+
override def resume(): ReadStream[Long] = this
67+
68+
override def endHandler(endHandler: Handler[Void]): ReadStream[Long] = {
69+
this.endHandler = endHandler
70+
this
71+
}
8172

82-
val wsServerEndpoint = wsEndpoint.serverLogicSuccess[Future] { _ =>
83-
Future.successful {
84-
laggedTimestampPipe
73+
override def exceptionHandler(exceptionHandler: Handler[Throwable]): ReadStream[Long] = {
74+
this.exceptionHandler = exceptionHandler
75+
this
8576
}
8677
}
78+
79+
}
80+
81+
val wsServerEndpoint = wsEndpoint.serverLogicSuccess[Future] { _ =>
82+
Future.successful {
83+
laggedTimestampPipe
84+
}
85+
}
8786
(wsServerEndpoint :: genEndpointsFuture(nRoutes)).map(interpreter.route(_)(router)).last
8887
}
8988
}
@@ -93,65 +92,60 @@ object Vanilla extends Endpoints {
9392
def webSocketHandler(vertx: Vertx): Router => Route = { router =>
9493
router.get("/ws/ts").handler { ctx =>
9594
val wss = ctx.request().toWebSocket()
96-
wss.map {
97-
ws: ServerWebSocket =>
98-
ws.textMessageHandler(_ => ())
99-
100-
// Set a periodic timer to send timestamps every 100 milliseconds
101-
val timerId = vertx.setPeriodic(
102-
WebSocketSingleResponseLag.toMillis,
103-
{ _ =>
104-
ws.writeTextMessage(System.currentTimeMillis().toString): Unit
105-
}
106-
)
95+
wss.map { ws: ServerWebSocket =>
96+
ws.textMessageHandler(_ => ())
97+
98+
// Set a periodic timer to send timestamps every 100 milliseconds
99+
val timerId = vertx.setPeriodic(
100+
WebSocketSingleResponseLag.toMillis,
101+
{ _ =>
102+
ws.writeTextMessage(System.currentTimeMillis().toString): Unit
103+
}
104+
)
107105

108-
// Close the timer when the WebSocket is closed
109-
ws.closeHandler(_ => vertx.cancelTimer(timerId): Unit)
106+
// Close the timer when the WebSocket is closed
107+
ws.closeHandler(_ => vertx.cancelTimer(timerId): Unit)
110108
}: Unit
111109
}
112110
}
113111
def route: Int => Vertx => Router => Route = { (nRoutes: Int) => _ => router =>
114112
(0 until nRoutes).map { n =>
115-
router.get(s"/path$n/:id").handler {
116-
ctx: RoutingContext =>
117-
val id = ctx.request().getParam("id").toInt
118-
val _ = ctx
119-
.response()
120-
.putHeader("content-type", "text/plain")
121-
.end(s"${id + n}")
113+
router.get(s"/path$n/:id").handler { ctx: RoutingContext =>
114+
val id = ctx.request().getParam("id").toInt
115+
val _ = ctx
116+
.response()
117+
.putHeader("content-type", "text/plain")
118+
.end(s"${id + n}")
122119
}
123120

124-
router.post(s"/path$n").handler(bodyHandler).handler {
125-
ctx: RoutingContext =>
126-
val body = ctx.body.asString()
127-
val _ = ctx
128-
.response()
129-
.putHeader("content-type", "text/plain")
130-
.end(s"Ok [$n], string length = ${body.length}")
121+
router.post(s"/path$n").handler(bodyHandler).handler { ctx: RoutingContext =>
122+
val body = ctx.body.asString()
123+
val _ = ctx
124+
.response()
125+
.putHeader("content-type", "text/plain")
126+
.end(s"Ok [$n], string length = ${body.length}")
131127
}
132128

133-
router.post(s"/pathBytes$n").handler(bodyHandler).handler {
134-
ctx: RoutingContext =>
135-
val bytes = ctx.body().asString()
136-
val _ = ctx
137-
.response()
138-
.putHeader("content-type", "text/plain")
139-
.end(s"Ok [$n], bytes length = ${bytes.length}")
129+
router.post(s"/pathBytes$n").handler(bodyHandler).handler { ctx: RoutingContext =>
130+
val bytes = ctx.body().asString()
131+
val _ = ctx
132+
.response()
133+
.putHeader("content-type", "text/plain")
134+
.end(s"Ok [$n], bytes length = ${bytes.length}")
140135
}
141136

142-
router.post(s"/pathFile$n").handler(bodyHandler).handler {
143-
ctx: RoutingContext =>
144-
val filePath = newTempFilePath()
145-
val fs = ctx.vertx.fileSystem
146-
val _ = fs
147-
.createFile(filePath.toString)
148-
.flatMap(_ => fs.writeFile(filePath.toString, ctx.body().buffer()))
149-
.flatMap(_ =>
150-
ctx
151-
.response()
152-
.putHeader("content-type", "text/plain")
153-
.end(s"Ok [$n], file saved to $filePath")
154-
)
137+
router.post(s"/pathFile$n").handler(bodyHandler).handler { ctx: RoutingContext =>
138+
val filePath = newTempFilePath()
139+
val fs = ctx.vertx.fileSystem
140+
val _ = fs
141+
.createFile(filePath.toString)
142+
.flatMap(_ => fs.writeFile(filePath.toString, ctx.body().buffer()))
143+
.flatMap(_ =>
144+
ctx
145+
.response()
146+
.putHeader("content-type", "text/plain")
147+
.end(s"Ok [$n], file saved to $filePath")
148+
)
155149
}
156150
}.last
157151
}

0 commit comments

Comments
 (0)