Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ lazy val testProjects: CompositeProject = new CompositeProject {
"storage" -> "v1",
"aiplatform" -> "v1",
"iamcredentials" -> "v1",
"redis" -> "v1"
"redis" -> "v1",
"sheets" -> "v4"
)
httpSource <- Seq("Sttp4")
jsonCodec <- Seq("ZioJson", "Jsoniter")
Expand Down
22 changes: 12 additions & 10 deletions modules/core/shared/src/main/scala/codegen.scala
Original file line number Diff line number Diff line change
Expand Up @@ -291,14 +291,14 @@ def resourceCode(
val sttpClientPkg = httpSource match
case HttpSource.Sttp4 => "sttp.client4"

val sttpUriPkg = "sttp.model.Uri"

List(
s"package $pkg",
"",
s"import $schemasPkg.*",
s"import $resourcesPkg.*",
"",
s"import sttp.model.Uri, sttp.model.Uri.PathSegment, $sttpClientPkg.*",
"",
s"object ${resourceName} {" +
resource.methods
.map { (k, method) =>
Expand All @@ -308,10 +308,11 @@ def resourceCode(
.filter(_.nonEmpty)
.map(s =>
"\\{(.*?)\\}".r.findAllIn(s).toList match
case Nil => s"PathSegment(\"$s\")"
case v :: Nil if v == s => "PathSegment(" + toScalaName(v.stripPrefix("{").stripSuffix("}")) + ")"
case vars =>
"PathSegment(s\"" + vars
case Nil => s"$sttpUriPkg.PathSegment(\"$s\")"
case v :: Nil if v == s =>
s"$sttpUriPkg.PathSegment(" + toScalaName(v.stripPrefix("{").stripSuffix("}")) + ")"
case vars =>
s"$sttpUriPkg.PathSegment(s\"" + vars
.foldLeft(s)((res, v) => res.replace(v, "$" + v.stripPrefix("{").stripSuffix("}"))) + "\")"
)

Expand Down Expand Up @@ -340,13 +341,14 @@ def resourceCode(
s"${toComment(t.description, indent)}$indent$n: ${t.scalaType(arrType)} = None"
) :::
List(
s"${indent}endpointUrl: Uri = $rootPkg.baseUrl",
s"${indent}endpointUrl: $sttpUriPkg = $rootPkg.baseUrl",
s"${indent}commonQueryParams: QueryParameters = " + ((
method.mediaUploads,
commonQueryParams.collectFirst { case ("uploadType", Parameter(_, _, e: SchemaType.Enum, _, _)) => e }
) match {
case (Some(m), Some(ut)) => s"""QueryParameters(uploadType = Some("${ut.values.head.value}"))"""
case _ => "QueryParameters.empty"
case (Some(m), Some(ut)) =>
s"""QueryParameters(uploadType = Some("${ut.values.head.value}"))"""
case _ => "QueryParameters.empty"
})
)

Expand Down Expand Up @@ -382,7 +384,7 @@ def resourceCode(
def responseType(t: String) =
httpSource match
case HttpSource.Sttp4 =>
s"Request[Either[ResponseException[String], $t]]"
s"$sttpClientPkg.Request[Either[$sttpClientPkg.ResponseException[String], $t]]"

val (resType, mapResponse) = method.response match
case Some(r) if r.schemaPath.forall(hasProps) =>
Expand Down
Loading