swift-server / swift-aws-lambda-runtime

Swift implementation of AWS Lambda Runtime
Apache License 2.0
1.13k stars 102 forks source link

JSONCoder extensions... Potentially dangerous. #226

Open fabianfett opened 2 years ago

fabianfett commented 2 years ago

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.

stevapple commented 2 years ago

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.