-
Notifications
You must be signed in to change notification settings - Fork 475
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
Add trim support for Amazon.Lambda.Annotations #1610
Add trim support for Amazon.Lambda.Annotations #1610
Conversation
@@ -14,9 +14,9 @@ public class HttpResultsTest | |||
[Fact] | |||
public void OkNoBody() | |||
{ | |||
var result = HttpResults.Ok(); | |||
var result = () => HttpResults.Ok(); |
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.
This is the change mention in the description where ValidateResult
runs across the different combinations of API Gateway responses. The unit tests were change to pass in a Func
instead of a single instance so we didn't reuse the same IHttpResult
for each iteration in ValidateResult
.
@@ -162,9 +162,9 @@ public void Execute(GeneratorExecutionContext context) | |||
} | |||
} | |||
|
|||
var serializerString = GetSerializerAttribute(context, lambdaMethodModel); | |||
var serializerInfo = GetSerializerInfoAttribute(context, lambdaMethodModel); |
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.
This was changed to GetSerializerInfoAttribute
because now we are getting the optional JsonSerializerContext
as well as the serializer name.
Libraries/test/TestExecutableServerlessApp/SourceGenerationSerializationExample.cs
Show resolved
Hide resolved
Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Models/LambdaSerializerInfo.cs
Show resolved
Hide resolved
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.
All looks good to me. Testing with .NET 8 and native AOT and it works perfectly.
Description of changes:
Add trimming support for Lambda Annotations. Using trimming requires users to use the
SourceGeneratorLambdaJsonSerializer
lambda serializer so that JSON serialization is not being done via reflection.The
HttpResults
class was modified to use theJsonSerializerContext
that theSourceGeneratorLambdaJsonSerializer
is registered with via the generic parameter. It uses theJsonSerializerContext
to serialize the HTTP response body. It means the user has to register any types returned via HttpResults in the body with theJsonSerializerContext
via theJsonSerializable
attribute.Another slight change to
HttpResults
is it used to handle the serialization as soon as part of the constructor but there is no way to get theJsonSerializerContext
into the constructor. So I changed body serialization to the when we serialize theHttpResults
. This affected the unit tests because they were unintended reusing the sameIHttpResult
for each serialization format. So I change the test to create a new instance every time we run the serializer.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.