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

correct circe encoder for OpenAPI #1003

Merged
merged 1 commit into from Feb 11, 2021
Merged

correct circe encoder for OpenAPI #1003

merged 1 commit into from Feb 11, 2021

Conversation

dkarwacki
Copy link
Contributor

No description provided.

@dkarwacki dkarwacki requested a review from adamw February 10, 2021 13:38
@@ -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))
Copy link
Member

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?

Copy link
Contributor Author

@dkarwacki dkarwacki Feb 10, 2021

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

Copy link
Contributor Author

@dkarwacki dkarwacki Feb 10, 2021

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

import sttp.tapir.openapi.circe.yaml._

println(docs.toYaml)
println(docs.asJson)
Copy link
Member

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?

Copy link
Contributor Author

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

Copy link
Member

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)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

corrected

@adamw adamw merged commit 0a56d69 into master Feb 11, 2021
@mergify mergify bot deleted the open-api-to-json branch February 11, 2021 07:33
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 this pull request may close these issues.

None yet

2 participants