diff --git a/Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Generator.cs b/Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Generator.cs index 4ff503042..01413fb16 100644 --- a/Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Generator.cs +++ b/Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Generator.cs @@ -356,7 +356,6 @@ private bool HasSerializerAttribute(GeneratorExecutionContext context, IMethodSy private LambdaSerializerInfo GetSerializerInfoAttribute(GeneratorExecutionContext context, IMethodSymbol methodModel) { var serializerString = DEFAULT_LAMBDA_SERIALIZER; - string serializerJsonContext = null; ISymbol symbol = null; @@ -377,24 +376,19 @@ private LambdaSerializerInfo GetSerializerInfoAttribute(GeneratorExecutionContex // Else return the default serializer. else { - return new LambdaSerializerInfo(serializerString, serializerJsonContext); + return new LambdaSerializerInfo(serializerString); } var attribute = symbol.GetAttributes().FirstOrDefault(attr => attr.AttributeClass.Name == TypeFullNames.LambdaSerializerAttributeWithoutNamespace); var serializerValue = attribute.ConstructorArguments.FirstOrDefault(kvp => kvp.Type.Name == nameof(Type)).Value; - if(serializerValue is INamedTypeSymbol typeSymbol && typeSymbol.Name.Contains("SourceGeneratorLambdaJsonSerializer") && typeSymbol.TypeArguments.Length == 1) - { - serializerJsonContext = typeSymbol.TypeArguments[0].ToString(); - } - if (serializerValue != null) { serializerString = serializerValue.ToString(); } - return new LambdaSerializerInfo(serializerString, serializerJsonContext); + return new LambdaSerializerInfo(serializerString); } public void Initialize(GeneratorInitializationContext context) diff --git a/Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Models/GeneratedMethodModelBuilder.cs b/Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Models/GeneratedMethodModelBuilder.cs index 5a0460beb..6150dda8d 100644 --- a/Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Models/GeneratedMethodModelBuilder.cs +++ b/Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Models/GeneratedMethodModelBuilder.cs @@ -148,7 +148,8 @@ private static IList BuildParameters(IMethodSymbol lambdaMethodS Type = new TypeModel { FullName = TypeFullNames.ILambdaContext - } + }, + Documentation = "The ILambdaContext that provides methods for logging and describing the Lambda environment." }; if (lambdaMethodSymbol.HasAttribute(context, TypeFullNames.RestApiAttribute)) @@ -158,7 +159,8 @@ private static IList BuildParameters(IMethodSymbol lambdaMethodS var requestParameter = new ParameterModel { Name = "__request__", - Type = type + Type = type, + Documentation = "The API Gateway request object that will be processed by the Lambda function handler." }; parameters.Add(requestParameter); parameters.Add(contextParameter); @@ -188,7 +190,8 @@ private static IList BuildParameters(IMethodSymbol lambdaMethodS var requestParameter = new ParameterModel { Name = "__request__", - Type = type + Type = type, + Documentation = "The API Gateway request object that will be processed by the Lambda function handler." }; parameters.Add(requestParameter); parameters.Add(contextParameter); @@ -208,6 +211,11 @@ private static IList BuildParameters(IMethodSymbol lambdaMethodS else if(param.Type.FullName == TypeFullNames.ILambdaContext) { param.Name = "__context__"; + param.Documentation = "The ILambdaContext that provides methods for logging and describing the Lambda environment."; + } + else + { + param.Documentation = "The request object that will be processed by the Lambda function handler."; } parameters.Add(param); diff --git a/Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Models/LambdaFunctionModel.cs b/Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Models/LambdaFunctionModel.cs index cba07d22a..8ef99542c 100644 --- a/Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Models/LambdaFunctionModel.cs +++ b/Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Models/LambdaFunctionModel.cs @@ -35,7 +35,7 @@ public class LambdaFunctionModel : ILambdaFunctionSerializable /// Gets or sets fully qualified name of the serializer used for serialization or deserialization. /// public LambdaSerializerInfo SerializerInfo { get; set; } = - new LambdaSerializerInfo("Amazon.Lambda.Serialization.SystemTextJson.DefaultLambdaJsonSerializer", null); + new LambdaSerializerInfo("Amazon.Lambda.Serialization.SystemTextJson.DefaultLambdaJsonSerializer"); /// /// Gets or sets if the output is an executable. diff --git a/Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Models/LambdaSerializerInfo.cs b/Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Models/LambdaSerializerInfo.cs index 195818065..b73ce84af 100644 --- a/Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Models/LambdaSerializerInfo.cs +++ b/Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Models/LambdaSerializerInfo.cs @@ -14,20 +14,14 @@ public class LambdaSerializerInfo /// /// /// - public LambdaSerializerInfo(string serializerName, string serializerJsonContextName) + public LambdaSerializerInfo(string serializerName) { SerializerName = serializerName; - SerializerJsonContextName = serializerJsonContextName; } /// /// The full name of the type registered as the ILambdaSerializer. /// public string SerializerName { get; } - - /// - /// The full name of the type used as the generic parameter of the SourceGeneratorLambdaJsonSerializer. - /// - public string SerializerJsonContextName { get; } } } diff --git a/Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Models/ParameterModel.cs b/Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Models/ParameterModel.cs index ddcaa525b..26780f09b 100644 --- a/Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Models/ParameterModel.cs +++ b/Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Models/ParameterModel.cs @@ -23,5 +23,10 @@ public class ParameterModel /// an empty list. /// public IList Attributes { get; set; } = new List(); + + /// + /// Gets or sets the documentation of parameter. + /// + public string Documentation { get; set; } } } \ No newline at end of file diff --git a/Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Templates/APIGatewayInvoke.cs b/Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Templates/APIGatewayInvoke.cs index 36dff2f66..2e7b0ef9e 100644 --- a/Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Templates/APIGatewayInvoke.cs +++ b/Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Templates/APIGatewayInvoke.cs @@ -22,7 +22,7 @@ namespace Amazon.Lambda.Annotations.SourceGenerator.Templates /// Class to produce the template output /// - #line 1 "C:\codebase\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\APIGatewayInvoke.tt" + #line 1 "C:\codebase\V3\HLL\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\APIGatewayInvoke.tt" [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.TextTemplating", "17.0.0.0")] public partial class APIGatewayInvoke : APIGatewayInvokeBase { @@ -33,7 +33,7 @@ public partial class APIGatewayInvoke : APIGatewayInvokeBase public virtual string TransformText() { - #line 10 "C:\codebase\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\APIGatewayInvoke.tt" + #line 10 "C:\codebase\V3\HLL\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\APIGatewayInvoke.tt" var restApiAttribute = _model.LambdaMethod.Attributes.FirstOrDefault(att => att.Type.FullName == TypeFullNames.RestApiAttribute) as AttributeModel; var httpApiAttribute = _model.LambdaMethod.Attributes.FirstOrDefault(att => att.Type.FullName == TypeFullNames.HttpApiAttribute) as AttributeModel; @@ -46,27 +46,27 @@ public virtual string TransformText() #line hidden this.Write(" var httpResults = "); - #line 17 "C:\codebase\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\APIGatewayInvoke.tt" + #line 17 "C:\codebase\V3\HLL\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\APIGatewayInvoke.tt" this.Write(this.ToStringHelper.ToStringWithCulture(_model.LambdaMethod.ReturnsGenericTask ? "await " : "")); #line default #line hidden - #line 17 "C:\codebase\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\APIGatewayInvoke.tt" + #line 17 "C:\codebase\V3\HLL\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\APIGatewayInvoke.tt" this.Write(this.ToStringHelper.ToStringWithCulture(_model.LambdaMethod.ContainingType.Name.ToCamelCase())); #line default #line hidden this.Write("."); - #line 17 "C:\codebase\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\APIGatewayInvoke.tt" + #line 17 "C:\codebase\V3\HLL\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\APIGatewayInvoke.tt" this.Write(this.ToStringHelper.ToStringWithCulture(_model.LambdaMethod.Name)); #line default #line hidden this.Write("("); - #line 17 "C:\codebase\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\APIGatewayInvoke.tt" + #line 17 "C:\codebase\V3\HLL\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\APIGatewayInvoke.tt" this.Write(this.ToStringHelper.ToStringWithCulture(_parameterSignature)); #line default @@ -74,7 +74,7 @@ public virtual string TransformText() this.Write(");\r\n HttpResultSerializationOptions.ProtocolFormat serializationFormat" + " = "); - #line 18 "C:\codebase\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\APIGatewayInvoke.tt" + #line 18 "C:\codebase\V3\HLL\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\APIGatewayInvoke.tt" this.Write(this.ToStringHelper.ToStringWithCulture(restApiAttribute != null ? "HttpResultSerializationOptions.ProtocolFormat.RestApi" : "HttpResultSerializationOptions.ProtocolFormat.HttpApi")); #line default @@ -82,25 +82,17 @@ public virtual string TransformText() this.Write(";\r\n HttpResultSerializationOptions.ProtocolVersion serializationVersio" + "n = "); - #line 19 "C:\codebase\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\APIGatewayInvoke.tt" + #line 19 "C:\codebase\V3\HLL\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\APIGatewayInvoke.tt" this.Write(this.ToStringHelper.ToStringWithCulture(restApiAttribute != null || httpApiAttribute?.Data.Version == Amazon.Lambda.Annotations.APIGateway.HttpApiVersion.V1 ? "HttpResultSerializationOptions.ProtocolVersion.V1" : "HttpResultSerializationOptions.ProtocolVersion.V2")); - #line default - #line hidden - this.Write(";\r\n System.Text.Json.Serialization.JsonSerializerContext jsonContext =" + - " "); - - #line 20 "C:\codebase\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\APIGatewayInvoke.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(_model.SerializerInfo.SerializerJsonContextName != null ? _model.SerializerInfo.SerializerJsonContextName + ".Default" : "null")); - #line default #line hidden this.Write(";\r\n var serializationOptions = new HttpResultSerializationOptions { Fo" + - "rmat = serializationFormat, Version = serializationVersion, JsonContext = jsonCo" + - "ntext };\r\n var response = httpResults.Serialize(serializationOptions)" + - ";\r\n"); + "rmat = serializationFormat, Version = serializationVersion, Serializer = seriali" + + "zer };\r\n var response = httpResults.Serialize(serializationOptions);\r" + + "\n"); - #line 23 "C:\codebase\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\APIGatewayInvoke.tt" + #line 22 "C:\codebase\V3\HLL\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\APIGatewayInvoke.tt" } else if (_model.LambdaMethod.ReturnsVoid) @@ -111,28 +103,28 @@ public virtual string TransformText() #line hidden this.Write(" "); - #line 28 "C:\codebase\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\APIGatewayInvoke.tt" + #line 27 "C:\codebase\V3\HLL\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\APIGatewayInvoke.tt" this.Write(this.ToStringHelper.ToStringWithCulture(_model.LambdaMethod.ContainingType.Name.ToCamelCase())); #line default #line hidden this.Write("."); - #line 28 "C:\codebase\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\APIGatewayInvoke.tt" + #line 27 "C:\codebase\V3\HLL\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\APIGatewayInvoke.tt" this.Write(this.ToStringHelper.ToStringWithCulture(_model.LambdaMethod.Name)); #line default #line hidden this.Write("("); - #line 28 "C:\codebase\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\APIGatewayInvoke.tt" + #line 27 "C:\codebase\V3\HLL\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\APIGatewayInvoke.tt" this.Write(this.ToStringHelper.ToStringWithCulture(_parameterSignature)); #line default #line hidden this.Write(");\r\n"); - #line 29 "C:\codebase\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\APIGatewayInvoke.tt" + #line 28 "C:\codebase\V3\HLL\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\APIGatewayInvoke.tt" } else if (_model.LambdaMethod.ReturnsVoidTask) @@ -143,28 +135,28 @@ public virtual string TransformText() #line hidden this.Write(" await "); - #line 34 "C:\codebase\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\APIGatewayInvoke.tt" + #line 33 "C:\codebase\V3\HLL\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\APIGatewayInvoke.tt" this.Write(this.ToStringHelper.ToStringWithCulture(_model.LambdaMethod.ContainingType.Name.ToCamelCase())); #line default #line hidden this.Write("."); - #line 34 "C:\codebase\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\APIGatewayInvoke.tt" + #line 33 "C:\codebase\V3\HLL\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\APIGatewayInvoke.tt" this.Write(this.ToStringHelper.ToStringWithCulture(_model.LambdaMethod.Name)); #line default #line hidden this.Write("("); - #line 34 "C:\codebase\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\APIGatewayInvoke.tt" + #line 33 "C:\codebase\V3\HLL\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\APIGatewayInvoke.tt" this.Write(this.ToStringHelper.ToStringWithCulture(_parameterSignature)); #line default #line hidden this.Write(");\r\n"); - #line 35 "C:\codebase\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\APIGatewayInvoke.tt" + #line 34 "C:\codebase\V3\HLL\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\APIGatewayInvoke.tt" } else @@ -175,34 +167,34 @@ public virtual string TransformText() #line hidden this.Write(" var response = "); - #line 40 "C:\codebase\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\APIGatewayInvoke.tt" + #line 39 "C:\codebase\V3\HLL\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\APIGatewayInvoke.tt" this.Write(this.ToStringHelper.ToStringWithCulture(_model.LambdaMethod.ReturnsGenericTask ? "await " : "")); #line default #line hidden - #line 40 "C:\codebase\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\APIGatewayInvoke.tt" + #line 39 "C:\codebase\V3\HLL\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\APIGatewayInvoke.tt" this.Write(this.ToStringHelper.ToStringWithCulture(_model.LambdaMethod.ContainingType.Name.ToCamelCase())); #line default #line hidden this.Write("."); - #line 40 "C:\codebase\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\APIGatewayInvoke.tt" + #line 39 "C:\codebase\V3\HLL\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\APIGatewayInvoke.tt" this.Write(this.ToStringHelper.ToStringWithCulture(_model.LambdaMethod.Name)); #line default #line hidden this.Write("("); - #line 40 "C:\codebase\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\APIGatewayInvoke.tt" + #line 39 "C:\codebase\V3\HLL\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\APIGatewayInvoke.tt" this.Write(this.ToStringHelper.ToStringWithCulture(_parameterSignature)); #line default #line hidden this.Write(");\r\n"); - #line 41 "C:\codebase\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\APIGatewayInvoke.tt" + #line 40 "C:\codebase\V3\HLL\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\APIGatewayInvoke.tt" } @@ -214,7 +206,7 @@ public virtual string TransformText() #line hidden this.Write(" return response;\r\n"); - #line 48 "C:\codebase\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\APIGatewayInvoke.tt" + #line 47 "C:\codebase\V3\HLL\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\APIGatewayInvoke.tt" } else @@ -229,7 +221,7 @@ public virtual string TransformText() #line hidden this.Write("\r\n var body = response.ToString();\r\n"); - #line 59 "C:\codebase\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\APIGatewayInvoke.tt" + #line 58 "C:\codebase\V3\HLL\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\APIGatewayInvoke.tt" } else if (_model.LambdaMethod.ReturnType.IsString()) @@ -251,7 +243,7 @@ public virtual string TransformText() var body = reader.ReadToEnd(); "); - #line 75 "C:\codebase\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\APIGatewayInvoke.tt" + #line 74 "C:\codebase\V3\HLL\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\APIGatewayInvoke.tt" } } @@ -261,14 +253,14 @@ public virtual string TransformText() #line hidden this.Write("\r\n return new "); - #line 80 "C:\codebase\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\APIGatewayInvoke.tt" + #line 79 "C:\codebase\V3\HLL\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\APIGatewayInvoke.tt" this.Write(this.ToStringHelper.ToStringWithCulture(_model.LambdaMethod.ReturnsVoidOrGenericTask ? _model.GeneratedMethod.ReturnType.TaskTypeArgument : _model.GeneratedMethod.ReturnType.FullName)); #line default #line hidden this.Write("\r\n {\r\n"); - #line 82 "C:\codebase\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\APIGatewayInvoke.tt" + #line 81 "C:\codebase\V3\HLL\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\APIGatewayInvoke.tt" if (!_model.LambdaMethod.ReturnsVoid && !_model.LambdaMethod.ReturnsVoidTask) { @@ -278,7 +270,7 @@ public virtual string TransformText() #line hidden this.Write(" Body = "); - #line 86 "C:\codebase\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\APIGatewayInvoke.tt" + #line 85 "C:\codebase\V3\HLL\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\APIGatewayInvoke.tt" this.Write(this.ToStringHelper.ToStringWithCulture(_model.LambdaMethod.ReturnType.IsString() ? "response" : "body")); #line default @@ -286,14 +278,14 @@ public virtual string TransformText() this.Write(",\r\n Headers = new Dictionary\r\n {\r\n " + " {\"Content-Type\", "); - #line 89 "C:\codebase\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\APIGatewayInvoke.tt" + #line 88 "C:\codebase\V3\HLL\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\APIGatewayInvoke.tt" this.Write(this.ToStringHelper.ToStringWithCulture(_model.LambdaMethod.ReturnType.IsString() ? "\"text/plain\"" : "\"application/json\"")); #line default #line hidden this.Write("}\r\n },\r\n"); - #line 91 "C:\codebase\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\APIGatewayInvoke.tt" + #line 90 "C:\codebase\V3\HLL\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\APIGatewayInvoke.tt" } @@ -302,7 +294,7 @@ public virtual string TransformText() #line hidden this.Write(" StatusCode = 200\r\n };\r\n"); - #line 96 "C:\codebase\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\APIGatewayInvoke.tt" + #line 95 "C:\codebase\V3\HLL\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\APIGatewayInvoke.tt" } diff --git a/Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Templates/APIGatewayInvoke.tt b/Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Templates/APIGatewayInvoke.tt index c7cc555a2..890a72972 100644 --- a/Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Templates/APIGatewayInvoke.tt +++ b/Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Templates/APIGatewayInvoke.tt @@ -17,8 +17,7 @@ var httpResults = <#= _model.LambdaMethod.ReturnsGenericTask ? "await " : "" #><#= _model.LambdaMethod.ContainingType.Name.ToCamelCase() #>.<#= _model.LambdaMethod.Name #>(<#= _parameterSignature #>); HttpResultSerializationOptions.ProtocolFormat serializationFormat = <#= restApiAttribute != null ? "HttpResultSerializationOptions.ProtocolFormat.RestApi" : "HttpResultSerializationOptions.ProtocolFormat.HttpApi"#>; HttpResultSerializationOptions.ProtocolVersion serializationVersion = <#= restApiAttribute != null || httpApiAttribute?.Data.Version == Amazon.Lambda.Annotations.APIGateway.HttpApiVersion.V1 ? "HttpResultSerializationOptions.ProtocolVersion.V1" : "HttpResultSerializationOptions.ProtocolVersion.V2"#>; - System.Text.Json.Serialization.JsonSerializerContext jsonContext = <#= _model.SerializerInfo.SerializerJsonContextName != null ? _model.SerializerInfo.SerializerJsonContextName + ".Default" : "null"#>; - var serializationOptions = new HttpResultSerializationOptions { Format = serializationFormat, Version = serializationVersion, JsonContext = jsonContext }; + var serializationOptions = new HttpResultSerializationOptions { Format = serializationFormat, Version = serializationVersion, Serializer = serializer }; var response = httpResults.Serialize(serializationOptions); <# } diff --git a/Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Templates/ExecutableAssembly.cs b/Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Templates/ExecutableAssembly.cs index 34a04334b..1ecd7c311 100644 --- a/Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Templates/ExecutableAssembly.cs +++ b/Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Templates/ExecutableAssembly.cs @@ -23,7 +23,7 @@ namespace Amazon.Lambda.Annotations.SourceGenerator.Templates /// Class to produce the template output /// - #line 1 "C:\codebase\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\ExecutableAssembly.tt" + #line 1 "C:\codebase\V3\HLL\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\ExecutableAssembly.tt" [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.TextTemplating", "17.0.0.0")] public partial class ExecutableAssembly : ExecutableAssemblyBase { @@ -33,20 +33,30 @@ public partial class ExecutableAssembly : ExecutableAssemblyBase /// public virtual string TransformText() { - this.Write("using System;\r\nusing System.Linq;\r\nusing System.Collections.Generic;\r\nusing Syste" + - "m.Text;\r\nusing System.Threading.Tasks;\r\nusing System.IO;\r\nusing Amazon.Lambda.Co" + - "re;\r\n\r\nnamespace "); + this.Write("// \r\n\r\nusing System;\r\nusing System.Linq;\r\nusing System.Collectio" + + "ns.Generic;\r\nusing System.Text;\r\nusing System.Threading.Tasks;\r\nusing System.IO;" + + "\r\nusing Amazon.Lambda.Core;\r\n\r\nnamespace "); - #line 19 "C:\codebase\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\ExecutableAssembly.tt" + #line 21 "C:\codebase\V3\HLL\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\ExecutableAssembly.tt" this.Write(this.ToStringHelper.ToStringWithCulture(this._containingNamespace)); #line default #line hidden - this.Write(";\r\n\r\npublic class GeneratedProgram\r\n{\r\n public static async Task Main(string[]" + - " args)\r\n {\r\n\r\n switch (Environment.GetEnvironmentVariable(\"ANNOTATIONS" + - "_HANDLER\"))\r\n {\r\n"); + this.Write(@"; + +public class GeneratedProgram +{ + /// + /// This is responsible for inspecting the 'ANNOTATIONS_HANDLER' environment variable and invoking the appropriate Lambda function handler. + /// + public static async Task Main(string[] args) + { + + switch (Environment.GetEnvironmentVariable(""ANNOTATIONS_HANDLER"")) + { +"); - #line 28 "C:\codebase\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\ExecutableAssembly.tt" + #line 33 "C:\codebase\V3\HLL\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\ExecutableAssembly.tt" foreach (var model in this._lambdaFunctions) { @@ -56,14 +66,14 @@ public virtual string TransformText() #line hidden this.Write(" case \""); - #line 32 "C:\codebase\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\ExecutableAssembly.tt" + #line 37 "C:\codebase\V3\HLL\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\ExecutableAssembly.tt" this.Write(this.ToStringHelper.ToStringWithCulture(model.LambdaMethod.Name)); #line default #line hidden this.Write("\":\r\n"); - #line 33 "C:\codebase\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\ExecutableAssembly.tt" + #line 38 "C:\codebase\V3\HLL\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\ExecutableAssembly.tt" if (model.GeneratedMethod.ReturnType.FullName == "void") { @@ -73,42 +83,42 @@ public virtual string TransformText() #line hidden this.Write(" Action<"); - #line 37 "C:\codebase\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\ExecutableAssembly.tt" + #line 42 "C:\codebase\V3\HLL\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\ExecutableAssembly.tt" this.Write(this.ToStringHelper.ToStringWithCulture(model.GeneratedMethod.Parameters.Any() ? string.Join(", ", model.GeneratedMethod.Parameters.Select(p => $"{p.Type.FullName}")) : "Stream")); #line default #line hidden this.Write("> "); - #line 37 "C:\codebase\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\ExecutableAssembly.tt" + #line 42 "C:\codebase\V3\HLL\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\ExecutableAssembly.tt" this.Write(this.ToStringHelper.ToStringWithCulture(model.LambdaMethod.ExecutableAssemblyHandlerName)); #line default #line hidden this.Write(" = new "); - #line 37 "C:\codebase\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\ExecutableAssembly.tt" + #line 42 "C:\codebase\V3\HLL\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\ExecutableAssembly.tt" this.Write(this.ToStringHelper.ToStringWithCulture(model.LambdaMethod.ContainingNamespace)); #line default #line hidden this.Write("."); - #line 37 "C:\codebase\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\ExecutableAssembly.tt" + #line 42 "C:\codebase\V3\HLL\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\ExecutableAssembly.tt" this.Write(this.ToStringHelper.ToStringWithCulture(model.LambdaMethod.ContainingType.Name)); #line default #line hidden this.Write("_"); - #line 37 "C:\codebase\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\ExecutableAssembly.tt" + #line 42 "C:\codebase\V3\HLL\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\ExecutableAssembly.tt" this.Write(this.ToStringHelper.ToStringWithCulture(model.LambdaMethod.Name)); #line default #line hidden this.Write("_Generated()."); - #line 37 "C:\codebase\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\ExecutableAssembly.tt" + #line 42 "C:\codebase\V3\HLL\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\ExecutableAssembly.tt" this.Write(this.ToStringHelper.ToStringWithCulture(model.LambdaMethod.Name)); #line default @@ -116,21 +126,21 @@ public virtual string TransformText() this.Write(";\r\n await Amazon.Lambda.RuntimeSupport.LambdaBootstrapBuilder.Crea" + "te("); - #line 38 "C:\codebase\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\ExecutableAssembly.tt" + #line 43 "C:\codebase\V3\HLL\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\ExecutableAssembly.tt" this.Write(this.ToStringHelper.ToStringWithCulture(model.LambdaMethod.ExecutableAssemblyHandlerName)); #line default #line hidden this.Write(", new "); - #line 38 "C:\codebase\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\ExecutableAssembly.tt" + #line 43 "C:\codebase\V3\HLL\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\ExecutableAssembly.tt" this.Write(this.ToStringHelper.ToStringWithCulture(this._lambdaFunctions[0].SerializerInfo.SerializerName)); #line default #line hidden this.Write("()).Build().RunAsync();\r\n break;\r\n"); - #line 40 "C:\codebase\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\ExecutableAssembly.tt" + #line 45 "C:\codebase\V3\HLL\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\ExecutableAssembly.tt" } else @@ -141,49 +151,49 @@ public virtual string TransformText() #line hidden this.Write(" Func<"); - #line 45 "C:\codebase\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\ExecutableAssembly.tt" + #line 50 "C:\codebase\V3\HLL\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\ExecutableAssembly.tt" this.Write(this.ToStringHelper.ToStringWithCulture(model.GeneratedMethod.Parameters.Any() ? string.Join(", ", model.GeneratedMethod.Parameters.Select(p => $"{p.Type.FullName}")) : "Stream")); #line default #line hidden this.Write(", "); - #line 45 "C:\codebase\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\ExecutableAssembly.tt" + #line 50 "C:\codebase\V3\HLL\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\ExecutableAssembly.tt" this.Write(this.ToStringHelper.ToStringWithCulture(model.GeneratedMethod.ReturnType.FullName)); #line default #line hidden this.Write("> "); - #line 45 "C:\codebase\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\ExecutableAssembly.tt" + #line 50 "C:\codebase\V3\HLL\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\ExecutableAssembly.tt" this.Write(this.ToStringHelper.ToStringWithCulture(model.LambdaMethod.ExecutableAssemblyHandlerName)); #line default #line hidden this.Write(" = new "); - #line 45 "C:\codebase\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\ExecutableAssembly.tt" + #line 50 "C:\codebase\V3\HLL\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\ExecutableAssembly.tt" this.Write(this.ToStringHelper.ToStringWithCulture(model.LambdaMethod.ContainingNamespace)); #line default #line hidden this.Write("."); - #line 45 "C:\codebase\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\ExecutableAssembly.tt" + #line 50 "C:\codebase\V3\HLL\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\ExecutableAssembly.tt" this.Write(this.ToStringHelper.ToStringWithCulture(model.LambdaMethod.ContainingType.Name)); #line default #line hidden this.Write("_"); - #line 45 "C:\codebase\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\ExecutableAssembly.tt" + #line 50 "C:\codebase\V3\HLL\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\ExecutableAssembly.tt" this.Write(this.ToStringHelper.ToStringWithCulture(model.LambdaMethod.Name)); #line default #line hidden this.Write("_Generated()."); - #line 45 "C:\codebase\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\ExecutableAssembly.tt" + #line 50 "C:\codebase\V3\HLL\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\ExecutableAssembly.tt" this.Write(this.ToStringHelper.ToStringWithCulture(model.LambdaMethod.Name)); #line default @@ -191,21 +201,21 @@ public virtual string TransformText() this.Write(";\r\n await Amazon.Lambda.RuntimeSupport.LambdaBootstrapBuilder.Crea" + "te("); - #line 46 "C:\codebase\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\ExecutableAssembly.tt" + #line 51 "C:\codebase\V3\HLL\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\ExecutableAssembly.tt" this.Write(this.ToStringHelper.ToStringWithCulture(model.LambdaMethod.ExecutableAssemblyHandlerName)); #line default #line hidden this.Write(", new "); - #line 46 "C:\codebase\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\ExecutableAssembly.tt" + #line 51 "C:\codebase\V3\HLL\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\ExecutableAssembly.tt" this.Write(this.ToStringHelper.ToStringWithCulture(model.SerializerInfo.SerializerName)); #line default #line hidden this.Write("()).Build().RunAsync();\r\n break;\r\n"); - #line 48 "C:\codebase\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\ExecutableAssembly.tt" + #line 53 "C:\codebase\V3\HLL\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\ExecutableAssembly.tt" } } @@ -215,7 +225,7 @@ public virtual string TransformText() #line hidden this.Write("\r\n }\r\n"); - #line 54 "C:\codebase\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\ExecutableAssembly.tt" + #line 59 "C:\codebase\V3\HLL\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\ExecutableAssembly.tt" diff --git a/Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Templates/ExecutableAssembly.tt b/Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Templates/ExecutableAssembly.tt index 526e9b65e..f387a999b 100644 --- a/Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Templates/ExecutableAssembly.tt +++ b/Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Templates/ExecutableAssembly.tt @@ -8,6 +8,8 @@ <#@ import namespace="Amazon.Lambda.Annotations.SourceGenerator.Validation" #> <#@ import namespace="Amazon.Lambda.Annotations.SourceGenerator.Models" #> <#@ import namespace="Amazon.Lambda.Annotations.SourceGenerator.Models.Attributes" #> +// + using System; using System.Linq; using System.Collections.Generic; @@ -20,6 +22,9 @@ namespace <#= this._containingNamespace #>; public class GeneratedProgram { + /// + /// This is responsible for inspecting the 'ANNOTATIONS_HANDLER' environment variable and invoking the appropriate Lambda function handler. + /// public static async Task Main(string[] args) { diff --git a/Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Templates/FieldsAndConstructor.cs b/Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Templates/FieldsAndConstructor.cs index c606fb5d0..aa63be57b 100644 --- a/Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Templates/FieldsAndConstructor.cs +++ b/Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Templates/FieldsAndConstructor.cs @@ -19,7 +19,7 @@ namespace Amazon.Lambda.Annotations.SourceGenerator.Templates /// Class to produce the template output /// - #line 1 "C:\codebase\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\FieldsAndConstructor.tt" + #line 1 "C:\codebase\V3\HLL\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\FieldsAndConstructor.tt" [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.TextTemplating", "17.0.0.0")] public partial class FieldsAndConstructor : FieldsAndConstructorBase { @@ -30,7 +30,7 @@ public partial class FieldsAndConstructor : FieldsAndConstructorBase public virtual string TransformText() { - #line 7 "C:\codebase\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\FieldsAndConstructor.tt" + #line 7 "C:\codebase\V3\HLL\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\FieldsAndConstructor.tt" if (_model.LambdaMethod.UsingDependencyInjection) { @@ -40,7 +40,7 @@ public virtual string TransformText() #line hidden this.Write(" private readonly ServiceProvider serviceProvider;\r\n"); - #line 12 "C:\codebase\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\FieldsAndConstructor.tt" + #line 12 "C:\codebase\V3\HLL\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\FieldsAndConstructor.tt" } else @@ -51,44 +51,50 @@ public virtual string TransformText() #line hidden this.Write(" private readonly "); - #line 17 "C:\codebase\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\FieldsAndConstructor.tt" + #line 17 "C:\codebase\V3\HLL\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\FieldsAndConstructor.tt" this.Write(this.ToStringHelper.ToStringWithCulture(_model.LambdaMethod.ContainingType.Name)); #line default #line hidden this.Write(" "); - #line 17 "C:\codebase\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\FieldsAndConstructor.tt" + #line 17 "C:\codebase\V3\HLL\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\FieldsAndConstructor.tt" this.Write(this.ToStringHelper.ToStringWithCulture(_model.LambdaMethod.ContainingType.Name.ToCamelCase())); #line default #line hidden this.Write(";\r\n private readonly "); - #line 18 "C:\codebase\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\FieldsAndConstructor.tt" + #line 18 "C:\codebase\V3\HLL\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\FieldsAndConstructor.tt" this.Write(this.ToStringHelper.ToStringWithCulture(_model.SerializerInfo.SerializerName)); #line default #line hidden this.Write(" serializer;\r\n"); - #line 19 "C:\codebase\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\FieldsAndConstructor.tt" + #line 19 "C:\codebase\V3\HLL\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\FieldsAndConstructor.tt" } #line default #line hidden - this.Write("\r\n public "); + this.Write(@" + /// + /// Default constructor. This constructor is used by Lambda to construct the instance. When invoked in a Lambda environment + /// the AWS credentials will come from the IAM role associated with the function and the AWS region will be set to the + /// region the Lambda function is executed in. + /// + public "); - #line 23 "C:\codebase\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\FieldsAndConstructor.tt" + #line 28 "C:\codebase\V3\HLL\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\FieldsAndConstructor.tt" this.Write(this.ToStringHelper.ToStringWithCulture(_model.GeneratedMethod.ContainingType.Name)); #line default #line hidden this.Write("()\r\n {\r\n SetExecutionEnvironment();\r\n"); - #line 26 "C:\codebase\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\FieldsAndConstructor.tt" + #line 31 "C:\codebase\V3\HLL\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\FieldsAndConstructor.tt" if (_model.LambdaMethod.UsingDependencyInjection) { @@ -102,21 +108,21 @@ public virtual string TransformText() // To use a different lifetime, specify the lifetime in Startup.ConfigureServices(IServiceCollection) method. services.AddSingleton<"); - #line 34 "C:\codebase\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\FieldsAndConstructor.tt" + #line 39 "C:\codebase\V3\HLL\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\FieldsAndConstructor.tt" this.Write(this.ToStringHelper.ToStringWithCulture(_model.LambdaMethod.ContainingType.Name)); #line default #line hidden this.Write(">();\r\n services.AddSingleton<"); - #line 35 "C:\codebase\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\FieldsAndConstructor.tt" + #line 40 "C:\codebase\V3\HLL\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\FieldsAndConstructor.tt" this.Write(this.ToStringHelper.ToStringWithCulture(_model.SerializerInfo.SerializerName)); #line default #line hidden this.Write(">();\r\n\r\n var startup = new "); - #line 37 "C:\codebase\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\FieldsAndConstructor.tt" + #line 42 "C:\codebase\V3\HLL\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\FieldsAndConstructor.tt" this.Write(this.ToStringHelper.ToStringWithCulture(_model.StartupType.FullName)); #line default @@ -124,7 +130,7 @@ public virtual string TransformText() this.Write("();\r\n startup.ConfigureServices(services);\r\n serviceProvide" + "r = services.BuildServiceProvider();\r\n"); - #line 40 "C:\codebase\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\FieldsAndConstructor.tt" + #line 45 "C:\codebase\V3\HLL\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\FieldsAndConstructor.tt" } else @@ -135,28 +141,28 @@ public virtual string TransformText() #line hidden this.Write(" "); - #line 45 "C:\codebase\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\FieldsAndConstructor.tt" + #line 50 "C:\codebase\V3\HLL\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\FieldsAndConstructor.tt" this.Write(this.ToStringHelper.ToStringWithCulture(_model.LambdaMethod.ContainingType.Name.ToCamelCase())); #line default #line hidden this.Write(" = new "); - #line 45 "C:\codebase\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\FieldsAndConstructor.tt" + #line 50 "C:\codebase\V3\HLL\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\FieldsAndConstructor.tt" this.Write(this.ToStringHelper.ToStringWithCulture(_model.LambdaMethod.ContainingType.Name)); #line default #line hidden this.Write("();\r\n serializer = new "); - #line 46 "C:\codebase\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\FieldsAndConstructor.tt" + #line 51 "C:\codebase\V3\HLL\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\FieldsAndConstructor.tt" this.Write(this.ToStringHelper.ToStringWithCulture(_model.SerializerInfo.SerializerName)); #line default #line hidden this.Write("();\r\n"); - #line 47 "C:\codebase\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\FieldsAndConstructor.tt" + #line 52 "C:\codebase\V3\HLL\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\FieldsAndConstructor.tt" } diff --git a/Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Templates/FieldsAndConstructor.tt b/Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Templates/FieldsAndConstructor.tt index 8434ff348..6c4fd3d43 100644 --- a/Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Templates/FieldsAndConstructor.tt +++ b/Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Templates/FieldsAndConstructor.tt @@ -20,6 +20,11 @@ } #> + /// + /// Default constructor. This constructor is used by Lambda to construct the instance. When invoked in a Lambda environment + /// the AWS credentials will come from the IAM role associated with the function and the AWS region will be set to the + /// region the Lambda function is executed in. + /// public <#= _model.GeneratedMethod.ContainingType.Name #>() { SetExecutionEnvironment(); diff --git a/Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Templates/LambdaFunctionTemplate.cs b/Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Templates/LambdaFunctionTemplate.cs index 5352e3e34..0dfa338e2 100644 --- a/Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Templates/LambdaFunctionTemplate.cs +++ b/Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Templates/LambdaFunctionTemplate.cs @@ -34,8 +34,9 @@ public partial class LambdaFunctionTemplate : LambdaFunctionTemplateBase /// public virtual string TransformText() { + this.Write("// \r\n\r\n"); - #line 12 "C:\codebase\V3\HLL\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\LambdaFunctionTemplate.tt" + #line 14 "C:\codebase\V3\HLL\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\LambdaFunctionTemplate.tt" foreach (var ns in _model.GeneratedMethod.Usings) { @@ -45,14 +46,14 @@ public virtual string TransformText() #line hidden this.Write("using "); - #line 16 "C:\codebase\V3\HLL\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\LambdaFunctionTemplate.tt" + #line 18 "C:\codebase\V3\HLL\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\LambdaFunctionTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(ns)); #line default #line hidden this.Write(";\r\n"); - #line 17 "C:\codebase\V3\HLL\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\LambdaFunctionTemplate.tt" + #line 19 "C:\codebase\V3\HLL\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\LambdaFunctionTemplate.tt" } @@ -61,57 +62,84 @@ public virtual string TransformText() #line hidden this.Write("\r\nnamespace "); - #line 21 "C:\codebase\V3\HLL\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\LambdaFunctionTemplate.tt" + #line 23 "C:\codebase\V3\HLL\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\LambdaFunctionTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(_model.LambdaMethod.ContainingNamespace)); #line default #line hidden this.Write("\r\n{\r\n public class "); - #line 23 "C:\codebase\V3\HLL\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\LambdaFunctionTemplate.tt" + #line 25 "C:\codebase\V3\HLL\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\LambdaFunctionTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(_model.GeneratedMethod.ContainingType.Name)); #line default #line hidden this.Write("\r\n {\r\n"); - #line 25 "C:\codebase\V3\HLL\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\LambdaFunctionTemplate.tt" + #line 27 "C:\codebase\V3\HLL\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\LambdaFunctionTemplate.tt" this.Write(new FieldsAndConstructor(_model).TransformText()); #line default #line hidden - this.Write("\r\n\r\n public "); + this.Write("\r\n\r\n"); + + #line 32 "C:\codebase\V3\HLL\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\LambdaFunctionTemplate.tt" + + var methodDocumentationLines = GetMethodDocumentation(); + foreach (var line in methodDocumentationLines) + { + + + #line default + #line hidden + this.Write(" "); + + #line 37 "C:\codebase\V3\HLL\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\LambdaFunctionTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(line)); + + #line default + #line hidden + this.Write("\r\n"); - #line 30 "C:\codebase\V3\HLL\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\LambdaFunctionTemplate.tt" + #line 38 "C:\codebase\V3\HLL\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\LambdaFunctionTemplate.tt" + + } + + + #line default + #line hidden + this.Write(" public "); + + #line 41 "C:\codebase\V3\HLL\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\LambdaFunctionTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(_model.LambdaMethod.ReturnsVoidOrGenericTask ? "async " : "")); #line default #line hidden - #line 30 "C:\codebase\V3\HLL\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\LambdaFunctionTemplate.tt" + #line 41 "C:\codebase\V3\HLL\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\LambdaFunctionTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(_model.GeneratedMethod.ReturnType.FullName)); #line default #line hidden this.Write(" "); - #line 30 "C:\codebase\V3\HLL\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\LambdaFunctionTemplate.tt" + #line 41 "C:\codebase\V3\HLL\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\LambdaFunctionTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(_model.LambdaMethod.Name)); #line default #line hidden this.Write("("); - #line 30 "C:\codebase\V3\HLL\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\LambdaFunctionTemplate.tt" + #line 41 "C:\codebase\V3\HLL\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\LambdaFunctionTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(_model.GeneratedMethod.Parameters.Any() ? string.Join(", ", _model.GeneratedMethod.Parameters.Select(p => $"{p.Type.FullName} {p.Name}")) : "Stream stream")); #line default #line hidden this.Write(")\r\n {\r\n"); - #line 32 "C:\codebase\V3\HLL\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\LambdaFunctionTemplate.tt" + #line 43 "C:\codebase\V3\HLL\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\LambdaFunctionTemplate.tt" if (_model.LambdaMethod.UsingDependencyInjection) { @@ -123,28 +151,28 @@ public virtual string TransformText() "ting scoped dependencies without creating a scope manually.\r\n using v" + "ar scope = serviceProvider.CreateScope();\r\n var "); - #line 39 "C:\codebase\V3\HLL\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\LambdaFunctionTemplate.tt" + #line 50 "C:\codebase\V3\HLL\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\LambdaFunctionTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(_model.LambdaMethod.ContainingType.Name.ToCamelCase())); #line default #line hidden this.Write(" = scope.ServiceProvider.GetRequiredService<"); - #line 40 "C:\codebase\V3\HLL\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\LambdaFunctionTemplate.tt" + #line 51 "C:\codebase\V3\HLL\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\LambdaFunctionTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(_model.LambdaMethod.ContainingType.Name)); #line default #line hidden this.Write(">();\r\n var serializer = scope.ServiceProvider.GetRequiredService<"); - #line 41 "C:\codebase\V3\HLL\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\LambdaFunctionTemplate.tt" + #line 52 "C:\codebase\V3\HLL\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\LambdaFunctionTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(_model.SerializerInfo.SerializerName)); #line default #line hidden this.Write(">();\r\n\r\n"); - #line 43 "C:\codebase\V3\HLL\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\LambdaFunctionTemplate.tt" + #line 54 "C:\codebase\V3\HLL\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\LambdaFunctionTemplate.tt" } @@ -178,7 +206,7 @@ private static void SetExecutionEnvironment() envValue.Append(""lib/amazon-lambda-annotations#"); - #line 71 "C:\codebase\V3\HLL\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\LambdaFunctionTemplate.tt" + #line 82 "C:\codebase\V3\HLL\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\LambdaFunctionTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(_model.SourceGeneratorVersion)); #line default diff --git a/Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Templates/LambdaFunctionTemplate.tt b/Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Templates/LambdaFunctionTemplate.tt index c38e683d9..f1aa76cb0 100644 --- a/Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Templates/LambdaFunctionTemplate.tt +++ b/Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Templates/LambdaFunctionTemplate.tt @@ -9,6 +9,8 @@ <#@ import namespace="Amazon.Lambda.Annotations.SourceGenerator.Models.Attributes" #> <#@ import namespace="Microsoft.CodeAnalysis" #> <#@ import namespace="Amazon.Lambda.Annotations.SourceGenerator.Validation" #> +// + <# foreach (var ns in _model.GeneratedMethod.Usings) { @@ -27,6 +29,15 @@ this.Write(new FieldsAndConstructor(_model).TransformText()); #> +<# + var methodDocumentationLines = GetMethodDocumentation(); + foreach (var line in methodDocumentationLines) + { +#> + <#= line #> +<# + } +#> public <#= _model.LambdaMethod.ReturnsVoidOrGenericTask ? "async " : "" #><#= _model.GeneratedMethod.ReturnType.FullName #> <#= _model.LambdaMethod.Name #>(<#= _model.GeneratedMethod.Parameters.Any() ? string.Join(", ", _model.GeneratedMethod.Parameters.Select(p => $"{p.Type.FullName} {p.Name}")) : "Stream stream" #>) { <# diff --git a/Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Templates/LambdaFunctionTemplateCode.cs b/Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Templates/LambdaFunctionTemplateCode.cs index 64120260f..311b253f0 100644 --- a/Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Templates/LambdaFunctionTemplateCode.cs +++ b/Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Templates/LambdaFunctionTemplateCode.cs @@ -1,4 +1,8 @@ using Amazon.Lambda.Annotations.SourceGenerator.Models; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using YamlDotNet.Core.Tokens; namespace Amazon.Lambda.Annotations.SourceGenerator.Templates { @@ -10,5 +14,33 @@ public LambdaFunctionTemplate(LambdaFunctionModel model) { _model = model; } + + private List GetMethodDocumentation() + { + var lambdaMethod = _model.LambdaMethod; + var generatedMethod = _model.GeneratedMethod; + var docStringlines = new List + { + "/// " + }; + if (lambdaMethod.Parameters.Any()) + { + docStringlines.Add($"/// The generated Lambda function handler for p.Type.FullName))})\"/>"); + } + else + { + docStringlines.Add($"/// The generated Lambda function handler for "); + } + docStringlines.Add("/// "); + + foreach (var parameter in generatedMethod.Parameters) + { + docStringlines.Add($"/// {parameter.Documentation}"); + } + + docStringlines.Add("/// Result of the Lambda function execution"); + + return docStringlines; + } } } \ No newline at end of file diff --git a/Libraries/src/Amazon.Lambda.Annotations/APIGateway/HttpResults.cs b/Libraries/src/Amazon.Lambda.Annotations/APIGateway/HttpResults.cs index a8224a32c..539da4546 100644 --- a/Libraries/src/Amazon.Lambda.Annotations/APIGateway/HttpResults.cs +++ b/Libraries/src/Amazon.Lambda.Annotations/APIGateway/HttpResults.cs @@ -3,6 +3,8 @@ using System.IO; using System.Linq; using System.Net; +using Amazon.Lambda.Core; + #if NET6_0_OR_GREATER using System.Buffers; using System.Text.Json; @@ -66,16 +68,11 @@ public enum ProtocolVersion { /// public ProtocolVersion Version { get; set; } -#if !NETSTANDARD2_0 /// - /// The JsonSerializerContext used for serializing response body using .NET's source generator serializer. - /// This is set when the SourceGeneratorLambdaJsonSerializer serializer is registered taking the JsonSerializerContext - /// assigned with it. If SourceGeneratorLambdaJsonSerializer is not used then the reflection based - /// JsonSerializer.Serialize method is used. + /// The JSON serializer used for serializing the response body. /// - public JsonSerializerContext JsonContext { get; set; } -#endif + public ILambdaSerializer Serializer { get; set; } } /// @@ -350,13 +347,7 @@ public static IHttpResult NewResult(HttpStatusCode statusCode, object body = nul #if !NETSTANDARD2_0 - // See comment in class documentation on the rules for serializing. If any changes are made in this method be sure to update - // the comment above. - [System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026", - Justification = "When using this library with the Native AOT the SourceGeneratorLambdaJsonSerializer has to be registered which will provide the information needed for JsonSerializerContext and avoid the reflection based JsonSerializer.Serialize call")] - [System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage("ReflectionAnalysis", "IL3050", - Justification = "When using this library with the Native AOT the SourceGeneratorLambdaJsonSerializer has to be registered which will provide the information needed for JsonSerializerContext and avoid the reflection based JsonSerializer.Serialize call")] - private static (string body, string contentType, bool base64Encoded) FormatBody(object body, JsonSerializerContext context) + private static (string body, string contentType, bool base64Encoded) FormatBody(object body, ILambdaSerializer serializer) { if (body == null) return new (null, null, false); @@ -392,16 +383,10 @@ private static (string body, string contentType, bool base64Encoded) FormatBody( } else { - string serializedBody; - if (context != null) - { - serializedBody = JsonSerializer.Serialize(body, body.GetType(), context); - } - else - { - serializedBody = JsonSerializer.Serialize(body); - } - + var bodyStream = new MemoryStream(); + serializer.Serialize(body, bodyStream); + bodyStream.Position = 0; + var serializedBody = new StreamReader(bodyStream).ReadToEnd(); return new(serializedBody, CONTENT_TYPE_APPLICATION_JSON, false); } } @@ -421,7 +406,7 @@ public Stream Serialize(HttpResultSerializationOptions options) throw new NotImplementedException(); #else - var (serializedBody, defaultContentType, isBase64Encoded) = FormatBody(_rawBody, options.JsonContext); + var (serializedBody, defaultContentType, isBase64Encoded) = FormatBody(_rawBody, options.Serializer); // If the user didn't explicit set the content type then default to application/json if (!string.IsNullOrEmpty(serializedBody) && (_headers == null || !_headers.ContainsKey(HEADER_NAME_CONTENT_TYPE))) @@ -429,7 +414,6 @@ public Stream Serialize(HttpResultSerializationOptions options) AddHeader(HEADER_NAME_CONTENT_TYPE, defaultContentType); } - var stream = new MemoryStream(); object response; Type responseType; if (options.Format == HttpResultSerializationOptions.ProtocolFormat.RestApi || @@ -457,9 +441,8 @@ public Stream Serialize(HttpResultSerializationOptions options) responseType = typeof(APIGatewayV2Response); } - + var stream = new MemoryStream(); JsonSerializer.Serialize(stream, response, responseType, AnnotationsResponseJsonSerializerContext.Default); - stream.Position = 0; return stream; #endif diff --git a/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Amazon.Lambda.Annotations.SourceGenerators.Tests.csproj b/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Amazon.Lambda.Annotations.SourceGenerators.Tests.csproj index b57a3f00c..1d89cbeb6 100644 --- a/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Amazon.Lambda.Annotations.SourceGenerators.Tests.csproj +++ b/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Amazon.Lambda.Annotations.SourceGenerators.Tests.csproj @@ -11,6 +11,7 @@ + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/HtttpResultsStatusCodeUsage.cs b/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/HttpResultsStatusCodeUsage.cs similarity index 95% rename from Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/HtttpResultsStatusCodeUsage.cs rename to Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/HttpResultsStatusCodeUsage.cs index e9dc6acb3..0d99b0a7e 100644 --- a/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/HtttpResultsStatusCodeUsage.cs +++ b/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/HttpResultsStatusCodeUsage.cs @@ -5,7 +5,7 @@ namespace Amazon.Lambda.Annotations.SourceGenerators.Tests { - public class HtttpResultsStatusCodeUsage + public class HttpResultsStatusCodeUsage { [Fact] public void UsageOfIHttpResultStatusCode() diff --git a/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/HttpResultsTest.cs b/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/HttpResultsTest.cs index 04e72cdd7..df4b8a73f 100644 --- a/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/HttpResultsTest.cs +++ b/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/HttpResultsTest.cs @@ -6,6 +6,9 @@ using Xunit; using System.IO; using System.Linq; +using Amazon.Lambda.Serialization.SystemTextJson; +using Amazon.Lambda.Core; +using Microsoft.VisualStudio.TestPlatform.PlatformAbstractions.Interfaces; namespace Amazon.Lambda.Annotations.SourceGenerators.Tests { @@ -357,21 +360,42 @@ public void ServiceUnavailable_WithRetryAfter() }); } + [Fact] + public void HttpResult_WithCustomSerializer() + { + var result = HttpResults.Ok(new Person { FirstName = "John", LastName = "Doe" }); + var response = result.Serialize(new HttpResultSerializationOptions + { + Format = HttpResultSerializationOptions.ProtocolFormat.HttpApi, + Version = HttpResultSerializationOptions.ProtocolVersion.V2, + Serializer = new CustomLambdaSerializer() + }); + + var jsonDoc = JsonDocument.Parse(response); + Assert.Equal(200, jsonDoc.RootElement.GetProperty("statusCode").GetInt32()); + + var body = jsonDoc.RootElement.GetProperty("body").GetString(); + var person = JsonSerializer.Deserialize>(body); + Assert.Equal("John", person["FIRST_NAME"]); + Assert.Equal("Doe", person["LAST_NAME"]); + } + private void ValidateResult(Func resultCreator, HttpStatusCode statusCode, string body = null, bool isBase64Encoded = false, IDictionary> headers = null) { - var testScenarios = new List> + var lambdaSerializer = new DefaultLambdaJsonSerializer(); + var testScenarios = new List> { - new (HttpResultSerializationOptions.ProtocolFormat.RestApi, HttpResultSerializationOptions.ProtocolVersion.V1), - new (HttpResultSerializationOptions.ProtocolFormat.HttpApi, HttpResultSerializationOptions.ProtocolVersion.V1), - new (HttpResultSerializationOptions.ProtocolFormat.HttpApi, HttpResultSerializationOptions.ProtocolVersion.V2) + new (HttpResultSerializationOptions.ProtocolFormat.RestApi, HttpResultSerializationOptions.ProtocolVersion.V1, lambdaSerializer), + new (HttpResultSerializationOptions.ProtocolFormat.HttpApi, HttpResultSerializationOptions.ProtocolVersion.V1, lambdaSerializer), + new (HttpResultSerializationOptions.ProtocolFormat.HttpApi, HttpResultSerializationOptions.ProtocolVersion.V2, lambdaSerializer) }; - foreach(var (format, version) in testScenarios) + foreach(var (format, version, serializer) in testScenarios) { IHttpResult result = resultCreator(); - var stream = result.Serialize(new HttpResultSerializationOptions { Format = format, Version = version }); + var stream = result.Serialize(new HttpResultSerializationOptions { Format = format, Version = version, Serializer = serializer }); var jsonDoc = JsonDocument.Parse(stream); if (format == HttpResultSerializationOptions.ProtocolFormat.RestApi || (format == HttpResultSerializationOptions.ProtocolFormat.HttpApi && version == HttpResultSerializationOptions.ProtocolVersion.V1)) { @@ -456,5 +480,26 @@ public class FakeBody { public int Id { get; set; } = 1; } + + public class Person + { + public string FirstName { get; set; } + public string LastName { get; set; } + } + + public class CustomLambdaSerializer : DefaultLambdaJsonSerializer + { + public CustomLambdaSerializer() + : base(CreateCustomizer()) + { } + + private static Action CreateCustomizer() + { + return (JsonSerializerOptions options) => + { + options.PropertyNamingPolicy = JsonNamingPolicy.SnakeCaseUpper; + }; + } + } } } diff --git a/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/ComplexCalculator_Add_Generated.g.cs b/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/ComplexCalculator_Add_Generated.g.cs index 368ab6f97..7d24f327f 100644 --- a/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/ComplexCalculator_Add_Generated.g.cs +++ b/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/ComplexCalculator_Add_Generated.g.cs @@ -1,4 +1,6 @@ -using System; +// + +using System; using System.Linq; using System.Collections.Generic; using System.Text; @@ -13,6 +15,11 @@ public class ComplexCalculator_Add_Generated private readonly ComplexCalculator complexCalculator; private readonly Amazon.Lambda.Serialization.SystemTextJson.DefaultLambdaJsonSerializer serializer; + /// + /// Default constructor. This constructor is used by Lambda to construct the instance. When invoked in a Lambda environment + /// the AWS credentials will come from the IAM role associated with the function and the AWS region will be set to the + /// region the Lambda function is executed in. + /// public ComplexCalculator_Add_Generated() { SetExecutionEnvironment(); @@ -20,6 +27,12 @@ public ComplexCalculator_Add_Generated() serializer = new Amazon.Lambda.Serialization.SystemTextJson.DefaultLambdaJsonSerializer(); } + /// + /// The generated Lambda function handler for + /// + /// The API Gateway request object that will be processed by the Lambda function handler. + /// The ILambdaContext that provides methods for logging and describing the Lambda environment. + /// Result of the Lambda function execution public Amazon.Lambda.APIGatewayEvents.APIGatewayHttpApiV2ProxyResponse Add(Amazon.Lambda.APIGatewayEvents.APIGatewayHttpApiV2ProxyRequest __request__, Amazon.Lambda.Core.ILambdaContext __context__) { var complexNumbers = __request__.Body; diff --git a/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/ComplexCalculator_Subtract_Generated.g.cs b/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/ComplexCalculator_Subtract_Generated.g.cs index b1a77978d..5178eb44d 100644 --- a/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/ComplexCalculator_Subtract_Generated.g.cs +++ b/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/ComplexCalculator_Subtract_Generated.g.cs @@ -1,4 +1,6 @@ -using System; +// + +using System; using System.Linq; using System.Collections.Generic; using System.Text; @@ -13,6 +15,11 @@ public class ComplexCalculator_Subtract_Generated private readonly ComplexCalculator complexCalculator; private readonly Amazon.Lambda.Serialization.SystemTextJson.DefaultLambdaJsonSerializer serializer; + /// + /// Default constructor. This constructor is used by Lambda to construct the instance. When invoked in a Lambda environment + /// the AWS credentials will come from the IAM role associated with the function and the AWS region will be set to the + /// region the Lambda function is executed in. + /// public ComplexCalculator_Subtract_Generated() { SetExecutionEnvironment(); @@ -20,6 +27,12 @@ public ComplexCalculator_Subtract_Generated() serializer = new Amazon.Lambda.Serialization.SystemTextJson.DefaultLambdaJsonSerializer(); } + /// + /// The generated Lambda function handler for + /// + /// The API Gateway request object that will be processed by the Lambda function handler. + /// The ILambdaContext that provides methods for logging and describing the Lambda environment. + /// Result of the Lambda function execution public Amazon.Lambda.APIGatewayEvents.APIGatewayHttpApiV2ProxyResponse Subtract(Amazon.Lambda.APIGatewayEvents.APIGatewayHttpApiV2ProxyRequest __request__, Amazon.Lambda.Core.ILambdaContext __context__) { var validationErrors = new List(); diff --git a/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/CustomizeResponseExamples_NotFoundResponseWithHeaderV1Async_Generated.g.cs b/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/CustomizeResponseExamples_NotFoundResponseWithHeaderV1Async_Generated.g.cs index 66a9b2f4c..8f4ca49ab 100644 --- a/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/CustomizeResponseExamples_NotFoundResponseWithHeaderV1Async_Generated.g.cs +++ b/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/CustomizeResponseExamples_NotFoundResponseWithHeaderV1Async_Generated.g.cs @@ -1,3 +1,5 @@ +// + using System; using System.Linq; using System.Collections.Generic; @@ -14,6 +16,11 @@ public class CustomizeResponseExamples_NotFoundResponseWithHeaderV1Async_Generat private readonly CustomizeResponseExamples customizeResponseExamples; private readonly Amazon.Lambda.Serialization.SystemTextJson.DefaultLambdaJsonSerializer serializer; + /// + /// Default constructor. This constructor is used by Lambda to construct the instance. When invoked in a Lambda environment + /// the AWS credentials will come from the IAM role associated with the function and the AWS region will be set to the + /// region the Lambda function is executed in. + /// public CustomizeResponseExamples_NotFoundResponseWithHeaderV1Async_Generated() { SetExecutionEnvironment(); @@ -21,6 +28,12 @@ public CustomizeResponseExamples_NotFoundResponseWithHeaderV1Async_Generated() serializer = new Amazon.Lambda.Serialization.SystemTextJson.DefaultLambdaJsonSerializer(); } + /// + /// The generated Lambda function handler for + /// + /// The API Gateway request object that will be processed by the Lambda function handler. + /// The ILambdaContext that provides methods for logging and describing the Lambda environment. + /// Result of the Lambda function execution public async System.Threading.Tasks.Task NotFoundResponseWithHeaderV1Async(Amazon.Lambda.APIGatewayEvents.APIGatewayProxyRequest __request__, Amazon.Lambda.Core.ILambdaContext __context__) { var validationErrors = new List(); @@ -60,8 +73,7 @@ public CustomizeResponseExamples_NotFoundResponseWithHeaderV1Async_Generated() var httpResults = await customizeResponseExamples.NotFoundResponseWithHeaderV1Async(x, __context__); HttpResultSerializationOptions.ProtocolFormat serializationFormat = HttpResultSerializationOptions.ProtocolFormat.HttpApi; HttpResultSerializationOptions.ProtocolVersion serializationVersion = HttpResultSerializationOptions.ProtocolVersion.V1; - System.Text.Json.Serialization.JsonSerializerContext jsonContext = null; - var serializationOptions = new HttpResultSerializationOptions { Format = serializationFormat, Version = serializationVersion, JsonContext = jsonContext }; + var serializationOptions = new HttpResultSerializationOptions { Format = serializationFormat, Version = serializationVersion, Serializer = serializer }; var response = httpResults.Serialize(serializationOptions); return response; } diff --git a/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/CustomizeResponseExamples_NotFoundResponseWithHeaderV1_Generated.g.cs b/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/CustomizeResponseExamples_NotFoundResponseWithHeaderV1_Generated.g.cs index dc9f19a6c..0d2ceb3ec 100644 --- a/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/CustomizeResponseExamples_NotFoundResponseWithHeaderV1_Generated.g.cs +++ b/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/CustomizeResponseExamples_NotFoundResponseWithHeaderV1_Generated.g.cs @@ -1,3 +1,5 @@ +// + using System; using System.Linq; using System.Collections.Generic; @@ -14,6 +16,11 @@ public class CustomizeResponseExamples_NotFoundResponseWithHeaderV1_Generated private readonly CustomizeResponseExamples customizeResponseExamples; private readonly Amazon.Lambda.Serialization.SystemTextJson.DefaultLambdaJsonSerializer serializer; + /// + /// Default constructor. This constructor is used by Lambda to construct the instance. When invoked in a Lambda environment + /// the AWS credentials will come from the IAM role associated with the function and the AWS region will be set to the + /// region the Lambda function is executed in. + /// public CustomizeResponseExamples_NotFoundResponseWithHeaderV1_Generated() { SetExecutionEnvironment(); @@ -21,6 +28,12 @@ public CustomizeResponseExamples_NotFoundResponseWithHeaderV1_Generated() serializer = new Amazon.Lambda.Serialization.SystemTextJson.DefaultLambdaJsonSerializer(); } + /// + /// The generated Lambda function handler for + /// + /// The API Gateway request object that will be processed by the Lambda function handler. + /// The ILambdaContext that provides methods for logging and describing the Lambda environment. + /// Result of the Lambda function execution public System.IO.Stream NotFoundResponseWithHeaderV1(Amazon.Lambda.APIGatewayEvents.APIGatewayProxyRequest __request__, Amazon.Lambda.Core.ILambdaContext __context__) { var validationErrors = new List(); @@ -60,8 +73,7 @@ public System.IO.Stream NotFoundResponseWithHeaderV1(Amazon.Lambda.APIGatewayEve var httpResults = customizeResponseExamples.NotFoundResponseWithHeaderV1(x, __context__); HttpResultSerializationOptions.ProtocolFormat serializationFormat = HttpResultSerializationOptions.ProtocolFormat.HttpApi; HttpResultSerializationOptions.ProtocolVersion serializationVersion = HttpResultSerializationOptions.ProtocolVersion.V1; - System.Text.Json.Serialization.JsonSerializerContext jsonContext = null; - var serializationOptions = new HttpResultSerializationOptions { Format = serializationFormat, Version = serializationVersion, JsonContext = jsonContext }; + var serializationOptions = new HttpResultSerializationOptions { Format = serializationFormat, Version = serializationVersion, Serializer = serializer }; var response = httpResults.Serialize(serializationOptions); return response; } diff --git a/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/CustomizeResponseExamples_NotFoundResponseWithHeaderV2Async_Generated.g.cs b/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/CustomizeResponseExamples_NotFoundResponseWithHeaderV2Async_Generated.g.cs index 50cb6c472..efc53ac27 100644 --- a/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/CustomizeResponseExamples_NotFoundResponseWithHeaderV2Async_Generated.g.cs +++ b/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/CustomizeResponseExamples_NotFoundResponseWithHeaderV2Async_Generated.g.cs @@ -1,3 +1,5 @@ +// + using System; using System.Linq; using System.Collections.Generic; @@ -14,6 +16,11 @@ public class CustomizeResponseExamples_NotFoundResponseWithHeaderV2Async_Generat private readonly CustomizeResponseExamples customizeResponseExamples; private readonly Amazon.Lambda.Serialization.SystemTextJson.DefaultLambdaJsonSerializer serializer; + /// + /// Default constructor. This constructor is used by Lambda to construct the instance. When invoked in a Lambda environment + /// the AWS credentials will come from the IAM role associated with the function and the AWS region will be set to the + /// region the Lambda function is executed in. + /// public CustomizeResponseExamples_NotFoundResponseWithHeaderV2Async_Generated() { SetExecutionEnvironment(); @@ -21,6 +28,12 @@ public CustomizeResponseExamples_NotFoundResponseWithHeaderV2Async_Generated() serializer = new Amazon.Lambda.Serialization.SystemTextJson.DefaultLambdaJsonSerializer(); } + /// + /// The generated Lambda function handler for + /// + /// The API Gateway request object that will be processed by the Lambda function handler. + /// The ILambdaContext that provides methods for logging and describing the Lambda environment. + /// Result of the Lambda function execution public async System.Threading.Tasks.Task NotFoundResponseWithHeaderV2Async(Amazon.Lambda.APIGatewayEvents.APIGatewayHttpApiV2ProxyRequest __request__, Amazon.Lambda.Core.ILambdaContext __context__) { var validationErrors = new List(); @@ -60,8 +73,7 @@ public CustomizeResponseExamples_NotFoundResponseWithHeaderV2Async_Generated() var httpResults = await customizeResponseExamples.NotFoundResponseWithHeaderV2Async(x, __context__); HttpResultSerializationOptions.ProtocolFormat serializationFormat = HttpResultSerializationOptions.ProtocolFormat.HttpApi; HttpResultSerializationOptions.ProtocolVersion serializationVersion = HttpResultSerializationOptions.ProtocolVersion.V2; - System.Text.Json.Serialization.JsonSerializerContext jsonContext = null; - var serializationOptions = new HttpResultSerializationOptions { Format = serializationFormat, Version = serializationVersion, JsonContext = jsonContext }; + var serializationOptions = new HttpResultSerializationOptions { Format = serializationFormat, Version = serializationVersion, Serializer = serializer }; var response = httpResults.Serialize(serializationOptions); return response; } diff --git a/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/CustomizeResponseExamples_NotFoundResponseWithHeaderV2_Generated.g.cs b/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/CustomizeResponseExamples_NotFoundResponseWithHeaderV2_Generated.g.cs index d809f6c9b..7aab90492 100644 --- a/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/CustomizeResponseExamples_NotFoundResponseWithHeaderV2_Generated.g.cs +++ b/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/CustomizeResponseExamples_NotFoundResponseWithHeaderV2_Generated.g.cs @@ -1,3 +1,5 @@ +// + using System; using System.Linq; using System.Collections.Generic; @@ -14,6 +16,11 @@ public class CustomizeResponseExamples_NotFoundResponseWithHeaderV2_Generated private readonly CustomizeResponseExamples customizeResponseExamples; private readonly Amazon.Lambda.Serialization.SystemTextJson.DefaultLambdaJsonSerializer serializer; + /// + /// Default constructor. This constructor is used by Lambda to construct the instance. When invoked in a Lambda environment + /// the AWS credentials will come from the IAM role associated with the function and the AWS region will be set to the + /// region the Lambda function is executed in. + /// public CustomizeResponseExamples_NotFoundResponseWithHeaderV2_Generated() { SetExecutionEnvironment(); @@ -21,6 +28,12 @@ public CustomizeResponseExamples_NotFoundResponseWithHeaderV2_Generated() serializer = new Amazon.Lambda.Serialization.SystemTextJson.DefaultLambdaJsonSerializer(); } + /// + /// The generated Lambda function handler for + /// + /// The API Gateway request object that will be processed by the Lambda function handler. + /// The ILambdaContext that provides methods for logging and describing the Lambda environment. + /// Result of the Lambda function execution public System.IO.Stream NotFoundResponseWithHeaderV2(Amazon.Lambda.APIGatewayEvents.APIGatewayHttpApiV2ProxyRequest __request__, Amazon.Lambda.Core.ILambdaContext __context__) { var validationErrors = new List(); @@ -60,8 +73,7 @@ public System.IO.Stream NotFoundResponseWithHeaderV2(Amazon.Lambda.APIGatewayEve var httpResults = customizeResponseExamples.NotFoundResponseWithHeaderV2(x, __context__); HttpResultSerializationOptions.ProtocolFormat serializationFormat = HttpResultSerializationOptions.ProtocolFormat.HttpApi; HttpResultSerializationOptions.ProtocolVersion serializationVersion = HttpResultSerializationOptions.ProtocolVersion.V2; - System.Text.Json.Serialization.JsonSerializerContext jsonContext = null; - var serializationOptions = new HttpResultSerializationOptions { Format = serializationFormat, Version = serializationVersion, JsonContext = jsonContext }; + var serializationOptions = new HttpResultSerializationOptions { Format = serializationFormat, Version = serializationVersion, Serializer = serializer }; var response = httpResults.Serialize(serializationOptions); return response; } diff --git a/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/CustomizeResponseExamples_OkResponseWithCustomSerializer_Generated.g.cs b/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/CustomizeResponseExamples_OkResponseWithCustomSerializer_Generated.g.cs new file mode 100644 index 000000000..b4674fa21 --- /dev/null +++ b/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/CustomizeResponseExamples_OkResponseWithCustomSerializer_Generated.g.cs @@ -0,0 +1,111 @@ +// + +using System; +using System.Linq; +using System.Collections.Generic; +using System.Text; +using System.Threading.Tasks; +using System.IO; +using Amazon.Lambda.Core; +using Amazon.Lambda.Annotations.APIGateway; + +namespace TestServerlessApp +{ + public class CustomizeResponseExamples_OkResponseWithCustomSerializer_Generated + { + private readonly CustomizeResponseExamples customizeResponseExamples; + private readonly TestServerlessApp.PersonSerializer serializer; + + /// + /// Default constructor. This constructor is used by Lambda to construct the instance. When invoked in a Lambda environment + /// the AWS credentials will come from the IAM role associated with the function and the AWS region will be set to the + /// region the Lambda function is executed in. + /// + public CustomizeResponseExamples_OkResponseWithCustomSerializer_Generated() + { + SetExecutionEnvironment(); + customizeResponseExamples = new CustomizeResponseExamples(); + serializer = new TestServerlessApp.PersonSerializer(); + } + + /// + /// The generated Lambda function handler for + /// + /// The API Gateway request object that will be processed by the Lambda function handler. + /// The ILambdaContext that provides methods for logging and describing the Lambda environment. + /// Result of the Lambda function execution + public async System.Threading.Tasks.Task OkResponseWithCustomSerializer(Amazon.Lambda.APIGatewayEvents.APIGatewayProxyRequest __request__, Amazon.Lambda.Core.ILambdaContext __context__) + { + var validationErrors = new List(); + + var firstName = default(string); + if (__request__.PathParameters?.ContainsKey("firstName") == true) + { + try + { + firstName = (string)Convert.ChangeType(__request__.PathParameters["firstName"], typeof(string)); + } + catch (Exception e) when (e is InvalidCastException || e is FormatException || e is OverflowException || e is ArgumentException) + { + validationErrors.Add($"Value {__request__.PathParameters["firstName"]} at 'firstName' failed to satisfy constraint: {e.Message}"); + } + } + + var lastName = default(string); + if (__request__.PathParameters?.ContainsKey("lastName") == true) + { + try + { + lastName = (string)Convert.ChangeType(__request__.PathParameters["lastName"], typeof(string)); + } + catch (Exception e) when (e is InvalidCastException || e is FormatException || e is OverflowException || e is ArgumentException) + { + validationErrors.Add($"Value {__request__.PathParameters["lastName"]} at 'lastName' failed to satisfy constraint: {e.Message}"); + } + } + + // return 400 Bad Request if there exists a validation error + if (validationErrors.Any()) + { + var errorResult = new Amazon.Lambda.APIGatewayEvents.APIGatewayProxyResponse + { + Body = @$"{{""message"": ""{validationErrors.Count} validation error(s) detected: {string.Join(",", validationErrors)}""}}", + Headers = new Dictionary + { + {"Content-Type", "application/json"}, + {"x-amzn-ErrorType", "ValidationException"} + }, + StatusCode = 400 + }; + var errorStream = new System.IO.MemoryStream(); + serializer.Serialize(errorResult, errorStream); + errorStream.Position = 0; + return errorStream; + } + + var httpResults = await customizeResponseExamples.OkResponseWithCustomSerializer(firstName, lastName, __context__); + HttpResultSerializationOptions.ProtocolFormat serializationFormat = HttpResultSerializationOptions.ProtocolFormat.HttpApi; + HttpResultSerializationOptions.ProtocolVersion serializationVersion = HttpResultSerializationOptions.ProtocolVersion.V1; + var serializationOptions = new HttpResultSerializationOptions { Format = serializationFormat, Version = serializationVersion, Serializer = serializer }; + var response = httpResults.Serialize(serializationOptions); + return response; + } + + private static void SetExecutionEnvironment() + { + const string envName = "AWS_EXECUTION_ENV"; + + var envValue = new StringBuilder(); + + // If there is an existing execution environment variable add the annotations package as a suffix. + if(!string.IsNullOrEmpty(Environment.GetEnvironmentVariable(envName))) + { + envValue.Append($"{Environment.GetEnvironmentVariable(envName)}_"); + } + + envValue.Append("lib/amazon-lambda-annotations#1.3.1.0"); + + Environment.SetEnvironmentVariable(envName, envValue.ToString()); + } + } +} \ No newline at end of file diff --git a/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/CustomizeResponseExamples_OkResponseWithHeaderAsync_Generated.g.cs b/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/CustomizeResponseExamples_OkResponseWithHeaderAsync_Generated.g.cs index 6f56db9fa..366cc83e7 100644 --- a/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/CustomizeResponseExamples_OkResponseWithHeaderAsync_Generated.g.cs +++ b/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/CustomizeResponseExamples_OkResponseWithHeaderAsync_Generated.g.cs @@ -1,3 +1,5 @@ +// + using System; using System.Linq; using System.Collections.Generic; @@ -14,6 +16,11 @@ public class CustomizeResponseExamples_OkResponseWithHeaderAsync_Generated private readonly CustomizeResponseExamples customizeResponseExamples; private readonly Amazon.Lambda.Serialization.SystemTextJson.DefaultLambdaJsonSerializer serializer; + /// + /// Default constructor. This constructor is used by Lambda to construct the instance. When invoked in a Lambda environment + /// the AWS credentials will come from the IAM role associated with the function and the AWS region will be set to the + /// region the Lambda function is executed in. + /// public CustomizeResponseExamples_OkResponseWithHeaderAsync_Generated() { SetExecutionEnvironment(); @@ -21,6 +28,12 @@ public CustomizeResponseExamples_OkResponseWithHeaderAsync_Generated() serializer = new Amazon.Lambda.Serialization.SystemTextJson.DefaultLambdaJsonSerializer(); } + /// + /// The generated Lambda function handler for + /// + /// The API Gateway request object that will be processed by the Lambda function handler. + /// The ILambdaContext that provides methods for logging and describing the Lambda environment. + /// Result of the Lambda function execution public async System.Threading.Tasks.Task OkResponseWithHeaderAsync(Amazon.Lambda.APIGatewayEvents.APIGatewayProxyRequest __request__, Amazon.Lambda.Core.ILambdaContext __context__) { var validationErrors = new List(); @@ -60,8 +73,7 @@ public CustomizeResponseExamples_OkResponseWithHeaderAsync_Generated() var httpResults = await customizeResponseExamples.OkResponseWithHeaderAsync(x, __context__); HttpResultSerializationOptions.ProtocolFormat serializationFormat = HttpResultSerializationOptions.ProtocolFormat.RestApi; HttpResultSerializationOptions.ProtocolVersion serializationVersion = HttpResultSerializationOptions.ProtocolVersion.V1; - System.Text.Json.Serialization.JsonSerializerContext jsonContext = null; - var serializationOptions = new HttpResultSerializationOptions { Format = serializationFormat, Version = serializationVersion, JsonContext = jsonContext }; + var serializationOptions = new HttpResultSerializationOptions { Format = serializationFormat, Version = serializationVersion, Serializer = serializer }; var response = httpResults.Serialize(serializationOptions); return response; } diff --git a/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/CustomizeResponseExamples_OkResponseWithHeader_Generated.g.cs b/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/CustomizeResponseExamples_OkResponseWithHeader_Generated.g.cs index d56149923..c99f4c2b3 100644 --- a/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/CustomizeResponseExamples_OkResponseWithHeader_Generated.g.cs +++ b/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/CustomizeResponseExamples_OkResponseWithHeader_Generated.g.cs @@ -1,3 +1,5 @@ +// + using System; using System.Linq; using System.Collections.Generic; @@ -14,6 +16,11 @@ public class CustomizeResponseExamples_OkResponseWithHeader_Generated private readonly CustomizeResponseExamples customizeResponseExamples; private readonly Amazon.Lambda.Serialization.SystemTextJson.DefaultLambdaJsonSerializer serializer; + /// + /// Default constructor. This constructor is used by Lambda to construct the instance. When invoked in a Lambda environment + /// the AWS credentials will come from the IAM role associated with the function and the AWS region will be set to the + /// region the Lambda function is executed in. + /// public CustomizeResponseExamples_OkResponseWithHeader_Generated() { SetExecutionEnvironment(); @@ -21,6 +28,12 @@ public CustomizeResponseExamples_OkResponseWithHeader_Generated() serializer = new Amazon.Lambda.Serialization.SystemTextJson.DefaultLambdaJsonSerializer(); } + /// + /// The generated Lambda function handler for + /// + /// The API Gateway request object that will be processed by the Lambda function handler. + /// The ILambdaContext that provides methods for logging and describing the Lambda environment. + /// Result of the Lambda function execution public System.IO.Stream OkResponseWithHeader(Amazon.Lambda.APIGatewayEvents.APIGatewayProxyRequest __request__, Amazon.Lambda.Core.ILambdaContext __context__) { var validationErrors = new List(); @@ -60,8 +73,7 @@ public System.IO.Stream OkResponseWithHeader(Amazon.Lambda.APIGatewayEvents.APIG var httpResults = customizeResponseExamples.OkResponseWithHeader(x, __context__); HttpResultSerializationOptions.ProtocolFormat serializationFormat = HttpResultSerializationOptions.ProtocolFormat.RestApi; HttpResultSerializationOptions.ProtocolVersion serializationVersion = HttpResultSerializationOptions.ProtocolVersion.V1; - System.Text.Json.Serialization.JsonSerializerContext jsonContext = null; - var serializationOptions = new HttpResultSerializationOptions { Format = serializationFormat, Version = serializationVersion, JsonContext = jsonContext }; + var serializationOptions = new HttpResultSerializationOptions { Format = serializationFormat, Version = serializationVersion, Serializer = serializer }; var response = httpResults.Serialize(serializationOptions); return response; } diff --git a/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/DynamicExample_DynamicInput_Generated.g.cs b/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/DynamicExample_DynamicInput_Generated.g.cs index dc55b2493..51c294ee7 100644 --- a/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/DynamicExample_DynamicInput_Generated.g.cs +++ b/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/DynamicExample_DynamicInput_Generated.g.cs @@ -1,3 +1,5 @@ +// + using System; using System.Linq; using System.Collections.Generic; @@ -13,6 +15,11 @@ public class DynamicExample_DynamicInput_Generated private readonly DynamicExample dynamicExample; private readonly Amazon.Lambda.Serialization.SystemTextJson.DefaultLambdaJsonSerializer serializer; + /// + /// Default constructor. This constructor is used by Lambda to construct the instance. When invoked in a Lambda environment + /// the AWS credentials will come from the IAM role associated with the function and the AWS region will be set to the + /// region the Lambda function is executed in. + /// public DynamicExample_DynamicInput_Generated() { SetExecutionEnvironment(); @@ -20,6 +27,12 @@ public DynamicExample_DynamicInput_Generated() serializer = new Amazon.Lambda.Serialization.SystemTextJson.DefaultLambdaJsonSerializer(); } + /// + /// The generated Lambda function handler for + /// + /// The request object that will be processed by the Lambda function handler. + /// The ILambdaContext that provides methods for logging and describing the Lambda environment. + /// Result of the Lambda function execution public string DynamicInput(dynamic text, Amazon.Lambda.Core.ILambdaContext __context__) { return dynamicExample.DynamicInput(text, __context__); diff --git a/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/DynamicExample_DynamicReturn_Generated.g.cs b/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/DynamicExample_DynamicReturn_Generated.g.cs index 22ac630dc..160864b99 100644 --- a/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/DynamicExample_DynamicReturn_Generated.g.cs +++ b/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/DynamicExample_DynamicReturn_Generated.g.cs @@ -1,3 +1,5 @@ +// + using System; using System.Linq; using System.Collections.Generic; @@ -13,6 +15,11 @@ public class DynamicExample_DynamicReturn_Generated private readonly DynamicExample dynamicExample; private readonly Amazon.Lambda.Serialization.SystemTextJson.DefaultLambdaJsonSerializer serializer; + /// + /// Default constructor. This constructor is used by Lambda to construct the instance. When invoked in a Lambda environment + /// the AWS credentials will come from the IAM role associated with the function and the AWS region will be set to the + /// region the Lambda function is executed in. + /// public DynamicExample_DynamicReturn_Generated() { SetExecutionEnvironment(); @@ -20,6 +27,12 @@ public DynamicExample_DynamicReturn_Generated() serializer = new Amazon.Lambda.Serialization.SystemTextJson.DefaultLambdaJsonSerializer(); } + /// + /// The generated Lambda function handler for + /// + /// The request object that will be processed by the Lambda function handler. + /// The ILambdaContext that provides methods for logging and describing the Lambda environment. + /// Result of the Lambda function execution public dynamic DynamicReturn(string text, Amazon.Lambda.Core.ILambdaContext __context__) { return dynamicExample.DynamicReturn(text, __context__); diff --git a/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/Functions_AsyncStartupToLower_Generated.g.cs b/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/Functions_AsyncStartupToLower_Generated.g.cs index a95cfeb01..7bca2834e 100644 --- a/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/Functions_AsyncStartupToLower_Generated.g.cs +++ b/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/Functions_AsyncStartupToLower_Generated.g.cs @@ -1,3 +1,5 @@ +// + using System; using System.Linq; using System.Collections.Generic; @@ -13,6 +15,11 @@ public class FunctionsZipOutput_ToLower_Generated { private readonly ServiceProvider serviceProvider; + /// + /// Default constructor. This constructor is used by Lambda to construct the instance. When invoked in a Lambda environment + /// the AWS credentials will come from the IAM role associated with the function and the AWS region will be set to the + /// region the Lambda function is executed in. + /// public FunctionsZipOutput_ToLower_Generated() { SetExecutionEnvironment(); @@ -28,6 +35,11 @@ public FunctionsZipOutput_ToLower_Generated() serviceProvider = services.BuildServiceProvider(); } + /// + /// The generated Lambda function handler for + /// + /// The request object that will be processed by the Lambda function handler. + /// Result of the Lambda function execution public string ToLower(string text) { // Create a scope for every request, diff --git a/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/Functions_AsyncStartupToUpper_Generated.g.cs b/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/Functions_AsyncStartupToUpper_Generated.g.cs index c2249cd46..854b69221 100644 --- a/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/Functions_AsyncStartupToUpper_Generated.g.cs +++ b/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/Functions_AsyncStartupToUpper_Generated.g.cs @@ -1,3 +1,5 @@ +// + using System; using System.Linq; using System.Collections.Generic; @@ -13,6 +15,11 @@ public class Functions_ToUpper_Generated { private readonly ServiceProvider serviceProvider; + /// + /// Default constructor. This constructor is used by Lambda to construct the instance. When invoked in a Lambda environment + /// the AWS credentials will come from the IAM role associated with the function and the AWS region will be set to the + /// region the Lambda function is executed in. + /// public Functions_ToUpper_Generated() { SetExecutionEnvironment(); @@ -28,6 +35,11 @@ public Functions_ToUpper_Generated() serviceProvider = services.BuildServiceProvider(); } + /// + /// The generated Lambda function handler for + /// + /// The request object that will be processed by the Lambda function handler. + /// Result of the Lambda function execution public string ToUpper(string text) { // Create a scope for every request, diff --git a/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/Functions_ToUpper_Generated.g.cs b/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/Functions_ToUpper_Generated.g.cs index 07ece12af..8e80d3711 100644 --- a/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/Functions_ToUpper_Generated.g.cs +++ b/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/Functions_ToUpper_Generated.g.cs @@ -1,3 +1,5 @@ +// + using System; using System.Linq; using System.Collections.Generic; @@ -13,6 +15,11 @@ public class Functions_ToUpper_Generated private readonly Functions functions; private readonly Amazon.Lambda.Serialization.SystemTextJson.DefaultLambdaJsonSerializer serializer; + /// + /// Default constructor. This constructor is used by Lambda to construct the instance. When invoked in a Lambda environment + /// the AWS credentials will come from the IAM role associated with the function and the AWS region will be set to the + /// region the Lambda function is executed in. + /// public Functions_ToUpper_Generated() { SetExecutionEnvironment(); @@ -20,6 +27,11 @@ public Functions_ToUpper_Generated() serializer = new Amazon.Lambda.Serialization.SystemTextJson.DefaultLambdaJsonSerializer(); } + /// + /// The generated Lambda function handler for + /// + /// The request object that will be processed by the Lambda function handler. + /// Result of the Lambda function execution public string ToUpper(string text) { return functions.ToUpper(text); diff --git a/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/Functions_ToUpper_Generated_NET8.g.cs b/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/Functions_ToUpper_Generated_NET8.g.cs index 9a2db7419..214a8df58 100644 --- a/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/Functions_ToUpper_Generated_NET8.g.cs +++ b/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/Functions_ToUpper_Generated_NET8.g.cs @@ -1,3 +1,5 @@ +// + using System; using System.Linq; using System.Collections.Generic; @@ -13,6 +15,11 @@ public class Functions_ToUpper_Generated private readonly Functions functions; private readonly Amazon.Lambda.Serialization.SystemTextJson.DefaultLambdaJsonSerializer serializer; + /// + /// Default constructor. This constructor is used by Lambda to construct the instance. When invoked in a Lambda environment + /// the AWS credentials will come from the IAM role associated with the function and the AWS region will be set to the + /// region the Lambda function is executed in. + /// public Functions_ToUpper_Generated() { SetExecutionEnvironment(); @@ -20,6 +27,11 @@ public Functions_ToUpper_Generated() serializer = new Amazon.Lambda.Serialization.SystemTextJson.DefaultLambdaJsonSerializer(); } + /// + /// The generated Lambda function handler for + /// + /// The request object that will be processed by the Lambda function handler. + /// Result of the Lambda function execution public string ToUpper(string text) { return functions.ToUpper(text); diff --git a/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/GreeterExecutable_SayHelloAsync_Generated.g.cs b/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/GreeterExecutable_SayHelloAsync_Generated.g.cs index 29f4c59cf..5e0d66ee3 100644 --- a/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/GreeterExecutable_SayHelloAsync_Generated.g.cs +++ b/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/GreeterExecutable_SayHelloAsync_Generated.g.cs @@ -1,4 +1,6 @@ -using System; +// + +using System; using System.Linq; using System.Collections.Generic; using System.Text; @@ -13,6 +15,11 @@ public class Greeter_SayHelloAsync_Generated { private readonly ServiceProvider serviceProvider; + /// + /// Default constructor. This constructor is used by Lambda to construct the instance. When invoked in a Lambda environment + /// the AWS credentials will come from the IAM role associated with the function and the AWS region will be set to the + /// region the Lambda function is executed in. + /// public Greeter_SayHelloAsync_Generated() { SetExecutionEnvironment(); @@ -28,6 +35,12 @@ public Greeter_SayHelloAsync_Generated() serviceProvider = services.BuildServiceProvider(); } + /// + /// The generated Lambda function handler for + /// + /// The API Gateway request object that will be processed by the Lambda function handler. + /// The ILambdaContext that provides methods for logging and describing the Lambda environment. + /// Result of the Lambda function execution public async System.Threading.Tasks.Task SayHelloAsync(Amazon.Lambda.APIGatewayEvents.APIGatewayProxyRequest __request__, Amazon.Lambda.Core.ILambdaContext __context__) { // Create a scope for every request, diff --git a/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/GreeterExecutable_SayHello_Generated.g.cs b/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/GreeterExecutable_SayHello_Generated.g.cs index 6583888c0..b9034fa37 100644 --- a/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/GreeterExecutable_SayHello_Generated.g.cs +++ b/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/GreeterExecutable_SayHello_Generated.g.cs @@ -1,4 +1,6 @@ -using System; +// + +using System; using System.Linq; using System.Collections.Generic; using System.Text; @@ -13,6 +15,11 @@ public class Greeter_SayHello_Generated { private readonly ServiceProvider serviceProvider; + /// + /// Default constructor. This constructor is used by Lambda to construct the instance. When invoked in a Lambda environment + /// the AWS credentials will come from the IAM role associated with the function and the AWS region will be set to the + /// region the Lambda function is executed in. + /// public Greeter_SayHello_Generated() { SetExecutionEnvironment(); @@ -28,6 +35,12 @@ public Greeter_SayHello_Generated() serviceProvider = services.BuildServiceProvider(); } + /// + /// The generated Lambda function handler for + /// + /// The API Gateway request object that will be processed by the Lambda function handler. + /// The ILambdaContext that provides methods for logging and describing the Lambda environment. + /// Result of the Lambda function execution public Amazon.Lambda.APIGatewayEvents.APIGatewayProxyResponse SayHello(Amazon.Lambda.APIGatewayEvents.APIGatewayProxyRequest __request__, Amazon.Lambda.Core.ILambdaContext __context__) { // Create a scope for every request, diff --git a/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/Greeter_SayHelloAsync_Generated.g.cs b/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/Greeter_SayHelloAsync_Generated.g.cs index bf255b7df..2b3da55eb 100644 --- a/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/Greeter_SayHelloAsync_Generated.g.cs +++ b/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/Greeter_SayHelloAsync_Generated.g.cs @@ -1,4 +1,6 @@ -using System; +// + +using System; using System.Linq; using System.Collections.Generic; using System.Text; @@ -13,6 +15,11 @@ public class Greeter_SayHelloAsync_Generated private readonly Greeter greeter; private readonly Amazon.Lambda.Serialization.SystemTextJson.DefaultLambdaJsonSerializer serializer; + /// + /// Default constructor. This constructor is used by Lambda to construct the instance. When invoked in a Lambda environment + /// the AWS credentials will come from the IAM role associated with the function and the AWS region will be set to the + /// region the Lambda function is executed in. + /// public Greeter_SayHelloAsync_Generated() { SetExecutionEnvironment(); @@ -20,6 +27,12 @@ public Greeter_SayHelloAsync_Generated() serializer = new Amazon.Lambda.Serialization.SystemTextJson.DefaultLambdaJsonSerializer(); } + /// + /// The generated Lambda function handler for + /// + /// The API Gateway request object that will be processed by the Lambda function handler. + /// The ILambdaContext that provides methods for logging and describing the Lambda environment. + /// Result of the Lambda function execution public async System.Threading.Tasks.Task SayHelloAsync(Amazon.Lambda.APIGatewayEvents.APIGatewayProxyRequest __request__, Amazon.Lambda.Core.ILambdaContext __context__) { var validationErrors = new List(); diff --git a/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/Greeter_SayHello_Generated.g.cs b/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/Greeter_SayHello_Generated.g.cs index 186f814f9..6120f86ce 100644 --- a/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/Greeter_SayHello_Generated.g.cs +++ b/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/Greeter_SayHello_Generated.g.cs @@ -1,4 +1,6 @@ -using System; +// + +using System; using System.Linq; using System.Collections.Generic; using System.Text; @@ -13,6 +15,11 @@ public class Greeter_SayHello_Generated private readonly Greeter greeter; private readonly Amazon.Lambda.Serialization.SystemTextJson.DefaultLambdaJsonSerializer serializer; + /// + /// Default constructor. This constructor is used by Lambda to construct the instance. When invoked in a Lambda environment + /// the AWS credentials will come from the IAM role associated with the function and the AWS region will be set to the + /// region the Lambda function is executed in. + /// public Greeter_SayHello_Generated() { SetExecutionEnvironment(); @@ -20,6 +27,12 @@ public Greeter_SayHello_Generated() serializer = new Amazon.Lambda.Serialization.SystemTextJson.DefaultLambdaJsonSerializer(); } + /// + /// The generated Lambda function handler for + /// + /// The API Gateway request object that will be processed by the Lambda function handler. + /// The ILambdaContext that provides methods for logging and describing the Lambda environment. + /// Result of the Lambda function execution public Amazon.Lambda.APIGatewayEvents.APIGatewayProxyResponse SayHello(Amazon.Lambda.APIGatewayEvents.APIGatewayProxyRequest __request__, Amazon.Lambda.Core.ILambdaContext __context__) { var validationErrors = new List(); diff --git a/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/IntrinsicExample_HasIntrinsic_Generated.g.cs b/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/IntrinsicExample_HasIntrinsic_Generated.g.cs index a1c627ca1..f45bdedb9 100644 --- a/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/IntrinsicExample_HasIntrinsic_Generated.g.cs +++ b/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/IntrinsicExample_HasIntrinsic_Generated.g.cs @@ -1,4 +1,6 @@ -using System; +// + +using System; using System.Linq; using System.Collections.Generic; using System.Text; @@ -13,6 +15,11 @@ public class IntrinsicExample_HasIntrinsic_Generated private readonly IntrinsicExample intrinsicExample; private readonly Amazon.Lambda.Serialization.SystemTextJson.DefaultLambdaJsonSerializer serializer; + /// + /// Default constructor. This constructor is used by Lambda to construct the instance. When invoked in a Lambda environment + /// the AWS credentials will come from the IAM role associated with the function and the AWS region will be set to the + /// region the Lambda function is executed in. + /// public IntrinsicExample_HasIntrinsic_Generated() { SetExecutionEnvironment(); @@ -20,6 +27,12 @@ public IntrinsicExample_HasIntrinsic_Generated() serializer = new Amazon.Lambda.Serialization.SystemTextJson.DefaultLambdaJsonSerializer(); } + /// + /// The generated Lambda function handler for + /// + /// The request object that will be processed by the Lambda function handler. + /// The ILambdaContext that provides methods for logging and describing the Lambda environment. + /// Result of the Lambda function execution public void HasIntrinsic(string text, Amazon.Lambda.Core.ILambdaContext __context__) { intrinsicExample.HasIntrinsic(text, __context__); diff --git a/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/NullableReferenceTypeExample_NullableHeaderHttpApi_Generated.g.cs b/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/NullableReferenceTypeExample_NullableHeaderHttpApi_Generated.g.cs index 60da26f9d..53987cc9a 100644 --- a/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/NullableReferenceTypeExample_NullableHeaderHttpApi_Generated.g.cs +++ b/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/NullableReferenceTypeExample_NullableHeaderHttpApi_Generated.g.cs @@ -1,3 +1,5 @@ +// + using System; using System.Linq; using System.Collections.Generic; @@ -13,6 +15,11 @@ public class NullableReferenceTypeExample_NullableHeaderHttpApi_Generated private readonly NullableReferenceTypeExample nullableReferenceTypeExample; private readonly Amazon.Lambda.Serialization.SystemTextJson.DefaultLambdaJsonSerializer serializer; + /// + /// Default constructor. This constructor is used by Lambda to construct the instance. When invoked in a Lambda environment + /// the AWS credentials will come from the IAM role associated with the function and the AWS region will be set to the + /// region the Lambda function is executed in. + /// public NullableReferenceTypeExample_NullableHeaderHttpApi_Generated() { SetExecutionEnvironment(); @@ -20,6 +27,12 @@ public NullableReferenceTypeExample_NullableHeaderHttpApi_Generated() serializer = new Amazon.Lambda.Serialization.SystemTextJson.DefaultLambdaJsonSerializer(); } + /// + /// The generated Lambda function handler for + /// + /// The API Gateway request object that will be processed by the Lambda function handler. + /// The ILambdaContext that provides methods for logging and describing the Lambda environment. + /// Result of the Lambda function execution public Amazon.Lambda.APIGatewayEvents.APIGatewayHttpApiV2ProxyResponse NullableHeaderHttpApi(Amazon.Lambda.APIGatewayEvents.APIGatewayHttpApiV2ProxyRequest __request__, Amazon.Lambda.Core.ILambdaContext __context__) { var validationErrors = new List(); diff --git a/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/ParameterlessMethodWithResponse_ToUpper_Generated.g.cs b/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/ParameterlessMethodWithResponse_ToUpper_Generated.g.cs index bc295995c..e96636875 100644 --- a/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/ParameterlessMethodWithResponse_ToUpper_Generated.g.cs +++ b/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/ParameterlessMethodWithResponse_ToUpper_Generated.g.cs @@ -1,3 +1,5 @@ +// + using System; using System.Linq; using System.Collections.Generic; @@ -13,6 +15,11 @@ public class ParameterlessMethodWithResponse_NoParameterWithResponse_Generated private readonly ParameterlessMethodWithResponse parameterlessMethodWithResponse; private readonly Amazon.Lambda.Serialization.SystemTextJson.DefaultLambdaJsonSerializer serializer; + /// + /// Default constructor. This constructor is used by Lambda to construct the instance. When invoked in a Lambda environment + /// the AWS credentials will come from the IAM role associated with the function and the AWS region will be set to the + /// region the Lambda function is executed in. + /// public ParameterlessMethodWithResponse_NoParameterWithResponse_Generated() { SetExecutionEnvironment(); @@ -20,6 +27,10 @@ public ParameterlessMethodWithResponse_NoParameterWithResponse_Generated() serializer = new Amazon.Lambda.Serialization.SystemTextJson.DefaultLambdaJsonSerializer(); } + /// + /// The generated Lambda function handler for + /// + /// Result of the Lambda function execution public string NoParameterWithResponse(Stream stream) { return parameterlessMethodWithResponse.NoParameterWithResponse(); diff --git a/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/ParameterlessMethods_ToUpper_Generated.g.cs b/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/ParameterlessMethods_ToUpper_Generated.g.cs index a20de4643..d2e8e4c7b 100644 --- a/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/ParameterlessMethods_ToUpper_Generated.g.cs +++ b/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/ParameterlessMethods_ToUpper_Generated.g.cs @@ -1,3 +1,5 @@ +// + using System; using System.Linq; using System.Collections.Generic; @@ -13,6 +15,11 @@ public class ParameterlessMethods_NoParameter_Generated private readonly ParameterlessMethods parameterlessMethods; private readonly Amazon.Lambda.Serialization.SystemTextJson.DefaultLambdaJsonSerializer serializer; + /// + /// Default constructor. This constructor is used by Lambda to construct the instance. When invoked in a Lambda environment + /// the AWS credentials will come from the IAM role associated with the function and the AWS region will be set to the + /// region the Lambda function is executed in. + /// public ParameterlessMethods_NoParameter_Generated() { SetExecutionEnvironment(); @@ -20,6 +27,10 @@ public ParameterlessMethods_NoParameter_Generated() serializer = new Amazon.Lambda.Serialization.SystemTextJson.DefaultLambdaJsonSerializer(); } + /// + /// The generated Lambda function handler for + /// + /// Result of the Lambda function execution public void NoParameter(Stream stream) { parameterlessMethods.NoParameter(); diff --git a/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/Program.g.cs b/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/Program.g.cs index 594bd7af9..58299b050 100644 --- a/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/Program.g.cs +++ b/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/Program.g.cs @@ -1,4 +1,6 @@ -using System; +// + +using System; using System.Linq; using System.Collections.Generic; using System.Text; @@ -10,6 +12,9 @@ namespace TestServerlessApp.Sub1; public class GeneratedProgram { + /// + /// This is responsible for inspecting the 'ANNOTATIONS_HANDLER' environment variable and invoking the appropriate Lambda function handler. + /// public static async Task Main(string[] args) { diff --git a/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/ProgramMultiHandler.g.cs b/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/ProgramMultiHandler.g.cs index d3b7728d5..909f9c604 100644 --- a/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/ProgramMultiHandler.g.cs +++ b/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/ProgramMultiHandler.g.cs @@ -1,4 +1,6 @@ -using System; +// + +using System; using System.Linq; using System.Collections.Generic; using System.Text; @@ -10,6 +12,9 @@ namespace TestServerlessApp; public class GeneratedProgram { + /// + /// This is responsible for inspecting the 'ANNOTATIONS_HANDLER' environment variable and invoking the appropriate Lambda function handler. + /// public static async Task Main(string[] args) { diff --git a/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/ProgramParameterless.g.cs b/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/ProgramParameterless.g.cs index dcf6c591a..39d79eca7 100644 --- a/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/ProgramParameterless.g.cs +++ b/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/ProgramParameterless.g.cs @@ -1,4 +1,6 @@ -using System; +// + +using System; using System.Linq; using System.Collections.Generic; using System.Text; @@ -10,6 +12,9 @@ namespace TestServerlessApp; public class GeneratedProgram { + /// + /// This is responsible for inspecting the 'ANNOTATIONS_HANDLER' environment variable and invoking the appropriate Lambda function handler. + /// public static async Task Main(string[] args) { diff --git a/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/ProgramParameterlessWithResponse.g.cs b/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/ProgramParameterlessWithResponse.g.cs index b60ed0e85..f9077a6d9 100644 --- a/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/ProgramParameterlessWithResponse.g.cs +++ b/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/ProgramParameterlessWithResponse.g.cs @@ -1,4 +1,6 @@ -using System; +// + +using System; using System.Linq; using System.Collections.Generic; using System.Text; @@ -10,6 +12,9 @@ namespace TestServerlessApp; public class GeneratedProgram { + /// + /// This is responsible for inspecting the 'ANNOTATIONS_HANDLER' environment variable and invoking the appropriate Lambda function handler. + /// public static async Task Main(string[] args) { diff --git a/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/ProgramSourceGeneratorSerializationExample.g.cs b/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/ProgramSourceGeneratorSerializationExample.g.cs index 850761100..3bb638a28 100644 --- a/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/ProgramSourceGeneratorSerializationExample.g.cs +++ b/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/ProgramSourceGeneratorSerializationExample.g.cs @@ -1,4 +1,6 @@ -using System; +// + +using System; using System.Linq; using System.Collections.Generic; using System.Text; @@ -10,6 +12,9 @@ namespace TestExecutableServerlessApp; public class GeneratedProgram { + /// + /// This is responsible for inspecting the 'ANNOTATIONS_HANDLER' environment variable and invoking the appropriate Lambda function handler. + /// public static async Task Main(string[] args) { diff --git a/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/ProgramZipOutput.g.cs b/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/ProgramZipOutput.g.cs index 337fc01f7..2518a7ce8 100644 --- a/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/ProgramZipOutput.g.cs +++ b/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/ProgramZipOutput.g.cs @@ -1,4 +1,6 @@ -using System; +// + +using System; using System.Linq; using System.Collections.Generic; using System.Text; @@ -10,6 +12,9 @@ namespace TestServerlessApp.Sub1; public class GeneratedProgram { + /// + /// This is responsible for inspecting the 'ANNOTATIONS_HANDLER' environment variable and invoking the appropriate Lambda function handler. + /// public static async Task Main(string[] args) { diff --git a/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/ServerlessTemplates/customizeResponse.template b/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/ServerlessTemplates/customizeResponse.template index 2ccc7b4ca..d0c7c6879 100644 --- a/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/ServerlessTemplates/customizeResponse.template +++ b/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/ServerlessTemplates/customizeResponse.template @@ -196,6 +196,39 @@ } } } + }, + "TestServerlessAppCustomizeResponseExamplesOkResponseWithCustomSerializerGenerated": { + "Type": "AWS::Serverless::Function", + "Metadata": { + "Tool": "Amazon.Lambda.Annotations", + "SyncedEvents": [ + "RootGet" + ] + }, + "Properties": { + "MemorySize": 512, + "Timeout": 30, + "Policies": [ + "AWSLambdaBasicExecutionRole" + ], + "PackageType": "Image", + "ImageUri": ".", + "ImageConfig": { + "Command": [ + "TestProject::TestServerlessApp.CustomizeResponseExamples_OkResponseWithCustomSerializer_Generated::OkResponseWithCustomSerializer" + ] + }, + "Events": { + "RootGet": { + "Type": "HttpApi", + "Properties": { + "Path": "/okresponsewithcustomserializerasync/{firstName}/{lastName}", + "Method": "GET", + "PayloadFormatVersion": "1.0" + } + } + } + } } } } \ No newline at end of file diff --git a/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/SimpleCalculator_Add_Generated.g.cs b/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/SimpleCalculator_Add_Generated.g.cs index 4429228c8..c5935847c 100644 --- a/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/SimpleCalculator_Add_Generated.g.cs +++ b/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/SimpleCalculator_Add_Generated.g.cs @@ -1,4 +1,6 @@ -using System; +// + +using System; using System.Linq; using System.Collections.Generic; using System.Text; @@ -13,6 +15,11 @@ public class SimpleCalculator_Add_Generated { private readonly ServiceProvider serviceProvider; + /// + /// Default constructor. This constructor is used by Lambda to construct the instance. When invoked in a Lambda environment + /// the AWS credentials will come from the IAM role associated with the function and the AWS region will be set to the + /// region the Lambda function is executed in. + /// public SimpleCalculator_Add_Generated() { SetExecutionEnvironment(); @@ -28,6 +35,12 @@ public SimpleCalculator_Add_Generated() serviceProvider = services.BuildServiceProvider(); } + /// + /// The generated Lambda function handler for + /// + /// The API Gateway request object that will be processed by the Lambda function handler. + /// The ILambdaContext that provides methods for logging and describing the Lambda environment. + /// Result of the Lambda function execution public Amazon.Lambda.APIGatewayEvents.APIGatewayProxyResponse Add(Amazon.Lambda.APIGatewayEvents.APIGatewayProxyRequest __request__, Amazon.Lambda.Core.ILambdaContext __context__) { // Create a scope for every request, diff --git a/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/SimpleCalculator_DivideAsync_Generated.g.cs b/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/SimpleCalculator_DivideAsync_Generated.g.cs index c89c25ba1..59cf33f3b 100644 --- a/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/SimpleCalculator_DivideAsync_Generated.g.cs +++ b/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/SimpleCalculator_DivideAsync_Generated.g.cs @@ -1,4 +1,6 @@ -using System; +// + +using System; using System.Linq; using System.Collections.Generic; using System.Text; @@ -13,6 +15,11 @@ public class SimpleCalculator_DivideAsync_Generated { private readonly ServiceProvider serviceProvider; + /// + /// Default constructor. This constructor is used by Lambda to construct the instance. When invoked in a Lambda environment + /// the AWS credentials will come from the IAM role associated with the function and the AWS region will be set to the + /// region the Lambda function is executed in. + /// public SimpleCalculator_DivideAsync_Generated() { SetExecutionEnvironment(); @@ -28,6 +35,12 @@ public SimpleCalculator_DivideAsync_Generated() serviceProvider = services.BuildServiceProvider(); } + /// + /// The generated Lambda function handler for + /// + /// The API Gateway request object that will be processed by the Lambda function handler. + /// The ILambdaContext that provides methods for logging and describing the Lambda environment. + /// Result of the Lambda function execution public async System.Threading.Tasks.Task DivideAsync(Amazon.Lambda.APIGatewayEvents.APIGatewayProxyRequest __request__, Amazon.Lambda.Core.ILambdaContext __context__) { // Create a scope for every request, diff --git a/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/SimpleCalculator_Multiply_Generated.g.cs b/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/SimpleCalculator_Multiply_Generated.g.cs index ba715c9e9..77dde822a 100644 --- a/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/SimpleCalculator_Multiply_Generated.g.cs +++ b/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/SimpleCalculator_Multiply_Generated.g.cs @@ -1,4 +1,6 @@ -using System; +// + +using System; using System.Linq; using System.Collections.Generic; using System.Text; @@ -13,6 +15,11 @@ public class SimpleCalculator_Multiply_Generated { private readonly ServiceProvider serviceProvider; + /// + /// Default constructor. This constructor is used by Lambda to construct the instance. When invoked in a Lambda environment + /// the AWS credentials will come from the IAM role associated with the function and the AWS region will be set to the + /// region the Lambda function is executed in. + /// public SimpleCalculator_Multiply_Generated() { SetExecutionEnvironment(); @@ -28,6 +35,12 @@ public SimpleCalculator_Multiply_Generated() serviceProvider = services.BuildServiceProvider(); } + /// + /// The generated Lambda function handler for + /// + /// The API Gateway request object that will be processed by the Lambda function handler. + /// The ILambdaContext that provides methods for logging and describing the Lambda environment. + /// Result of the Lambda function execution public Amazon.Lambda.APIGatewayEvents.APIGatewayProxyResponse Multiply(Amazon.Lambda.APIGatewayEvents.APIGatewayProxyRequest __request__, Amazon.Lambda.Core.ILambdaContext __context__) { // Create a scope for every request, diff --git a/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/SimpleCalculator_Pi_Generated.g.cs b/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/SimpleCalculator_Pi_Generated.g.cs index 3439eab52..c1df83995 100644 --- a/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/SimpleCalculator_Pi_Generated.g.cs +++ b/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/SimpleCalculator_Pi_Generated.g.cs @@ -1,4 +1,6 @@ -using System; +// + +using System; using System.Linq; using System.Collections.Generic; using System.Text; @@ -13,6 +15,11 @@ public class SimpleCalculator_Pi_Generated { private readonly ServiceProvider serviceProvider; + /// + /// Default constructor. This constructor is used by Lambda to construct the instance. When invoked in a Lambda environment + /// the AWS credentials will come from the IAM role associated with the function and the AWS region will be set to the + /// region the Lambda function is executed in. + /// public SimpleCalculator_Pi_Generated() { SetExecutionEnvironment(); @@ -28,6 +35,10 @@ public SimpleCalculator_Pi_Generated() serviceProvider = services.BuildServiceProvider(); } + /// + /// The generated Lambda function handler for + /// + /// Result of the Lambda function execution public double Pi(Stream stream) { // Create a scope for every request, diff --git a/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/SimpleCalculator_Random_Generated.g.cs b/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/SimpleCalculator_Random_Generated.g.cs index f6a99480b..2f837b721 100644 --- a/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/SimpleCalculator_Random_Generated.g.cs +++ b/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/SimpleCalculator_Random_Generated.g.cs @@ -1,4 +1,6 @@ -using System; +// + +using System; using System.Linq; using System.Collections.Generic; using System.Text; @@ -13,6 +15,11 @@ public class SimpleCalculator_Random_Generated { private readonly ServiceProvider serviceProvider; + /// + /// Default constructor. This constructor is used by Lambda to construct the instance. When invoked in a Lambda environment + /// the AWS credentials will come from the IAM role associated with the function and the AWS region will be set to the + /// region the Lambda function is executed in. + /// public SimpleCalculator_Random_Generated() { SetExecutionEnvironment(); @@ -28,6 +35,12 @@ public SimpleCalculator_Random_Generated() serviceProvider = services.BuildServiceProvider(); } + /// + /// The generated Lambda function handler for + /// + /// The request object that will be processed by the Lambda function handler. + /// The ILambdaContext that provides methods for logging and describing the Lambda environment. + /// Result of the Lambda function execution public async System.Threading.Tasks.Task Random(int maxValue, Amazon.Lambda.Core.ILambdaContext __context__) { // Create a scope for every request, diff --git a/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/SimpleCalculator_Randoms_Generated.g.cs b/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/SimpleCalculator_Randoms_Generated.g.cs index 6af86d1be..31885ce85 100644 --- a/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/SimpleCalculator_Randoms_Generated.g.cs +++ b/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/SimpleCalculator_Randoms_Generated.g.cs @@ -1,4 +1,6 @@ -using System; +// + +using System; using System.Linq; using System.Collections.Generic; using System.Text; @@ -13,6 +15,11 @@ public class SimpleCalculator_Randoms_Generated { private readonly ServiceProvider serviceProvider; + /// + /// Default constructor. This constructor is used by Lambda to construct the instance. When invoked in a Lambda environment + /// the AWS credentials will come from the IAM role associated with the function and the AWS region will be set to the + /// region the Lambda function is executed in. + /// public SimpleCalculator_Randoms_Generated() { SetExecutionEnvironment(); @@ -28,6 +35,12 @@ public SimpleCalculator_Randoms_Generated() serviceProvider = services.BuildServiceProvider(); } + /// + /// The generated Lambda function handler for + /// + /// The request object that will be processed by the Lambda function handler. + /// The ILambdaContext that provides methods for logging and describing the Lambda environment. + /// Result of the Lambda function execution public System.Collections.Generic.IList Randoms(TestServerlessApp.SimpleCalculator.RandomsInput input, Amazon.Lambda.Core.ILambdaContext __context__) { // Create a scope for every request, diff --git a/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/SimpleCalculator_Subtract_Generated.g.cs b/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/SimpleCalculator_Subtract_Generated.g.cs index 8edda1d35..db0d3a798 100644 --- a/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/SimpleCalculator_Subtract_Generated.g.cs +++ b/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/SimpleCalculator_Subtract_Generated.g.cs @@ -1,4 +1,6 @@ -using System; +// + +using System; using System.Linq; using System.Collections.Generic; using System.Text; @@ -13,6 +15,11 @@ public class SimpleCalculator_Subtract_Generated { private readonly ServiceProvider serviceProvider; + /// + /// Default constructor. This constructor is used by Lambda to construct the instance. When invoked in a Lambda environment + /// the AWS credentials will come from the IAM role associated with the function and the AWS region will be set to the + /// region the Lambda function is executed in. + /// public SimpleCalculator_Subtract_Generated() { SetExecutionEnvironment(); @@ -28,6 +35,12 @@ public SimpleCalculator_Subtract_Generated() serviceProvider = services.BuildServiceProvider(); } + /// + /// The generated Lambda function handler for + /// + /// The API Gateway request object that will be processed by the Lambda function handler. + /// The ILambdaContext that provides methods for logging and describing the Lambda environment. + /// Result of the Lambda function execution public Amazon.Lambda.APIGatewayEvents.APIGatewayProxyResponse Subtract(Amazon.Lambda.APIGatewayEvents.APIGatewayProxyRequest __request__, Amazon.Lambda.Core.ILambdaContext __context__) { // Create a scope for every request, diff --git a/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/SourceGenerationSerializationExample_GetPerson_Generated.g.cs b/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/SourceGenerationSerializationExample_GetPerson_Generated.g.cs index f23c50208..930690a11 100644 --- a/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/SourceGenerationSerializationExample_GetPerson_Generated.g.cs +++ b/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/SourceGenerationSerializationExample_GetPerson_Generated.g.cs @@ -1,3 +1,5 @@ +// + using System; using System.Linq; using System.Collections.Generic; @@ -14,6 +16,11 @@ public class SourceGenerationSerializationExample_GetPerson_Generated private readonly SourceGenerationSerializationExample sourceGenerationSerializationExample; private readonly Amazon.Lambda.Serialization.SystemTextJson.SourceGeneratorLambdaJsonSerializer serializer; + /// + /// Default constructor. This constructor is used by Lambda to construct the instance. When invoked in a Lambda environment + /// the AWS credentials will come from the IAM role associated with the function and the AWS region will be set to the + /// region the Lambda function is executed in. + /// public SourceGenerationSerializationExample_GetPerson_Generated() { SetExecutionEnvironment(); @@ -21,13 +28,18 @@ public SourceGenerationSerializationExample_GetPerson_Generated() serializer = new Amazon.Lambda.Serialization.SystemTextJson.SourceGeneratorLambdaJsonSerializer(); } + /// + /// The generated Lambda function handler for + /// + /// The API Gateway request object that will be processed by the Lambda function handler. + /// The ILambdaContext that provides methods for logging and describing the Lambda environment. + /// Result of the Lambda function execution public System.IO.Stream GetPerson(Amazon.Lambda.APIGatewayEvents.APIGatewayProxyRequest __request__, Amazon.Lambda.Core.ILambdaContext __context__) { var httpResults = sourceGenerationSerializationExample.GetPerson(__context__); HttpResultSerializationOptions.ProtocolFormat serializationFormat = HttpResultSerializationOptions.ProtocolFormat.RestApi; HttpResultSerializationOptions.ProtocolVersion serializationVersion = HttpResultSerializationOptions.ProtocolVersion.V1; - System.Text.Json.Serialization.JsonSerializerContext jsonContext = TestExecutableServerlessApp.HttpApiJsonSerializerContext.Default; - var serializationOptions = new HttpResultSerializationOptions { Format = serializationFormat, Version = serializationVersion, JsonContext = jsonContext }; + var serializationOptions = new HttpResultSerializationOptions { Format = serializationFormat, Version = serializationVersion, Serializer = serializer }; var response = httpResults.Serialize(serializationOptions); return response; } diff --git a/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/TaskExample_TaskReturn_Generated.g.cs b/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/TaskExample_TaskReturn_Generated.g.cs index 1bc6301ec..3b2ba2198 100644 --- a/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/TaskExample_TaskReturn_Generated.g.cs +++ b/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/TaskExample_TaskReturn_Generated.g.cs @@ -1,3 +1,5 @@ +// + using System; using System.Linq; using System.Collections.Generic; @@ -13,6 +15,11 @@ public class TaskExample_TaskReturn_Generated private readonly TaskExample taskExample; private readonly Amazon.Lambda.Serialization.SystemTextJson.DefaultLambdaJsonSerializer serializer; + /// + /// Default constructor. This constructor is used by Lambda to construct the instance. When invoked in a Lambda environment + /// the AWS credentials will come from the IAM role associated with the function and the AWS region will be set to the + /// region the Lambda function is executed in. + /// public TaskExample_TaskReturn_Generated() { SetExecutionEnvironment(); @@ -20,6 +27,12 @@ public TaskExample_TaskReturn_Generated() serializer = new Amazon.Lambda.Serialization.SystemTextJson.DefaultLambdaJsonSerializer(); } + /// + /// The generated Lambda function handler for + /// + /// The request object that will be processed by the Lambda function handler. + /// The ILambdaContext that provides methods for logging and describing the Lambda environment. + /// Result of the Lambda function execution public async System.Threading.Tasks.Task TaskReturn(string text, Amazon.Lambda.Core.ILambdaContext __context__) { await taskExample.TaskReturn(text, __context__); diff --git a/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/VoidExample_VoidReturn_Generated.g.cs b/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/VoidExample_VoidReturn_Generated.g.cs index addc8db10..ec097ee71 100644 --- a/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/VoidExample_VoidReturn_Generated.g.cs +++ b/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/VoidExample_VoidReturn_Generated.g.cs @@ -1,3 +1,5 @@ +// + using System; using System.Linq; using System.Collections.Generic; @@ -13,6 +15,11 @@ public class VoidExample_VoidReturn_Generated private readonly VoidExample voidExample; private readonly Amazon.Lambda.Serialization.SystemTextJson.DefaultLambdaJsonSerializer serializer; + /// + /// Default constructor. This constructor is used by Lambda to construct the instance. When invoked in a Lambda environment + /// the AWS credentials will come from the IAM role associated with the function and the AWS region will be set to the + /// region the Lambda function is executed in. + /// public VoidExample_VoidReturn_Generated() { SetExecutionEnvironment(); @@ -20,6 +27,12 @@ public VoidExample_VoidReturn_Generated() serializer = new Amazon.Lambda.Serialization.SystemTextJson.DefaultLambdaJsonSerializer(); } + /// + /// The generated Lambda function handler for + /// + /// The request object that will be processed by the Lambda function handler. + /// The ILambdaContext that provides methods for logging and describing the Lambda environment. + /// Result of the Lambda function execution public void VoidReturn(string text, Amazon.Lambda.Core.ILambdaContext __context__) { voidExample.VoidReturn(text, __context__); diff --git a/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/SourceGeneratorTests.cs b/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/SourceGeneratorTests.cs index a8c04be0d..6b02c6015 100644 --- a/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/SourceGeneratorTests.cs +++ b/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/SourceGeneratorTests.cs @@ -284,7 +284,6 @@ public async Task VerifyFunctionInSubNamespace() { var expectedTemplateContent = (await File.ReadAllTextAsync(Path.Combine("Snapshots", "ServerlessTemplates", "subnamespace.template"))).ToEnvironmentLineEndings(); var expectedSubNamespaceGenerated = (await File.ReadAllTextAsync(Path.Combine("Snapshots", "Functions_ToUpper_Generated.g.cs"))).ToEnvironmentLineEndings(); - var expectedProgramGenerated = (await File.ReadAllTextAsync(Path.Combine("Snapshots", "Program.g.cs"))).ToEnvironmentLineEndings(); await new VerifyCS.Test { @@ -552,7 +551,6 @@ public async Task VerifyExecutableAssembly_WithNullAttributeValues_ShouldComplet { var expectedTemplateContent = (await File.ReadAllTextAsync(Path.Combine("Snapshots", "ServerlessTemplates", "subnamespace.template"))).ToEnvironmentLineEndings(); var expectedSubNamespaceGenerated = (await File.ReadAllTextAsync(Path.Combine("Snapshots", "Functions_ToUpper_Generated.g.cs"))).ToEnvironmentLineEndings(); - var expectedProgramGenerated = (await File.ReadAllTextAsync(Path.Combine("Snapshots", "Program.g.cs"))).ToEnvironmentLineEndings(); await new VerifyCS.Test { @@ -691,10 +689,9 @@ public async Task VerifySourceGeneratorSerializerWithHttpResultsBody() // The test framework doesn't appear to also execute the System.Text.Json source generator so Annotations generated code relying on the generated System.Text.Json code does not exist // so we get compile errors. In an real world scenario they are both run and the applicaton compiles correctly. - DiagnosticResult.CompilerError("CS0117").WithSpan($"Amazon.Lambda.Annotations.SourceGenerator{Path.DirectorySeparatorChar}Amazon.Lambda.Annotations.SourceGenerator.Generator{Path.DirectorySeparatorChar}SourceGenerationSerializationExample_GetPerson_Generated.g.cs", 29, 137, 29, 144).WithArguments("TestExecutableServerlessApp.HttpApiJsonSerializerContext", "Default"), - DiagnosticResult.CompilerError("CS0534").WithSpan($"TestExecutableServerlessApp{Path.DirectorySeparatorChar}SourceGenerationSerializationExample.cs", 28, 26, 28, 54).WithArguments("TestExecutableServerlessApp.HttpApiJsonSerializerContext", "System.Text.Json.Serialization.JsonSerializerContext.GeneratedSerializerOptions.get"), - DiagnosticResult.CompilerError("CS0534").WithSpan($"TestExecutableServerlessApp{Path.DirectorySeparatorChar}SourceGenerationSerializationExample.cs", 28, 26, 28, 54).WithArguments("TestExecutableServerlessApp.HttpApiJsonSerializerContext", "System.Text.Json.Serialization.JsonSerializerContext.GetTypeInfo(System.Type)"), - DiagnosticResult.CompilerError("CS7036").WithSpan($"TestExecutableServerlessApp{Path.DirectorySeparatorChar}SourceGenerationSerializationExample.cs", 28, 26, 28, 54).WithArguments("options", "System.Text.Json.Serialization.JsonSerializerContext.JsonSerializerContext(System.Text.Json.JsonSerializerOptions?)"), + DiagnosticResult.CompilerError("CS0534").WithSpan($"TestExecutableServerlessApp{Path.DirectorySeparatorChar}SourceGenerationSerializationExample.cs", 26, 26, 26, 54).WithArguments("TestExecutableServerlessApp.HttpApiJsonSerializerContext", "System.Text.Json.Serialization.JsonSerializerContext.GeneratedSerializerOptions.get"), + DiagnosticResult.CompilerError("CS0534").WithSpan($"TestExecutableServerlessApp{Path.DirectorySeparatorChar}SourceGenerationSerializationExample.cs", 26, 26, 26, 54).WithArguments("TestExecutableServerlessApp.HttpApiJsonSerializerContext", "System.Text.Json.Serialization.JsonSerializerContext.GetTypeInfo(System.Type)"), + DiagnosticResult.CompilerError("CS7036").WithSpan($"TestExecutableServerlessApp{Path.DirectorySeparatorChar}SourceGenerationSerializationExample.cs", 26, 26, 26, 54).WithArguments("options", "System.Text.Json.Serialization.JsonSerializerContext.JsonSerializerContext(System.Text.Json.JsonSerializerOptions?)"), } } }; @@ -882,6 +879,7 @@ public async Task CustomizeResponses() var expectedOkResponseWithHeaderAsyncGenerated = (await File.ReadAllTextAsync(Path.Combine("Snapshots", "CustomizeResponseExamples_OkResponseWithHeaderAsync_Generated.g.cs"))).ToEnvironmentLineEndings(); var expectedNotFoundResponseWithHeaderV2AsyncGenerated = (await File.ReadAllTextAsync(Path.Combine("Snapshots", "CustomizeResponseExamples_NotFoundResponseWithHeaderV2Async_Generated.g.cs"))).ToEnvironmentLineEndings(); var expectedNotFoundResponseWithHeaderV1AsyncGenerated = (await File.ReadAllTextAsync(Path.Combine("Snapshots", "CustomizeResponseExamples_NotFoundResponseWithHeaderV1Async_Generated.g.cs"))).ToEnvironmentLineEndings(); + var expectedOkResponseWithCustomSerializerGenerated = (await File.ReadAllTextAsync(Path.Combine("Snapshots", "CustomizeResponseExamples_OkResponseWithCustomSerializer_Generated.g.cs"))).ToEnvironmentLineEndings(); await new VerifyCS.Test { @@ -927,6 +925,11 @@ public async Task CustomizeResponses() typeof(SourceGenerator.Generator), "CustomizeResponseExamples_NotFoundResponseWithHeaderV1Async_Generated.g.cs", SourceText.From(expectedNotFoundResponseWithHeaderV1AsyncGenerated, Encoding.UTF8, SourceHashAlgorithm.Sha256) + ), + ( + typeof(SourceGenerator.Generator), + "CustomizeResponseExamples_OkResponseWithCustomSerializer_Generated.g.cs", + SourceText.From(expectedOkResponseWithCustomSerializerGenerated, Encoding.UTF8, SourceHashAlgorithm.Sha256) ) }, ExpectedDiagnostics = @@ -936,10 +939,15 @@ public async Task CustomizeResponses() new DiagnosticResult("AWSLambda0103", DiagnosticSeverity.Info).WithArguments("CustomizeResponseExamples_NotFoundResponseWithHeaderV2_Generated.g.cs", expectedNotFoundResponseWithHeaderV2Generated), new DiagnosticResult("AWSLambda0103", DiagnosticSeverity.Info).WithArguments("CustomizeResponseExamples_NotFoundResponseWithHeaderV2Async_Generated.g.cs", expectedNotFoundResponseWithHeaderV2AsyncGenerated), - + new DiagnosticResult("AWSLambda0103", DiagnosticSeverity.Info).WithArguments("CustomizeResponseExamples_NotFoundResponseWithHeaderV1_Generated.g.cs", expectedNotFoundResponseWithHeaderV1Generated), new DiagnosticResult("AWSLambda0103", DiagnosticSeverity.Info).WithArguments("CustomizeResponseExamples_NotFoundResponseWithHeaderV1Async_Generated.g.cs", expectedNotFoundResponseWithHeaderV1AsyncGenerated), + new DiagnosticResult("AWSLambda0103", DiagnosticSeverity.Info).WithArguments("CustomizeResponseExamples_OkResponseWithCustomSerializer_Generated.g.cs", expectedOkResponseWithCustomSerializerGenerated), + // The test framework doesn't appear to also execute the System.Text.Json source generator so Annotations generated code relying on the generated System.Text.Json code does not exist + // so we get compile errors. In an real world scenario they are both run and the applicaton compiles correctly. + DiagnosticResult.CompilerError("CS0117").WithSpan($"TestServerlessApp{Path.DirectorySeparatorChar}CustomizeResponseExamples.cs", 99, 65, 99, 79).WithArguments("System.Text.Json.JsonNamingPolicy", "SnakeCaseUpper"), + new DiagnosticResult("AWSLambda0103", DiagnosticSeverity.Info).WithArguments($"TestServerlessApp{Path.DirectorySeparatorChar}serverless.template", expectedTemplateContent) } } diff --git a/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/WriterTests/CloudFormationWriterTests.cs b/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/WriterTests/CloudFormationWriterTests.cs index d10267a52..4495a572d 100644 --- a/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/WriterTests/CloudFormationWriterTests.cs +++ b/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/WriterTests/CloudFormationWriterTests.cs @@ -56,7 +56,7 @@ public void ApplyLambdaFunctionDefaultProperties(CloudFormationTemplateFormat te Assert.False(templateWriter.Exists("ImageConfig")); } - [Theory] + [Theory] [InlineData(CloudFormationTemplateFormat.Json)] [InlineData(CloudFormationTemplateFormat.Yaml)] public void AddSingletonFunctionToEmptyTemplate(CloudFormationTemplateFormat templateFormat) diff --git a/Libraries/test/TestExecutableServerlessApp/SourceGenerationSerializationExample.cs b/Libraries/test/TestExecutableServerlessApp/SourceGenerationSerializationExample.cs index 32362c0b8..80fda943f 100644 --- a/Libraries/test/TestExecutableServerlessApp/SourceGenerationSerializationExample.cs +++ b/Libraries/test/TestExecutableServerlessApp/SourceGenerationSerializationExample.cs @@ -22,8 +22,6 @@ public IHttpResult GetPerson(ILambdaContext context) } } - [JsonSerializable(typeof(APIGatewayHttpApiV2ProxyRequest))] - [JsonSerializable(typeof(APIGatewayHttpApiV2ProxyResponse))] [JsonSerializable(typeof(Person))] public partial class HttpApiJsonSerializerContext : JsonSerializerContext { diff --git a/Libraries/test/TestServerlessApp.IntegrationTests/CustomResponse.cs b/Libraries/test/TestServerlessApp.IntegrationTests/CustomResponse.cs index 07735277a..3d987c391 100644 --- a/Libraries/test/TestServerlessApp.IntegrationTests/CustomResponse.cs +++ b/Libraries/test/TestServerlessApp.IntegrationTests/CustomResponse.cs @@ -37,5 +37,17 @@ public async Task OkResponseWithHeader_ReturnsValidationErrors() var expectedErrorMessage = "1 validation error(s) detected: Value hello at 'x' failed to satisfy constraint: Input string was not in a correct format."; Assert.Equal(expectedErrorMessage, errorJson["message"]); } + + [Fact] + public async Task OkResponseWithCustomSerializer_Returns200Status() + { + var response = await _fixture.HttpClient.GetAsync($"{_fixture.HttpApiUrlPrefix}/okresponsewithcustomserializerasync/John/Doe"); + response.EnsureSuccessStatusCode(); + + var content = await response.Content.ReadAsStringAsync(); + var person = JObject.Parse(content); + Assert.Equal("John", person["FIRST_NAME"]); + Assert.Equal("Doe", person["LAST_NAME"]); + } } } diff --git a/Libraries/test/TestServerlessApp.IntegrationTests/IntegrationTestContextFixture.cs b/Libraries/test/TestServerlessApp.IntegrationTests/IntegrationTestContextFixture.cs index 211abab5b..8e2d0fafd 100644 --- a/Libraries/test/TestServerlessApp.IntegrationTests/IntegrationTestContextFixture.cs +++ b/Libraries/test/TestServerlessApp.IntegrationTests/IntegrationTestContextFixture.cs @@ -55,7 +55,7 @@ public async Task InitializeAsync() Assert.Equal(StackStatus.CREATE_COMPLETE, await _cloudFormationHelper.GetStackStatusAsync(_stackName)); Assert.True(await _s3Helper.BucketExistsAsync(_bucketName)); - Assert.Equal(26, LambdaFunctions.Count); + Assert.Equal(27, LambdaFunctions.Count); Assert.False(string.IsNullOrEmpty(RestApiUrlPrefix)); Assert.False(string.IsNullOrEmpty(RestApiUrlPrefix)); diff --git a/Libraries/test/TestServerlessApp/CustomizeResponseExamples.cs b/Libraries/test/TestServerlessApp/CustomizeResponseExamples.cs index 708921d45..12d0dc702 100644 --- a/Libraries/test/TestServerlessApp/CustomizeResponseExamples.cs +++ b/Libraries/test/TestServerlessApp/CustomizeResponseExamples.cs @@ -1,6 +1,10 @@ using Amazon.Lambda.Annotations; using Amazon.Lambda.Annotations.APIGateway; using Amazon.Lambda.Core; +using Amazon.Lambda.Serialization.SystemTextJson; +using System; +using System.Text.Json; +using System.Text.Json.Serialization; using System.Threading.Tasks; namespace TestServerlessApp @@ -66,5 +70,34 @@ public Task NotFoundResponseWithHeaderV1Async(int x, ILambdaContext .AddHeader("Multi-Header", "Foo") .AddHeader("Multi-Header", "Bar")); } + + [LambdaFunction(PackageType = LambdaPackageType.Image)] + [HttpApi(LambdaHttpMethod.Get, "/okresponsewithcustomserializerasync/{firstName}/{lastName}", Version = HttpApiVersion.V1)] + [LambdaSerializer(typeof(PersonSerializer))] + public Task OkResponseWithCustomSerializer(string firstName, string lastName, ILambdaContext context) + { + return Task.FromResult(HttpResults.Ok(new Person { FirstName = firstName, LastName = lastName })); + } + } + + public class Person + { + public string FirstName { get; set; } + public string LastName { get; set; } + } + + public class PersonSerializer : DefaultLambdaJsonSerializer + { + public PersonSerializer() + : base(CreateCustomizer()) + { } + + private static Action CreateCustomizer() + { + return (JsonSerializerOptions options) => + { + options.PropertyNamingPolicy = JsonNamingPolicy.SnakeCaseUpper; + }; + } } } diff --git a/Libraries/test/TestServerlessApp/TestServerlessApp.csproj b/Libraries/test/TestServerlessApp/TestServerlessApp.csproj index 043085adc..37fbb5832 100644 --- a/Libraries/test/TestServerlessApp/TestServerlessApp.csproj +++ b/Libraries/test/TestServerlessApp/TestServerlessApp.csproj @@ -19,6 +19,7 @@ + diff --git a/Libraries/test/TestServerlessApp/serverless.template b/Libraries/test/TestServerlessApp/serverless.template index cd81651fe..fbad7233d 100644 --- a/Libraries/test/TestServerlessApp/serverless.template +++ b/Libraries/test/TestServerlessApp/serverless.template @@ -737,6 +737,39 @@ ] } } + }, + "TestServerlessAppCustomizeResponseExamplesOkResponseWithCustomSerializerGenerated": { + "Type": "AWS::Serverless::Function", + "Metadata": { + "Tool": "Amazon.Lambda.Annotations", + "SyncedEvents": [ + "RootGet" + ] + }, + "Properties": { + "MemorySize": 512, + "Timeout": 30, + "Policies": [ + "AWSLambdaBasicExecutionRole" + ], + "PackageType": "Image", + "ImageUri": ".", + "ImageConfig": { + "Command": [ + "TestServerlessApp::TestServerlessApp.CustomizeResponseExamples_OkResponseWithCustomSerializer_Generated::OkResponseWithCustomSerializer" + ] + }, + "Events": { + "RootGet": { + "Type": "HttpApi", + "Properties": { + "Path": "/okresponsewithcustomserializerasync/{firstName}/{lastName}", + "Method": "GET", + "PayloadFormatVersion": "1.0" + } + } + } + } } }, "Outputs": {