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..1fd49deb47 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 @@ -52,8 +52,8 @@ object AkkaHttpHelper { case _: JacksonModelGenerator => Target.pure( List( - param"implicit mapper: com.fasterxml.jackson.databind.ObjectMapper", - param"implicit validator: javax.validation.Validator" + param"mapper: com.fasterxml.jackson.databind.ObjectMapper", + param"validator: javax.validation.Validator" ) ) 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..7c8e99c4b5 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( @@ -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} } 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