Skip to content

Commit

Permalink
Fix linting
Browse files Browse the repository at this point in the history
  • Loading branch information
blockvote committed Jun 3, 2024
1 parent 1ecb2ff commit 6d7fb5a
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ object ProtoBufUtils {

fun removeWrapperObjects(json: String): String {
return removeWrapperObjects(
jacksonObjectMapper().readTree(json)
jacksonObjectMapper().readTree(json),
).toString()
}

Expand All @@ -38,7 +38,7 @@ object ProtoBufUtils {
if (entry.value.size() > 0) {
result.replace(
entry.key,
removeWrapperObjects(entry.value)
removeWrapperObjects(entry.value),
)
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ class ProtoDeserializationHandler : DeserializationHandler {
MediaType.parse(input.contentType()).let { proto.isCompatibleWith(it) || protoStructuredSuffixWildcard.isCompatibleWith(it) }
}

override fun deserialize(input: APIGatewayProxyRequestEvent, target: KType?): Any {
override fun deserialize(
input: APIGatewayProxyRequestEvent,
target: KType?,
): Any {
val bytes = Base64.getDecoder().decode(input.body)
val parser = (target?.classifier as KClass<*>).staticFunctions.first { it.name == "parser" }.call() as Parser<*>
return parser.parseFrom(bytes)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,13 @@ import io.moia.router.RequestHandler
import io.moia.router.ResponseEntity

abstract class ProtoEnabledRequestHandler : RequestHandler() {
override fun serializationHandlers() = listOf(ProtoSerializationHandler()) + super.serializationHandlers()

override fun serializationHandlers() =
listOf(ProtoSerializationHandler()) + super.serializationHandlers()

override fun deserializationHandlers() =
listOf(ProtoDeserializationHandler()) + super.deserializationHandlers()
override fun deserializationHandlers() = listOf(ProtoDeserializationHandler()) + super.deserializationHandlers()

override fun <T> createResponse(
contentType: MediaType,
response: ResponseEntity<T>
response: ResponseEntity<T>,
): APIGatewayProxyResponseEvent {
return super.createResponse(contentType, response).withIsBase64Encoded(true)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,18 @@ import isCompatibleWith
import java.util.Base64

class ProtoSerializationHandler : SerializationHandler {

private val json = MediaType.parse("application/json")
private val jsonStructuredSuffixWildcard = MediaType.parse("application/*+json")

override fun supports(acceptHeader: MediaType, body: Any): Boolean =
body is GeneratedMessageV3
override fun supports(
acceptHeader: MediaType,
body: Any,
): Boolean = body is GeneratedMessageV3

override fun serialize(acceptHeader: MediaType, body: Any): String {
override fun serialize(
acceptHeader: MediaType,
body: Any,
): String {
val message = body as GeneratedMessageV3
return if (json.isCompatibleWith(acceptHeader) || jsonStructuredSuffixWildcard.isCompatibleWith(acceptHeader)) {
ProtoBufUtils.toJsonWithoutWrappers(message)
Expand Down

0 comments on commit 6d7fb5a

Please sign in to comment.