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.2 #3849

Merged
merged 3 commits into from
Jun 17, 2024
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 @@ -45,3 +45,6 @@ ab79cadbb13aac7c32015ce5caf24d57290ee59b

# Scala Steward: Reformat with scalafmt 3.8.1
e003ec3b61e3bd582ae6a5200177fa6433099c09

# Scala Steward: Reformat with scalafmt 3.8.2
9b44bd1451b796259b0592afe54bb5891f63f48e
2 changes: 1 addition & 1 deletion .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version = 3.8.1
version = 3.8.2
maxColumn = 140
runner.dialect = scala3
fileOverride {
Expand Down
3 changes: 2 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,8 @@ lazy val perfTests: ProjectMatrix = (projectMatrix in file("perf-tests"))
libraryDependencies ++= Seq(
// Required to force newer jackson in Pekko, a version that is compatible with Gatling's Jackson dependency
"io.gatling.highcharts" % "gatling-charts-highcharts" % "3.11.3" % "test" exclude (
"com.fasterxml.jackson.core", "jackson-databind"
"com.fasterxml.jackson.core",
"jackson-databind"
),
"io.gatling" % "gatling-test-framework" % "3.11.3" % "test" exclude ("com.fasterxml.jackson.core", "jackson-databind"),
"com.fasterxml.jackson.module" %% "jackson-module-scala" % "2.17.1",
Expand Down
4 changes: 3 additions & 1 deletion core/src/test/scala/sttp/tapir/SchemaMacroTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,9 @@ class SchemaMacroTest extends AnyFlatSpec with Matchers with TableDrivenProperty

parentSchema.name.map(_.fullName) shouldBe Some("CustomHericium")
parentSchema.schemaType.asInstanceOf[SCoproduct[Hericium]].subtypes.flatMap(_.name.map(_.fullName)) should contain allOf (
"sttp.tapir.SchemaMacroTestData.Hericium.Abietis", "sttp.tapir.SchemaMacroTestData.Hericium.Botryoides", "CustomErinaceus"
"sttp.tapir.SchemaMacroTestData.Hericium.Abietis",
"sttp.tapir.SchemaMacroTestData.Hericium.Botryoides",
"CustomErinaceus"
)
child1Schema.name.map(_.fullName) shouldBe Some("CustomErinaceus")
child2Schema.name.map(_.fullName) shouldBe Some("sttp.tapir.SchemaMacroTestData.Hericium.Botryoides")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,13 @@ private[docs] class TSchemaToASchema(
.map(apply(_, allowReference = true))
.sortBy {
case schema if schema.$ref.isDefined => schema.$ref.get
case schema => schema.`type`.collect {
case List(t) => t.value
case List(t, SchemaType.Null) => t.value
}.getOrElse("") + schema.toString
case schema =>
schema.`type`
.collect {
case List(t) => t.value
case List(t, SchemaType.Null) => t.value
}
.getOrElse("") + schema.toString
},
d.map(tDiscriminatorToADiscriminator)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,10 @@ trait TapirCodecIron extends DescriptionWitness with LowPriorityValidatorForPred
witness: ValueOf[NM]
): PrimitiveValidatorForPredicate[C[X], MinLength[NM]] =
ValidatorForPredicate.fromPrimitiveValidator(Validator.minSize[X, C](witness.value))

inline given validatorForNonEmptyIterable[X, C[X] <: Iterable[X], NM <: Int]: PrimitiveValidatorForPredicate[C[X], Not[Empty]] =
ValidatorForPredicate.fromPrimitiveValidator(Validator.minSize[X, C](1))

inline given validatorForMaxLengthOnIterable[X, C[X] <: Iterable[X], NM <: Int](using
witness: ValueOf[NM]
): PrimitiveValidatorForPredicate[C[X], MaxLength[NM]] =
Expand Down Expand Up @@ -134,7 +134,7 @@ trait TapirCodecIron extends DescriptionWitness with LowPriorityValidatorForPred
case _: (head *: tail) =>
val headValidator: ValidatorForPredicate[N, ?] = summonFrom {
case pv: PrimitiveValidatorForPredicate[N, head] => pv
case _ => summonInline[ValidatorForPredicate[N, head]]
case _ => summonInline[ValidatorForPredicate[N, head]]
}
headValidator.asInstanceOf[ValidatorForPredicate[N, Any]] :: summonValidators[N, tail]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ trait UnionTypeMirror[A] {
// Number of elements in the union
def size: Int
}

// Building a class is more convenient to instantiate using macros
class UnionTypeMirrorImpl[A, T <: NonEmptyTuple](val size: Int) extends UnionTypeMirror[A] {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,8 @@ class TapirCodecRefinedTestScala3 extends AnyFlatSpec with Matchers with TapirCo
case Validator.Mapped(Validator.Any(List(Validator.Min(3, true), Validator.Max(-3, true))), _) =>
}
}
"Generated schema for NonEmpty and MinSize" should "not be optional" in {

"Generated schema for NonEmpty and MinSize" should "not be optional" in {
assert(implicitly[Schema[List[Int]]].isOptional)
assert(!implicitly[Schema[List[Int] Refined NonEmpty]].isOptional)
assert(!implicitly[Schema[Set[Int] Refined NonEmpty]].isOptional)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ class CreateDerivedEnumerationPickler[T: ClassTag](
upickleMacros.tagName[C],
Annotator.Checker.Val(upickleMacros.getSingleton[C])
)
override lazy val reader = annotate[C](SingletonReader[C](upickleMacros.getSingleton[C]),
override lazy val reader = annotate[C](
SingletonReader[C](upickleMacros.getSingleton[C]),
Annotator.defaultTagKey, // not used in enumerations
upickleMacros.tagName[C]
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ private[pickler] trait Writers extends WritersVersionSpecific with UpickleHelper
ctx,
childWriters,
childDefaults,
config.transientNone
config.transientNone
)
}

Expand All @@ -76,7 +76,12 @@ private[pickler] trait Writers extends WritersVersionSpecific with UpickleHelper
else if upickleMacros.isSingleton[T]
then // moved after "if MemberOfSealed" to handle case objects in hierarchy as case classes - with discriminator, for consistency
// here we handle enums
annotate[T](SingletonWriter[T](null.asInstanceOf[T]), config.discriminator, upickleMacros.tagName[T], Annotator.Checker.Val(upickleMacros.getSingleton[T]))
annotate[T](
SingletonWriter[T](null.asInstanceOf[T]),
config.discriminator,
upickleMacros.tagName[T],
Annotator.Checker.Val(upickleMacros.getSingleton[T])
)
else writer

inline def macroSumW[T: ClassTag](childPicklers: => List[Pickler[? <: T]], subtypeDiscriminator: SubtypeDiscriminator[T])(using
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,15 @@ class PicklerBasicTest extends AnyFlatSpec with Matchers {
jsonStr1 shouldBe """{"fieldA":"fieldA value","fieldB":-4018,"fieldC":true}"""
jsonStr2 shouldBe """{"innerField":{"fieldA":"fieldA value2","fieldC":true}}"""
jsonStr3 shouldBe """{"fieldA":"fieldA value","fieldC":true}"""
pickler1.toCodec.decode("""{"fieldA":"fieldA value3","fieldC":true}""") shouldBe Value(FlatClassWithOption("fieldA value3", None, true))
pickler1.toCodec.decode("""{"fieldA":"fieldA value4", "fieldB": null, "fieldC": true}""") shouldBe Value(FlatClassWithOption("fieldA value4", None, true))
pickler1.toCodec.decode("""{"fieldA":"fieldA value3","fieldC":true}""") shouldBe Value(
FlatClassWithOption("fieldA value3", None, true)
)
pickler1.toCodec.decode("""{"fieldA":"fieldA value4", "fieldB": null, "fieldC": true}""") shouldBe Value(
FlatClassWithOption("fieldA value4", None, true)
)
}
}

it should "serialize Options to nulls if transientNone = false" in {
import generic.auto.* // for Pickler auto-derivation

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,9 @@ class SchemaGenericAutoTest extends AsyncFlatSpec with Matchers with Inside {

parentSchema.name.map(_.fullName) shouldBe Some("CustomHericium")
parentSchema.schemaType.asInstanceOf[SCoproduct[Hericium]].subtypes.flatMap(_.name.map(_.fullName)) should contain allOf (
"sttp.tapir.SchemaMacroTestData.Hericium.Abietis", "sttp.tapir.SchemaMacroTestData.Hericium.Botryoides", "CustomErinaceus"
"sttp.tapir.SchemaMacroTestData.Hericium.Abietis",
"sttp.tapir.SchemaMacroTestData.Hericium.Botryoides",
"CustomErinaceus"
)
child1Schema.name.map(_.fullName) shouldBe Some("CustomErinaceus")
child2Schema.name.map(_.fullName) shouldBe Some("sttp.tapir.SchemaMacroTestData.Hericium.Botryoides")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,34 +75,55 @@ object GenScala {
}

val cmd: Command[IO[ExitCode]] = Command("genscala", "Generate Scala classes", helpFlag = true) {
(fileOpt, packageNameOpt, destDirOpt, objectNameOpt, targetScala3Opt, headTagForNamesOpt, jsonLibOpt, validateNonDiscriminatedOneOfsOpt, maxSchemasPerFileOpt)
.mapN { case (file, packageName, destDir, maybeObjectName, targetScala3, headTagForNames, jsonLib, validateNonDiscriminatedOneOfs, maxSchemasPerFile) =>
val objectName = maybeObjectName.getOrElse(DefaultObjectName)

def generateCode(doc: OpenapiDocument): IO[Unit] = for {
contents <- IO.pure(
BasicGenerator.generateObjects(
doc,
(
fileOpt,
packageNameOpt,
destDirOpt,
objectNameOpt,
targetScala3Opt,
headTagForNamesOpt,
jsonLibOpt,
validateNonDiscriminatedOneOfsOpt,
maxSchemasPerFileOpt
)
.mapN {
case (
file,
packageName,
objectName,
destDir,
maybeObjectName,
targetScala3,
headTagForNames,
jsonLib.getOrElse("circe"),
jsonLib,
validateNonDiscriminatedOneOfs,
maxSchemasPerFile.getOrElse(400)
maxSchemasPerFile
) =>
val objectName = maybeObjectName.getOrElse(DefaultObjectName)

def generateCode(doc: OpenapiDocument): IO[Unit] = for {
contents <- IO.pure(
BasicGenerator.generateObjects(
doc,
packageName,
objectName,
targetScala3,
headTagForNames,
jsonLib.getOrElse("circe"),
validateNonDiscriminatedOneOfs,
maxSchemasPerFile.getOrElse(400)
)
)
)
destFiles <- contents.toVector.traverse { case (fileName, content) => writeGeneratedFile(destDir, fileName, content) }
_ <- IO.println(s"Generated endpoints written to: ${destFiles.mkString(", ")}")
} yield ()

for {
parsed <- readFile(file).map(YamlParser.parseFile)
exitCode <- parsed match {
case Left(err) => IO.println(s"Invalid YAML file: ${err.getMessage}").as(ExitCode.Error)
case Right(doc) => generateCode(doc).as(ExitCode.Success)
}
} yield exitCode
destFiles <- contents.toVector.traverse { case (fileName, content) => writeGeneratedFile(destDir, fileName, content) }
_ <- IO.println(s"Generated endpoints written to: ${destFiles.mkString(", ")}")
} yield ()

for {
parsed <- readFile(file).map(YamlParser.parseFile)
exitCode <- parsed match {
case Left(err) => IO.println(s"Invalid YAML file: ${err.getMessage}").as(ExitCode.Error)
case Right(doc) => generateCode(doc).as(ExitCode.Success)
}
} yield exitCode
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class EndpointGenerator {
m.responses.flatMap(_.content.map(c => (c.contentType, c.schema))))
.collect { case (contentType, schema) if contentType == "application/json" => schema }
.collect {
case ref: OpenapiSchemaRef if ref.isSchema => ref.stripped
case ref: OpenapiSchemaRef if ref.isSchema => ref.stripped
case OpenapiSchemaArray(ref: OpenapiSchemaRef, _) if ref.isSchema => ref.stripped
case OpenapiSchemaArray(OpenapiSchemaAny(_), _) =>
bail("Cannot generate schema for 'Any' with jsoniter library")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
|
|""".stripMargin)
else addSbtPlugin("com.softwaremill.sttp.tapir" % "sbt-openapi-codegen" % pluginVersion)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class JsonRoundtrip extends AnyFreeSpec with Matchers {

locally {
val reqBody: ADTWithoutDiscriminator = SubtypeWithoutD3("a string", Some(123), Some(23.4))
val reqJsonBody = reqBody.toJson(TapirGeneratedEndpointsJsonSerdes.aDTWithoutDiscriminatorJsonEncoder)
val reqJsonBody = reqBody.toJson(TapirGeneratedEndpointsJsonSerdes.aDTWithoutDiscriminatorJsonEncoder)
val respBody: ADTWithoutDiscriminator = SubtypeWithoutD3("a string+SubtypeWithoutD3", Some(123), Some(23.4))
val respJsonBody = respBody.toJson(TapirGeneratedEndpointsJsonSerdes.aDTWithoutDiscriminatorJsonEncoder)
reqJsonBody shouldEqual """{"s":"a string","i":123,"d":23.4}"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
|
|""".stripMargin)
else addSbtPlugin("com.softwaremill.sttp.tapir" % "sbt-openapi-codegen" % pluginVersion)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
|
|""".stripMargin)
else addSbtPlugin("com.softwaremill.sttp.tapir" % "sbt-openapi-codegen" % pluginVersion)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
|
|""".stripMargin)
else addSbtPlugin("com.softwaremill.sttp.tapir" % "sbt-openapi-codegen" % pluginVersion)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ class ServerInterpreterTest extends AnyFlatSpec with Matchers {
// added to the endpoint interceptor stack in the correct place
val interceptor2 = new RequestInterceptor[Identity] {
override def apply[R, B](
responder: Responder[Identity, B],
requestHandler: EndpointInterceptor[Identity] => RequestHandler[Identity, R, B]
responder: Responder[Identity, B],
requestHandler: EndpointInterceptor[Identity] => RequestHandler[Identity, R, B]
): RequestHandler[Identity, R, B] = RequestHandler.from { (request, endpoints, monad) =>
callTrail.append("2 request")
requestHandler(new AddToTrailInterceptor(callTrail.append(_: String), "2")).apply(request, endpoints)(monad)
Expand Down Expand Up @@ -141,8 +141,8 @@ class ServerInterpreterTest extends AnyFlatSpec with Matchers {
}

override def onSecurityFailure[A](ctx: SecurityFailureContext[Identity, A])(implicit
monad: MonadError[Identity],
bodyListener: BodyListener[Identity, B]
monad: MonadError[Identity],
bodyListener: BodyListener[Identity, B]
): Identity[ServerResponse[B]] = {
addCallTrail(s"$prefix security failure")
endpointHandler.onSecurityFailure(ctx)(idMonad, bodyListener)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import java.net.InetSocketAddress
import java.util.concurrent.Executor

case class JdkHttpServer(
endpoints: Vector[ServerEndpoint[Any, Identity]] = Vector.empty,
options: JdkHttpServerOptions = JdkHttpServerOptions.Default
endpoints: Vector[ServerEndpoint[Any, Identity]] = Vector.empty,
options: JdkHttpServerOptions = JdkHttpServerOptions.Default
) {

/** Sets the port to which the server will be bound. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,17 @@ import java.util.logging.{Level, Logger}
* entirely in memory. Default is 50MB.
*/
case class JdkHttpServerOptions(
interceptors: List[Interceptor[Identity]],
createFile: ServerRequest => TapirFile,
deleteFile: TapirFile => Unit,
send404WhenRequestNotHandled: Boolean = true,
basePath: String = "/",
port: Int = 0,
host: String = "0.0.0.0",
executor: Option[Executor] = None,
httpsConfigurator: Option[HttpsConfigurator] = None,
backlogSize: Int = 0,
multipartFileThresholdBytes: Long = 52_428_800
interceptors: List[Interceptor[Identity]],
createFile: ServerRequest => TapirFile,
deleteFile: TapirFile => Unit,
send404WhenRequestNotHandled: Boolean = true,
basePath: String = "/",
port: Int = 0,
host: String = "0.0.0.0",
executor: Option[Executor] = None,
httpsConfigurator: Option[HttpsConfigurator] = None,
backlogSize: Int = 0,
multipartFileThresholdBytes: Long = 52_428_800
) {
require(0 <= port && port <= 65535, "Port has to be in 1-65535 range or 0 if random!")
def prependInterceptor(i: Interceptor[Identity]): JdkHttpServerOptions = copy(interceptors = i :: interceptors)
Expand Down
Loading
Loading