From b77e61ef8ee343c73febe8f5e7dd0cd1226eadee Mon Sep 17 00:00:00 2001 From: Devon Stewart Date: Wed, 11 Oct 2023 22:30:11 -0700 Subject: [PATCH 1/5] Adding matchStructure to scala-support for tests --- .../src/test/scala/support/ScalaMetaSupport.scala | 14 +++++++++++++- src/test/scala/support/ScalaMetaMatchers.scala | 12 ++++++------ 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/modules/scala-support/src/test/scala/support/ScalaMetaSupport.scala b/modules/scala-support/src/test/scala/support/ScalaMetaSupport.scala index 15a813df71..2bc708279a 100644 --- a/modules/scala-support/src/test/scala/support/ScalaMetaSupport.scala +++ b/modules/scala-support/src/test/scala/support/ScalaMetaSupport.scala @@ -1,7 +1,8 @@ package support import org.scalactic.Equality -import scala.meta.Tree +import org.scalatest.matchers._ +import scala.meta._ trait ScalaMetaMatchers { implicit def TreeEquality[A <: Tree]: Equality[A] = @@ -12,4 +13,15 @@ trait ScalaMetaMatchers { case _ => false } } + + class StructureMatcher(expectedStructure: Tree) extends Matcher[Tree] { + def apply(left: Tree) = + MatchResult( + expectedStructure.syntax == left.syntax, + s"""${expectedStructure.syntax} did not equal ${left.syntax}""", + s"""Failure message""" + ) + } + + def matchStructure(expectedStructure: Tree) = new StructureMatcher(expectedStructure) } diff --git a/src/test/scala/support/ScalaMetaMatchers.scala b/src/test/scala/support/ScalaMetaMatchers.scala index b0997f87f8..89fedd184a 100644 --- a/src/test/scala/support/ScalaMetaMatchers.scala +++ b/src/test/scala/support/ScalaMetaMatchers.scala @@ -4,16 +4,16 @@ import scala.meta._ import org.scalatest.matchers._ trait ScalaMetaMatchers { - class StructureMatcher(right: Term) extends Matcher[Term] { - def apply(left: Term): MatchResult = + class StructureMatcher(right: Tree) extends Matcher[Tree] { + def apply(left: Tree): MatchResult = MatchResult( - left.structure == right.structure, - s"""$left did not match structure $right""", - s"""$left matched structure $right""" + left.syntax == right.syntax, + s"""$left did not match $right""", + s"""$left matched $right""" ) } - def matchStructure(right: Term): StructureMatcher = + def matchStructure(right: Tree): StructureMatcher = new StructureMatcher(right) } From f8039f924055eb1b2aeefaff7ba2e3d930a11f78 Mon Sep 17 00:00:00 2001 From: Devon Stewart Date: Wed, 11 Oct 2023 22:34:08 -0700 Subject: [PATCH 2/5] Switching scala tests over to matchStructure There are some minor differences in .structure due to scalameta upgrade --- .../src/test/scala/core/issues/Issue122.scala | 8 ++++---- .../src/test/scala/core/issues/Issue126.scala | 8 ++++---- .../src/test/scala/core/issues/Issue127.scala | 8 ++++---- .../src/test/scala/core/issues/Issue313.scala | 8 ++++---- .../AkkaHttpClientGeneratorTest.scala | 12 +++++------ .../akkaHttp/AkkaHttpServerTest.scala | 16 +++++++-------- .../akkaHttp/CustomHeaderTest.scala | 8 ++++---- .../generators/akkaHttp/DefinitionSpec.scala | 20 +++++++++---------- .../tests/generators/akkaHttp/EnumTest.scala | 10 +++++----- .../akkaHttp/PropertyExtractors.scala | 8 ++++---- .../akkaHttp/StaticParametersTest.scala | 8 ++++---- .../client/AkkaHttpClientTracingTest.scala | 8 ++++---- .../akkaHttp/client/BasicTest.scala | 12 +++++------ .../client/DefaultParametersTest.scala | 8 ++++---- .../akkaHttp/client/FormFieldsTest.scala | 6 +++--- .../akkaHttp/client/HardcodedQSSpec.scala | 6 +++--- .../akkaHttp/client/HttpBodiesTest.scala | 6 +++--- .../akkaHttp/client/MultipartTest.scala | 6 +++--- .../akkaHttp/client/ParamConflictsTest.scala | 10 +++++----- .../akkaHttp/client/SchemeTest.scala | 8 ++++---- .../client/contentType/TextPlainTest.scala | 8 ++++---- .../akkaHttp/server/FormFieldsTest.scala | 8 ++++---- .../src/test/scala/core/issues/Issue166.scala | 6 +++--- .../tests/core/FullyQualifiedNames.scala | 4 ++-- .../tests/generators/http4s/BasicTest.scala | 16 +++++++-------- .../generators/http4s/Http4sServerTest.scala | 16 +++++++-------- .../http4s/client/DefaultParametersTest.scala | 10 +++++----- .../tests/circe/ArrayValidationTest.scala | 8 ++++---- .../scala/tests/circe/BigObjectSpec.scala | 8 ++++---- .../scala/tests/circe/ValidationTest.scala | 6 +++--- src/test/scala/tests/core/BacktickTest.scala | 14 ++++++------- .../tests/core/DereferencingAliasesSpec.scala | 20 +++++++++---------- 32 files changed, 154 insertions(+), 154 deletions(-) diff --git a/modules/scala-akka-http/src/test/scala/core/issues/Issue122.scala b/modules/scala-akka-http/src/test/scala/core/issues/Issue122.scala index a9a768882b..aefaffcca9 100644 --- a/modules/scala-akka-http/src/test/scala/core/issues/Issue122.scala +++ b/modules/scala-akka-http/src/test/scala/core/issues/Issue122.scala @@ -3,14 +3,14 @@ package tests.core.issues import org.scalatest.funsuite.AnyFunSuite import org.scalatest.matchers.should.Matchers import scala.meta._ -import support.SwaggerSpecRunner +import support.{ ScalaMetaMatchers, SwaggerSpecRunner } import dev.guardrail.Context import dev.guardrail.generators.scala.ScalaGeneratorMappings.scalaInterpreter import dev.guardrail.generators.scala.syntax.companionForStaticDefns import dev.guardrail.generators.{ Client, Clients } -class Issue122 extends AnyFunSuite with Matchers with SwaggerSpecRunner { +class Issue122 extends AnyFunSuite with Matchers with SwaggerSpecRunner with ScalaMetaMatchers { val spec: String = s""" |swagger: "2.0" |info: @@ -94,7 +94,7 @@ class Issue122 extends AnyFunSuite with Matchers with SwaggerSpecRunner { } """ - cls.head.value.structure shouldBe client.structure - cmp.structure shouldBe companion.structure + cls.head.value should matchStructure(client) + cmp should matchStructure(companion) } } diff --git a/modules/scala-akka-http/src/test/scala/core/issues/Issue126.scala b/modules/scala-akka-http/src/test/scala/core/issues/Issue126.scala index 9a8d83d2c9..df31b48a1c 100644 --- a/modules/scala-akka-http/src/test/scala/core/issues/Issue126.scala +++ b/modules/scala-akka-http/src/test/scala/core/issues/Issue126.scala @@ -3,11 +3,11 @@ package tests.core.issues import dev.guardrail.generators.scala.ScalaGeneratorMappings.scalaInterpreter import dev.guardrail.Context import dev.guardrail.generators.{ Server, Servers } -import support.SwaggerSpecRunner +import support.{ ScalaMetaMatchers, SwaggerSpecRunner } import org.scalatest.funsuite.AnyFunSuite import org.scalatest.matchers.should.Matchers -class Issue126 extends AnyFunSuite with Matchers with SwaggerSpecRunner { +class Issue126 extends AnyFunSuite with Matchers with SwaggerSpecRunner with ScalaMetaMatchers { import scala.meta._ val spec: String = s""" @@ -60,7 +60,7 @@ class Issue126 extends AnyFunSuite with Matchers with SwaggerSpecRunner { } """ - genHandler.structure shouldEqual handler.structure - genResource.structure shouldEqual resource.structure + genHandler should matchStructure(handler) + genResource should matchStructure(resource) } } diff --git a/modules/scala-akka-http/src/test/scala/core/issues/Issue127.scala b/modules/scala-akka-http/src/test/scala/core/issues/Issue127.scala index d954781aab..4815601c83 100644 --- a/modules/scala-akka-http/src/test/scala/core/issues/Issue127.scala +++ b/modules/scala-akka-http/src/test/scala/core/issues/Issue127.scala @@ -3,13 +3,13 @@ package tests.core.issues import dev.guardrail.generators.scala.ScalaGeneratorMappings.scalaInterpreter import dev.guardrail.Context import dev.guardrail.generators.{ Server, Servers } -import support.SwaggerSpecRunner +import support.{ ScalaMetaMatchers, SwaggerSpecRunner } import scala.meta._ import org.scalatest.funsuite.AnyFunSuite import org.scalatest.matchers.should.Matchers -class Issue127 extends AnyFunSuite with Matchers with SwaggerSpecRunner { +class Issue127 extends AnyFunSuite with Matchers with SwaggerSpecRunner with ScalaMetaMatchers { val spec: String = s""" |swagger: '2.0' |host: localhost:1234 @@ -161,7 +161,7 @@ class Issue127 extends AnyFunSuite with Matchers with SwaggerSpecRunner { } """ - genHandler.structure shouldBe handler.structure - genResource.structure shouldBe resource.structure + genHandler should matchStructure(handler) + genResource should matchStructure(resource) } } diff --git a/modules/scala-akka-http/src/test/scala/core/issues/Issue313.scala b/modules/scala-akka-http/src/test/scala/core/issues/Issue313.scala index 26d93f77df..09b1c7c3b5 100644 --- a/modules/scala-akka-http/src/test/scala/core/issues/Issue313.scala +++ b/modules/scala-akka-http/src/test/scala/core/issues/Issue313.scala @@ -7,11 +7,11 @@ import dev.guardrail.Context import dev.guardrail.generators.{ Client, Clients } import org.scalatest.funsuite.AnyFunSuite import org.scalatest.matchers.should.Matchers -import support.SwaggerSpecRunner +import support.{ ScalaMetaMatchers, SwaggerSpecRunner } import scala.meta._ -class Issue313 extends AnyFunSuite with Matchers with SwaggerSpecRunner { +class Issue313 extends AnyFunSuite with Matchers with SwaggerSpecRunner with ScalaMetaMatchers { val spec: String = s""" |openapi: 3.0.2 |info: @@ -88,7 +88,7 @@ class Issue313 extends AnyFunSuite with Matchers with SwaggerSpecRunner { } """ - cls.structure shouldBe client.structure - cmp.structure shouldBe companion.structure + cls should matchStructure(client) + cmp should matchStructure(companion) } } diff --git a/modules/scala-akka-http/src/test/scala/tests/generators/akkaHttp/AkkaHttpClientGeneratorTest.scala b/modules/scala-akka-http/src/test/scala/tests/generators/akkaHttp/AkkaHttpClientGeneratorTest.scala index ca03786443..ccb5d4abbf 100644 --- a/modules/scala-akka-http/src/test/scala/tests/generators/akkaHttp/AkkaHttpClientGeneratorTest.scala +++ b/modules/scala-akka-http/src/test/scala/tests/generators/akkaHttp/AkkaHttpClientGeneratorTest.scala @@ -4,11 +4,11 @@ import dev.guardrail.generators.scala.ScalaGeneratorMappings.scalaInterpreter import dev.guardrail.generators.scala.syntax.companionForStaticDefns import dev.guardrail.Context import dev.guardrail.generators.{ Client, Clients } -import support.SwaggerSpecRunner +import support.{ ScalaMetaMatchers, SwaggerSpecRunner } import org.scalatest.funsuite.AnyFunSuite import org.scalatest.matchers.should.Matchers -class AkkaHttpClientGeneratorTest extends AnyFunSuite with Matchers with SwaggerSpecRunner { +class AkkaHttpClientGeneratorTest extends AnyFunSuite with Matchers with SwaggerSpecRunner with ScalaMetaMatchers { import scala.meta._ val spec: String = s""" @@ -177,8 +177,8 @@ class AkkaHttpClientGeneratorTest extends AnyFunSuite with Matchers with Swagger } """ - cmp.structure should equal(companion.structure) - cls.head.value.structure should equal(client.structure) + cmp should matchStructure(companion) + cls.head.value should matchStructure(client) } test("Ensure traced responses are generated") { @@ -249,7 +249,7 @@ class AkkaHttpClientGeneratorTest extends AnyFunSuite with Matchers with Swagger } """ - cmp.structure should equal(companion.structure) - cls.head.value.structure should equal(client.structure) + cmp should matchStructure(companion) + cls.head.value should matchStructure(client) } } diff --git a/modules/scala-akka-http/src/test/scala/tests/generators/akkaHttp/AkkaHttpServerTest.scala b/modules/scala-akka-http/src/test/scala/tests/generators/akkaHttp/AkkaHttpServerTest.scala index e93885b9d5..f79e9bf151 100644 --- a/modules/scala-akka-http/src/test/scala/tests/generators/akkaHttp/AkkaHttpServerTest.scala +++ b/modules/scala-akka-http/src/test/scala/tests/generators/akkaHttp/AkkaHttpServerTest.scala @@ -3,11 +3,11 @@ package tests.generators.akkaHttp import dev.guardrail.generators.scala.ScalaGeneratorMappings.scalaInterpreter import dev.guardrail.Context import dev.guardrail.generators.{ Server, Servers } -import support.SwaggerSpecRunner +import support.{ ScalaMetaMatchers, SwaggerSpecRunner } import org.scalatest.funsuite.AnyFunSuite import org.scalatest.matchers.should.Matchers -class AkkaHttpServerTest extends AnyFunSuite with Matchers with SwaggerSpecRunner { +class AkkaHttpServerTest extends AnyFunSuite with Matchers with SwaggerSpecRunner with ScalaMetaMatchers { import scala.meta._ val spec: String = s""" @@ -258,8 +258,8 @@ class AkkaHttpServerTest extends AnyFunSuite with Matchers with SwaggerSpecRunne } """ - genHandler.structure shouldEqual handler.structure - genResource.structure shouldEqual resource.structure + genHandler should matchStructure(handler) + genResource should matchStructure(resource) } test("Ensure routes are generated with tracing") { @@ -395,8 +395,8 @@ class AkkaHttpServerTest extends AnyFunSuite with Matchers with SwaggerSpecRunne } """ - genHandler.structure should equal(handler.structure) - genResource.structure should equal(resource.structure) + genHandler should matchStructure(handler) + genResource should matchStructure(resource) } test("Ensure routes are generated with custom extraction") { @@ -532,7 +532,7 @@ class AkkaHttpServerTest extends AnyFunSuite with Matchers with SwaggerSpecRunne } """ - genHandler.structure should equal(handler.structure) - genResource.structure should equal(resource.structure) + genHandler should matchStructure(handler) + genResource should matchStructure(resource) } } diff --git a/modules/scala-akka-http/src/test/scala/tests/generators/akkaHttp/CustomHeaderTest.scala b/modules/scala-akka-http/src/test/scala/tests/generators/akkaHttp/CustomHeaderTest.scala index a5ebad3e85..01e743ffca 100644 --- a/modules/scala-akka-http/src/test/scala/tests/generators/akkaHttp/CustomHeaderTest.scala +++ b/modules/scala-akka-http/src/test/scala/tests/generators/akkaHttp/CustomHeaderTest.scala @@ -3,13 +3,13 @@ package tests.generators.akkaHttp import dev.guardrail.generators.scala.ScalaGeneratorMappings.scalaInterpreter import dev.guardrail.Context import dev.guardrail.generators.{ Clients, Server, Servers } -import support.SwaggerSpecRunner +import support.{ ScalaMetaMatchers, SwaggerSpecRunner } import scala.meta._ import org.scalatest.funsuite.AnyFunSuite import org.scalatest.matchers.should.Matchers -class CustomHeaderTest extends AnyFunSuite with Matchers with SwaggerSpecRunner { +class CustomHeaderTest extends AnyFunSuite with Matchers with SwaggerSpecRunner with ScalaMetaMatchers { val spec: String = s""" |swagger: "2.0" |info: @@ -77,7 +77,7 @@ class CustomHeaderTest extends AnyFunSuite with Matchers with SwaggerSpecRunner } """ - genHandler.structure should equal(handler.structure) - genResource.structure should equal(resource.structure) + genHandler should matchStructure(handler) + genResource should matchStructure(resource) } } diff --git a/modules/scala-akka-http/src/test/scala/tests/generators/akkaHttp/DefinitionSpec.scala b/modules/scala-akka-http/src/test/scala/tests/generators/akkaHttp/DefinitionSpec.scala index 0fbb1b0eb2..fb6d16f8cc 100644 --- a/modules/scala-akka-http/src/test/scala/tests/generators/akkaHttp/DefinitionSpec.scala +++ b/modules/scala-akka-http/src/test/scala/tests/generators/akkaHttp/DefinitionSpec.scala @@ -4,7 +4,7 @@ import org.scalatest.funsuite.AnyFunSuite import org.scalatest.matchers.should.Matchers import scala.meta._ -import support.SwaggerSpecRunner +import support.{ ScalaMetaMatchers, SwaggerSpecRunner } import dev.guardrail.Context import dev.guardrail.generators.ProtocolDefinitions @@ -12,7 +12,7 @@ import dev.guardrail.generators.scala.ScalaGeneratorMappings.scalaInterpreter import dev.guardrail.generators.scala.syntax.companionForStaticDefns import dev.guardrail.terms.protocol.{ ClassDefinition, EnumDefinition } -class DefinitionSpec extends AnyFunSuite with Matchers with SwaggerSpecRunner { +class DefinitionSpec extends AnyFunSuite with Matchers with SwaggerSpecRunner with ScalaMetaMatchers { val spec = s""" |swagger: "2.0" @@ -92,8 +92,8 @@ class DefinitionSpec extends AnyFunSuite with Matchers with SwaggerSpecRunner { } """ - cls.structure should equal(definition.structure) - cmp.structure should equal(companion.structure) + cls should matchStructure(definition) + cmp should matchStructure(companion) } test("Enumerations should be generated") { @@ -128,8 +128,8 @@ class DefinitionSpec extends AnyFunSuite with Matchers with SwaggerSpecRunner { } """ - cls.structure should equal(definition.structure) - cmp.structure should equal(companion.structure) + cls should matchStructure(definition) + cmp should matchStructure(companion) } test("Camel case conversion should happen") { @@ -152,8 +152,8 @@ class DefinitionSpec extends AnyFunSuite with Matchers with SwaggerSpecRunner { } """ - cls.structure should equal(definition.structure) - cmp.structure should equal(companion.structure) + cls should matchStructure(definition) + cmp should matchStructure(companion) } test("Defaults should work") { @@ -176,7 +176,7 @@ class DefinitionSpec extends AnyFunSuite with Matchers with SwaggerSpecRunner { } """ - cls.structure should equal(definition.structure) - cmp.structure should equal(companion.structure) + cls should matchStructure(definition) + cmp should matchStructure(companion) } } diff --git a/modules/scala-akka-http/src/test/scala/tests/generators/akkaHttp/EnumTest.scala b/modules/scala-akka-http/src/test/scala/tests/generators/akkaHttp/EnumTest.scala index 67876dbca6..48906c203f 100644 --- a/modules/scala-akka-http/src/test/scala/tests/generators/akkaHttp/EnumTest.scala +++ b/modules/scala-akka-http/src/test/scala/tests/generators/akkaHttp/EnumTest.scala @@ -4,7 +4,7 @@ import org.scalatest.funsuite.AnyFunSuite import org.scalatest.matchers.should.Matchers import scala.meta._ -import support.SwaggerSpecRunner +import support.{ ScalaMetaMatchers, SwaggerSpecRunner } import dev.guardrail.Context import dev.guardrail.generators.ProtocolDefinitions @@ -13,7 +13,7 @@ import dev.guardrail.generators.scala.syntax.companionForStaticDefns import dev.guardrail.generators.{ Client, Clients } import dev.guardrail.terms.protocol.EnumDefinition -class EnumTest extends AnyFunSuite with Matchers with SwaggerSpecRunner { +class EnumTest extends AnyFunSuite with Matchers with SwaggerSpecRunner with ScalaMetaMatchers { val spec: String = s""" |swagger: "2.0" @@ -91,8 +91,8 @@ class EnumTest extends AnyFunSuite with Matchers with SwaggerSpecRunner { } """ - cls.structure should equal(definition.structure) - cmp.structure should equal(companion.structure) + cls should matchStructure(definition) + cmp should matchStructure(companion) } test("Use enums") { @@ -132,6 +132,6 @@ class EnumTest extends AnyFunSuite with Matchers with SwaggerSpecRunner { } """ - cls.head.value.structure should equal(client.structure) + cls.head.value should matchStructure(client) } } diff --git a/modules/scala-akka-http/src/test/scala/tests/generators/akkaHttp/PropertyExtractors.scala b/modules/scala-akka-http/src/test/scala/tests/generators/akkaHttp/PropertyExtractors.scala index 041eeb3692..aed5de7a89 100644 --- a/modules/scala-akka-http/src/test/scala/tests/generators/akkaHttp/PropertyExtractors.scala +++ b/modules/scala-akka-http/src/test/scala/tests/generators/akkaHttp/PropertyExtractors.scala @@ -4,7 +4,7 @@ import org.scalatest.funsuite.AnyFunSuite import org.scalatest.matchers.should.Matchers import scala.meta._ -import support.SwaggerSpecRunner +import support.{ ScalaMetaMatchers, SwaggerSpecRunner } import dev.guardrail.Context import dev.guardrail.generators.ProtocolDefinitions @@ -12,7 +12,7 @@ import dev.guardrail.generators.scala.ScalaGeneratorMappings.scalaInterpreter import dev.guardrail.generators.scala.syntax.companionForStaticDefns import dev.guardrail.terms.protocol.ClassDefinition -class PropertyExtractors extends AnyFunSuite with Matchers with SwaggerSpecRunner { +class PropertyExtractors extends AnyFunSuite with Matchers with SwaggerSpecRunner with ScalaMetaMatchers { val spec: String = s""" |swagger: "2.0" |info: @@ -98,7 +98,7 @@ class PropertyExtractors extends AnyFunSuite with Matchers with SwaggerSpecRunne } """ - cls.structure should equal(definition.structure) - cmp.structure should equal(companion.structure) + cls should matchStructure(definition) + cmp should matchStructure(companion) } } diff --git a/modules/scala-akka-http/src/test/scala/tests/generators/akkaHttp/StaticParametersTest.scala b/modules/scala-akka-http/src/test/scala/tests/generators/akkaHttp/StaticParametersTest.scala index cfb5fec2be..031f3c4f96 100644 --- a/modules/scala-akka-http/src/test/scala/tests/generators/akkaHttp/StaticParametersTest.scala +++ b/modules/scala-akka-http/src/test/scala/tests/generators/akkaHttp/StaticParametersTest.scala @@ -3,12 +3,12 @@ package tests.generators.akkaHttp import dev.guardrail.generators.scala.ScalaGeneratorMappings.scalaInterpreter import dev.guardrail.Context import dev.guardrail.generators.{ Server, Servers } -import support.SwaggerSpecRunner +import support.{ ScalaMetaMatchers, SwaggerSpecRunner } import scala.meta._ import org.scalatest.funsuite.AnyFunSuite import org.scalatest.matchers.should.Matchers -class StaticParametersTest extends AnyFunSuite with Matchers with SwaggerSpecRunner { +class StaticParametersTest extends AnyFunSuite with Matchers with SwaggerSpecRunner with ScalaMetaMatchers { val spec: String = s""" |swagger: "2.0" |info: @@ -85,7 +85,7 @@ class StaticParametersTest extends AnyFunSuite with Matchers with SwaggerSpecRun } """ - genHandler.structure should equal(handler.structure) - genResource.structure should equal(resource.structure) + genHandler should matchStructure(handler) + genResource should matchStructure(resource) } } diff --git a/modules/scala-akka-http/src/test/scala/tests/generators/akkaHttp/client/AkkaHttpClientTracingTest.scala b/modules/scala-akka-http/src/test/scala/tests/generators/akkaHttp/client/AkkaHttpClientTracingTest.scala index 8531570a7b..79bdf9b743 100644 --- a/modules/scala-akka-http/src/test/scala/tests/generators/akkaHttp/client/AkkaHttpClientTracingTest.scala +++ b/modules/scala-akka-http/src/test/scala/tests/generators/akkaHttp/client/AkkaHttpClientTracingTest.scala @@ -3,12 +3,12 @@ package tests.generators.akkaHttp.client import dev.guardrail.generators.scala.ScalaGeneratorMappings.scalaInterpreter import dev.guardrail.Context import dev.guardrail.generators.{ Client, Clients } -import support.SwaggerSpecRunner +import support.{ ScalaMetaMatchers, SwaggerSpecRunner } import scala.meta._ import org.scalatest.funsuite.AnyFunSuite import org.scalatest.matchers.should.Matchers -class AkkaHttpClientTracingTest extends AnyFunSuite with Matchers with SwaggerSpecRunner { +class AkkaHttpClientTracingTest extends AnyFunSuite with Matchers with SwaggerSpecRunner with ScalaMetaMatchers { test("Manage child tracing span") { val spec = s""" @@ -64,7 +64,7 @@ class AkkaHttpClientTracingTest extends AnyFunSuite with Matchers with SwaggerSp } """ - cls.head.value.structure should equal(client.structure) + cls.head.value should matchStructure(client) } test("Manage child span with tags") { @@ -120,6 +120,6 @@ class AkkaHttpClientTracingTest extends AnyFunSuite with Matchers with SwaggerSp } """ - cls.head.value.structure should equal(client.structure) + cls.head.value should matchStructure(client) } } diff --git a/modules/scala-akka-http/src/test/scala/tests/generators/akkaHttp/client/BasicTest.scala b/modules/scala-akka-http/src/test/scala/tests/generators/akkaHttp/client/BasicTest.scala index a1ccd7aac5..f350947f37 100644 --- a/modules/scala-akka-http/src/test/scala/tests/generators/akkaHttp/client/BasicTest.scala +++ b/modules/scala-akka-http/src/test/scala/tests/generators/akkaHttp/client/BasicTest.scala @@ -4,7 +4,7 @@ import org.scalatest.funsuite.AnyFunSuite import org.scalatest.matchers.should.Matchers import scala.meta._ -import support.SwaggerSpecRunner +import support.{ ScalaMetaMatchers, SwaggerSpecRunner } import dev.guardrail.Context import dev.guardrail.generators.ProtocolDefinitions @@ -13,7 +13,7 @@ import dev.guardrail.generators.scala.syntax.companionForStaticDefns import dev.guardrail.generators.{ Client, Clients } import dev.guardrail.terms.protocol.{ ClassDefinition, RandomType } -class BasicTest extends AnyFunSuite with Matchers with SwaggerSpecRunner { +class BasicTest extends AnyFunSuite with Matchers with SwaggerSpecRunner with ScalaMetaMatchers { val spec: String = s""" |swagger: "2.0" |info: @@ -81,7 +81,7 @@ class BasicTest extends AnyFunSuite with Matchers with SwaggerSpecRunner { _ ) = runSwaggerSpec(scalaInterpreter)(spec)(Context.empty, "akka-http") - tpe.structure should equal(t"io.circe.Json".structure) + tpe should matchStructure(t"io.circe.Json") } test("Handle json subvalues") { @@ -105,8 +105,8 @@ class BasicTest extends AnyFunSuite with Matchers with SwaggerSpecRunner { } """ - cls.structure should equal(definition.structure) - cmp.structure should equal(companion.structure) + cls should matchStructure(definition) + cmp should matchStructure(companion) } test("Properly handle all methods") { @@ -217,6 +217,6 @@ class BasicTest extends AnyFunSuite with Matchers with SwaggerSpecRunner { } """ - cls.head.value.structure should equal(client.structure) + cls.head.value should matchStructure(client) } } diff --git a/modules/scala-akka-http/src/test/scala/tests/generators/akkaHttp/client/DefaultParametersTest.scala b/modules/scala-akka-http/src/test/scala/tests/generators/akkaHttp/client/DefaultParametersTest.scala index 3d03396a2f..b4b8d094b7 100644 --- a/modules/scala-akka-http/src/test/scala/tests/generators/akkaHttp/client/DefaultParametersTest.scala +++ b/modules/scala-akka-http/src/test/scala/tests/generators/akkaHttp/client/DefaultParametersTest.scala @@ -4,11 +4,11 @@ import dev.guardrail.generators.scala.ScalaGeneratorMappings.scalaInterpreter import dev.guardrail.generators.scala.syntax.companionForStaticDefns import dev.guardrail.Context import dev.guardrail.generators.{ Client, Clients } -import support.SwaggerSpecRunner +import support.{ ScalaMetaMatchers, SwaggerSpecRunner } import org.scalatest.funsuite.AnyFunSuite import org.scalatest.matchers.should.Matchers -class DefaultParametersTest extends AnyFunSuite with Matchers with SwaggerSpecRunner { +class DefaultParametersTest extends AnyFunSuite with Matchers with SwaggerSpecRunner with ScalaMetaMatchers { import scala.meta._ val spec = s""" @@ -188,7 +188,7 @@ class DefaultParametersTest extends AnyFunSuite with Matchers with SwaggerSpecRu } """ - cmp.structure should equal(companion.structure) - cls.head.value.structure should equal(client.structure) + cmp should matchStructure(companion) + cls.head.value should matchStructure(client) } } diff --git a/modules/scala-akka-http/src/test/scala/tests/generators/akkaHttp/client/FormFieldsTest.scala b/modules/scala-akka-http/src/test/scala/tests/generators/akkaHttp/client/FormFieldsTest.scala index d4172b789b..c459f064a8 100644 --- a/modules/scala-akka-http/src/test/scala/tests/generators/akkaHttp/client/FormFieldsTest.scala +++ b/modules/scala-akka-http/src/test/scala/tests/generators/akkaHttp/client/FormFieldsTest.scala @@ -3,12 +3,12 @@ package tests.generators.akkaHttp.client import dev.guardrail.generators.scala.ScalaGeneratorMappings.scalaInterpreter import dev.guardrail.Context import dev.guardrail.generators.{ Client, Clients } -import support.SwaggerSpecRunner +import support.{ ScalaMetaMatchers, SwaggerSpecRunner } import scala.meta._ import org.scalatest.funsuite.AnyFunSuite import org.scalatest.matchers.should.Matchers -class FormFieldsTest extends AnyFunSuite with Matchers with SwaggerSpecRunner { +class FormFieldsTest extends AnyFunSuite with Matchers with SwaggerSpecRunner with ScalaMetaMatchers { val spec: String = s""" |swagger: "2.0" |info: @@ -77,6 +77,6 @@ class FormFieldsTest extends AnyFunSuite with Matchers with SwaggerSpecRunner { } """ - cls.head.value.structure should equal(client.structure) + cls.head.value should matchStructure(client) } } diff --git a/modules/scala-akka-http/src/test/scala/tests/generators/akkaHttp/client/HardcodedQSSpec.scala b/modules/scala-akka-http/src/test/scala/tests/generators/akkaHttp/client/HardcodedQSSpec.scala index 328a3d698c..23a01699b3 100644 --- a/modules/scala-akka-http/src/test/scala/tests/generators/akkaHttp/client/HardcodedQSSpec.scala +++ b/modules/scala-akka-http/src/test/scala/tests/generators/akkaHttp/client/HardcodedQSSpec.scala @@ -3,12 +3,12 @@ package tests.generators.akkaHttp.client import dev.guardrail.generators.scala.ScalaGeneratorMappings.scalaInterpreter import dev.guardrail.Context import dev.guardrail.generators.{ Client, Clients } -import support.SwaggerSpecRunner +import support.{ ScalaMetaMatchers, SwaggerSpecRunner } import scala.meta._ import org.scalatest.funsuite.AnyFunSuite import org.scalatest.matchers.should.Matchers -class HardcodedQSSpec extends AnyFunSuite with Matchers with SwaggerSpecRunner { +class HardcodedQSSpec extends AnyFunSuite with Matchers with SwaggerSpecRunner with ScalaMetaMatchers { val spec: String = s""" |swagger: "2.0" |info: @@ -91,6 +91,6 @@ class HardcodedQSSpec extends AnyFunSuite with Matchers with SwaggerSpecRunner { } """ - cls.head.value.structure should equal(client.structure) + cls.head.value should matchStructure(client) } } diff --git a/modules/scala-akka-http/src/test/scala/tests/generators/akkaHttp/client/HttpBodiesTest.scala b/modules/scala-akka-http/src/test/scala/tests/generators/akkaHttp/client/HttpBodiesTest.scala index e78781614e..6be18170f2 100644 --- a/modules/scala-akka-http/src/test/scala/tests/generators/akkaHttp/client/HttpBodiesTest.scala +++ b/modules/scala-akka-http/src/test/scala/tests/generators/akkaHttp/client/HttpBodiesTest.scala @@ -3,12 +3,12 @@ package tests.generators.akkaHttp.client import dev.guardrail.generators.scala.ScalaGeneratorMappings.scalaInterpreter import dev.guardrail.Context import dev.guardrail.generators.{ Client, Clients } -import support.SwaggerSpecRunner +import support.{ ScalaMetaMatchers, SwaggerSpecRunner } import scala.meta._ import org.scalatest.funsuite.AnyFunSuite import org.scalatest.matchers.should.Matchers -class HttpBodiesTest extends AnyFunSuite with Matchers with SwaggerSpecRunner { +class HttpBodiesTest extends AnyFunSuite with Matchers with SwaggerSpecRunner with ScalaMetaMatchers { val spec: String = s""" |swagger: "2.0" |info: @@ -165,6 +165,6 @@ class HttpBodiesTest extends AnyFunSuite with Matchers with SwaggerSpecRunner { } """ - cls.head.value.structure should equal(client.structure) + cls.head.value should matchStructure(client) } } diff --git a/modules/scala-akka-http/src/test/scala/tests/generators/akkaHttp/client/MultipartTest.scala b/modules/scala-akka-http/src/test/scala/tests/generators/akkaHttp/client/MultipartTest.scala index 12c09c7e50..02b28ae60c 100644 --- a/modules/scala-akka-http/src/test/scala/tests/generators/akkaHttp/client/MultipartTest.scala +++ b/modules/scala-akka-http/src/test/scala/tests/generators/akkaHttp/client/MultipartTest.scala @@ -3,12 +3,12 @@ package tests.generators.akkaHttp.client import dev.guardrail.generators.scala.ScalaGeneratorMappings.scalaInterpreter import dev.guardrail.Context import dev.guardrail.generators.{ Client, Clients } -import support.SwaggerSpecRunner +import support.{ ScalaMetaMatchers, SwaggerSpecRunner } import scala.meta._ import org.scalatest.funsuite.AnyFunSuite import org.scalatest.matchers.should.Matchers -class MultipartTest extends AnyFunSuite with Matchers with SwaggerSpecRunner { +class MultipartTest extends AnyFunSuite with Matchers with SwaggerSpecRunner with ScalaMetaMatchers { val spec: String = s""" |swagger: "2.0" |info: @@ -85,6 +85,6 @@ class MultipartTest extends AnyFunSuite with Matchers with SwaggerSpecRunner { } """ - cls.head.value.structure should equal(client.structure) + cls.head.value should matchStructure(client) } } diff --git a/modules/scala-akka-http/src/test/scala/tests/generators/akkaHttp/client/ParamConflictsTest.scala b/modules/scala-akka-http/src/test/scala/tests/generators/akkaHttp/client/ParamConflictsTest.scala index ff024712aa..88bd42811b 100644 --- a/modules/scala-akka-http/src/test/scala/tests/generators/akkaHttp/client/ParamConflictsTest.scala +++ b/modules/scala-akka-http/src/test/scala/tests/generators/akkaHttp/client/ParamConflictsTest.scala @@ -4,7 +4,7 @@ import org.scalatest.funsuite.AnyFunSuite import org.scalatest.matchers.should.Matchers import scala.meta._ -import support.SwaggerSpecRunner +import support.{ ScalaMetaMatchers, SwaggerSpecRunner } import dev.guardrail.Context import dev.guardrail.generators.ProtocolDefinitions @@ -13,7 +13,7 @@ import dev.guardrail.generators.scala.syntax.companionForStaticDefns import dev.guardrail.generators.{ Client, Clients } import dev.guardrail.terms.protocol.ClassDefinition -class ParamConflictsTest extends AnyFunSuite with Matchers with SwaggerSpecRunner { +class ParamConflictsTest extends AnyFunSuite with Matchers with SwaggerSpecRunner with ScalaMetaMatchers { val spec = s""" |swagger: "2.0" @@ -82,7 +82,7 @@ class ParamConflictsTest extends AnyFunSuite with Matchers with SwaggerSpecRunne } """ - cls.head.value.structure should equal(client.structure) + cls.head.value should matchStructure(client) } test("Generate non-conflicting names in definitions") { @@ -105,7 +105,7 @@ class ParamConflictsTest extends AnyFunSuite with Matchers with SwaggerSpecRunne } """ - cls.structure should equal(definition.structure) - cmp.structure should equal(companion.structure) + cls should matchStructure(definition) + cmp should matchStructure(companion) } } diff --git a/modules/scala-akka-http/src/test/scala/tests/generators/akkaHttp/client/SchemeTest.scala b/modules/scala-akka-http/src/test/scala/tests/generators/akkaHttp/client/SchemeTest.scala index efe65003f8..584bce92d7 100644 --- a/modules/scala-akka-http/src/test/scala/tests/generators/akkaHttp/client/SchemeTest.scala +++ b/modules/scala-akka-http/src/test/scala/tests/generators/akkaHttp/client/SchemeTest.scala @@ -4,12 +4,12 @@ import dev.guardrail.generators.scala.ScalaGeneratorMappings.scalaInterpreter import dev.guardrail.generators.scala.syntax._ import dev.guardrail.Context import dev.guardrail.generators.{ Client, Clients } -import support.SwaggerSpecRunner +import support.{ ScalaMetaMatchers, SwaggerSpecRunner } import scala.meta._ import org.scalatest.funsuite.AnyFunSuite import org.scalatest.matchers.should.Matchers -class SchemeTest extends AnyFunSuite with Matchers with SwaggerSpecRunner { +class SchemeTest extends AnyFunSuite with Matchers with SwaggerSpecRunner with ScalaMetaMatchers { val spec: String = s""" |swagger: "2.0" @@ -77,7 +77,7 @@ class SchemeTest extends AnyFunSuite with Matchers with SwaggerSpecRunner { } """ - cmp.structure should equal(companion.structure) - cls.head.value.structure should equal(client.structure) + cmp should matchStructure(companion) + cls.head.value should matchStructure(client) } } diff --git a/modules/scala-akka-http/src/test/scala/tests/generators/akkaHttp/client/contentType/TextPlainTest.scala b/modules/scala-akka-http/src/test/scala/tests/generators/akkaHttp/client/contentType/TextPlainTest.scala index ffb7f0337f..1b5827606f 100644 --- a/modules/scala-akka-http/src/test/scala/tests/generators/akkaHttp/client/contentType/TextPlainTest.scala +++ b/modules/scala-akka-http/src/test/scala/tests/generators/akkaHttp/client/contentType/TextPlainTest.scala @@ -4,12 +4,12 @@ import dev.guardrail.generators.scala.ScalaGeneratorMappings.scalaInterpreter import dev.guardrail.generators.scala.syntax.companionForStaticDefns import dev.guardrail.Context import dev.guardrail.generators.{ Client, Clients } -import support.SwaggerSpecRunner +import support.{ ScalaMetaMatchers, SwaggerSpecRunner } import scala.meta._ import org.scalatest.funsuite.AnyFunSuite import org.scalatest.matchers.should.Matchers -class TextPlainTest extends AnyFunSuite with Matchers with SwaggerSpecRunner { +class TextPlainTest extends AnyFunSuite with Matchers with SwaggerSpecRunner with ScalaMetaMatchers { val spec: String = s""" |swagger: "2.0" |info: @@ -75,7 +75,7 @@ class TextPlainTest extends AnyFunSuite with Matchers with SwaggerSpecRunner { } """ - cmp.structure should equal(companion.structure) - cls.head.value.structure should equal(client.structure) + cmp should matchStructure(companion) + cls.head.value should matchStructure(client) } } diff --git a/modules/scala-akka-http/src/test/scala/tests/generators/akkaHttp/server/FormFieldsTest.scala b/modules/scala-akka-http/src/test/scala/tests/generators/akkaHttp/server/FormFieldsTest.scala index 9de20c7563..e1a5f020cd 100644 --- a/modules/scala-akka-http/src/test/scala/tests/generators/akkaHttp/server/FormFieldsTest.scala +++ b/modules/scala-akka-http/src/test/scala/tests/generators/akkaHttp/server/FormFieldsTest.scala @@ -3,11 +3,11 @@ package tests.generators.akkaHttp.server import dev.guardrail.generators.scala.ScalaGeneratorMappings.scalaInterpreter import dev.guardrail.Context import dev.guardrail.generators.{ Server, Servers } -import support.SwaggerSpecRunner +import support.{ ScalaMetaMatchers, SwaggerSpecRunner } import org.scalatest.funsuite.AnyFunSuite import org.scalatest.matchers.should.Matchers -class FormFieldsServerTest extends AnyFunSuite with Matchers with SwaggerSpecRunner { +class FormFieldsServerTest extends AnyFunSuite with Matchers with SwaggerSpecRunner with ScalaMetaMatchers { import scala.meta._ val spec: String = s""" @@ -196,7 +196,7 @@ class FormFieldsServerTest extends AnyFunSuite with Matchers with SwaggerSpecRun } """ - genHandler.structure shouldEqual handler.structure - genResource.structure shouldEqual resource.structure + genHandler should matchStructure(handler) + genResource should matchStructure(resource) } } diff --git a/modules/scala-http4s/src/test/scala/core/issues/Issue166.scala b/modules/scala-http4s/src/test/scala/core/issues/Issue166.scala index da73535d0f..a6a7c9fc85 100644 --- a/modules/scala-http4s/src/test/scala/core/issues/Issue166.scala +++ b/modules/scala-http4s/src/test/scala/core/issues/Issue166.scala @@ -7,7 +7,7 @@ import org.scalatest.funsuite.AnyFunSuite import org.scalatest.matchers.should.Matchers import scala.meta._ -import support.SwaggerSpecRunner +import support.{ ScalaMetaMatchers, SwaggerSpecRunner } import dev.guardrail._ import dev.guardrail.core.Tracker @@ -17,7 +17,7 @@ import dev.guardrail.generators.scala.ScalaGeneratorMappings.scalaInterpreter import dev.guardrail.generators.scala.http4s.Http4sVersion import dev.guardrail.terms.protocol.ClassDefinition -class Issue166 extends AnyFunSuite with Matchers with SwaggerSpecRunner { +class Issue166 extends AnyFunSuite with Matchers with SwaggerSpecRunner with ScalaMetaMatchers { val spec = s""" |swagger: "2.0" @@ -71,7 +71,7 @@ class Issue166 extends AnyFunSuite with Matchers with SwaggerSpecRunner { case class Blix(map: String) """ - cls.structure should equal(definition.structure) + cls should matchStructure(definition) } testVersion(Http4sVersion.V0_22) diff --git a/modules/scala-http4s/src/test/scala/tests/core/FullyQualifiedNames.scala b/modules/scala-http4s/src/test/scala/tests/core/FullyQualifiedNames.scala index 23c398be93..3803e135d3 100644 --- a/modules/scala-http4s/src/test/scala/tests/core/FullyQualifiedNames.scala +++ b/modules/scala-http4s/src/test/scala/tests/core/FullyQualifiedNames.scala @@ -50,7 +50,7 @@ class FullyQualifiedNames extends AnyFunSuite with Matchers with SwaggerSpecRunn ) = runSwaggerSpec(scalaInterpreter)(spec, List("_root_", "com", "test"))(Context.empty, version.value) clz.fullType shouldEqual t"_root_.com.test.User" - client.head.toOption.get shouldEqual q""" + client.head.toOption.get should matchStructure(q""" class Client[F[_]](host: String)(implicit F: Async[F], httpClient: Http4sClient[F]) { val basePath: String = "" private def parseOptionalHeader(response: Response[F], header: String): F[Option[String]] = F.pure(response.headers.get(CIString(header)).map(_.head.value)) @@ -67,7 +67,7 @@ class FullyQualifiedNames extends AnyFunSuite with Matchers with SwaggerSpecRunn }) } } - """ + """) respTrait shouldEqual q""" diff --git a/modules/scala-http4s/src/test/scala/tests/generators/http4s/BasicTest.scala b/modules/scala-http4s/src/test/scala/tests/generators/http4s/BasicTest.scala index 1dbe00a3a7..558884b0ad 100644 --- a/modules/scala-http4s/src/test/scala/tests/generators/http4s/BasicTest.scala +++ b/modules/scala-http4s/src/test/scala/tests/generators/http4s/BasicTest.scala @@ -4,7 +4,7 @@ import org.scalatest.funsuite.AnyFunSuite import org.scalatest.matchers.should.Matchers import scala.meta._ -import support.SwaggerSpecRunner +import support.{ ScalaMetaMatchers, SwaggerSpecRunner } import dev.guardrail.Context import dev.guardrail.generators.ProtocolDefinitions @@ -14,7 +14,7 @@ import dev.guardrail.generators.scala.syntax.companionForStaticDefns import dev.guardrail.generators.{ Client, Clients } import dev.guardrail.terms.protocol.{ ClassDefinition, RandomType } -class BasicTest extends AnyFunSuite with Matchers with SwaggerSpecRunner { +class BasicTest extends AnyFunSuite with Matchers with SwaggerSpecRunner with ScalaMetaMatchers { val spec = s""" |swagger: "2.0" |info: @@ -83,7 +83,7 @@ class BasicTest extends AnyFunSuite with Matchers with SwaggerSpecRunner { _ ) = runSwaggerSpec(scalaInterpreter)(spec)(Context.empty, version.value) - tpe.structure should equal(t"io.circe.Json".structure) + tpe should matchStructure(t"io.circe.Json") } test(s"$version - Handle json subvalues") { @@ -107,8 +107,8 @@ class BasicTest extends AnyFunSuite with Matchers with SwaggerSpecRunner { } """ - cls.structure should equal(definition.structure) - cmp.structure should equal(companion.structure) + cls should matchStructure(definition) + cmp should matchStructure(companion) } test(s"$version - Properly handle all methods") { @@ -261,9 +261,9 @@ class BasicTest extends AnyFunSuite with Matchers with SwaggerSpecRunner { q"""object DeleteFooResponse { case object Ok extends DeleteFooResponse }""" ) - expected.zip(statements).foreach { case (a, b) => a.structure should equal(b.structure) } - cmp.structure should equal(companion.structure) - cls.head.value.structure should equal(client.structure) + expected.zip(statements).foreach { case (a, b) => a should matchStructure(b) } + cmp should matchStructure(companion) + cls.head.value should matchStructure(client) } } diff --git a/modules/scala-http4s/src/test/scala/tests/generators/http4s/Http4sServerTest.scala b/modules/scala-http4s/src/test/scala/tests/generators/http4s/Http4sServerTest.scala index 228dc4c336..a7e32be2ce 100644 --- a/modules/scala-http4s/src/test/scala/tests/generators/http4s/Http4sServerTest.scala +++ b/modules/scala-http4s/src/test/scala/tests/generators/http4s/Http4sServerTest.scala @@ -4,11 +4,11 @@ import dev.guardrail.generators.scala.ScalaGeneratorMappings.scalaInterpreter import dev.guardrail.generators.scala.http4s.Http4sVersion import dev.guardrail.Context import dev.guardrail.generators.{ Server, Servers } -import support.SwaggerSpecRunner +import support.{ ScalaMetaMatchers, SwaggerSpecRunner } import org.scalatest.funsuite.AnyFunSuite import org.scalatest.matchers.should.Matchers -class Http4sServerTest extends AnyFunSuite with Matchers with SwaggerSpecRunner { +class Http4sServerTest extends AnyFunSuite with Matchers with SwaggerSpecRunner with ScalaMetaMatchers { import scala.meta._ @@ -211,8 +211,8 @@ class Http4sServerTest extends AnyFunSuite with Matchers with SwaggerSpecRunner } """ - genHandler.structure shouldEqual handler.structure - genResource.structure should equal(resource.structure) + genHandler should matchStructure(handler) + genResource should matchStructure(resource) } test(s"$version - Ensure routes are generated with tracing") { @@ -302,8 +302,8 @@ class Http4sServerTest extends AnyFunSuite with Matchers with SwaggerSpecRunner } """ - genHandler.structure should equal(handler.structure) - genResource.structure should equal(resource.structure) + genHandler should matchStructure(handler) + genResource should matchStructure(resource) } test(s"$version - Ensure routes are generated with custom extraction") { @@ -392,8 +392,8 @@ class Http4sServerTest extends AnyFunSuite with Matchers with SwaggerSpecRunner } """ - genHandler.structure should equal(handler.structure) - genResource.structure should equal(resource.structure) + genHandler should matchStructure(handler) + genResource should matchStructure(resource) } } diff --git a/modules/scala-http4s/src/test/scala/tests/generators/http4s/client/DefaultParametersTest.scala b/modules/scala-http4s/src/test/scala/tests/generators/http4s/client/DefaultParametersTest.scala index 5b744b8888..4b02dfdbe2 100644 --- a/modules/scala-http4s/src/test/scala/tests/generators/http4s/client/DefaultParametersTest.scala +++ b/modules/scala-http4s/src/test/scala/tests/generators/http4s/client/DefaultParametersTest.scala @@ -5,11 +5,11 @@ import dev.guardrail.generators.scala.http4s.Http4sVersion import dev.guardrail.generators.scala.syntax.companionForStaticDefns import dev.guardrail.Context import dev.guardrail.generators.{ Client, Clients } -import support.SwaggerSpecRunner +import support.{ ScalaMetaMatchers, SwaggerSpecRunner } import org.scalatest.funsuite.AnyFunSuite import org.scalatest.matchers.should.Matchers -class DefaultParametersTest extends AnyFunSuite with Matchers with SwaggerSpecRunner { +class DefaultParametersTest extends AnyFunSuite with Matchers with SwaggerSpecRunner with ScalaMetaMatchers { import scala.meta._ val spec: String = s""" @@ -206,10 +206,10 @@ class DefaultParametersTest extends AnyFunSuite with Matchers with SwaggerSpecRu }""" ) - cls.head.value.structure should equal(clientClass.structure) - cmp.structure should equal(clientCompanion.structure) + cls.head.value should matchStructure(clientClass) + cmp should matchStructure(clientCompanion) - statements.zip(expected).foreach { case (a, b) => a.structure should equal(b.structure) } + statements.zip(expected).foreach { case (a, b) => a should matchStructure(b) } } testVersion(Http4sVersion.V0_22) diff --git a/modules/scala-support/src/test/scala/tests/circe/ArrayValidationTest.scala b/modules/scala-support/src/test/scala/tests/circe/ArrayValidationTest.scala index 71181ec6fe..e4fd6d84f6 100644 --- a/modules/scala-support/src/test/scala/tests/circe/ArrayValidationTest.scala +++ b/modules/scala-support/src/test/scala/tests/circe/ArrayValidationTest.scala @@ -17,9 +17,9 @@ import dev.guardrail.terms.protocol.PropertyRequirement import org.scalatest.freespec.AnyFreeSpec import org.scalatest.matchers.should.Matchers import scala.meta._ -import support.SwaggerSpecRunner +import support.{ ScalaMetaMatchers, SwaggerSpecRunner } -class ArrayValidationTest extends AnyFreeSpec with Matchers with SwaggerSpecRunner { +class ArrayValidationTest extends AnyFreeSpec with Matchers with SwaggerSpecRunner with ScalaMetaMatchers { val spec: String = s""" @@ -111,7 +111,7 @@ class ArrayValidationTest extends AnyFreeSpec with Matchers with SwaggerSpecRunn _root_.eu.timepit.refined.collection.Size[_root_.eu.timepit.refined.numeric.Interval.Closed[_root_.shapeless.Witness.`1`.T, _root_.shapeless.Witness.`10`.T]]] = None, shouldNotCollide: Option[String Refined _root_.eu.timepit.refined.string.MatchesRegex[ValidatedCollections.`".*pet.*"`.T]] = None)""" - cls.structure should equal(expected.structure) + cls should matchStructure(expected) } @@ -130,7 +130,7 @@ class ArrayValidationTest extends AnyFreeSpec with Matchers with SwaggerSpecRunn q"""case class ValidatedCollections(boundedSizeArray: Option[Vector[Int Refined _root_.eu.timepit.refined.numeric.GreaterEqual[_root_.shapeless.Witness.`1`.T]] Refined _root_.eu.timepit.refined.collection.Size[_root_.eu.timepit.refined.numeric.Interval.Closed[_root_.shapeless.Witness.`1`.T, _root_.shapeless.Witness.`10`.T]]] = None)""" - cls.structure should equal(expected.structure) + cls should matchStructure(expected) } } diff --git a/modules/scala-support/src/test/scala/tests/circe/BigObjectSpec.scala b/modules/scala-support/src/test/scala/tests/circe/BigObjectSpec.scala index 4e920ea066..38bab41d49 100644 --- a/modules/scala-support/src/test/scala/tests/circe/BigObjectSpec.scala +++ b/modules/scala-support/src/test/scala/tests/circe/BigObjectSpec.scala @@ -6,7 +6,7 @@ import scala.meta._ import org.scalatest.funsuite.AnyFunSuite import org.scalatest.matchers.should.Matchers -import support.SwaggerSpecRunner +import support.{ ScalaMetaMatchers, SwaggerSpecRunner } import dev.guardrail.Target import dev.guardrail.core.Tracker @@ -22,7 +22,7 @@ import dev.guardrail.terms.framework.FrameworkTerms import dev.guardrail.terms.protocol.ClassDefinition import dev.guardrail.terms.protocol.PropertyRequirement -class BigObjectSpec extends AnyFunSuite with Matchers with SwaggerSpecRunner { +class BigObjectSpec extends AnyFunSuite with Matchers with SwaggerSpecRunner with ScalaMetaMatchers { val spec: String = s""" |swagger: "2.0" @@ -202,7 +202,7 @@ class BigObjectSpec extends AnyFunSuite with Matchers with SwaggerSpecRunner { } """ - cls.structure should equal(definition.structure) - cmp.structure should equal(companion.structure) + cls should matchStructure(definition) + cmp should matchStructure(companion) } } diff --git a/modules/scala-support/src/test/scala/tests/circe/ValidationTest.scala b/modules/scala-support/src/test/scala/tests/circe/ValidationTest.scala index 4e6ffc03ba..b4db0e30a8 100644 --- a/modules/scala-support/src/test/scala/tests/circe/ValidationTest.scala +++ b/modules/scala-support/src/test/scala/tests/circe/ValidationTest.scala @@ -17,9 +17,9 @@ import dev.guardrail.terms.protocol.PropertyRequirement import org.scalatest.freespec.AnyFreeSpec import org.scalatest.matchers.should.Matchers import scala.meta._ -import support.SwaggerSpecRunner +import support.{ ScalaMetaMatchers, SwaggerSpecRunner } -class ValidationTest extends AnyFreeSpec with Matchers with SwaggerSpecRunner { +class ValidationTest extends AnyFreeSpec with Matchers with SwaggerSpecRunner with ScalaMetaMatchers { val spec: String = s""" @@ -82,7 +82,7 @@ class ValidationTest extends AnyFreeSpec with Matchers with SwaggerSpecRunner { q"""case class ValidatedObject(v1: Option[Int Refined _root_.eu.timepit.refined.numeric.Interval.Closed[_root_.shapeless.Witness.`1`.T, _root_.shapeless.Witness.`100`.T]] = Option(10), v2: Option[String Refined _root_.eu.timepit.refined.string.MatchesRegex[ValidatedObject.`".*[0-9]+.*"`.T]] = None)""" - cls.structure should equal(expected.structure) + cls should matchStructure(expected) } } diff --git a/src/test/scala/tests/core/BacktickTest.scala b/src/test/scala/tests/core/BacktickTest.scala index aecadb8d40..7f9db66d3c 100644 --- a/src/test/scala/tests/core/BacktickTest.scala +++ b/src/test/scala/tests/core/BacktickTest.scala @@ -4,7 +4,7 @@ import scala.meta._ import org.scalatest.funsuite.AnyFunSuite import org.scalatest.matchers.should.Matchers -import support.SwaggerSpecRunner +import support.{ ScalaMetaMatchers, SwaggerSpecRunner } import dev.guardrail.Context import dev.guardrail.generators.scala.syntax.companionForStaticDefns @@ -12,7 +12,7 @@ import dev.guardrail.generators.{ Client, Clients, ProtocolDefinitions } import dev.guardrail.terms.protocol.{ ClassDefinition, EnumDefinition } import dev.guardrail.generators.scala.ScalaGeneratorMappings.scalaInterpreter -class BacktickTest extends AnyFunSuite with Matchers with SwaggerSpecRunner { +class BacktickTest extends AnyFunSuite with Matchers with SwaggerSpecRunner with ScalaMetaMatchers { val spec = s""" |swagger: "2.0" @@ -123,7 +123,7 @@ class BacktickTest extends AnyFunSuite with Matchers with SwaggerSpecRunner { } """ - cls.head.value.structure should equal(client.structure) + cls.head.value should matchStructure (client) cls.head.value.toString should include("class DashyPackageClient") cls.head.value.toString should include("def dashyOpId") cls.head.value.toString should include("dashyParameter: String") @@ -161,12 +161,12 @@ class BacktickTest extends AnyFunSuite with Matchers with SwaggerSpecRunner { } """ - cls.structure should equal(definition.structure) + cls should matchStructure (definition) cls.toString should include("case class DashyClass") cls.toString should include("dashyParam") cls.toString shouldNot include("``") - cmp.structure should equal(companion.structure) + cmp should matchStructure (companion) cmp.toString should include("encodeDashyClass") cmp.toString should include("decodeDashyClass") cmp.toString should include("DashyClass(v0)") @@ -208,11 +208,11 @@ class BacktickTest extends AnyFunSuite with Matchers with SwaggerSpecRunner { } """ - cls.structure should equal(definition.structure) + cls should matchStructure (definition) cls.toString should include("sealed abstract class DashyEnum") cls.toString shouldNot include("``") - cmp.structure should equal(companion.structure) + cmp should matchStructure (companion) cmp.toString should include("val DashyValueA") cmp.toString should include("case object DashyValueB") cmp.toString should include("encodeDashyEnum") diff --git a/src/test/scala/tests/core/DereferencingAliasesSpec.scala b/src/test/scala/tests/core/DereferencingAliasesSpec.scala index e98bc19ba6..64ec91f8aa 100644 --- a/src/test/scala/tests/core/DereferencingAliasesSpec.scala +++ b/src/test/scala/tests/core/DereferencingAliasesSpec.scala @@ -4,7 +4,7 @@ import scala.meta._ import org.scalatest.funsuite.AnyFunSuite import org.scalatest.matchers.should.Matchers -import support.SwaggerSpecRunner +import support.{ ScalaMetaMatchers, SwaggerSpecRunner } import dev.guardrail.Context import dev.guardrail.generators.ProtocolDefinitions @@ -13,7 +13,7 @@ import dev.guardrail.generators.scala.syntax.companionForStaticDefns import dev.guardrail.generators.{ Client, Clients } import dev.guardrail.terms.protocol.ClassDefinition -class DereferencingAliasesSpec extends AnyFunSuite with Matchers with SwaggerSpecRunner { +class DereferencingAliasesSpec extends AnyFunSuite with Matchers with SwaggerSpecRunner with ScalaMetaMatchers { val spec = s""" |swagger: "2.0" @@ -197,10 +197,10 @@ class DereferencingAliasesSpec extends AnyFunSuite with Matchers with SwaggerSpe } """ - cls.structure should equal(definition.structure) - cmp.structure should equal(companion.structure) - clientCmp.structure should equal(clientCompanion.structure) - clientCls.head.value.structure should equal(client.structure) + cls should matchStructure (definition) + cmp should matchStructure (companion) + clientCmp should matchStructure (clientCompanion) + clientCls.head.value should matchStructure (client) } test("All types should be dereferenced (OpenAPI)") { @@ -263,9 +263,9 @@ class DereferencingAliasesSpec extends AnyFunSuite with Matchers with SwaggerSpe } """ - cls.structure should equal(definition.structure) - cmp.structure should equal(companion.structure) - clientCmp.structure should equal(clientCompanion.structure) - clientCls.head.value.structure should equal(client.structure) + cls should matchStructure (definition) + cmp should matchStructure (companion) + clientCmp should matchStructure (clientCompanion) + clientCls.head.value should matchStructure (client) } } From ffb7f3a508c0d07ed57644a0ce5b1eace585f442 Mon Sep 17 00:00:00 2001 From: Scala Steward Date: Tue, 26 Sep 2023 15:35:23 +0000 Subject: [PATCH 3/5] Update scalameta to 4.8.11 --- project/src/main/scala/modules/scalaSupport.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/project/src/main/scala/modules/scalaSupport.scala b/project/src/main/scala/modules/scalaSupport.scala index 11273c82e5..1537f15918 100644 --- a/project/src/main/scala/modules/scalaSupport.scala +++ b/project/src/main/scala/modules/scalaSupport.scala @@ -9,6 +9,6 @@ object scalaSupport { val project = commonModule("scala-support") .settings( - libraryDependencies += "org.scalameta" %% "scalameta" % "4.5.13" + libraryDependencies += "org.scalameta" %% "scalameta" % "4.8.11" ) } From a705fbc2bf4036aabb1e9cddd9616fdb42cf8a8e Mon Sep 17 00:00:00 2001 From: Devon Stewart Date: Tue, 10 Oct 2023 22:59:01 -0700 Subject: [PATCH 4/5] Exciting Clause related alterations --- .../src/main/scala/DocsHelpers.scala | 2 +- .../akkaHttp/AkkaHttpClientGenerator.scala | 20 +++++----- .../akkaHttp/AkkaHttpServerGenerator.scala | 29 +++++++++----- .../DropwizardServerGenerator.scala | 27 +++++++------ .../scala/http4s/Http4sClientGenerator.scala | 21 +++++----- .../scala/http4s/Http4sServerGenerator.scala | 15 +++---- .../generators/scala/ResponseADTHelper.scala | 4 +- .../circe/CirceRefinedProtocolGenerator.scala | 2 +- .../jackson/JacksonProtocolGenerator.scala | 11 ++++-- .../helpers/JacksonHelpersTest.scala | 6 ++- .../scala/tests/core/EscapeTreeSpec.scala | 2 +- .../server/DropwizardScalaJsr310Test.scala | 39 +++++++++++-------- 12 files changed, 102 insertions(+), 76 deletions(-) diff --git a/modules/microsite/src/main/scala/DocsHelpers.scala b/modules/microsite/src/main/scala/DocsHelpers.scala index df639e59ee..c44d4f3a22 100644 --- a/modules/microsite/src/main/scala/DocsHelpers.scala +++ b/modules/microsite/src/main/scala/DocsHelpers.scala @@ -98,7 +98,7 @@ object DocsHelpers { q""" def routes(...${parms}): ${rtpe} = ${Term.Apply( fun = q"HttpRoutes.of", - args = List(Term.Block(stats = List(Term.PartialFunction(cases = cases.take(2))))) + argClause = Term.ArgClause(List(Term.Block(stats = List(Term.PartialFunction(cases = cases.take(2)))))) )} """ }.toList diff --git a/modules/scala-akka-http/src/main/scala/dev/guardrail/generators/scala/akkaHttp/AkkaHttpClientGenerator.scala b/modules/scala-akka-http/src/main/scala/dev/guardrail/generators/scala/akkaHttp/AkkaHttpClientGenerator.scala index b12b62a7b4..8471a7adf2 100644 --- a/modules/scala-akka-http/src/main/scala/dev/guardrail/generators/scala/akkaHttp/AkkaHttpClientGenerator.scala +++ b/modules/scala-akka-http/src/main/scala/dev/guardrail/generators/scala/akkaHttp/AkkaHttpClientGenerator.scala @@ -399,7 +399,7 @@ class AkkaHttpClientGenerator private (modelGeneratorType: ModelGeneratorType) e HttpProtocols.`HTTP/1.1` ).flatMap(req => EitherT(${httpClientName}(req).flatMap(resp => - ${Term.Match(q"resp.status", cases)} + ${Term.Match(q"resp.status", cases, Nil)} ).recover({ case e: Throwable => Left(Left(e)) @@ -557,17 +557,17 @@ class AkkaHttpClientGenerator private (modelGeneratorType: ModelGeneratorType) e ) } - def paramsToArgs(params: List[List[Term.Param]]): List[List[Term]] = - params.map { - _.map(_.name.value) - .map(v => Term.Assign(Term.Name(v), Term.Name(v))) - .toList + def paramsToArgs(params: List[List[Term.Param]]): List[Term.ArgClause] = + params.map { params => + Term.ArgClause( + params + .map(_.name.value) + .map(v => Term.Assign(Term.Name(v), Term.Name(v))) + .toList + ) }.toList - val ctorCall: Term.New = - q""" - new ${Type.Name(clientName)}(...${paramsToArgs(ctorArgs)}) - """ + val ctorCall: Term.New = Term.New(Init(Type.Name(clientName), Name.Anonymous(), paramsToArgs(ctorArgs))) for { extraDecls <- extraConstructors(tracingName, serverUrls, Type.Name(clientName), ctorCall, tracing) diff --git a/modules/scala-akka-http/src/main/scala/dev/guardrail/generators/scala/akkaHttp/AkkaHttpServerGenerator.scala b/modules/scala-akka-http/src/main/scala/dev/guardrail/generators/scala/akkaHttp/AkkaHttpServerGenerator.scala index 01651cb667..0389e909fe 100644 --- a/modules/scala-akka-http/src/main/scala/dev/guardrail/generators/scala/akkaHttp/AkkaHttpServerGenerator.scala +++ b/modules/scala-akka-http/src/main/scala/dev/guardrail/generators/scala/akkaHttp/AkkaHttpServerGenerator.scala @@ -295,8 +295,12 @@ class AkkaHttpServerGenerator private (akkaHttpVersion: AkkaHttpVersion, modelGe ${Defn.Def( List(mod"implicit"), Term.Name(s"${responseClsName.uncapitalized}TRM"), - tparams = List.empty, - NonEmptyList.fromList(protocolImplicits).fold(List.empty[List[Term.Param]])(nel => List(nel.toList)), + List( + Member.ParamClauseGroup( + Type.ParamClause(Nil), + NonEmptyList.fromList(protocolImplicits).fold(List.empty[Term.ParamClause])(nel => List(Term.ParamClause(nel.toList))) + ) + ), Some(t"ToResponseMarshaller[${responseSuperType}]"), q"""Marshaller { implicit ec => resp => ${Term.Name(s"${responseClsName.uncapitalized}TR")}(resp) }""" )}; @@ -304,7 +308,7 @@ class AkkaHttpServerGenerator private (akkaHttpVersion: AkkaHttpVersion, modelGe .Name( s"${responseClsName.uncapitalized}TR" )}(value: ${responseSuperType})(..$toResponseImplicits): scala.concurrent.Future[List[Marshalling[HttpResponse]]] = - ${Term.Match(Term.Name("value"), marshallers)} + ${Term.Match(Term.Name("value"), marshallers, Nil)} def apply[T](value: T)(implicit ev: T => ${responseSuperType}): ${responseSuperType} = ev(value) @@ -681,7 +685,7 @@ class AkkaHttpServerGenerator private (akkaHttpVersion: AkkaHttpVersion, modelGe val ${collected.toVar} = successes.collectFirst(${Term.PartialFunction( List( Case( - Pat.Extract(Term.Select(partsTerm, containerName.toTerm), List(pats)), + Pat.Extract(Term.Select(partsTerm, containerName.toTerm), Pat.ArgClause(List(pats))), None, terms ) @@ -878,7 +882,7 @@ class AkkaHttpServerGenerator private (akkaHttpVersion: AkkaHttpVersion, modelGe Nil } }).mapAsync(1)(${Term.Block( - List(Term.Function(List(Term.Param(List.empty, q"part", None, None)), Term.Match(q"part.name", allCases))) + List(Term.Function(Term.ParamClause(List(Term.Param(List.empty, q"part", None, None))), Term.Match(q"part.name", allCases, Nil))) )}) .toMat(Sink.seq[Either[Throwable, ${Type.Select(partsTerm, Type.Name("Part"))}]])(Keep.right).run() } yield { @@ -1056,11 +1060,14 @@ class AkkaHttpServerGenerator private (akkaHttpVersion: AkkaHttpVersion, modelGe .fold[Term => Term](identity)(_.foldLeft[Term => Term](identity) { case (acc, (directive, params)) => params match { case List() => - next => acc(Term.Apply(directive, List(next))) + next => acc(Term.Apply(directive, Term.ArgClause(List(next)))) case xs => next => acc( - Term.Apply(Term.Select(directive, Term.Name("apply")), List(Term.Function(xs.map(x => Term.Param(List.empty, x, None, None)), next))) + Term.Apply( + Term.Select(directive, Term.Name("apply")), + Term.ArgClause(List(Term.Function(Term.ParamClause(xs.map(x => Term.Param(List.empty, x, None, None))), next))) + ) ) } }) @@ -1146,8 +1153,12 @@ class AkkaHttpServerGenerator private (akkaHttpVersion: AkkaHttpVersion, modelGe } yield Defn.Def( mods = List.empty, Term.Name(s"${methodName}Decoder"), - tparams = List.empty, - NonEmptyList.fromList(decoderImplicits).fold(List.empty[List[Term.Param]])(nel => List(nel.toList)), + List( + Member.ParamClauseGroup( + Type.ParamClause(Nil), + NonEmptyList.fromList(decoderImplicits).fold(List.empty[List[Term.Param]])(nel => List(Term.ParamClause(nel.toList))) + ) + ), Some(t"FromRequestUnmarshaller[$baseType]"), q""" val extractEntity = implicitly[Unmarshaller[HttpMessage, HttpEntity]] diff --git a/modules/scala-dropwizard/src/main/scala/dev/guardrail/generators/scala/dropwizard/DropwizardServerGenerator.scala b/modules/scala-dropwizard/src/main/scala/dev/guardrail/generators/scala/dropwizard/DropwizardServerGenerator.scala index 18bbf559db..4c8cb1ebd4 100644 --- a/modules/scala-dropwizard/src/main/scala/dev/guardrail/generators/scala/dropwizard/DropwizardServerGenerator.scala +++ b/modules/scala-dropwizard/src/main/scala/dev/guardrail/generators/scala/dropwizard/DropwizardServerGenerator.scala @@ -172,7 +172,7 @@ class DropwizardServerGenerator private extends ServerTerms[ScalaLanguage, Targe } private def unwrapContainer(tpe: Type): (Type, Type => Type) = { - def rewrap(wrapper: Type)(tpe: Type): Type = Type.Apply(wrapper, List(tpe)) + def rewrap(wrapper: Type)(tpe: Type): Type = Type.Apply(wrapper, Type.ArgClause(List(tpe))) tpe match { case t"Option[$inner]" => (inner, rewrap(t"Option")) case t"Vector[$inner]" => (inner, rewrap(t"Vector")) @@ -180,14 +180,16 @@ class DropwizardServerGenerator private extends ServerTerms[ScalaLanguage, Targe case t"Seq[$inner]" => (inner, rewrap(t"Seq")) case t"IndexedSeq[$inner]" => (inner, rewrap(t"IndexedSeq")) case t"Iterable[$inner]" => (inner, rewrap(t"Iterable")) - case t"Map[$keyTpe, $inner]" => (inner, x => Type.Apply(t"Map", List(keyTpe, x))) + case t"Map[$keyTpe, $inner]" => (inner, x => Type.Apply(t"Map", Type.ArgClause(List(keyTpe, x)))) case other => (other, identity) } } private object paramTransformers { private def annotateHttpParameter(parameterName: RawParameterName, annotationName: Option[String])(param: Term.Param): Term.Param = param.copy( - mods = annotationName.map(an => Mod.Annot(Init(Type.Name(an), Name.Anonymous(), List(List(Lit.String(parameterName.value)))))).toList ++ param.mods + mods = annotationName + .map(an => Mod.Annot(Init(Type.Name(an), Name.Anonymous(), List(Term.ArgClause(List(Lit.String(parameterName.value)), None))))) + .toList ++ param.mods ) private def handleDefaultValue(defaultValue: Option[Term])(param: Term.Param): Term.Param = param.copy( @@ -204,7 +206,7 @@ class DropwizardServerGenerator private extends ServerTerms[ScalaLanguage, Targe case Lit.Double(d) => Some(Lit.String(d)) case _ => None } - defaultStr.map(s => Mod.Annot(Init(Type.Name("DefaultValue"), Name.Anonymous(), List(List(s))))) + defaultStr.map(s => Mod.Annot(Init(Type.Name("DefaultValue"), Name.Anonymous(), List(Term.ArgClause(List(s)))))) }.toList ++ param.mods, default = None ) @@ -231,7 +233,8 @@ class DropwizardServerGenerator private extends ServerTerms[ScalaLanguage, Targe def stripOptionFromCollections(param: Term.Param): Term.Param = param.copy( decltpe = param.decltpe.map { - case Type.Apply(t"Option", List(Type.Apply(containerType, innerTypes))) if CONTAINER_TYPES.contains(containerType.toString) => + case Type.Apply.After_4_6_0(t"Option", Type.ArgClause(List(Type.Apply.After_4_6_0(containerType, innerTypes)))) + if CONTAINER_TYPES.contains(containerType.toString) => t"$containerType[..$innerTypes]" case other => other } @@ -436,7 +439,7 @@ class DropwizardServerGenerator private extends ServerTerms[ScalaLanguage, Targe val pathSuffix = ResponseHelpers.splitPathComponents(path.unwrapTracker).drop(commonPathPrefix.length).mkString("/", "/", "") val pathAnnotation = Option(pathSuffix).filter(_.nonEmpty).filterNot(_ == "/").map(p => mod"@Path(${Lit.String(p)})") - val httpMethodAnnotation = Mod.Annot(Init(Type.Name(method.name()), Name.Anonymous(), List.empty)) + val httpMethodAnnotation = Mod.Annot(Init(Type.Name(method.name()), Name.Anonymous(), List.empty[Term.ArgClause])) val allConsumes = operation.downField("consumes", _.consumes).map(_.flatMap(ContentType.unapply)).unwrapTracker val consumes = ResponseHelpers.getBestConsumes(operation, allConsumes, parameters) @@ -481,10 +484,10 @@ class DropwizardServerGenerator private extends ServerTerms[ScalaLanguage, Targe val handlerArgs = handlerParams.map { param => val nameTerm = Term.Name(param.name.value) param.decltpe.fold[Term](nameTerm) { - case Type.Select(Term.Select(q"java", q"time"), _) => q"$nameTerm.get" - case Type.Apply(_, List(Type.Select(Term.Select(q"java", q"time"), _))) => q"$nameTerm.map(_.get)" - case Type.Apply(t"Map", List(_, Type.Select(Term.Select(q"java", q"time"), _))) => q"$nameTerm.mapValues(_.get)" - case _ => nameTerm + case Type.Select(Term.Select(q"java", q"time"), _) => q"$nameTerm.get" + case Type.Apply.After_4_6_0(_, Type.ArgClause(List(Type.Select(Term.Select(q"java", q"time"), _)))) => q"$nameTerm.map(_.get)" + case Type.Apply.After_4_6_0(t"Map", Type.ArgClause(List(_, Type.Select(Term.Select(q"java", q"time"), _)))) => q"$nameTerm.mapValues(_.get)" + case _ => nameTerm } } @@ -494,7 +497,7 @@ class DropwizardServerGenerator private extends ServerTerms[ScalaLanguage, Targe response.value.fold( p"case $resourceNameTerm.$responseClsSubTerm => responseBuilder.build()" ) { _ => - p"case ${Pat.Extract(Term.Select(resourceNameTerm, responseClsSubTerm), List(p"value"))} => responseBuilder.entity(value).build()" + p"case ${Pat.Extract(Term.Select(resourceNameTerm, responseClsSubTerm), Pat.ArgClause(List(p"value")))} => responseBuilder.entity(value).build()" } } @@ -509,7 +512,7 @@ class DropwizardServerGenerator private extends ServerTerms[ScalaLanguage, Targe this.handler.$methodNameTerm($responseClsTerm)(..$handlerArgs).onComplete({ case scala.util.Success(result) => val responseBuilder = Response.status(result.statusCode) - val response = ${Term.Match(Term.Name("result"), responseCases)} + val response = ${Term.Match(Term.Name("result"), responseCases, Nil)} asyncResponse.resume(response) case scala.util.Failure(err) => logger.error("{} threw an exception ({}): {}", ${Lit.String(s"$resourceName.$methodName")}, err.getClass.getName, err.getMessage, err) diff --git a/modules/scala-http4s/src/main/scala/dev/guardrail/generators/scala/http4s/Http4sClientGenerator.scala b/modules/scala-http4s/src/main/scala/dev/guardrail/generators/scala/http4s/Http4sClientGenerator.scala index 785bdf06a1..b0373c6d2f 100644 --- a/modules/scala-http4s/src/main/scala/dev/guardrail/generators/scala/http4s/Http4sClientGenerator.scala +++ b/modules/scala-http4s/src/main/scala/dev/guardrail/generators/scala/http4s/Http4sClientGenerator.scala @@ -539,21 +539,20 @@ class Http4sClientGenerator(version: Http4sVersion) extends ClientTerms[ScalaLan ) } - def paramsToArgs(params: List[List[Term.Param]]): List[List[Term]] = - params.map { - _.map(_.name.value) - .map(v => Term.Assign(Term.Name(v), Term.Name(v))) - .toList + def paramsToArgs(params: List[List[Term.Param]]): List[Term.ArgClause] = + params.map { params => + Term.ArgClause( + params + .map(_.name.value) + .map(v => Term.Assign(Term.Name(v), Term.Name(v))) + .toList + ) }.toList - val ctorCall: Term.New = - q""" - new ${Type - .Apply(Type.Name(clientName), List(Type.Name("F")))}(...${paramsToArgs(ctorArgs)}) - """ + val ctorCall: Term.New = Term.New(Init(Type.Apply(Type.Name(clientName), Type.ArgClause(List(Type.Name("F")))), Name.Anonymous(), paramsToArgs(ctorArgs))) val decls: List[Defn] = - q"""def apply[F[_]](...${ctorArgs}): ${Type.Apply(Type.Name(clientName), List(Type.Name("F")))} = ${ctorCall}""" +: + q"""def apply[F[_]](...${ctorArgs}): ${Type.Apply(Type.Name(clientName), Type.ArgClause(List(Type.Name("F"))))} = ${ctorCall}""" +: extraConstructors(tracingName, serverUrls, Type.Name(clientName), ctorCall, tracing) Target.pure( StaticDefns[ScalaLanguage]( diff --git a/modules/scala-http4s/src/main/scala/dev/guardrail/generators/scala/http4s/Http4sServerGenerator.scala b/modules/scala-http4s/src/main/scala/dev/guardrail/generators/scala/http4s/Http4sServerGenerator.scala index e396eb8859..589f54f2b4 100644 --- a/modules/scala-http4s/src/main/scala/dev/guardrail/generators/scala/http4s/Http4sServerGenerator.scala +++ b/modules/scala-http4s/src/main/scala/dev/guardrail/generators/scala/http4s/Http4sServerGenerator.scala @@ -284,7 +284,7 @@ class Http4sServerGenerator private (version: Http4sVersion) extends ServerTerms val errorTermName = Term.Name(authErrorTypeName.value) val (simpleAuthErrors, simpleAuthenticator) = if (authImplementation == AuthImplementation.Simple) { - val errorInit = Init(authErrorTypeName, Name(""), List.empty) + val errorInit = Init(authErrorTypeName, Name(""), List.empty[Term.ArgClause]) val authErrors = List( q"""sealed trait $authErrorTypeName""", q""" @@ -330,7 +330,7 @@ class Http4sServerGenerator private (version: Http4sVersion) extends ServerTerms else Target.log.warning(s"Security requirement '${reqName.unwrapTracker}' is missing in security schemes (${reqName.showHistory})") existanceCheck *> Target.pure(q""" - case object ${securitySchemeNameToClassName(reqName.unwrapTracker)} extends ${Init(authSchemesTypeName, Name(""), List.empty)} { + case object ${securitySchemeNameToClassName(reqName.unwrapTracker)} extends ${Init(authSchemesTypeName, Name(""), List.empty[Term.ArgClause])} { override val name: String = ${Lit.String(reqName.unwrapTracker)} } """) @@ -346,8 +346,8 @@ class Http4sServerGenerator private (version: Http4sVersion) extends ServerTerms sealed trait $authRequirementTypeName object ${Term.Name(authRequirementTypeName.value)} { - case object Required extends ${Init(authRequirementTypeName, Name(""), List.empty)} - case object Optional extends ${Init(authRequirementTypeName, Name(""), List.empty)} + case object Required extends ${Init(authRequirementTypeName, Name(""), List.empty[Term.ArgClause])} + case object Optional extends ${Init(authRequirementTypeName, Name(""), List.empty[Term.ArgClause])} } ..$list @@ -984,7 +984,7 @@ class Http4sServerGenerator private (version: Http4sVersion) extends ServerTerms val marshallers = responses.value.map { case Response(statusCodeName, valueType, headers) => val responseTerm = Term.Name(s"${statusCodeName.value}") val baseRespType = Type.Select(responseCompanionTerm, Type.Name(statusCodeName.value)) - val respType = if (isGeneric) Type.Apply(baseRespType, List(t"F")) else baseRespType + val respType = if (isGeneric) Type.Apply(baseRespType, Type.ArgClause(List(t"F"))) else baseRespType val generatorName = Term.Name(s"$methodName${statusCodeName}EntityResponseGenerator") val encoderName = Term.Name(s"$methodName${statusCodeName}Encoder") (valueType, headers.value) match { @@ -1016,7 +1016,7 @@ class Http4sServerGenerator private (version: Http4sVersion) extends ServerTerms val matchers = (http4sForm ++ http4sHeaders).flatMap(_.matcher) val responseInMatch = NonEmptyList.fromList(matchers).fold(responseExpr) { case NonEmptyList((expr, pat), Nil) => - Term.Match(expr, List(Case(pat, None, responseExpr), Case(p"_", None, q"""BadRequest("Invalid data")"""))) + Term.Match(expr, List(Case(pat, None, responseExpr), Case(p"_", None, q"""BadRequest("Invalid data")""")), Nil) case matchers @ NonEmptyList(_, _) => val NonEmptyList(head, xs) = matchers.reverse val (base, rest) = xs.splitAt(21).bimap(left => NonEmptyList(head, left).reverse, _.grouped(21).map(_.reverse.unzip).toList) @@ -1037,7 +1037,8 @@ class Http4sServerGenerator private (version: Http4sVersion) extends ServerTerms List( Case(fullPat, None, responseExpr), Case(Pat.Wildcard(), None, q"""BadRequest("Invalid data")""") - ) + ), + Nil ) } val responseInMatchInFor = (http4sForm ++ http4sHeaders).flatMap(_.generator) match { diff --git a/modules/scala-support/src/main/scala/dev/guardrail/generators/scala/ResponseADTHelper.scala b/modules/scala-support/src/main/scala/dev/guardrail/generators/scala/ResponseADTHelper.scala index 56920003bf..031f352e9d 100644 --- a/modules/scala-support/src/main/scala/dev/guardrail/generators/scala/ResponseADTHelper.scala +++ b/modules/scala-support/src/main/scala/dev/guardrail/generators/scala/ResponseADTHelper.scala @@ -17,7 +17,7 @@ object ResponseADTHelper { val responseSuperType = Type.Name(responseClsName) val responseSuperTerm = Term.Name(responseClsName) - val responseSuperTemplate = Init(if (isGeneric) Type.Apply(responseSuperType, extraTypes) else responseSuperType, Name(""), List.empty) + val responseSuperTemplate = Init(if (isGeneric) Type.Apply(responseSuperType, Type.ArgClause(extraTypes)) else responseSuperType, Name(""), Seq.empty) val (terms, foldPair) = responses.value.map { case Response(statusCodeName, valueType, headers) => val responseTerm = Term.Name(s"${statusCodeName.value}") @@ -52,7 +52,7 @@ object ResponseADTHelper { val cls = q""" sealed abstract class ${responseSuperType}[..$extraTypeParams] { - def fold[A](..${foldParams}): A = ${Term.Match(Term.This(Name("")), foldCases)} + def fold[A](..${foldParams}): A = ${Term.Match(Term.This(Name("")), foldCases, Nil)} } """ List[Defn](cls, companion) diff --git a/modules/scala-support/src/main/scala/dev/guardrail/generators/scala/circe/CirceRefinedProtocolGenerator.scala b/modules/scala-support/src/main/scala/dev/guardrail/generators/scala/circe/CirceRefinedProtocolGenerator.scala index 7b1c3950f7..34d225842f 100644 --- a/modules/scala-support/src/main/scala/dev/guardrail/generators/scala/circe/CirceRefinedProtocolGenerator.scala +++ b/modules/scala-support/src/main/scala/dev/guardrail/generators/scala/circe/CirceRefinedProtocolGenerator.scala @@ -104,7 +104,7 @@ object CirceRefinedProtocolGenerator { val refined = Type.Apply( t"_root_.eu.timepit.refined.string.MatchesRegex", - List(Type.Select(Term.Select(Term.Name(className), Term.Name(s""""$prepend$pat$append"""")), t"T")) + Type.ArgClause(List(Type.Select(Term.Select(Term.Name(className), Term.Name(s""""$prepend$pat$append"""")), t"T"))) ) t"""String Refined $refined""" } diff --git a/modules/scala-support/src/main/scala/dev/guardrail/generators/scala/jackson/JacksonProtocolGenerator.scala b/modules/scala-support/src/main/scala/dev/guardrail/generators/scala/jackson/JacksonProtocolGenerator.scala index 34d0b72e7b..f73bf8a71c 100644 --- a/modules/scala-support/src/main/scala/dev/guardrail/generators/scala/jackson/JacksonProtocolGenerator.scala +++ b/modules/scala-support/src/main/scala/dev/guardrail/generators/scala/jackson/JacksonProtocolGenerator.scala @@ -86,7 +86,7 @@ class JacksonProtocolGenerator private extends ProtocolTerms[ScalaLanguage, Targ case _ => List.empty } val presenceHandling = param.term.decltpe match { - case Some(t"Presence[_]") | Some(Type.Apply(Type.Select(_, Type.Name("Presence")), _)) => + case Some(t"Presence[_]") | Some(Type.Apply.After_4_6_0(Type.Select(_, Type.Name("Presence")), _)) => List( mod"@com.fasterxml.jackson.annotation.JsonInclude(value = com.fasterxml.jackson.annotation.JsonInclude.Include.NON_EMPTY)", mod"@com.fasterxml.jackson.databind.annotation.JsonSerialize(using = classOf[$presenceSerType])", @@ -1282,8 +1282,13 @@ class JacksonProtocolGenerator private extends ProtocolTerms[ScalaLanguage, Targ parentOpt .fold(base)(parent => base.copy( - templ = - Template(Nil, (parent.clsName +: parent.interfaces).map(n => Init(Type.Name(n), Name(""), Nil)), Self(Name(""), None), base.templ.stats, Nil) + templ = Template( + Nil, + (parent.clsName +: parent.interfaces).map(n => Init(Type.Name(n), Name(""), List.empty[Term.ArgClause])), + Self(Name(""), None), + base.templ.stats, + Nil + ) ) ) } diff --git a/modules/scala-support/src/test/scala/tests/generators/helpers/JacksonHelpersTest.scala b/modules/scala-support/src/test/scala/tests/generators/helpers/JacksonHelpersTest.scala index 7828dadee6..7ff40590d0 100644 --- a/modules/scala-support/src/test/scala/tests/generators/helpers/JacksonHelpersTest.scala +++ b/modules/scala-support/src/test/scala/tests/generators/helpers/JacksonHelpersTest.scala @@ -52,7 +52,8 @@ class JacksonHelpersTest extends AnyFreeSpec with Matchers { } "from a bigint" in { - val Term.Apply(Term.Name("BigInt"), List(Lit.String(bigintStr))) = discriminatorExpression("12345678901234567890", "integer").value + val Term.Apply.After_4_6_0(Term.Name("BigInt"), Term.ArgClause(List(Lit.String(bigintStr)), None)) = + discriminatorExpression("12345678901234567890", "integer").value bigintStr mustBe "12345678901234567890" } @@ -67,7 +68,8 @@ class JacksonHelpersTest extends AnyFreeSpec with Matchers { } "from a bigdecimal" in { - val Term.Apply(Term.Name("BigDecimal"), List(Lit.String(bigdecStr))) = discriminatorExpression("12345678901234567890.0987654321", "number").value + val Term.Apply.After_4_6_0(Term.Name("BigDecimal"), Term.ArgClause(List(Lit.String(bigdecStr)), None)) = + discriminatorExpression("12345678901234567890.0987654321", "number").value bigdecStr mustBe "12345678901234567890.0987654321" } } diff --git a/src/test/scala/tests/core/EscapeTreeSpec.scala b/src/test/scala/tests/core/EscapeTreeSpec.scala index 10bbb834e1..a999f0bdac 100644 --- a/src/test/scala/tests/core/EscapeTreeSpec.scala +++ b/src/test/scala/tests/core/EscapeTreeSpec.scala @@ -16,7 +16,7 @@ class EscapeTreeSpec extends AnyFunSuite with Matchers { (Init(Type.Name("dashy-enum"), Name("what"), List()), "`dashy-enum`"), (Term.Name("dashy-class"), "`dashy-class`"), ( - Term.Param(Nil, Term.Name("dashy-param"), Some(Type.Apply(Type.Name("Option"), List(Type.Name("Long")))), Some(Term.Name("None"))), + Term.Param(Nil, Term.Name("dashy-param"), Some(Type.Apply(Type.Name("Option"), Type.ArgClause(List(Type.Name("Long"))))), Some(Term.Name("None"))), "`dashy-param`: Option[Long] = None" ), (Type.Name("dashy-class"), "`dashy-class`") diff --git a/src/test/scala/tests/generators/dropwizardScala/server/DropwizardScalaJsr310Test.scala b/src/test/scala/tests/generators/dropwizardScala/server/DropwizardScalaJsr310Test.scala index 4a2e4b40f9..582d760ef2 100644 --- a/src/test/scala/tests/generators/dropwizardScala/server/DropwizardScalaJsr310Test.scala +++ b/src/test/scala/tests/generators/dropwizardScala/server/DropwizardScalaJsr310Test.scala @@ -58,36 +58,41 @@ class DropwizardScalaJsr310Test extends AnyFreeSpec with Matchers with OptionVal ) = runSwaggerSpec(scalaInterpreter)(openapi)(Context.empty, "dropwizard", targets = NonEmptyList.of(CodegenTarget.Server)) handler match { - case Defn.Trait( + case Defn.Trait.After_4_6_0( _, Type.Name("Handler"), _, _, - Template(_, _, _, List(defn: Decl.Def)) + Template.After_4_4_0(_, _, _, List(defn: Decl.Def), _) ) => val List( - List(_), - List( - Term.Param(_, Name("when"), Some(t"java.time.OffsetDateTime"), _), - Term.Param(_, Name("dateTime"), Some(t"Option[java.time.OffsetDateTime]"), _), - Term.Param(_, Name("date"), Some(t"java.time.LocalDate"), _) - ) - ) = defn.paramss + Term.ParamClause(List(_), None), + Term.ParamClause(List( + Term.Param(_, Term.Name("when"), Some(t"java.time.OffsetDateTime"), None), + Term.Param(_, Term.Name("dateTime"), Some(t"Option[java.time.OffsetDateTime]"), None), + Term.Param(_, Term.Name("date"), Some(t"java.time.LocalDate"), None) + ), None) + ) = defn.paramClauses } - val resourceDefns = server.collectFirst { case Defn.Class(_, t"Resource", _, _, Template(_, _, _, defns)) => + val resourceDefns = server.collectFirst { case Defn.Class.After_4_6_0(_, t"Resource", _, _, Template.After_4_4_0(_, _, _, defns, _)) => defns }.value - val doFooParamss = resourceDefns.collectFirst { case Defn.Def(_, Term.Name("doFoo"), _, paramss, _, _) => - paramss + val doFooParamss: List[Member.ParamClauseGroup] = resourceDefns.collectFirst { case Defn.Def.After_4_7_3(_, Term.Name("doFoo"), paramClauseGroups, _, _) => + paramClauseGroups }.value val List( - List( - Term.Param(_, Name("when"), Some(t"GuardrailJerseySupport.Jsr310.OffsetDateTimeParam"), _), - Term.Param(_, Name("dateTime"), Some(t"Option[GuardrailJerseySupport.Jsr310.OffsetDateTimeParam]"), _), - Term.Param(_, Name("date"), Some(t"GuardrailJerseySupport.Jsr310.LocalDateParam"), _), - Term.Param(_, Name("asyncResponse"), Some(t"AsyncResponse"), _) + Member.ParamClauseGroup( + _, + List( + Term.ParamClause(List( + Term.Param(_, Term.Name("when"), Some(t"GuardrailJerseySupport.Jsr310.OffsetDateTimeParam"), _), + Term.Param(_, Term.Name("dateTime"), Some(t"Option[GuardrailJerseySupport.Jsr310.OffsetDateTimeParam]"), _), + Term.Param(_, Term.Name("date"), Some(t"GuardrailJerseySupport.Jsr310.LocalDateParam"), _), + Term.Param(_, Term.Name("asyncResponse"), Some(t"AsyncResponse"), _) + ), None) + ) ) ) = doFooParamss } From db99430b1496c5e13011bbaa05958685dd4a47c6 Mon Sep 17 00:00:00 2001 From: Devon Stewart Date: Wed, 11 Oct 2023 00:04:39 -0700 Subject: [PATCH 5/5] param"implicit ..." is invalid --- .../akkaHttp/AkkaHttpClientGenerator.scala | 42 +++++++++++-------- .../scala/akkaHttp/AkkaHttpHelper.scala | 13 +++--- .../akkaHttp/AkkaHttpServerGenerator.scala | 24 +++++++---- .../scala/http4s/Http4sClientGenerator.scala | 23 +++++----- 4 files changed, 61 insertions(+), 41 deletions(-) diff --git a/modules/scala-akka-http/src/main/scala/dev/guardrail/generators/scala/akkaHttp/AkkaHttpClientGenerator.scala b/modules/scala-akka-http/src/main/scala/dev/guardrail/generators/scala/akkaHttp/AkkaHttpClientGenerator.scala index 8471a7adf2..7f6786d221 100644 --- a/modules/scala-akka-http/src/main/scala/dev/guardrail/generators/scala/akkaHttp/AkkaHttpClientGenerator.scala +++ b/modules/scala-akka-http/src/main/scala/dev/guardrail/generators/scala/akkaHttp/AkkaHttpClientGenerator.scala @@ -496,19 +496,22 @@ class AkkaHttpClientGenerator private (modelGeneratorType: ModelGeneratorType) e tracingName: Option[String], serverUrls: Option[NonEmptyList[URI]], tracing: Boolean - ): Target[List[List[scala.meta.Term.Param]]] = { + ): Target[List[Term.ParamClause]] = { val implicits = List( - param"implicit httpClient: HttpRequest => Future[HttpResponse]", - param"implicit ec: ExecutionContext", - param"implicit mat: Materializer" + param"httpClient: HttpRequest => Future[HttpResponse]", + param"ec: ExecutionContext", + param"mat: Materializer" ) for { protocolImplicits <- AkkaHttpHelper.protocolImplicits(modelGeneratorType) } yield List( - List(formatHost(serverUrls)) ++ (if (tracing) - Some(formatClientName(tracingName)) - else None), - implicits ++ protocolImplicits + Term.ParamClause( + List(formatHost(serverUrls)) ++ (if (tracing) + Some(formatClientName(tracingName)) + else None), + None + ), + Term.ParamClause(implicits ++ protocolImplicits, Some(Mod.Implicit())) ) } private def generateResponseDefinitions( @@ -526,7 +529,7 @@ class AkkaHttpClientGenerator private (modelGeneratorType: ModelGeneratorType) e clientName: String, tracingName: Option[String], serverUrls: Option[NonEmptyList[URI]], - ctorArgs: List[List[scala.meta.Term.Param]], + ctorArgs: List[Term.ParamClause], tracing: Boolean ): Target[StaticDefns[ScalaLanguage]] = { def extraConstructors( @@ -537,8 +540,8 @@ class AkkaHttpClientGenerator private (modelGeneratorType: ModelGeneratorType) e tracing: Boolean ): Target[List[Defn]] = { val implicits = List( - param"implicit ec: ExecutionContext", - param"implicit mat: Materializer" + param"ec: ExecutionContext", + param"mat: Materializer" ) val tracingParams: List[Term.Param] = if (tracing) { List(formatClientName(tracingName)) @@ -548,16 +551,19 @@ class AkkaHttpClientGenerator private (modelGeneratorType: ModelGeneratorType) e for { protocolImplicits <- AkkaHttpHelper.protocolImplicits(modelGeneratorType) + args = List( + Term.ParamClause( + List(param"httpClient: HttpRequest => Future[HttpResponse]", formatHost(serverUrls)) ++ tracingParams, + None + ), + Term.ParamClause(implicits ++ protocolImplicits, Some(Mod.Implicit())) + ) } yield List( - q""" - def httpClient(httpClient: HttpRequest => Future[HttpResponse], ${formatHost( - serverUrls - )}, ..$tracingParams)(..${implicits ++ protocolImplicits}): $tpe = $ctorCall - """ + q"""def httpClient(...${args}): $tpe = $ctorCall""" ) } - def paramsToArgs(params: List[List[Term.Param]]): List[Term.ArgClause] = + def paramsToArgs(params: List[Term.ParamClause]): List[Term.ArgClause] = params.map { params => Term.ArgClause( params @@ -583,7 +589,7 @@ class AkkaHttpClientGenerator private (modelGeneratorType: ModelGeneratorType) e tracingName: Option[String], serverUrls: Option[NonEmptyList[URI]], basePath: Option[String], - ctorArgs: List[List[scala.meta.Term.Param]], + ctorArgs: List[Term.ParamClause], clientCalls: List[scala.meta.Defn], supportDefinitions: List[scala.meta.Defn], tracing: Boolean diff --git a/modules/scala-akka-http/src/main/scala/dev/guardrail/generators/scala/akkaHttp/AkkaHttpHelper.scala b/modules/scala-akka-http/src/main/scala/dev/guardrail/generators/scala/akkaHttp/AkkaHttpHelper.scala index e9689ea51a..e369c873d6 100644 --- a/modules/scala-akka-http/src/main/scala/dev/guardrail/generators/scala/akkaHttp/AkkaHttpHelper.scala +++ b/modules/scala-akka-http/src/main/scala/dev/guardrail/generators/scala/akkaHttp/AkkaHttpHelper.scala @@ -47,13 +47,16 @@ object AkkaHttpHelper { case _ => Left(s"Unknown modelGeneratorType: ${modelGeneratorType}") } - def protocolImplicits(modelGeneratorType: ModelGeneratorType): Target[List[Term.Param]] = modelGeneratorType match { - case _: CirceModelGenerator => Target.pure(List.empty) + def protocolImplicits(modelGeneratorType: ModelGeneratorType): Target[Term.ParamClause] = modelGeneratorType match { + case _: CirceModelGenerator => Target.pure(Term.ParamClause(Nil)) case _: JacksonModelGenerator => Target.pure( - List( - param"implicit mapper: com.fasterxml.jackson.databind.ObjectMapper", - param"implicit validator: javax.validation.Validator" + Term.ParamClause( + List( + param"mapper: com.fasterxml.jackson.databind.ObjectMapper", + param"validator: javax.validation.Validator" + ), + Some(Mod.Implicit()) ) ) case _ => Target.raiseError(RuntimeFailure(s"Unknown modelGeneratorType: ${modelGeneratorType}")) diff --git a/modules/scala-akka-http/src/main/scala/dev/guardrail/generators/scala/akkaHttp/AkkaHttpServerGenerator.scala b/modules/scala-akka-http/src/main/scala/dev/guardrail/generators/scala/akkaHttp/AkkaHttpServerGenerator.scala index 0389e909fe..9b2fc09c91 100644 --- a/modules/scala-akka-http/src/main/scala/dev/guardrail/generators/scala/akkaHttp/AkkaHttpServerGenerator.scala +++ b/modules/scala-akka-http/src/main/scala/dev/guardrail/generators/scala/akkaHttp/AkkaHttpServerGenerator.scala @@ -289,7 +289,7 @@ class AkkaHttpServerGenerator private (akkaHttpVersion: AkkaHttpVersion, modelGe q"implicit def ${Term.Name(s"${name.value}Ev")}(value: ${tpe}): ${responseSuperType} = ${name}(value)" } protocolImplicits <- AkkaHttpHelper.protocolImplicits(modelGeneratorType) - toResponseImplicits = List(param"implicit ec: scala.concurrent.ExecutionContext") ++ protocolImplicits + toResponseImplicits = List(param"ec: scala.concurrent.ExecutionContext") ++ protocolImplicits companion = q""" object ${responseSuperTerm} { ${Defn.Def( @@ -298,7 +298,7 @@ class AkkaHttpServerGenerator private (akkaHttpVersion: AkkaHttpVersion, modelGe List( Member.ParamClauseGroup( Type.ParamClause(Nil), - NonEmptyList.fromList(protocolImplicits).fold(List.empty[Term.ParamClause])(nel => List(Term.ParamClause(nel.toList))) + NonEmptyList.fromList(protocolImplicits).fold(List.empty[Term.ParamClause])(nel => List(Term.ParamClause(nel.toList, Some(Mod.Implicit())))) ) ), Some(t"ToResponseMarshaller[${responseSuperType}]"), @@ -307,7 +307,10 @@ class AkkaHttpServerGenerator private (akkaHttpVersion: AkkaHttpVersion, modelGe implicit def ${Term .Name( s"${responseClsName.uncapitalized}TR" - )}(value: ${responseSuperType})(..$toResponseImplicits): scala.concurrent.Future[List[Marshalling[HttpResponse]]] = + )}(value: ${responseSuperType})(..${Term.ParamClause( + toResponseImplicits, + Some(Mod.Implicit()) + )}): scala.concurrent.Future[List[Marshalling[HttpResponse]]] = ${Term.Match(Term.Name("value"), marshallers, Nil)} def apply[T](value: T)(implicit ev: T => ${responseSuperType}): ${responseSuperType} = ev(value) @@ -447,13 +450,18 @@ class AkkaHttpServerGenerator private (akkaHttpVersion: AkkaHttpVersion, modelGe baseHandlerType } } - val typeParams = if (customExtraction) List(tparam"$customExtractionTypeName") else List() - val routesParams = List(param"handler: $handlerType") ++ extraRouteParams - val routeImplicits = List(param"implicit mat: akka.stream.Materializer") ++ protocolImplicits + val typeParams = if (customExtraction) List(tparam"$customExtractionTypeName") else List() + val params = List( + Term.ParamClause( + List(param"handler: $handlerType") ++ extraRouteParams, + None + ), + Term.ParamClause(List(param"mat: akka.stream.Materializer") ++ protocolImplicits, Some(Mod.Implicit())) + ) List(q""" object ${Term.Name(resourceName)} { ..${supportDefinitions}; - def routes[..${typeParams}](..${routesParams})(..$routeImplicits): Route = { + def routes[..${typeParams}](...${params}): Route = { ..${combinedRouteTerms} } @@ -1156,7 +1164,7 @@ class AkkaHttpServerGenerator private (akkaHttpVersion: AkkaHttpVersion, modelGe List( Member.ParamClauseGroup( Type.ParamClause(Nil), - NonEmptyList.fromList(decoderImplicits).fold(List.empty[List[Term.Param]])(nel => List(Term.ParamClause(nel.toList))) + List(decoderImplicits).filter(_.nonEmpty) ) ), Some(t"FromRequestUnmarshaller[$baseType]"), diff --git a/modules/scala-http4s/src/main/scala/dev/guardrail/generators/scala/http4s/Http4sClientGenerator.scala b/modules/scala-http4s/src/main/scala/dev/guardrail/generators/scala/http4s/Http4sClientGenerator.scala index b0373c6d2f..83201a689b 100644 --- a/modules/scala-http4s/src/main/scala/dev/guardrail/generators/scala/http4s/Http4sClientGenerator.scala +++ b/modules/scala-http4s/src/main/scala/dev/guardrail/generators/scala/http4s/Http4sClientGenerator.scala @@ -488,15 +488,18 @@ class Http4sClientGenerator(version: Http4sVersion) extends ClientTerms[ScalaLan } def getImports(tracing: Boolean): Target[List[scala.meta.Import]] = Target.pure(List(q"import org.http4s.circe._")) def getExtraImports(tracing: Boolean): Target[List[scala.meta.Import]] = Target.pure(List.empty) - def clientClsArgs(tracingName: Option[String], serverUrls: Option[NonEmptyList[URI]], tracing: Boolean): Target[List[List[scala.meta.Term.Param]]] = { - val ihc = param"implicit httpClient: Http4sClient[F]" - val ief = param"implicit F: Async[F]" + def clientClsArgs(tracingName: Option[String], serverUrls: Option[NonEmptyList[URI]], tracing: Boolean): Target[List[Term.ParamClause]] = { + val ihc = param"httpClient: Http4sClient[F]" + val ief = param"F: Async[F]" Target.pure( List( - List(formatHost(serverUrls)) ++ (if (tracing) - Some(formatClientName(tracingName)) - else None), - List(ief, ihc) + Term.ParamClause( + List(formatHost(serverUrls)) ++ (if (tracing) + Some(formatClientName(tracingName)) + else None), + None + ), + Term.ParamClause(List(ief, ihc), Some(Mod.Implicit())) ) ) } @@ -516,7 +519,7 @@ class Http4sClientGenerator(version: Http4sVersion) extends ClientTerms[ScalaLan clientName: String, tracingName: Option[String], serverUrls: Option[NonEmptyList[URI]], - ctorArgs: List[List[scala.meta.Term.Param]], + ctorArgs: List[Term.ParamClause], tracing: Boolean ): Target[StaticDefns[ScalaLanguage]] = { def extraConstructors( @@ -539,7 +542,7 @@ class Http4sClientGenerator(version: Http4sVersion) extends ClientTerms[ScalaLan ) } - def paramsToArgs(params: List[List[Term.Param]]): List[Term.ArgClause] = + def paramsToArgs(params: List[Term.ParamClause]): List[Term.ArgClause] = params.map { params => Term.ArgClause( params @@ -567,7 +570,7 @@ class Http4sClientGenerator(version: Http4sVersion) extends ClientTerms[ScalaLan tracingName: Option[String], serverUrls: Option[NonEmptyList[URI]], basePath: Option[String], - ctorArgs: List[List[scala.meta.Term.Param]], + ctorArgs: List[Term.ParamClause], clientCalls: List[scala.meta.Defn], supportDefinitions: List[scala.meta.Defn], tracing: Boolean