swift-aws-lambda-runtime icon indicating copy to clipboard operation
swift-aws-lambda-runtime copied to clipboard

JSONCoder extensions... Potentially dangerous.

Open fabianfett opened this issue 4 years ago • 1 comments

We do something potentially dangerous here: https://github.com/swift-server/swift-aws-lambda-runtime/pull/144

We extend a type we don't own with an unprefixed method that only takes arguments we don't own.

fabianfett avatar Aug 26 '21 17:08 fabianfett

I agree that this extension should go away... APIGateway issue could have a better solution.

I'm not saying that I've already got a better solution. I'm just showing how I handle this in swift-tencent-scf-runtime:

https://github.com/stevapple/swift-tencent-scf-runtime/blob/a60f1596247d7fa4d4cf83ae37e5965fc61275b2/Sources/TencentSCFEvents/APIResponse.swift#L61..#L69 https://github.com/stevapple/swift-tencent-scf-runtime/blob/a60f1596247d7fa4d4cf83ae37e5965fc61275b2/Sources/TencentSCFEvents/APIGateway.swift#L69..#L78

Motivation: Request and Response are not handled in the same way. Request body is supposed to be of fixed type, thus using Generic. Response could have different types depending on processing result, thus using an enum to hold it.

stevapple avatar Aug 26 '21 18:08 stevapple