Skip to content
Merged
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 @@ -78,3 +78,6 @@ da85b978db204adf6f236bfd4e453628a6d4cdda

# Scala Steward: Reformat with scalafmt 3.10.2
80ad6edaa865797b52624a47728afc2e074b4f52

# Scala Steward: Reformat with scalafmt 3.10.7
32ddff2605807a89e66272507b85230c3d3adfa1
2 changes: 1 addition & 1 deletion .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version = 3.10.2
version = 3.10.7
maxColumn = 140
runner.dialect = scala213source3
fileOverride {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ import java.time.Instant
JwtCirce
.decodeAll(token, jwtKey, Seq(jwtAlgo))
.toEither match
case Left(err) => Left("Invalid token: " + err)
case Right(decoded) => Right(decoded._2.content)
case Left(err) => Left("Invalid token: " + err)
case Right(decoded) => Right(decoded._2.content)

// get user details from decoded jwt
val secretPlaceServerEndpoint = secretPlace
Expand All @@ -117,7 +117,7 @@ import java.time.Instant

supervised:
val backend = useInScope(HttpClientSyncBackend())(_.close())

val binding = useInScope(
NettySyncServer()
.host("localhost")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ private[pickler] object macros:
${ select }
)
}
if memberTypeRepr.typeSymbol == optionSymbol then '{ if !${ transientNone } || ${ select } != None then $snippet }
if memberTypeRepr.typeSymbol == optionSymbol then '{ if ! ${ transientNone } || ${ select } != None then $snippet }
else snippet
},
'{ () }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ class ClassDefinitionGenerator {
jsonParamRefs.toSeq.flatMap(ref => allSchemas.get(ref.stripPrefix("#/components/schemas/")))
)

val adtTypes = adtInheritanceMap.flatMap(_._2).toSeq.map(_._1).distinct.map(name => s"sealed trait $name").sorted.mkString("", "\n", "\n")
val adtTypes =
adtInheritanceMap.flatMap(_._2).toSeq.map(_._1).distinct.map(name => s"sealed trait $name").sorted.mkString("", "\n", "\n")
val enumSerdeHelper = if (!generatesQueryOrPathParamEnums) "" else enumSerdeHelperDefn(targetScala3)
val schemasWithAny = allSchemas.filter { case (_, schema) => schemaContainsAny(schema) }
val schemasContainAny = schemasWithAny.nonEmpty || allTransitiveJsonParamRefs.contains("io.circe.Json")
Expand Down Expand Up @@ -120,7 +121,8 @@ class ClassDefinitionGenerator {
validatedChildren.map(_ -> ((name, schema)))
}
.groupBy(_._1)
.mapValues(_.map(_._2)).toMap
.mapValues(_.map(_._2))
.toMap

