Skip to content

Commit b3bdc6c

Browse files
committed
use full path for sttp types to avoid conflicts, add google sheets api to test
1 parent 1e3f9be commit b3bdc6c

File tree

3 files changed

+8328
-11
lines changed

3 files changed

+8328
-11
lines changed

build.sbt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,8 @@ lazy val testProjects: CompositeProject = new CompositeProject {
129129
"storage" -> "v1",
130130
"aiplatform" -> "v1",
131131
"iamcredentials" -> "v1",
132-
"redis" -> "v1"
132+
"redis" -> "v1",
133+
"sheets" -> "v4"
133134
)
134135
httpSource <- Seq("Sttp4")
135136
jsonCodec <- Seq("ZioJson", "Jsoniter")

modules/core/shared/src/main/scala/codegen.scala

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -291,14 +291,14 @@ def resourceCode(
291291
val sttpClientPkg = httpSource match
292292
case HttpSource.Sttp4 => "sttp.client4"
293293

294+
val sttpUriPkg = "sttp.model.Uri"
295+
294296
List(
295297
s"package $pkg",
296298
"",
297299
s"import $schemasPkg.*",
298300
s"import $resourcesPkg.*",
299301
"",
300-
s"import sttp.model.Uri, sttp.model.Uri.PathSegment, $sttpClientPkg.*",
301-
"",
302302
s"object ${resourceName} {" +
303303
resource.methods
304304
.map { (k, method) =>
@@ -308,10 +308,11 @@ def resourceCode(
308308
.filter(_.nonEmpty)
309309
.map(s =>
310310
"\\{(.*?)\\}".r.findAllIn(s).toList match
311-
case Nil => s"PathSegment(\"$s\")"
312-
case v :: Nil if v == s => "PathSegment(" + toScalaName(v.stripPrefix("{").stripSuffix("}")) + ")"
313-
case vars =>
314-
"PathSegment(s\"" + vars
311+
case Nil => s"$sttpUriPkg.PathSegment(\"$s\")"
312+
case v :: Nil if v == s =>
313+
s"$sttpUriPkg.PathSegment(" + toScalaName(v.stripPrefix("{").stripSuffix("}")) + ")"
314+
case vars =>
315+
s"$sttpUriPkg.PathSegment(s\"" + vars
315316
.foldLeft(s)((res, v) => res.replace(v, "$" + v.stripPrefix("{").stripSuffix("}"))) + "\")"
316317
)
317318

@@ -340,13 +341,14 @@ def resourceCode(
340341
s"${toComment(t.description, indent)}$indent$n: ${t.scalaType(arrType)} = None"
341342
) :::
342343
List(
343-
s"${indent}endpointUrl: Uri = $rootPkg.baseUrl",
344+
s"${indent}endpointUrl: $sttpUriPkg = $rootPkg.baseUrl",
344345
s"${indent}commonQueryParams: QueryParameters = " + ((
345346
method.mediaUploads,
346347
commonQueryParams.collectFirst { case ("uploadType", Parameter(_, _, e: SchemaType.Enum, _, _)) => e }
347348
) match {
348-
case (Some(m), Some(ut)) => s"""QueryParameters(uploadType = Some("${ut.values.head.value}"))"""
349-
case _ => "QueryParameters.empty"
349+
case (Some(m), Some(ut)) =>
350+
s"""QueryParameters(uploadType = Some("${ut.values.head.value}"))"""
351+
case _ => "QueryParameters.empty"
350352
})
351353
)
352354

@@ -382,7 +384,7 @@ def resourceCode(
382384
def responseType(t: String) =
383385
httpSource match
384386
case HttpSource.Sttp4 =>
385-
s"Request[Either[ResponseException[String], $t]]"
387+
s"$sttpClientPkg.Request[Either[$sttpClientPkg.ResponseException[String], $t]]"
386388

387389
val (resType, mapResponse) = method.response match
388390
case Some(r) if r.schemaPath.forall(hasProps) =>

0 commit comments

Comments
 (0)