Scala Tapir无法解码带有“DecodingFailure”(CNil,list(DownArray))的密封特征列表`

Scala Tapir无法解码带有“DecodingFailure”(CNil,list(DownArray))的密封特征列表`,scala,circe,sttp,tapir,Scala,Circe,Sttp,Tapir,Tapir文档说明它支持解码以下特征: 但是,当我尝试使用此代码执行此操作时,会出现以下错误: 导入io.circe.generic.auto_ 导入sttp.client3_ 导入sttp.tapir.{Schema,} 导入sttp.tapir.client.sttp_ 导入sttp.tapir.generic.auto_ 导入sttp.tapir.json.circe_ 对象TmpApp扩展应用程序{ 封闭性状结果{ def状态:字符串 } 最终案例类IpInfo( 查询:字符串, 国家:

Tapir文档说明它支持解码以下特征:

但是,当我尝试使用此代码执行此操作时,会出现以下错误:

导入io.circe.generic.auto_
导入sttp.client3_
导入sttp.tapir.{Schema,}
导入sttp.tapir.client.sttp_
导入sttp.tapir.generic.auto_
导入sttp.tapir.json.circe_
对象TmpApp扩展应用程序{
封闭性状结果{
def状态:字符串
}
最终案例类IpInfo(
查询:字符串,
国家:字符串,
regionName:String,
城市:字符串,
拉特:浮动,
朗:浮子,
isp:字符串,
org:String,
as:String,
asname:String
)扩展结果{
def状态:String=“成功”
}
最终案例类失败(消息:字符串,查询:字符串)扩展结果{
def状态:String=“失败”
}
val sIpInfo=Schema.derivate[IpInfo]
val sFail=Schema.derivate[Fail]
隐式val sResult:Schema[结果]=
Schema.oneOfUsingField[Result,String](u.status,u.toString)(“success”->sIpInfo,“fail”->sFail)
val apidentpoint=endpoint.get
.in.(“批量”)
.in(查询[字符串](“字段”))
.in(jsonBody[List[String]])
.out(jsonBody[列表[结果])
.errorOut(stringBody)
val backend:SttpBackend[Identity,Any]=HttpURLConnectionBackend()
Apident
.tostPrequestunsafe(uri)http://ip-api.com/")
.适用((“4255449”,列表(
"127.0.0.1"
)))
.send(后端)
.身体
}
build.sbt:

  "com.softwaremill.sttp.tapir" %% "tapir-core" % "0.17.0-M10",
  "com.softwaremill.sttp.tapir" %% "tapir-sttp-client" % "0.17.0-M10",
  "com.softwaremill.sttp.tapir" %% "tapir-json-circe" % "0.17.0-M10",

此特定端点的文档可在此处找到:

解码委托给Circe。文档中所描述的只是
Schema
s的派生-这是文档所必需的


因此,我将通过检查范围内是否有正确的
解码器来查找错误原因,并检查如果您尝试直接使用circe解码示例值会发生什么情况。

以下是我解决问题的方法,以供将来参考

原来我错过了一个电路
解码器:

implicit val decoderResult:Decoder[Result]=解码器[Fail]。加宽或解码器[IpInfo]。加宽
在代码开始工作后,我也对代码进行了一些清理

import cats.syntax.functor_
输入io.circe.Decoder
导入io.circe.generic.auto_
导入sttp.client3_
导入sttp.tapir_
导入sttp.tapir.client.sttp_
导入sttp.tapir.generic.auto_
导入sttp.tapir.json.circe_
对象TmpApp扩展应用程序{
封闭性状结果
最终案例类IpInfo(
查询:字符串,
国家:字符串,
regionName:String,
城市:字符串,
拉特:浮动,
朗:浮子,
isp:字符串,
org:String,
as:String,
asname:String
)扩展结果
最终案例类失败(消息:字符串,查询:字符串)扩展结果
隐式val decoderResult:解码器[Result]=解码器[Fail]。加宽或解码器[IpInfo]。加宽
val Apident=
endpoint.get
.in.(“批量”)
.in(查询[字符串](“字段”))
.in(jsonBody[List[String]])
.out(jsonBody[列表[结果])
.errorOut(stringBody)
val backend:SttpBackend[Identity,Any]=HttpURLConnectionBackend()
普林顿(
Apident
.tostPrequestunsafe(uri)http://ip-api.com/")
.适用((“4255449”,列表(“127.0.0.1”))
.send(后端)
.身体
)
}

谢谢你,亚当!我能够在没有塔皮尔的情况下重现这一问题,而且只需要Circe。我确实缺少一个隐式的
解码器
。添加此行解决了我的问题:
implicit val decoderResult:Decoder[Result]=Decoder[Fail]。加宽或解码器[IpInfo]。加宽
  "com.softwaremill.sttp.tapir" %% "tapir-core" % "0.17.0-M10",
  "com.softwaremill.sttp.tapir" %% "tapir-sttp-client" % "0.17.0-M10",
  "com.softwaremill.sttp.tapir" %% "tapir-json-circe" % "0.17.0-M10",