Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing ListMap properties break decoding #136

Closed
Primetalk opened this issue Jan 18, 2024 · 2 comments · Fixed by #138
Closed

Missing ListMap properties break decoding #136

Primetalk opened this issue Jan 18, 2024 · 2 comments · Fixed by #138

Comments

@Primetalk
Copy link

When decoding MediaType without examples, circe issues an error:

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:

  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])
  }
@adamw
Copy link
Member

adamw commented Jan 22, 2024

@Primetalk Yes, decoding might have some holes. Maybe you'd like to attempt creating a PR to fix this? :)

Primetalk pushed a commit to Primetalk/sttp-apispec that referenced this issue Jan 25, 2024
Primetalk pushed a commit to Primetalk/sttp-apispec that referenced this issue Jan 25, 2024
@Primetalk
Copy link
Author

@adamw Could you take a look #138 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants