Skip to content

Commit

Permalink
Merge pull request #1822 from scala-steward/update/scalameta-4.8.11
Browse files Browse the repository at this point in the history
Update scalameta to 4.8.11
  • Loading branch information
blast-hardcheese committed Oct 18, 2023
2 parents fe2f2b1 + db99430 commit 8af72ed
Show file tree
Hide file tree
Showing 48 changed files with 333 additions and 275 deletions.
2 changes: 1 addition & 1 deletion modules/microsite/src/main/scala/DocsHelpers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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(
Expand All @@ -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(
Expand All @@ -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))
Expand All @@ -548,26 +551,29 @@ 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[List[Term]] =
params.map {
_.map(_.name.value)
.map(v => Term.Assign(Term.Name(v), Term.Name(v)))
.toList
def paramsToArgs(params: List[Term.ParamClause]): 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)
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,22 +289,29 @@ 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(
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(Mod.Implicit()))))
)
),
Some(t"ToResponseMarshaller[${responseSuperType}]"),
q"""Marshaller { implicit ec => resp => ${Term.Name(s"${responseClsName.uncapitalized}TR")}(resp) }"""
)};
implicit def ${Term
.Name(
s"${responseClsName.uncapitalized}TR"
)}(value: ${responseSuperType})(..$toResponseImplicits): scala.concurrent.Future[List[Marshalling[HttpResponse]]] =
${Term.Match(Term.Name("value"), marshallers)}
)}(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)

Expand Down Expand Up @@ -443,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}
}

Expand Down Expand Up @@ -681,7 +693,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
)
Expand Down Expand Up @@ -878,7 +890,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 {
Expand Down Expand Up @@ -1056,11 +1068,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)))
)
)
}
})
Expand Down Expand Up @@ -1146,8 +1161,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),
List(decoderImplicits).filter(_.nonEmpty)
)
),
Some(t"FromRequestUnmarshaller[$baseType]"),
q"""
val extractEntity = implicitly[Unmarshaller[HttpMessage, HttpEntity]]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand Down Expand Up @@ -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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand Down Expand Up @@ -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") {
Expand Down Expand Up @@ -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)
}
}
Loading

0 comments on commit 8af72ed

Please sign in to comment.