@@ -22,13 +22,12 @@ case class GeneratorConfig(
2222 httpSource : HttpSource ,
2323 jsonCodec : JsonCodec ,
2424 arrayType : ArrayType ,
25- dialect : Dialect ,
2625 preprocess : Specs => Specs = s => s
2726)
2827
2928object GeneratorConfig :
3029 enum HttpSource :
31- case Sttp4 , Sttp3
30+ case Sttp4
3231
3332 enum JsonCodec :
3433 case ZioJson , Jsoniter
@@ -43,10 +42,6 @@ object GeneratorConfig:
4342 case ZioChunk => s " zio.Chunk[ $t] "
4443 }
4544
46- // potential dialect options
47- enum Dialect :
48- case Scala3
49-
5045enum SpecsInput :
5146 case StdIn
5247 case FilePath (path : Path )
@@ -103,12 +98,10 @@ def generateBySpec(
10398 List (
10499 s " ${toComment(List (s " ${specs.title} ${specs.version}" , specs.description, specs.documentationLink))}" ,
105100 " " ,
106- config.dialect match
107- case Dialect .Scala3 => s " package ${config.outPkg}" ,
101+ s " package ${config.outPkg}" ,
108102 " " ,
109103 config.httpSource match {
110104 case HttpSource .Sttp4 => " import sttp.model.*\n import sttp.client4.*"
111- case HttpSource .Sttp3 => " import sttp.model.*\n import sttp.client3.*"
112105 },
113106 " " ,
114107 s """ val baseUrl: Uri = uri" ${specs.baseUrl}" """ ,
@@ -150,24 +143,17 @@ def generateBySpec(
150143 Files .writeString(
151144 path,
152145 List (
153- config.dialect match
154- case Dialect .Scala3 => s " package $resourcesPkg" ,
146+ s " package $resourcesPkg" ,
155147 " " ,
156148 config.httpSource match {
157149 case HttpSource .Sttp4 =>
158150 " import sttp.model.*\n import sttp.client4.*, sttp.client4.ResponseException.{DeserializationException, UnexpectedStatusCode}"
159- case HttpSource .Sttp3 => " import sttp.model.*\n import sttp.client3.*"
160151 },
161152 config.jsonCodec match {
162153 case JsonCodec .ZioJson => " import zio.json.*"
163154 case JsonCodec .Jsoniter => " import com.github.plokhotnyuk.jsoniter_scala.core.*"
164155 },
165- config.dialect match
166- case Dialect .Scala3 => " " ,
167- s " val resourceRequest: ${
168- if config.httpSource == HttpSource .Sttp3 then " RequestT[Empty, Either[String, String], Any]"
169- else " PartialRequest[Either[String, String]]"
170- } = basicRequest.headers(Header.contentType(MediaType.ApplicationJson)) " ,
156+ s " val resourceRequest: PartialRequest[Either[String, String]] = basicRequest.headers(Header.contentType(MediaType.ApplicationJson)) " ,
171157 " " ,
172158 s " export ${config.outPkg}.QueryParameters " ,
173159 " " ,
@@ -184,29 +170,11 @@ def generateBySpec(
184170 | }
185171 | else Left(UnexpectedStatusCode(String(bytes, java.nio.charset.StandardCharsets.UTF_8), metadata))
186172 | )""" .stripMargin
187- case (HttpSource .Sttp3 , JsonCodec .Jsoniter ) =>
188- """ |def asJson[T : JsonValueCodec]: ResponseAs[Either[ResponseException[String, Exception], T], Any] =
189- | asByteArrayAlways.mapWithMetadata((bytes, metadata) =>
190- | if metadata.isSuccess then
191- | try {
192- | Right(readFromArray[T](bytes))
193- | } catch {
194- | case e: Exception =>
195- | Left(DeserializationException(String(bytes, java.nio.charset.StandardCharsets.UTF_8), e))
196- | }
197- | else Left(HttpError(String(bytes, java.nio.charset.StandardCharsets.UTF_8), metadata.code))
198- | )""" .stripMargin
199173 case (HttpSource .Sttp4 , JsonCodec .ZioJson ) =>
200174 """ |def asJson[T : JsonDecoder]: ResponseAs[Either[ResponseException[String], T]] =
201175 | asStringAlways.mapWithMetadata((body, metadata) =>
202176 | if metadata.isSuccess then body.fromJson[T].left.map(e => DeserializationException(body, Exception(e), metadata))
203177 | else Left(UnexpectedStatusCode(body, metadata))
204- | )""" .stripMargin
205- case (HttpSource .Sttp3 , JsonCodec .ZioJson ) =>
206- """ |def asJson[T : JsonDecoder]: ResponseAs[Either[ResponseException[String, Exception], T], Any] =
207- | asStringAlways.mapWithMetadata((body, metadata) =>
208- | if metadata.isSuccess then body.fromJson[T].left.map(e => DeserializationException(body, Exception(e)))
209- | else Left(HttpError(body, metadata.code))
210178 | )""" .stripMargin,
211179 " " ,
212180 config.httpSource match
@@ -216,12 +184,6 @@ def generateBySpec(
216184 | if metadata.isSuccess then Right(body)
217185 | else Left(UnexpectedStatusCode(body, metadata))
218186 | )""" .stripMargin
219- case HttpSource .Sttp3 =>
220- """ |def asEmptyResponse: ResponseAs[Either[ResponseException[String, Exception], String], Any] =
221- | asStringAlways.mapWithMetadata((body, metadata) =>
222- | if metadata.isSuccess then Right(body)
223- | else Left(HttpError(body, metadata.code))
224- | )""" .stripMargin
225187 ).mkString(" \n " )
226188 )
227189 List (path.toFile())
@@ -272,7 +234,6 @@ def generateBySpec(
272234 schema = schema,
273235 pkg = schemasPkg,
274236 jsonCodec = config.jsonCodec,
275- dialect = config.dialect,
276237 hasProps = p => specs.hasProps(p),
277238 arrType = config.arrayType,
278239 commonCodecsPkg =
@@ -320,7 +281,6 @@ def resourceCode(
320281) =
321282 val sttpClientPkg = httpSource match
322283 case HttpSource .Sttp4 => " sttp.client4"
323- case HttpSource .Sttp3 => " sttp.client3"
324284
325285 List (
326286 s " package $pkg" ,
@@ -414,8 +374,6 @@ def resourceCode(
414374 httpSource match
415375 case HttpSource .Sttp4 =>
416376 s " Request[Either[ResponseException[String], $t]] "
417- case HttpSource .Sttp3 =>
418- s " RequestT[Identity, Either[ResponseException[String, Exception], $t], Any] "
419377
420378 val (resType, mapResponse) = method.response match
421379 case Some (r) if r.schemaPath.forall(hasProps) =>
@@ -440,7 +398,6 @@ def schemasCode(
440398 schema : Schema ,
441399 pkg : String ,
442400 jsonCodec : JsonCodec ,
443- dialect : Dialect ,
444401 hasProps : SchemaPath => Boolean ,
445402 arrType : ArrayType ,
446403 commonCodecsPkg : Option [String ]
@@ -505,10 +462,8 @@ def schemasCode(
505462 |import com.github.plokhotnyuk.jsoniter_scala.macros.*""" .stripMargin
506463 },
507464 commonCodecsPkg match
508- case Some (codecsPkg) =>
509- dialect match
510- case Dialect .Scala3 => s " import $codecsPkg.given "
511- case _ => " " ,
465+ case Some (codecsPkg) => s " import $codecsPkg.given "
466+ case _ => " " ,
512467 toSchemaClass(schema)
513468 ).mkString(" \n " )
514469}
0 commit comments