private def enumSerdeHelperDefn(targetScala3: Boolean): String = {
if (targetScala3)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ object DefaultValueRenderer {
renderStringWithName(value)(allModels, lookup(allModels, ref), ref.name.stripPrefix("#/components/schemas/"))
case OpenapiSchemaString(_, _, _, _) => '"' +: value :+ '"'
case OpenapiSchemaEnum(_, _, _) => s"$name.$value"
case OpenapiSchemaDate(_) => s"""java.time.LocalDate.parse("$value")"""
case OpenapiSchemaDate(_) => s"""java.time.LocalDate.parse("$value")"""
case OpenapiSchemaDateTime(_) => s"""java.time.Instant.parse("$value")"""
case OpenapiSchemaDuration(_) => s"""java.time.Duration.parse("$value")"""
case OpenapiSchemaBinary(_) => s""""$value".getBytes("utf-8")"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ package sttp.tapir.codegen.testutils

object VersionCheck {
def runTest(jsonSerde: String)(test: => Unit): Unit = if (jsonSerde == "circe") test else ()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ package sttp.tapir.codegen.testutils

object VersionCheck {
def runTest(jsonSerde: String)(test: => Unit): Unit = if (jsonSerde != "zio") test else ()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -117,15 +117,17 @@ class RootGeneratorSpec extends CompileCheckTestBase {
generated.shouldCompile()
})

VersionCheck.runTest(jsonSerdeLib)(it should s"compile endpoints with date and duration default values using ${jsonSerdeLib} serdes" in {
val doc = TestHelpers.parseYamlDocument(TestHelpers.dateAndDurationDefaultsYaml).fold(err => fail(err.getMessage), identity)
val generated = gen(doc, useHeadTagForObjectNames = false, jsonSerdeLib = jsonSerdeLib)
VersionCheck.runTest(jsonSerdeLib)(
it should s"compile endpoints with date and duration default values using ${jsonSerdeLib} serdes" in {
val doc = TestHelpers.parseYamlDocument(TestHelpers.dateAndDurationDefaultsYaml).fold(err => fail(err.getMessage), identity)
val generated = gen(doc, useHeadTagForObjectNames = false, jsonSerdeLib = jsonSerdeLib)

generated should include("""java.time.LocalDate.parse("2024-01-15")""")
generated should include("""java.time.Duration.parse("PT1H30M")""")
generated should include("""java.time.LocalDate.parse("2024-01-15")""")
generated should include("""java.time.Duration.parse("PT1H30M")""")

generated.shouldCompile()
})
generated.shouldCompile()
}
)
}

Seq("circe", "jsoniter", "zio") foreach testJsonLib
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@ object OpenapiCodegenPlugin extends AutoPlugin {
hashFile.delete()
java.nio.file.Files.write(hashFile.toPath, configHash)
val swaggerFiles = (c.swaggerFile +: c.additionalPackages.map(_._2)).filter(_.exists()).toSet + hashFile
FileFunction.cached(cacheDir / s"scala-$sv" / "openapi-inputs", FileInfo.hash) { _ =>
log.info("Generating OpenAPI sources...")
codegen(c, srcDir, sv).toSet
}(swaggerFiles).toSeq
FileFunction
.cached(cacheDir / s"scala-$sv" / "openapi-inputs", FileInfo.hash) { _ =>
log.info("Generating OpenAPI sources...")
codegen(c, srcDir, sv).toSet
}(swaggerFiles)
.toSeq
}.value,
generateTapirDefinitions / fileInputs ++= {
(openapiSwaggerFile.value +: openapiAdditionalPackages.value.map(_._2))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,3 @@ TaskKey[Unit]("check") := {
}
()
}

Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ libraryDependencies += "com.softwaremill.sttp.apispec" %% "openapi-circe-yaml" %
import scala.io.Source
import scala.util.Using



openapiAdditionalPackages := List(
"sttp.tapir.generated.swagger" -> baseDirectory.value / "swagger.yaml",
"sttp.tapir.generated.swagger2" -> baseDirectory.value / "swagger2.yaml"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ libraryDependencies ++= Seq(
import scala.io.Source
import scala.util.Using


TaskKey[Unit]("check") := {
def check(generatedFileName: String, expectedFileName: String) = {
val generatedCode =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ def compare(name: String, genFn: String, expFn: String) = {

}


TaskKey[Unit]("check") := {
compare("endpoints", s"${sourceManaged.value}/main/sbt-openapi-codegen/TapirGeneratedEndpoints.scala", "Expected.scala.txt")
compare(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,9 @@ class BinaryEndpoints extends AnyFreeSpec with Matchers {
.get(uri"http://test.com/dynamic/content-type/test")
.response(asStringAlways)
.header("accept", "*/*")
.response(sttp.client3.asStreamAlwaysWithMetadata(PekkoStreams) { case (s, meta) => Future.successful(s -> meta.header("content-type")) })
.response(sttp.client3.asStreamAlwaysWithMetadata(PekkoStreams) { case (s, meta) =>
Future.successful(s -> meta.header("content-type"))
})
.send[Future, PekkoStreams](stub)
.map { resp =>
resp.code.code shouldEqual 200
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ def compare(name: String, genFn: String, expFn: String) = {

}


TaskKey[Unit]("check") := {
compare("endpoints", s"${sourceManaged.value}/main/sbt-openapi-codegen/TapirGeneratedEndpoints.scala", "Expected.scala.txt")
compare(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ openapiGenerateEndpointTypes := true
import scala.io.Source
import scala.util.Using


TaskKey[Unit]("check") := {
val generatedCode =
Using(Source.fromFile(s"${sourceManaged.value}/main/sbt-openapi-codegen/TapirGeneratedEndpoints.scala"))(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ libraryDependencies ++= Seq(
import scala.io.Source
import scala.util.Using


TaskKey[Unit]("check") := {
def check(generatedFileName: String, expectedFileName: String) = {
val generatedCode =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package sttp.tapir.server.netty
/** Configuration for HTTP response compression in Netty server.
*
* @param enabled
* Whether compression is enabled. When enabled, the server will compress responses based on the client's Accept-Encoding header.
* Netty uses a default compression level of 6 (balanced between speed and compression ratio).
* Whether compression is enabled. When enabled, the server will compress responses based on the client's Accept-Encoding header. Netty
* uses a default compression level of 6 (balanced between speed and compression ratio).
*/
case class NettyCompressionConfig(
enabled: Boolean = false
Expand All @@ -13,10 +13,10 @@ case class NettyCompressionConfig(
}

object NettyCompressionConfig {

/** Compression disabled (default) */
val default: NettyCompressionConfig = NettyCompressionConfig()

/** Compression enabled with Netty's default settings */
val enabled: NettyCompressionConfig = NettyCompressionConfig(enabled = true)
}

Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ class InputStreamSyncPublisher(
range: InputStreamRange,
chunkSize: Int
) extends Publisher[HttpContent] {
override def subscribe(subscriber: Subscriber[_ >: HttpContent]): Unit = {
override def subscribe(subscriber: Subscriber[? >: HttpContent]): Unit = {
if (subscriber == null) throw new NullPointerException("Subscriber cannot be null")
val subscription = new InputStreamSyncSubscription(subscriber, range, chunkSize)
subscriber.onSubscribe(subscription)
}

private class InputStreamSyncSubscription(subscriber: Subscriber[_ >: HttpContent], range: InputStreamRange, chunkSize: Int)
private class InputStreamSyncSubscription(subscriber: Subscriber[? >: HttpContent], range: InputStreamRange, chunkSize: Int)
extends Subscription {
private lazy val stream: InputStream = range.inputStreamFromRangeStart()
private val demand = new AtomicLong(0L)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ object NettySyncServerRunner {
val LargeInputSize = 5 * 1024L * 1024L
val WebSocketSingleResponseLag = 100.millis

type EndpointGen = Int => PublicEndpoint[_, String, String, Any]
type EndpointGen = Int => PublicEndpoint[?, String, String, Any]
type ServerEndpointGen[F[_]] = Int => ServerEndpoint[Any, F]
def serverEndpoints[F[_]](reply: String => F[String]): List[ServerEndpointGen[F]] = {
List(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ private[aws] object AwsLambdaCodec {
*/
def decodeRequest[R: Decoder](json: String): Either[AwsResponse, AwsRequest] =
jsonDecode[R](json) match {
case Left(e) => Left(AwsResponse.badRequest(s"Invalid AWS request: ${e.getMessage}"))
case Left(e) => Left(AwsResponse.badRequest(s"Invalid AWS request: ${e.getMessage}"))
case Right(r: AwsRequestV1) => Right(r.toV2)
case Right(r: AwsRequest) => Right(r)
case Right(r) =>
case Right(r) =>
throw new IllegalArgumentException(s"Request of type ${r.getClass.getCanonicalName} is not supported")
}

Expand Down
Loading