@@ -129,9 +129,18 @@ def generateBySpec(
129129 if specs.endpoints.nonEmpty then " enum Endpoint(val location: String, val url: Uri):" else " " ,
130130 specs.endpoints
131131 .map(e =>
132+ // for cases where location is not unique we will append numbers
133+ val locationPostfix = specs.endpoints
134+ .collect { case Endpoint (location = e.location, endpointUrl = endpointUrl) =>
135+ endpointUrl
136+ }
137+ .zipWithIndex
138+ .collectFirst { case (e.endpointUrl, idx) if idx > 0 => (idx + 1 ).toString() }
139+ .getOrElse(" " )
140+
132141 s """ ${toComment(
133142 Some (e.description)
134- )} case ` ${e.location}` extends Endpoint(" ${e.location}", uri" ${e.endpointUrl}") """ .stripMargin
143+ )} case ` ${e.location}$locationPostfix ` extends Endpoint(" ${e.location}", uri" ${e.endpointUrl}") """ .stripMargin
135144 )
136145 .mkString(" \n " )
137146 ).mkString(" \n " )
@@ -220,7 +229,7 @@ def generateBySpec(
220229 hasProps = p => specs.hasProps(p),
221230 arrType = config.arrayType
222231 ) match
223- case None => Nil
232+ case None => Nil
224233 case Some (codecs) =>
225234 Files .writeString(commonCodecsPath, codecs)
226235 List (commonCodecsPath.toFile())
@@ -301,10 +310,9 @@ def resourceCode(
301310 " \\ {(.*?)\\ }" .r.findAllIn(s).toList match
302311 case Nil => s " PathSegment( \" $s\" ) "
303312 case v :: Nil if v == s => " PathSegment(" + toScalaName(v.stripPrefix(" {" ).stripSuffix(" }" )) + " )"
304- case vars =>
305- " PathSegment(s\" " + vars.foldLeft(s)((res, v) =>
306- res.replace(v, " $" + v.stripPrefix(" {" ).stripSuffix(" }" ))
307- ) + " \" )"
313+ case vars =>
314+ " PathSegment(s\" " + vars
315+ .foldLeft(s)((res, v) => res.replace(v, " $" + v.stripPrefix(" {" ).stripSuffix(" }" ))) + " \" )"
308316 )
309317
310318 val req = method.mediaUploads match
@@ -362,15 +370,14 @@ def resourceCode(
362370
363371 val queryParams = " \n val params = " +
364372 (method.scalaQueryParams match
365- case Nil => " commonQueryParams.value"
373+ case Nil => " commonQueryParams.value"
366374 case qParams =>
367375 qParams
368376 .map {
369377 case (k, p) if p.required => s """ Map(" $k" -> $k) """
370378 case (k, p) => s """ $k.map(p => Map(" $k" -> p.toString)).getOrElse(Map.empty) """
371379 }
372- .mkString(" " , " ++ " , " ++ commonQueryParams.value\n " )
373- )
380+ .mkString(" " , " ++ " , " ++ commonQueryParams.value\n " ))
374381
375382 def responseType (t : String ) =
376383 httpSource match
@@ -459,7 +466,7 @@ def schemasCode(
459466 s " package $pkg" ,
460467 " " ,
461468 jsonCodec match {
462- case JsonCodec .ZioJson => " import zio.json.*"
469+ case JsonCodec .ZioJson => " import zio.json.*"
463470 case JsonCodec .Jsoniter =>
464471 """ |import com.github.plokhotnyuk.jsoniter_scala.core.*
465472 |import com.github.plokhotnyuk.jsoniter_scala.macros.*""" .stripMargin
@@ -492,7 +499,7 @@ def commonSchemaCodecs(
492499 }
493500 )
494501 .distinct match
495- case Nil => None
502+ case Nil => None
496503 case props =>
497504 Some (
498505 List (
@@ -631,7 +638,7 @@ def readResources(
631638 resources match
632639 case (k, v) :: xs =>
633640 v.obj.remove(" resources" ).map(_.obj) match
634- case None => readResources(xs, result.updated(k, read[Resource ](v)))
641+ case None => readResources(xs, result.updated(k, read[Resource ](v)))
635642 case Some (obj) =>
636643 val newRes = obj.map((a, b) => ResourcePath (k, a) -> b).toList ::: xs
637644 Try (read[Resource ](v)) match
@@ -727,8 +734,8 @@ enum SchemaType(val optional: Boolean):
727734 case Primitive (" number" , _, Some (" double" | " float" )) => toType(" Double" )
728735 case Primitive (" boolean" , _, _) => toType(" Boolean" )
729736 case Ref (ref, _) => toType(ref.scalaName)
730- case Array (t, _) => toType(arrayType.toScalaType(t.scalaType(arrayType, enumType)))
731- case Object (t, _) => toType(s " Map[String, ${t.scalaType(arrayType)}] " )
737+ case Array (t, _) => toType(arrayType.toScalaType(t.scalaType(arrayType, enumType)))
738+ case Object (t, _) => toType(s " Map[String, ${t.scalaType(arrayType)}] " )
732739 case Enum (_, values, _) =>
733740 enumType match
734741 case SchemaType .EnumType .Literal => toType(values.map(v => v.value).mkString(" \" " , " \" | \" " , " \" " ))
@@ -777,7 +784,7 @@ object SchemaType:
777784 case _ =>
778785 o.value.get(" $ref" ).map(_.str) match
779786 case Some (ref) => SchemaType .Ref (SchemaPath (ref), optional)
780- case _ =>
787+ case _ =>
781788 if ! o.value.keySet.contains(" properties" ) then
782789 if Set (" uploadType" , " upload_protocol" ).exists(context.jsonPath.lastOption.contains) then
783790 """ "([\w]+)"""" .r
@@ -852,7 +859,7 @@ object Schema:
852859 result : Map [SchemaPath , Schema ]
853860 ): Map [SchemaPath , Schema ] =
854861 schemas match {
855- case Nil => result
862+ case Nil => result
856863 case (name, data) :: xs =>
857864 val schema = readSchema(name, data)
858865
@@ -862,7 +869,7 @@ object Schema:
862869 case None => Nil
863870 case Some (p) => List ((p, p.jsonPath.foldLeft(o)(_.apply(_).obj)))
864871 } match {
865- case Nil => readSchemas(xs, result.updated(name, schema))
872+ case Nil => readSchemas(xs, result.updated(name, schema))
866873 case nested =>
867874 readSchemas(nested ::: xs, result.updated(name, schema))
868875 }
0 commit comments