@@ -235,11 +235,9 @@ def generateBySpec(
235235 pkg = resourceKey.pkgName(resourcesPkg),
236236 resourcesPkg = resourcesPkg,
237237 schemasPkg = schemasPkg,
238- baseUrl = specs.baseUrl,
239238 resourceName = resourceName,
240239 resource = resource,
241240 httpSource = config.httpSource,
242- jsonCodec = config.jsonCodec,
243241 hasProps = p => specs.hasProps(p),
244242 arrType = config.arrayType,
245243 commonQueryParams = specs.queryParameters
@@ -304,19 +302,22 @@ def generateBySpec(
304302val scalaKeyWords = Set (" type" , " import" , " val" , " object" , " enum" , " export" )
305303
306304def toScalaName (n : String ): String =
307- if scalaKeyWords.contains(n) then s " ` $n` "
308- else n.replaceAll(" [^a-zA-Z0-9_]" , " " )
305+ n match
306+ // to fix a compiler warning like
307+ // import looks like a language import, but refers to something else: object language in object GoogleCloudAiplatformV1ExecutableCode
308+ case " language" => " Language"
309+ case _ =>
310+ if scalaKeyWords.contains(n) then s " ` $n` "
311+ else n.replaceAll(" [^a-zA-Z0-9_]" , " " )
309312
310313def resourceCode (
311314 rootPkg : String ,
312315 pkg : String ,
313316 resourcesPkg : String ,
314317 schemasPkg : String ,
315- baseUrl : String ,
316318 resourceName : String ,
317319 resource : Resource ,
318320 httpSource : HttpSource ,
319- jsonCodec : JsonCodec ,
320321 arrType : ArrayType ,
321322 hasProps : SchemaPath => Boolean ,
322323 commonQueryParams : Map [String , Parameter ]
@@ -335,7 +336,7 @@ def resourceCode(
335336 " " ,
336337 s " object ${resourceName} { " +
337338 resource.methods
338- .map { (k, v ) =>
339+ .map { (k, method ) =>
339340 def pathSegments (urlPath : String ) =
340341 urlPath
341342 .split(" /" )
@@ -350,11 +351,11 @@ def resourceCode(
350351 ) + " \" )"
351352 )
352353
353- val req = v.mediaUpload match
354- case None => v .request.filter(_.schemaPath.forall(hasProps))
354+ val req = method.mediaUploads match
355+ case None => method .request.filter(_.schemaPath.forall(hasProps))
355356 case Some (_) => None
356357
357- val uploadProtocol = v.mediaUpload match
358+ val uploadProtocol = method.mediaUploads match
358359 case Some (m) =>
359360 Some {
360361 val protocols = m.protocols.keySet.toList.sortBy {
@@ -366,7 +367,7 @@ def resourceCode(
366367 }
367368 case None => None
368369
369- val (requiredParams, optParams) = v .scalaParameters.partition(_._2.required)
370+ val (requiredParams, optParams) = method .scalaParameters.partition(_._2.required)
370371 val params =
371372 requiredParams.map((n, t) => s " ${toComment(t.description)}$n: ${t.scalaType(arrType)}" ) :::
372373 req.toList.map(r => s " request: ${r.scalaType(arrType)}" ) :::
@@ -375,17 +376,17 @@ def resourceCode(
375376 List (
376377 s " endpointUrl: Uri = $rootPkg.baseUrl " ,
377378 " commonQueryParams: QueryParameters = " + ((
378- v.mediaUpload ,
379+ method.mediaUploads ,
379380 commonQueryParams.collectFirst { case (" uploadType" , Parameter (_, _, e : SchemaType .Enum , _, _)) => e }
380381 ) match {
381382 case (Some (m), Some (ut)) => s """ QueryParameters(uploadType = Some(" ${ut.values.head.value}")) """
382383 case _ => " QueryParameters.empty"
383384 })
384385 )
385386
386- val setReqUri = v.mediaUpload match
387+ val setReqUri = method.mediaUploads match
387388 case None =>
388- s " val requestUri = endpointUrl.addPathSegments(List( ${pathSegments(v .urlPath).mkString(" , " )})) "
389+ s " val requestUri = endpointUrl.addPathSegments(List( ${pathSegments(method .urlPath).mkString(" , " )})) "
389390 case Some (m) =>
390391 List (
391392 " val requestUri = uploadProtocol match {" ,
@@ -402,7 +403,7 @@ def resourceCode(
402403 case Some (_) => """ .body(request.toJsonString)"""
403404
404405 val queryParams = " \n val params = " +
405- (v .scalaQueryParams match
406+ (method .scalaQueryParams match
406407 case Nil => " commonQueryParams.value"
407408 case qParams =>
408409 qParams
@@ -420,7 +421,7 @@ def resourceCode(
420421 case HttpSource .Sttp3 =>
421422 s " RequestT[Identity, Either[ResponseException[String, Exception], $t], Any] "
422423
423- val (resType, mapResponse) = v .response match
424+ val (resType, mapResponse) = method .response match
424425 case Some (r) if r.schemaPath.forall(hasProps) =>
425426 val bodyType = r.scalaType(arrType)
426427
@@ -432,7 +433,7 @@ def resourceCode(
432433
433434 s """ |def ${toScalaName(k)}(\n ${params.mkString(" ,\n " )}): $resType = { $queryParams
434435 | $setReqUri
435- | resourceRequest. ${v .httpMethod.toLowerCase()}(requestUri.addParams(params)) $body$mapResponse
436+ | resourceRequest. ${method .httpMethod.toLowerCase()}(requestUri.addParams(params)) $body$mapResponse
436437 |} """ .stripMargin
437438 }
438439 .mkString(" \n " , " \n\n " , " \n " ) +
@@ -584,7 +585,7 @@ case class Method(
584585 parameterOrder : List [String ],
585586 response : Option [SchemaType ],
586587 request : Option [SchemaType ] = None ,
587- mediaUpload : Option [MediaUpload ] = None
588+ private val mediaUpload : Option [MediaUpload ] = None
588589) {
589590 private lazy val flatPathParams : List [(String , Parameter )] = flatPath.toList.flatMap(p =>
590591 p.params.zipWithIndex.map((param, idx) =>
@@ -607,6 +608,20 @@ case class Method(
607608
608609 def urlPath : String = flatPath.map(_.path).getOrElse(path)
609610
611+ def mediaUploads : Option [MediaUpload ] = mediaUpload.map(m =>
612+ m.copy(protocols =
613+ m.protocols.view
614+ .mapValues(p =>
615+ // map the path to flatPath on placeholders with pattern like {+var_name} if the same is found in method path
616+ // need a better solution for this
617+ " \\ {(\\ +.*?)\\ }" .r.findAllIn(p.path).toList match
618+ case v :: Nil if path.contains(v) => p.copy(path = flatPath.map(_.path).getOrElse(p.path))
619+ case _ => p
620+ )
621+ .toMap
622+ )
623+ )
624+
610625 // filter out path params if flatPath params are given
611626 private lazy val pathParams : List [(String , Parameter )] =
612627 parameters.toList.filterNot((_, p) => flatPathParams.nonEmpty && p.location == " path" )
0 commit comments