-
Notifications
You must be signed in to change notification settings - Fork 423
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
correct circe encoder for OpenAPI #1003
Conversation
@@ -75,7 +75,7 @@ trait TapirOpenAPICirceEncoders { | |||
implicit val encoderInfo: Encoder[Info] = deriveEncoder[Info] | |||
implicit val encoderContact: Encoder[Contact] = deriveEncoder[Contact] | |||
implicit val encoderLicense: Encoder[License] = deriveEncoder[License] | |||
implicit val encoderOpenAPI: Encoder[OpenAPI] = deriveEncoder[OpenAPI] | |||
implicit val encoderOpenAPI: Encoder[OpenAPI] = deriveEncoder[OpenAPI].mapJsonObject(json => json.filter{ case (_, v) => !v.isNull}.mapValues(_.deepDropNullValues)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we need the filter
- isn't deepDropNullValues
enough?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep, without that filter, only nested nulls were dropped but the ones within first braces were not
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, it can be simplified to deriveEncoder[OpenAPI].mapJson(json => json.deepDropNullValues)
, i've made correction
doc/docs/openapi.md
Outdated
import sttp.tapir.openapi.circe.yaml._ | ||
|
||
println(docs.toYaml) | ||
println(docs.asJson) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.asJson
only coverts to a Json
object, this isn't yet serialised to a string, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, but println() automatically convert it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's maybe add an explicit example how to serialise to a string (if I remember correctly, using Printer
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
corrected
a31209f
to
7f536d3
Compare
7f536d3
to
4067bb9
Compare
No description provided.