-
Notifications
You must be signed in to change notification settings - Fork 494
Add trim support for Amazon.Lambda.Annotations #1610
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
Conversation
| 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.
| } | ||
|
|
||
| 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
SourceGeneratorLambdaJsonSerializerlambda serializer so that JSON serialization is not being done via reflection.The
HttpResultsclass was modified to use theJsonSerializerContextthat theSourceGeneratorLambdaJsonSerializeris registered with via the generic parameter. It uses theJsonSerializerContextto serialize the HTTP response body. It means the user has to register any types returned via HttpResults in the body with theJsonSerializerContextvia theJsonSerializableattribute.Another slight change to
HttpResultsis it used to handle the serialization as soon as part of the constructor but there is no way to get theJsonSerializerContextinto the constructor. So I changed body serialization to the when we serialize theHttpResults. This affected the unit tests because they were unintended reusing the sameIHttpResultfor 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.