From b5629a126c2c17997743145e2e32645f80433847 Mon Sep 17 00:00:00 2001 From: scala-steward Date: Sat, 15 Jun 2024 00:10:07 +0000 Subject: [PATCH 1/3] Update scalafmt-core to 3.8.2 --- .scalafmt.conf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.scalafmt.conf b/.scalafmt.conf index 5434f6f7e7..e08758e4ae 100644 --- a/.scalafmt.conf +++ b/.scalafmt.conf @@ -1,4 +1,4 @@ -version = 3.8.1 +version = 3.8.2 maxColumn = 140 runner.dialect = scala3 fileOverride { From 9b44bd1451b796259b0592afe54bb5891f63f48e Mon Sep 17 00:00:00 2001 From: scala-steward Date: Sat, 15 Jun 2024 00:10:25 +0000 Subject: [PATCH 2/3] Reformat with scalafmt 3.8.2 Executed command: scalafmt --non-interactive --- build.sbt | 3 +- .../scala/sttp/tapir/SchemaMacroTest.scala | 4 +- .../apispec/schema/TSchemaToASchema.scala | 11 +-- .../sttp/iron/codec/iron/TapirCodecIron.scala | 6 +- .../iron/codec/iron/UnionTypeMirror.scala | 2 +- .../refined/TapirCodecRefinedTestScala3.scala | 4 +- .../CreateDerivedEnumerationPickler.scala | 3 +- .../sttp/tapir/json/pickler/Writers.scala | 9 ++- .../tapir/json/pickler/PicklerBasicTest.scala | 10 ++- .../json/pickler/SchemaDerivationTest.scala | 4 +- .../scala/sttp/tapir/codegen/GenScala.scala | 67 ++++++++++++------- .../tapir/codegen/EndpointGenerator.scala | 2 +- .../project/plugins.sbt | 2 +- .../src/test/scala/JsonRoundtrip.scala | 2 +- .../oneOf-json-roundtrip/project/plugins.sbt | 2 +- .../project/plugins.sbt | 2 +- .../project/plugins.sbt | 2 +- .../interpreter/ServerInterpreterTest.scala | 8 +-- .../tapir/server/jdkhttp/JdkHttpServer.scala | 4 +- .../server/jdkhttp/JdkHttpServerOptions.scala | 22 +++--- .../ws/WebSocketFrameConverters.scala | 30 ++++----- .../sync/NettySyncServerInterpreter.scala | 4 +- .../netty/sync/NettySyncServerOptions.scala | 6 +- .../reactivestreams/OxProcessor.scala | 2 +- .../ws/OxSourceWebSocketProcessor.scala | 4 +- .../sync/NettySyncTestServerInterpreter.scala | 10 +-- .../tapir/server/nima/NimaServerOptions.scala | 6 +- .../tapir/server/tests/ServerBasicTests.scala | 2 +- .../tapir/server/tests/ServerOneOfTests.scala | 1 - .../server/tests/ServerSecurityTests.scala | 10 ++- 30 files changed, 145 insertions(+), 99 deletions(-) diff --git a/build.sbt b/build.sbt index 1b0b837e66..cc55caea40 100644 --- a/build.sbt +++ b/build.sbt @@ -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", diff --git a/core/src/test/scala/sttp/tapir/SchemaMacroTest.scala b/core/src/test/scala/sttp/tapir/SchemaMacroTest.scala index 5c386aabbb..2b3df4fa97 100644 --- a/core/src/test/scala/sttp/tapir/SchemaMacroTest.scala +++ b/core/src/test/scala/sttp/tapir/SchemaMacroTest.scala @@ -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") diff --git a/docs/apispec-docs/src/main/scala/sttp/tapir/docs/apispec/schema/TSchemaToASchema.scala b/docs/apispec-docs/src/main/scala/sttp/tapir/docs/apispec/schema/TSchemaToASchema.scala index f72aa54104..e0145e45c4 100644 --- a/docs/apispec-docs/src/main/scala/sttp/tapir/docs/apispec/schema/TSchemaToASchema.scala +++ b/docs/apispec-docs/src/main/scala/sttp/tapir/docs/apispec/schema/TSchemaToASchema.scala @@ -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) ) diff --git a/integrations/iron/src/main/scala/sttp/iron/codec/iron/TapirCodecIron.scala b/integrations/iron/src/main/scala/sttp/iron/codec/iron/TapirCodecIron.scala index 3498f0ad5c..6d9c7a7cce 100644 --- a/integrations/iron/src/main/scala/sttp/iron/codec/iron/TapirCodecIron.scala +++ b/integrations/iron/src/main/scala/sttp/iron/codec/iron/TapirCodecIron.scala @@ -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]] = @@ -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] } diff --git a/integrations/iron/src/main/scala/sttp/iron/codec/iron/UnionTypeMirror.scala b/integrations/iron/src/main/scala/sttp/iron/codec/iron/UnionTypeMirror.scala index 5c4fc78b9d..b2738eb150 100644 --- a/integrations/iron/src/main/scala/sttp/iron/codec/iron/UnionTypeMirror.scala +++ b/integrations/iron/src/main/scala/sttp/iron/codec/iron/UnionTypeMirror.scala @@ -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] { diff --git a/integrations/refined/src/test/scala-3/sttp/tapir/codec/refined/TapirCodecRefinedTestScala3.scala b/integrations/refined/src/test/scala-3/sttp/tapir/codec/refined/TapirCodecRefinedTestScala3.scala index 575606315c..d63525d38c 100644 --- a/integrations/refined/src/test/scala-3/sttp/tapir/codec/refined/TapirCodecRefinedTestScala3.scala +++ b/integrations/refined/src/test/scala-3/sttp/tapir/codec/refined/TapirCodecRefinedTestScala3.scala @@ -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) diff --git a/json/pickler/src/main/scala/sttp/tapir/json/pickler/CreateDerivedEnumerationPickler.scala b/json/pickler/src/main/scala/sttp/tapir/json/pickler/CreateDerivedEnumerationPickler.scala index 4f3a459779..dd015f25ba 100644 --- a/json/pickler/src/main/scala/sttp/tapir/json/pickler/CreateDerivedEnumerationPickler.scala +++ b/json/pickler/src/main/scala/sttp/tapir/json/pickler/CreateDerivedEnumerationPickler.scala @@ -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] ) diff --git a/json/pickler/src/main/scala/sttp/tapir/json/pickler/Writers.scala b/json/pickler/src/main/scala/sttp/tapir/json/pickler/Writers.scala index 68354d4ee8..289c28f4a4 100644 --- a/json/pickler/src/main/scala/sttp/tapir/json/pickler/Writers.scala +++ b/json/pickler/src/main/scala/sttp/tapir/json/pickler/Writers.scala @@ -62,7 +62,7 @@ private[pickler] trait Writers extends WritersVersionSpecific with UpickleHelper ctx, childWriters, childDefaults, - config.transientNone + config.transientNone ) } @@ -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 diff --git a/json/pickler/src/test/scala/sttp/tapir/json/pickler/PicklerBasicTest.scala b/json/pickler/src/test/scala/sttp/tapir/json/pickler/PicklerBasicTest.scala index df6d8bdf24..179795ab7f 100644 --- a/json/pickler/src/test/scala/sttp/tapir/json/pickler/PicklerBasicTest.scala +++ b/json/pickler/src/test/scala/sttp/tapir/json/pickler/PicklerBasicTest.scala @@ -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 diff --git a/json/pickler/src/test/scala/sttp/tapir/json/pickler/SchemaDerivationTest.scala b/json/pickler/src/test/scala/sttp/tapir/json/pickler/SchemaDerivationTest.scala index beaac68eff..af77c3ee4c 100644 --- a/json/pickler/src/test/scala/sttp/tapir/json/pickler/SchemaDerivationTest.scala +++ b/json/pickler/src/test/scala/sttp/tapir/json/pickler/SchemaDerivationTest.scala @@ -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") diff --git a/openapi-codegen/cli/src/main/scala/sttp/tapir/codegen/GenScala.scala b/openapi-codegen/cli/src/main/scala/sttp/tapir/codegen/GenScala.scala index 82e34a35d5..ad41daa46a 100644 --- a/openapi-codegen/cli/src/main/scala/sttp/tapir/codegen/GenScala.scala +++ b/openapi-codegen/cli/src/main/scala/sttp/tapir/codegen/GenScala.scala @@ -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 } } diff --git a/openapi-codegen/core/src/main/scala/sttp/tapir/codegen/EndpointGenerator.scala b/openapi-codegen/core/src/main/scala/sttp/tapir/codegen/EndpointGenerator.scala index aed0db4d0e..84adf5cc13 100644 --- a/openapi-codegen/core/src/main/scala/sttp/tapir/codegen/EndpointGenerator.scala +++ b/openapi-codegen/core/src/main/scala/sttp/tapir/codegen/EndpointGenerator.scala @@ -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") diff --git a/openapi-codegen/sbt-plugin/src/sbt-test/sbt-openapi-codegen/oneOf-json-roundtrip-zio/project/plugins.sbt b/openapi-codegen/sbt-plugin/src/sbt-test/sbt-openapi-codegen/oneOf-json-roundtrip-zio/project/plugins.sbt index 2e0b229d2a..cd0458c9d1 100644 --- a/openapi-codegen/sbt-plugin/src/sbt-test/sbt-openapi-codegen/oneOf-json-roundtrip-zio/project/plugins.sbt +++ b/openapi-codegen/sbt-plugin/src/sbt-test/sbt-openapi-codegen/oneOf-json-roundtrip-zio/project/plugins.sbt @@ -8,4 +8,4 @@ | |""".stripMargin) else addSbtPlugin("com.softwaremill.sttp.tapir" % "sbt-openapi-codegen" % pluginVersion) -} \ No newline at end of file +} diff --git a/openapi-codegen/sbt-plugin/src/sbt-test/sbt-openapi-codegen/oneOf-json-roundtrip-zio/src/test/scala/JsonRoundtrip.scala b/openapi-codegen/sbt-plugin/src/sbt-test/sbt-openapi-codegen/oneOf-json-roundtrip-zio/src/test/scala/JsonRoundtrip.scala index 81dc62e3f5..392e52b514 100644 --- a/openapi-codegen/sbt-plugin/src/sbt-test/sbt-openapi-codegen/oneOf-json-roundtrip-zio/src/test/scala/JsonRoundtrip.scala +++ b/openapi-codegen/sbt-plugin/src/sbt-test/sbt-openapi-codegen/oneOf-json-roundtrip-zio/src/test/scala/JsonRoundtrip.scala @@ -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}""" diff --git a/openapi-codegen/sbt-plugin/src/sbt-test/sbt-openapi-codegen/oneOf-json-roundtrip/project/plugins.sbt b/openapi-codegen/sbt-plugin/src/sbt-test/sbt-openapi-codegen/oneOf-json-roundtrip/project/plugins.sbt index 2e0b229d2a..cd0458c9d1 100644 --- a/openapi-codegen/sbt-plugin/src/sbt-test/sbt-openapi-codegen/oneOf-json-roundtrip/project/plugins.sbt +++ b/openapi-codegen/sbt-plugin/src/sbt-test/sbt-openapi-codegen/oneOf-json-roundtrip/project/plugins.sbt @@ -8,4 +8,4 @@ | |""".stripMargin) else addSbtPlugin("com.softwaremill.sttp.tapir" % "sbt-openapi-codegen" % pluginVersion) -} \ No newline at end of file +} diff --git a/openapi-codegen/sbt-plugin/src/sbt-test/sbt-openapi-codegen/oneOf-json-roundtrip_jsoniter/project/plugins.sbt b/openapi-codegen/sbt-plugin/src/sbt-test/sbt-openapi-codegen/oneOf-json-roundtrip_jsoniter/project/plugins.sbt index 2e0b229d2a..cd0458c9d1 100644 --- a/openapi-codegen/sbt-plugin/src/sbt-test/sbt-openapi-codegen/oneOf-json-roundtrip_jsoniter/project/plugins.sbt +++ b/openapi-codegen/sbt-plugin/src/sbt-test/sbt-openapi-codegen/oneOf-json-roundtrip_jsoniter/project/plugins.sbt @@ -8,4 +8,4 @@ | |""".stripMargin) else addSbtPlugin("com.softwaremill.sttp.tapir" % "sbt-openapi-codegen" % pluginVersion) -} \ No newline at end of file +} diff --git a/openapi-codegen/sbt-plugin/src/sbt-test/sbt-openapi-codegen/oneOf-json-roundtrip_scala3/project/plugins.sbt b/openapi-codegen/sbt-plugin/src/sbt-test/sbt-openapi-codegen/oneOf-json-roundtrip_scala3/project/plugins.sbt index 2e0b229d2a..cd0458c9d1 100644 --- a/openapi-codegen/sbt-plugin/src/sbt-test/sbt-openapi-codegen/oneOf-json-roundtrip_scala3/project/plugins.sbt +++ b/openapi-codegen/sbt-plugin/src/sbt-test/sbt-openapi-codegen/oneOf-json-roundtrip_scala3/project/plugins.sbt @@ -8,4 +8,4 @@ | |""".stripMargin) else addSbtPlugin("com.softwaremill.sttp.tapir" % "sbt-openapi-codegen" % pluginVersion) -} \ No newline at end of file +} diff --git a/server/core/src/test/scala/sttp/tapir/server/interpreter/ServerInterpreterTest.scala b/server/core/src/test/scala/sttp/tapir/server/interpreter/ServerInterpreterTest.scala index 82118255c6..6fef7c28da 100644 --- a/server/core/src/test/scala/sttp/tapir/server/interpreter/ServerInterpreterTest.scala +++ b/server/core/src/test/scala/sttp/tapir/server/interpreter/ServerInterpreterTest.scala @@ -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) @@ -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) diff --git a/server/jdkhttp-server/src/main/scala/sttp/tapir/server/jdkhttp/JdkHttpServer.scala b/server/jdkhttp-server/src/main/scala/sttp/tapir/server/jdkhttp/JdkHttpServer.scala index 3c41fcd8e1..1ff4a133fd 100644 --- a/server/jdkhttp-server/src/main/scala/sttp/tapir/server/jdkhttp/JdkHttpServer.scala +++ b/server/jdkhttp-server/src/main/scala/sttp/tapir/server/jdkhttp/JdkHttpServer.scala @@ -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. */ diff --git a/server/jdkhttp-server/src/main/scala/sttp/tapir/server/jdkhttp/JdkHttpServerOptions.scala b/server/jdkhttp-server/src/main/scala/sttp/tapir/server/jdkhttp/JdkHttpServerOptions.scala index 7166ae9abc..f1e92249fd 100644 --- a/server/jdkhttp-server/src/main/scala/sttp/tapir/server/jdkhttp/JdkHttpServerOptions.scala +++ b/server/jdkhttp-server/src/main/scala/sttp/tapir/server/jdkhttp/JdkHttpServerOptions.scala @@ -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) diff --git a/server/netty-server/src/main/scala/sttp/tapir/server/netty/internal/ws/WebSocketFrameConverters.scala b/server/netty-server/src/main/scala/sttp/tapir/server/netty/internal/ws/WebSocketFrameConverters.scala index 748dba94ac..703ba15170 100644 --- a/server/netty-server/src/main/scala/sttp/tapir/server/netty/internal/ws/WebSocketFrameConverters.scala +++ b/server/netty-server/src/main/scala/sttp/tapir/server/netty/internal/ws/WebSocketFrameConverters.scala @@ -38,20 +38,20 @@ object WebSocketFrameConverters { type Accumulator = Option[Either[Array[Byte], String]] val accumulateFrameState: (Accumulator, WebSocketFrame) => (Accumulator, Option[WebSocketFrame]) = { - case (None, f: WebSocketFrame.Ping) => (None, Some(f)) - case (None, f: WebSocketFrame.Pong) => (None, Some(f)) - case (None, f: WebSocketFrame.Close) => (None, Some(f)) - case (None, f: WebSocketFrame.Data[_]) if f.finalFragment => (None, Some(f)) - case (None, f: WebSocketFrame.Text) => (Some(Right(f.payload)), None) - case (None, f: WebSocketFrame.Binary) => (Some(Left(f.payload)), None) - case (Some(Left(acc)), f: WebSocketFrame.Binary) if f.finalFragment => (None, Some(f.copy(payload = acc ++ f.payload))) - case (Some(Left(acc)), f: WebSocketFrame.Binary) if !f.finalFragment => (Some(Left(acc ++ f.payload)), None) - case (Some(Right(acc)), f: WebSocketFrame.Binary) if f.finalFragment => - // Netty's ContinuationFrame is translated to Binary, so we need to handle a Binary frame received after accumulating Text - (None, Some(WebSocketFrame.Text(payload = acc + new String(f.payload), finalFragment = true, rsv = f.rsv))) - case (Some(Right(acc)), f: WebSocketFrame.Binary) if !f.finalFragment => (Some(Right(acc + new String(f.payload))), None) - case (Some(Right(acc)), f: WebSocketFrame.Text) if f.finalFragment => (None, Some(f.copy(payload = acc + f.payload))) - case (Some(Right(acc)), f: WebSocketFrame.Text) if !f.finalFragment => (Some(Right(acc + f.payload)), None) - case (acc, f) => throw new IllegalStateException(s"Cannot accumulate web socket frames. Accumulator: $acc, frame: $f.") + case (None, f: WebSocketFrame.Ping) => (None, Some(f)) + case (None, f: WebSocketFrame.Pong) => (None, Some(f)) + case (None, f: WebSocketFrame.Close) => (None, Some(f)) + case (None, f: WebSocketFrame.Data[_]) if f.finalFragment => (None, Some(f)) + case (None, f: WebSocketFrame.Text) => (Some(Right(f.payload)), None) + case (None, f: WebSocketFrame.Binary) => (Some(Left(f.payload)), None) + case (Some(Left(acc)), f: WebSocketFrame.Binary) if f.finalFragment => (None, Some(f.copy(payload = acc ++ f.payload))) + case (Some(Left(acc)), f: WebSocketFrame.Binary) if !f.finalFragment => (Some(Left(acc ++ f.payload)), None) + case (Some(Right(acc)), f: WebSocketFrame.Binary) if f.finalFragment => + // Netty's ContinuationFrame is translated to Binary, so we need to handle a Binary frame received after accumulating Text + (None, Some(WebSocketFrame.Text(payload = acc + new String(f.payload), finalFragment = true, rsv = f.rsv))) + case (Some(Right(acc)), f: WebSocketFrame.Binary) if !f.finalFragment => (Some(Right(acc + new String(f.payload))), None) + case (Some(Right(acc)), f: WebSocketFrame.Text) if f.finalFragment => (None, Some(f.copy(payload = acc + f.payload))) + case (Some(Right(acc)), f: WebSocketFrame.Text) if !f.finalFragment => (Some(Right(acc + f.payload)), None) + case (acc, f) => throw new IllegalStateException(s"Cannot accumulate web socket frames. Accumulator: $acc, frame: $f.") } } diff --git a/server/netty-server/sync/src/main/scala/sttp/tapir/server/netty/sync/NettySyncServerInterpreter.scala b/server/netty-server/sync/src/main/scala/sttp/tapir/server/netty/sync/NettySyncServerInterpreter.scala index 7deedb3ad1..0beab5e08d 100644 --- a/server/netty-server/sync/src/main/scala/sttp/tapir/server/netty/sync/NettySyncServerInterpreter.scala +++ b/server/netty-server/sync/src/main/scala/sttp/tapir/server/netty/sync/NettySyncServerInterpreter.scala @@ -19,8 +19,8 @@ trait NettySyncServerInterpreter: * processor. */ def toRoute( - ses: List[ServerEndpoint[OxStreams & WebSockets, Identity]], - oxDispatcher: OxDispatcher + ses: List[ServerEndpoint[OxStreams & WebSockets, Identity]], + oxDispatcher: OxDispatcher ): IdRoute = implicit val bodyListener: BodyListener[Identity, NettyResponse] = new NettyBodyListener(RunAsync.Id) val serverInterpreter = new ServerInterpreter[OxStreams with WebSockets, Identity, NettyResponse, OxStreams]( diff --git a/server/netty-server/sync/src/main/scala/sttp/tapir/server/netty/sync/NettySyncServerOptions.scala b/server/netty-server/sync/src/main/scala/sttp/tapir/server/netty/sync/NettySyncServerOptions.scala index f7b94960ae..097c20b24e 100644 --- a/server/netty-server/sync/src/main/scala/sttp/tapir/server/netty/sync/NettySyncServerOptions.scala +++ b/server/netty-server/sync/src/main/scala/sttp/tapir/server/netty/sync/NettySyncServerOptions.scala @@ -9,9 +9,9 @@ import sttp.tapir.server.interceptor.{CustomiseInterceptors, Interceptor} import sttp.tapir.{Defaults, TapirFile} case class NettySyncServerOptions( - interceptors: List[Interceptor[Identity]], - createFile: ServerRequest => TapirFile, - deleteFile: TapirFile => Unit + interceptors: List[Interceptor[Identity]], + createFile: ServerRequest => TapirFile, + deleteFile: TapirFile => Unit ): def prependInterceptor(i: Interceptor[Identity]): NettySyncServerOptions = copy(interceptors = i :: interceptors) def appendInterceptor(i: Interceptor[Identity]): NettySyncServerOptions = copy(interceptors = interceptors :+ i) diff --git a/server/netty-server/sync/src/main/scala/sttp/tapir/server/netty/sync/internal/reactivestreams/OxProcessor.scala b/server/netty-server/sync/src/main/scala/sttp/tapir/server/netty/sync/internal/reactivestreams/OxProcessor.scala index 35c7d3ffc6..c5a1ba09b5 100644 --- a/server/netty-server/sync/src/main/scala/sttp/tapir/server/netty/sync/internal/reactivestreams/OxProcessor.scala +++ b/server/netty-server/sync/src/main/scala/sttp/tapir/server/netty/sync/internal/reactivestreams/OxProcessor.scala @@ -89,7 +89,7 @@ private[sync] class OxProcessor[A, B]( pipelineFork.cancel() ) match { case Left(NonFatal(e)) => logger.error("Error when canceling pipeline fork", e) - case _ => () + case _ => () } } { e => logger.error("Error when canceling pipeline fork", e) }.discard } catch case NonFatal(e) => logger.error("Error when waiting for pipeline fork to start", e) diff --git a/server/netty-server/sync/src/main/scala/sttp/tapir/server/netty/sync/internal/ws/OxSourceWebSocketProcessor.scala b/server/netty-server/sync/src/main/scala/sttp/tapir/server/netty/sync/internal/ws/OxSourceWebSocketProcessor.scala index c3e4767f2a..fecdd2265d 100644 --- a/server/netty-server/sync/src/main/scala/sttp/tapir/server/netty/sync/internal/ws/OxSourceWebSocketProcessor.scala +++ b/server/netty-server/sync/src/main/scala/sttp/tapir/server/netty/sync/internal/ws/OxSourceWebSocketProcessor.scala @@ -70,10 +70,10 @@ private[sync] object OxSourceWebSocketProcessor: else s private def takeUntilCloseFrame(passAlongCloseFrame: Boolean)(s: Source[WebSocketFrame])(using Ox): Source[WebSocketFrame] = - s.takeWhile({ + s.takeWhile( + { case _: WebSocketFrame.Close => false case _ => true }, includeFailed = passAlongCloseFrame ) - diff --git a/server/netty-server/sync/src/test/scala/sttp/tapir/server/netty/sync/NettySyncTestServerInterpreter.scala b/server/netty-server/sync/src/test/scala/sttp/tapir/server/netty/sync/NettySyncTestServerInterpreter.scala index ee038bc859..28b507cdf3 100644 --- a/server/netty-server/sync/src/test/scala/sttp/tapir/server/netty/sync/NettySyncTestServerInterpreter.scala +++ b/server/netty-server/sync/src/test/scala/sttp/tapir/server/netty/sync/NettySyncTestServerInterpreter.scala @@ -55,9 +55,9 @@ class NettySyncTestServerInterpreter(eventLoopGroup: NioEventLoopGroup) useInScope(NettySyncServer(options, customizedConfig).start(routes.toList))(_.stop()) def scopedServerWithInterceptorsStop( - endpoint: ServerEndpoint[OxStreams with WebSockets, Identity], - interceptors: Interceptors = identity, - gracefulShutdownTimeout: Option[FiniteDuration] = None + endpoint: ServerEndpoint[OxStreams with WebSockets, Identity], + interceptors: Interceptors = identity, + gracefulShutdownTimeout: Option[FiniteDuration] = None )(using Ox): NettySyncServerBinding = val config = NettyConfig.default.eventLoopGroup(eventLoopGroup).randomPort.withDontShutdownEventLoopGroupOnClose.noGracefulShutdown @@ -66,8 +66,8 @@ class NettySyncTestServerInterpreter(eventLoopGroup: NioEventLoopGroup) useInScope(NettySyncServer(customizedConfig).addEndpoint(endpoint, options).start())(_.stop()) def scopedServerWithStop( - endpoints: NonEmptyList[ServerEndpoint[OxStreams with WebSockets, Identity]], - gracefulShutdownTimeout: Option[FiniteDuration] = None + endpoints: NonEmptyList[ServerEndpoint[OxStreams with WebSockets, Identity]], + gracefulShutdownTimeout: Option[FiniteDuration] = None )(using Ox): NettySyncServerBinding = val config = NettyConfig.default.eventLoopGroup(eventLoopGroup).randomPort.withDontShutdownEventLoopGroupOnClose.noGracefulShutdown diff --git a/server/nima-server/src/main/scala/sttp/tapir/server/nima/NimaServerOptions.scala b/server/nima-server/src/main/scala/sttp/tapir/server/nima/NimaServerOptions.scala index 65f1851ca6..4561c5a0b3 100644 --- a/server/nima-server/src/main/scala/sttp/tapir/server/nima/NimaServerOptions.scala +++ b/server/nima-server/src/main/scala/sttp/tapir/server/nima/NimaServerOptions.scala @@ -8,9 +8,9 @@ import sttp.tapir.server.interceptor.log.{DefaultServerLog, ServerLog} import sttp.tapir.server.interceptor.{CustomiseInterceptors, Interceptor} case class NimaServerOptions( - interceptors: List[Interceptor[Identity]], - createFile: ServerRequest => TapirFile, - deleteFile: TapirFile => Unit + interceptors: List[Interceptor[Identity]], + createFile: ServerRequest => TapirFile, + deleteFile: TapirFile => Unit ) { def prependInterceptor(i: Interceptor[Identity]): NimaServerOptions = copy(interceptors = i :: interceptors) def appendInterceptor(i: Interceptor[Identity]): NimaServerOptions = copy(interceptors = interceptors :+ i) diff --git a/server/tests/src/main/scala/sttp/tapir/server/tests/ServerBasicTests.scala b/server/tests/src/main/scala/sttp/tapir/server/tests/ServerBasicTests.scala index bbc9071f99..6bf11c137e 100644 --- a/server/tests/src/main/scala/sttp/tapir/server/tests/ServerBasicTests.scala +++ b/server/tests/src/main/scala/sttp/tapir/server/tests/ServerBasicTests.scala @@ -236,7 +236,7 @@ class ServerBasicTests[F[_], OPTIONS, ROUTE]( "should not fold multiple Set-Cookie headers" ) { (backend, baseUri) => basicRequest.response(asStringAlways).get(uri"$baseUri/cookies-test").send(backend).map { r => - r.headers should contain allOf( + r.headers should contain allOf ( Header.setCookie(CookieWithMeta.unsafeApply("name1", "value1", path = Some("/path1"))), Header.setCookie(CookieWithMeta.unsafeApply("name2", "value2", path = Some("/path2"))) ) diff --git a/server/tests/src/main/scala/sttp/tapir/server/tests/ServerOneOfTests.scala b/server/tests/src/main/scala/sttp/tapir/server/tests/ServerOneOfTests.scala index 28529a0701..1e84d1220c 100644 --- a/server/tests/src/main/scala/sttp/tapir/server/tests/ServerOneOfTests.scala +++ b/server/tests/src/main/scala/sttp/tapir/server/tests/ServerOneOfTests.scala @@ -170,6 +170,5 @@ class ServerOneOfTests[F[_], OPTIONS, ROUTE]( r.code shouldBe StatusCode.BadRequest } } - ) } diff --git a/server/tests/src/main/scala/sttp/tapir/server/tests/ServerSecurityTests.scala b/server/tests/src/main/scala/sttp/tapir/server/tests/ServerSecurityTests.scala index 11aad3c58e..ab4069fbfd 100644 --- a/server/tests/src/main/scala/sttp/tapir/server/tests/ServerSecurityTests.scala +++ b/server/tests/src/main/scala/sttp/tapir/server/tests/ServerSecurityTests.scala @@ -11,7 +11,15 @@ import sttp.shared.Identity import sttp.tapir._ import sttp.tapir.model.UsernamePassword import sttp.tapir.server.interceptor.decodefailure.DefaultDecodeFailureHandler -import sttp.tapir.tests.Security.{in_security_apikey_header_in_amount_out_string, in_security_apikey_header_out_string, in_security_apikey_query_out_string, in_security_basic_out_string, in_security_bearer_out_string, in_security_option_basic_option_bearer_out_string, in_security_option_basic_out_string} +import sttp.tapir.tests.Security.{ + in_security_apikey_header_in_amount_out_string, + in_security_apikey_header_out_string, + in_security_apikey_query_out_string, + in_security_basic_out_string, + in_security_bearer_out_string, + in_security_option_basic_option_bearer_out_string, + in_security_option_basic_out_string +} import sttp.tapir.tests.Test class ServerSecurityTests[F[_], S, OPTIONS, ROUTE](createServerTest: CreateServerTest[F, S, OPTIONS, ROUTE])(implicit m: MonadError[F]) From e848cf8e81ab4fb78a43c79db3ea7ca9c3184ae8 Mon Sep 17 00:00:00 2001 From: scala-steward Date: Sat, 15 Jun 2024 00:10:25 +0000 Subject: [PATCH 3/3] Add 'Reformat with scalafmt 3.8.2' to .git-blame-ignore-revs --- .git-blame-ignore-revs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.git-blame-ignore-revs b/.git-blame-ignore-revs index b7868c4084..1394554716 100644 --- a/.git-blame-ignore-revs +++ b/.git-blame-ignore-revs @@ -45,3 +45,6 @@ ab79cadbb13aac7c32015ce5caf24d57290ee59b # Scala Steward: Reformat with scalafmt 3.8.1 e003ec3b61e3bd582ae6a5200177fa6433099c09 + +# Scala Steward: Reformat with scalafmt 3.8.2 +9b44bd1451b796259b0592afe54bb5891f63f48e