Closed Primetalk closed 7 months ago
When decoding MediaType without examples, circe issues an error:
MediaType
examples
DecodingFailure at ./url.post.parameters.examples: Missing required field
A better alternative would be to use ListMap.empty. The implementation in https://github.com/softwaremill/sttp-apispec/blob/master/openapi-circe/src/main/scala/sttp/apispec/openapi/internal/InternalSttpOpenAPICirceDecoders.scala#L61:
ListMap.empty
implicit val mediaTypeDecoder: Decoder[MediaType] = withExtensions(deriveDecoder[MediaType])
is a bit too simple. It seems that we'd better use something like https://github.com/softwaremill/sttp-apispec/blob/master/openapi-circe/src/main/scala/sttp/apispec/openapi/internal/InternalSttpOpenAPICirceDecoders.scala#L65:
implicit val responseDecoder: Decoder[Response] = { implicit def listMapDecoder[A: Decoder]: Decoder[ListMap[String, ReferenceOr[A]]] = Decoder.decodeOption(Decoder.decodeMapLike[String, ReferenceOr[A], ListMap]).map(_.getOrElse(ListMap.empty)) implicit def listMapMediaTypeDecoder: Decoder[ListMap[String, MediaType]] = Decoder.decodeOption(Decoder.decodeMapLike[String, MediaType, ListMap]).map(_.getOrElse(ListMap.empty)) withExtensions(deriveDecoder[Response]) }
@Primetalk Yes, decoding might have some holes. Maybe you'd like to attempt creating a PR to fix this? :)
@adamw Could you take a look https://github.com/softwaremill/sttp-apispec/pull/138 ?
When decoding
MediaType
withoutexamples
, circe issues an error:A better alternative would be to use
ListMap.empty
. The implementation in https://github.com/softwaremill/sttp-apispec/blob/master/openapi-circe/src/main/scala/sttp/apispec/openapi/internal/InternalSttpOpenAPICirceDecoders.scala#L61:is a bit too simple. It seems that we'd better use something like https://github.com/softwaremill/sttp-apispec/blob/master/openapi-circe/src/main/scala/sttp/apispec/openapi/internal/InternalSttpOpenAPICirceDecoders.scala#L65: