diff --git a/Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Generator.cs b/Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Generator.cs index 75268b637..e502f1530 100644 --- a/Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Generator.cs +++ b/Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Generator.cs @@ -162,9 +162,9 @@ public void Execute(GeneratorExecutionContext context) } } - var serializerString = GetSerializerAttribute(context, lambdaMethodModel); + var serializerInfo = GetSerializerInfoAttribute(context, lambdaMethodModel); - var model = LambdaFunctionModelBuilder.Build(lambdaMethodModel, configureMethodModel, context, isExecutable, serializerString, defaultRuntime); + var model = LambdaFunctionModelBuilder.Build(lambdaMethodModel, configureMethodModel, context, isExecutable, serializerInfo, defaultRuntime); // If there are more than one event, report them as errors if (model.LambdaMethod.Events.Count > 1) @@ -334,9 +334,10 @@ private bool HasSerializerAttribute(GeneratorExecutionContext context, IMethodSy return methodModel.ContainingAssembly.HasAttribute(context, TypeFullNames.LambdaSerializerAttribute); } - private string GetSerializerAttribute(GeneratorExecutionContext context, IMethodSymbol methodModel) + private LambdaSerializerInfo GetSerializerInfoAttribute(GeneratorExecutionContext context, IMethodSymbol methodModel) { var serializerString = DEFAULT_LAMBDA_SERIALIZER; + string serializerJsonContext = null; ISymbol symbol = null; @@ -357,19 +358,24 @@ private string GetSerializerAttribute(GeneratorExecutionContext context, IMethod // Else return the default serializer. else { - return serializerString; + return new LambdaSerializerInfo(serializerString, serializerJsonContext); } 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 serializerString; + return new LambdaSerializerInfo(serializerString, serializerJsonContext); } public void Initialize(GeneratorInitializationContext context) diff --git a/Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Models/LambdaFunctionModel.cs b/Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Models/LambdaFunctionModel.cs index ddaf50b6e..cba07d22a 100644 --- a/Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Models/LambdaFunctionModel.cs +++ b/Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Models/LambdaFunctionModel.cs @@ -34,8 +34,8 @@ public class LambdaFunctionModel : ILambdaFunctionSerializable /// /// Gets or sets fully qualified name of the serializer used for serialization or deserialization. /// - public string Serializer { get; set; } = - "Amazon.Lambda.Serialization.SystemTextJson.DefaultLambdaJsonSerializer"; + public LambdaSerializerInfo SerializerInfo { get; set; } = + new LambdaSerializerInfo("Amazon.Lambda.Serialization.SystemTextJson.DefaultLambdaJsonSerializer", null); /// /// Gets or sets if the output is an executable. diff --git a/Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Models/LambdaFunctionModelBuilder.cs b/Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Models/LambdaFunctionModelBuilder.cs index 88300dcc6..545a5e8fa 100644 --- a/Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Models/LambdaFunctionModelBuilder.cs +++ b/Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Models/LambdaFunctionModelBuilder.cs @@ -9,7 +9,7 @@ namespace Amazon.Lambda.Annotations.SourceGenerator.Models /// public static class LambdaFunctionModelBuilder { - public static LambdaFunctionModel Build(IMethodSymbol lambdaMethodSymbol, IMethodSymbol configureMethodSymbol, GeneratorExecutionContext context, bool isExecutable, string serializer, string runtime) + public static LambdaFunctionModel Build(IMethodSymbol lambdaMethodSymbol, IMethodSymbol configureMethodSymbol, GeneratorExecutionContext context, bool isExecutable, LambdaSerializerInfo serializerInfo, string runtime) { var lambdaMethod = LambdaMethodModelBuilder.Build(lambdaMethodSymbol, configureMethodSymbol, context); var generatedMethod = GeneratedMethodModelBuilder.Build(lambdaMethodSymbol, configureMethodSymbol, lambdaMethod, context); @@ -17,7 +17,7 @@ public static LambdaFunctionModel Build(IMethodSymbol lambdaMethodSymbol, IMetho { GeneratedMethod = generatedMethod, LambdaMethod = lambdaMethod, - Serializer = serializer, + SerializerInfo = serializerInfo, StartupType = configureMethodSymbol != null ? TypeModelBuilder.Build(configureMethodSymbol.ContainingType, context) : null, SourceGeneratorVersion = context.Compilation .ReferencedAssemblyNames.FirstOrDefault(x => string.Equals(x.Name, "Amazon.Lambda.Annotations")) diff --git a/Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Models/LambdaSerializerInfo.cs b/Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Models/LambdaSerializerInfo.cs new file mode 100644 index 000000000..d9811159a --- /dev/null +++ b/Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Models/LambdaSerializerInfo.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Amazon.Lambda.Annotations.SourceGenerator.Models +{ + public class LambdaSerializerInfo + { + public LambdaSerializerInfo(string serializerName, string serializerJsonContextName) + { + SerializerName = serializerName; + SerializerJsonContextName = serializerJsonContextName; + } + + public string SerializerName { get; } + + public string SerializerJsonContextName { get; } + } +} diff --git a/Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Templates/APIGatewayInvoke.cs b/Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Templates/APIGatewayInvoke.cs index f2435c571..36dff2f66 100644 --- a/Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Templates/APIGatewayInvoke.cs +++ b/Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Templates/APIGatewayInvoke.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------ // // This code was generated by a tool. -// Runtime Version: 16.0.0.0 +// Runtime Version: 17.0.0.0 // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. @@ -22,8 +22,8 @@ namespace Amazon.Lambda.Annotations.SourceGenerator.Templates /// Class to produce the template output /// - #line 1 "C:\Users\jamesuk\source\github\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\APIGatewayInvoke.tt" - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.TextTemplating", "16.0.0.0")] + #line 1 "C:\codebase\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 { #line hidden @@ -33,7 +33,7 @@ public partial class APIGatewayInvoke : APIGatewayInvokeBase public virtual string TransformText() { - #line 10 "C:\Users\jamesuk\source\github\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\APIGatewayInvoke.tt" + #line 10 "C:\codebase\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,48 +46,61 @@ public virtual string TransformText() #line hidden this.Write(" var httpResults = "); - #line 17 "C:\Users\jamesuk\source\github\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\APIGatewayInvoke.tt" + #line 17 "C:\codebase\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:\Users\jamesuk\source\github\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\APIGatewayInvoke.tt" + #line 17 "C:\codebase\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:\Users\jamesuk\source\github\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\APIGatewayInvoke.tt" + #line 17 "C:\codebase\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:\Users\jamesuk\source\github\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\APIGatewayInvoke.tt" + #line 17 "C:\codebase\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 HttpResultSerializationOptions.ProtocolFormat serializationFormat = "); + this.Write(");\r\n HttpResultSerializationOptions.ProtocolFormat serializationFormat" + + " = "); - #line 18 "C:\Users\jamesuk\source\github\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\APIGatewayInvoke.tt" + #line 18 "C:\codebase\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 #line hidden - this.Write(";\r\n HttpResultSerializationOptions.ProtocolVersion serializationVersion = "); + this.Write(";\r\n HttpResultSerializationOptions.ProtocolVersion serializationVersio" + + "n = "); - #line 19 "C:\Users\jamesuk\source\github\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\APIGatewayInvoke.tt" + #line 19 "C:\codebase\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 var serializationOptions = new HttpResultSerializationOptions { Format = serializationFormat, Version = serializationVersion };\r\n var response = httpResults.Serialize(serializationOptions);\r\n"); + this.Write(";\r\n System.Text.Json.Serialization.JsonSerializerContext jsonContext =" + + " "); - #line 22 "C:\Users\jamesuk\source\github\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\APIGatewayInvoke.tt" + #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"); + + #line 23 "C:\codebase\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\APIGatewayInvoke.tt" } else if (_model.LambdaMethod.ReturnsVoid) @@ -98,28 +111,28 @@ public virtual string TransformText() #line hidden this.Write(" "); - #line 27 "C:\Users\jamesuk\source\github\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\APIGatewayInvoke.tt" + #line 28 "C:\codebase\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 27 "C:\Users\jamesuk\source\github\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\APIGatewayInvoke.tt" + #line 28 "C:\codebase\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 27 "C:\Users\jamesuk\source\github\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\APIGatewayInvoke.tt" + #line 28 "C:\codebase\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 28 "C:\Users\jamesuk\source\github\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\APIGatewayInvoke.tt" + #line 29 "C:\codebase\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\APIGatewayInvoke.tt" } else if (_model.LambdaMethod.ReturnsVoidTask) @@ -130,28 +143,28 @@ public virtual string TransformText() #line hidden this.Write(" await "); - #line 33 "C:\Users\jamesuk\source\github\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\APIGatewayInvoke.tt" + #line 34 "C:\codebase\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 33 "C:\Users\jamesuk\source\github\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\APIGatewayInvoke.tt" + #line 34 "C:\codebase\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 33 "C:\Users\jamesuk\source\github\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\APIGatewayInvoke.tt" + #line 34 "C:\codebase\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 34 "C:\Users\jamesuk\source\github\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\APIGatewayInvoke.tt" + #line 35 "C:\codebase\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\APIGatewayInvoke.tt" } else @@ -162,34 +175,34 @@ public virtual string TransformText() #line hidden this.Write(" var response = "); - #line 39 "C:\Users\jamesuk\source\github\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\APIGatewayInvoke.tt" + #line 40 "C:\codebase\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 39 "C:\Users\jamesuk\source\github\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\APIGatewayInvoke.tt" + #line 40 "C:\codebase\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 39 "C:\Users\jamesuk\source\github\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\APIGatewayInvoke.tt" + #line 40 "C:\codebase\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 39 "C:\Users\jamesuk\source\github\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\APIGatewayInvoke.tt" + #line 40 "C:\codebase\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 40 "C:\Users\jamesuk\source\github\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\APIGatewayInvoke.tt" + #line 41 "C:\codebase\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\APIGatewayInvoke.tt" } @@ -201,7 +214,7 @@ public virtual string TransformText() #line hidden this.Write(" return response;\r\n"); - #line 47 "C:\Users\jamesuk\source\github\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\APIGatewayInvoke.tt" + #line 48 "C:\codebase\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\APIGatewayInvoke.tt" } else @@ -216,7 +229,7 @@ public virtual string TransformText() #line hidden this.Write("\r\n var body = response.ToString();\r\n"); - #line 58 "C:\Users\jamesuk\source\github\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\APIGatewayInvoke.tt" + #line 59 "C:\codebase\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\APIGatewayInvoke.tt" } else if (_model.LambdaMethod.ReturnType.IsString()) @@ -229,9 +242,16 @@ public virtual string TransformText() #line default #line hidden - this.Write(" var memoryStream = new MemoryStream();\r\n serializer.Serialize(response, memoryStream);\r\n memoryStream.Position = 0;\r\n\r\n // convert stream to string\r\n StreamReader reader = new StreamReader( memoryStream );\r\n var body = reader.ReadToEnd();\r\n"); + this.Write(@" var memoryStream = new MemoryStream(); + serializer.Serialize(response, memoryStream); + memoryStream.Position = 0; + + // convert stream to string + StreamReader reader = new StreamReader( memoryStream ); + var body = reader.ReadToEnd(); +"); - #line 74 "C:\Users\jamesuk\source\github\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\APIGatewayInvoke.tt" + #line 75 "C:\codebase\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\APIGatewayInvoke.tt" } } @@ -241,14 +261,14 @@ public virtual string TransformText() #line hidden this.Write("\r\n return new "); - #line 79 "C:\Users\jamesuk\source\github\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\APIGatewayInvoke.tt" + #line 80 "C:\codebase\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 81 "C:\Users\jamesuk\source\github\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\APIGatewayInvoke.tt" + #line 82 "C:\codebase\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\APIGatewayInvoke.tt" if (!_model.LambdaMethod.ReturnsVoid && !_model.LambdaMethod.ReturnsVoidTask) { @@ -258,21 +278,22 @@ public virtual string TransformText() #line hidden this.Write(" Body = "); - #line 85 "C:\Users\jamesuk\source\github\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\APIGatewayInvoke.tt" + #line 86 "C:\codebase\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 #line hidden - this.Write(",\r\n Headers = new Dictionary\r\n {\r\n {\"Content-Type\", "); + this.Write(",\r\n Headers = new Dictionary\r\n {\r\n " + + " {\"Content-Type\", "); - #line 88 "C:\Users\jamesuk\source\github\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\APIGatewayInvoke.tt" + #line 89 "C:\codebase\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 90 "C:\Users\jamesuk\source\github\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\APIGatewayInvoke.tt" + #line 91 "C:\codebase\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\APIGatewayInvoke.tt" } @@ -281,7 +302,7 @@ public virtual string TransformText() #line hidden this.Write(" StatusCode = 200\r\n };\r\n"); - #line 95 "C:\Users\jamesuk\source\github\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\APIGatewayInvoke.tt" + #line 96 "C:\codebase\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\APIGatewayInvoke.tt" } @@ -298,7 +319,7 @@ public virtual string TransformText() /// /// Base class for this transformation /// - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.TextTemplating", "16.0.0.0")] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.TextTemplating", "17.0.0.0")] public class APIGatewayInvokeBase { #region Fields @@ -313,7 +334,7 @@ public class APIGatewayInvokeBase /// /// The string builder that generation-time code is using to assemble generated output /// - protected System.Text.StringBuilder GenerationEnvironment + public System.Text.StringBuilder GenerationEnvironment { get { diff --git a/Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Templates/APIGatewayInvoke.tt b/Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Templates/APIGatewayInvoke.tt index 577284842..c7cc555a2 100644 --- a/Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Templates/APIGatewayInvoke.tt +++ b/Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Templates/APIGatewayInvoke.tt @@ -17,7 +17,8 @@ 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"#>; - var serializationOptions = new HttpResultSerializationOptions { Format = serializationFormat, Version = serializationVersion }; + 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 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 304db3e8b..34a04334b 100644 --- a/Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Templates/ExecutableAssembly.cs +++ b/Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Templates/ExecutableAssembly.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------ // // This code was generated by a tool. -// Runtime Version: 16.0.0.0 +// Runtime Version: 17.0.0.0 // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. @@ -23,8 +23,8 @@ namespace Amazon.Lambda.Annotations.SourceGenerator.Templates /// Class to produce the template output /// - #line 1 "/Users/jameseastham/source/github/aws-lambda-dotnet/Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Templates/ExecutableAssembly.tt" - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.TextTemplating", "16.0.0.0")] + #line 1 "C:\codebase\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 { #line hidden @@ -33,16 +33,20 @@ public partial class ExecutableAssembly : ExecutableAssemblyBase /// public virtual string TransformText() { - this.Write("using System;\nusing System.Linq;\nusing System.Collections.Generic;\nusing System.Text;\nusing System.Threading.Tasks;\nusing System.IO;\nusing Amazon.Lambda.Core;\n\nnamespace "); + 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 "); - #line 19 "/Users/jameseastham/source/github/aws-lambda-dotnet/Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Templates/ExecutableAssembly.tt" + #line 19 "C:\codebase\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(";\n\npublic class GeneratedProgram\n{\n public static async Task Main(string[] args)\n {\n\n switch (Environment.GetEnvironmentVariable(\"ANNOTATIONS_HANDLER\"))\n {\n"); + 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"); - #line 28 "/Users/jameseastham/source/github/aws-lambda-dotnet/Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Templates/ExecutableAssembly.tt" + #line 28 "C:\codebase\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\ExecutableAssembly.tt" foreach (var model in this._lambdaFunctions) { @@ -52,14 +56,14 @@ public virtual string TransformText() #line hidden this.Write(" case \""); - #line 32 "/Users/jameseastham/source/github/aws-lambda-dotnet/Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Templates/ExecutableAssembly.tt" + #line 32 "C:\codebase\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("\":\n"); + this.Write("\":\r\n"); - #line 33 "/Users/jameseastham/source/github/aws-lambda-dotnet/Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Templates/ExecutableAssembly.tt" + #line 33 "C:\codebase\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\ExecutableAssembly.tt" if (model.GeneratedMethod.ReturnType.FullName == "void") { @@ -69,63 +73,64 @@ public virtual string TransformText() #line hidden this.Write(" Action<"); - #line 37 "/Users/jameseastham/source/github/aws-lambda-dotnet/Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Templates/ExecutableAssembly.tt" + #line 37 "C:\codebase\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 "/Users/jameseastham/source/github/aws-lambda-dotnet/Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Templates/ExecutableAssembly.tt" + #line 37 "C:\codebase\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 "/Users/jameseastham/source/github/aws-lambda-dotnet/Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Templates/ExecutableAssembly.tt" + #line 37 "C:\codebase\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 "/Users/jameseastham/source/github/aws-lambda-dotnet/Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Templates/ExecutableAssembly.tt" + #line 37 "C:\codebase\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 "/Users/jameseastham/source/github/aws-lambda-dotnet/Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Templates/ExecutableAssembly.tt" + #line 37 "C:\codebase\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 "/Users/jameseastham/source/github/aws-lambda-dotnet/Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Templates/ExecutableAssembly.tt" + #line 37 "C:\codebase\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(";\n await Amazon.Lambda.RuntimeSupport.LambdaBootstrapBuilder.Create("); + this.Write(";\r\n await Amazon.Lambda.RuntimeSupport.LambdaBootstrapBuilder.Crea" + + "te("); - #line 38 "/Users/jameseastham/source/github/aws-lambda-dotnet/Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Templates/ExecutableAssembly.tt" + #line 38 "C:\codebase\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 "/Users/jameseastham/source/github/aws-lambda-dotnet/Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Templates/ExecutableAssembly.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(this._lambdaFunctions[0].Serializer)); + #line 38 "C:\codebase\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();\n break;\n"); + this.Write("()).Build().RunAsync();\r\n break;\r\n"); - #line 40 "/Users/jameseastham/source/github/aws-lambda-dotnet/Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Templates/ExecutableAssembly.tt" + #line 40 "C:\codebase\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\ExecutableAssembly.tt" } else @@ -136,70 +141,71 @@ public virtual string TransformText() #line hidden this.Write(" Func<"); - #line 45 "/Users/jameseastham/source/github/aws-lambda-dotnet/Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Templates/ExecutableAssembly.tt" + #line 45 "C:\codebase\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 "/Users/jameseastham/source/github/aws-lambda-dotnet/Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Templates/ExecutableAssembly.tt" + #line 45 "C:\codebase\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 "/Users/jameseastham/source/github/aws-lambda-dotnet/Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Templates/ExecutableAssembly.tt" + #line 45 "C:\codebase\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 "/Users/jameseastham/source/github/aws-lambda-dotnet/Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Templates/ExecutableAssembly.tt" + #line 45 "C:\codebase\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 "/Users/jameseastham/source/github/aws-lambda-dotnet/Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Templates/ExecutableAssembly.tt" + #line 45 "C:\codebase\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 "/Users/jameseastham/source/github/aws-lambda-dotnet/Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Templates/ExecutableAssembly.tt" + #line 45 "C:\codebase\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 "/Users/jameseastham/source/github/aws-lambda-dotnet/Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Templates/ExecutableAssembly.tt" + #line 45 "C:\codebase\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(";\n await Amazon.Lambda.RuntimeSupport.LambdaBootstrapBuilder.Create("); + this.Write(";\r\n await Amazon.Lambda.RuntimeSupport.LambdaBootstrapBuilder.Crea" + + "te("); - #line 46 "/Users/jameseastham/source/github/aws-lambda-dotnet/Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Templates/ExecutableAssembly.tt" + #line 46 "C:\codebase\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 "/Users/jameseastham/source/github/aws-lambda-dotnet/Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Templates/ExecutableAssembly.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(model.Serializer)); + #line 46 "C:\codebase\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();\n break;\n"); + this.Write("()).Build().RunAsync();\r\n break;\r\n"); - #line 48 "/Users/jameseastham/source/github/aws-lambda-dotnet/Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Templates/ExecutableAssembly.tt" + #line 48 "C:\codebase\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\ExecutableAssembly.tt" } } @@ -207,15 +213,15 @@ public virtual string TransformText() #line default #line hidden - this.Write("\n }\n"); + this.Write("\r\n }\r\n"); - #line 54 "/Users/jameseastham/source/github/aws-lambda-dotnet/Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Templates/ExecutableAssembly.tt" + #line 54 "C:\codebase\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\ExecutableAssembly.tt" #line default #line hidden - this.Write(" }\n}"); + this.Write(" }\r\n}"); return this.GenerationEnvironment.ToString(); } } @@ -226,7 +232,7 @@ public virtual string TransformText() /// /// Base class for this transformation /// - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.TextTemplating", "16.0.0.0")] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.TextTemplating", "17.0.0.0")] public class ExecutableAssemblyBase { #region Fields @@ -241,7 +247,7 @@ public class ExecutableAssemblyBase /// /// The string builder that generation-time code is using to assemble generated output /// - protected System.Text.StringBuilder GenerationEnvironment + public System.Text.StringBuilder GenerationEnvironment { get { diff --git a/Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Templates/ExecutableAssembly.tt b/Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Templates/ExecutableAssembly.tt index 179e396e7..526e9b65e 100644 --- a/Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Templates/ExecutableAssembly.tt +++ b/Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Templates/ExecutableAssembly.tt @@ -35,7 +35,7 @@ public class GeneratedProgram { #> Action<<#= model.GeneratedMethod.Parameters.Any() ? string.Join(", ", model.GeneratedMethod.Parameters.Select(p => $"{p.Type.FullName}")) : "Stream" #>> <#= model.LambdaMethod.ExecutableAssemblyHandlerName #> = new <#= model.LambdaMethod.ContainingNamespace #>.<#= model.LambdaMethod.ContainingType.Name #>_<#= model.LambdaMethod.Name #>_Generated().<#= model.LambdaMethod.Name #>; - await Amazon.Lambda.RuntimeSupport.LambdaBootstrapBuilder.Create(<#= model.LambdaMethod.ExecutableAssemblyHandlerName #>, new <#= this._lambdaFunctions[0].Serializer #>()).Build().RunAsync(); + await Amazon.Lambda.RuntimeSupport.LambdaBootstrapBuilder.Create(<#= model.LambdaMethod.ExecutableAssemblyHandlerName #>, new <#= this._lambdaFunctions[0].SerializerInfo.SerializerName #>()).Build().RunAsync(); break; <# } @@ -43,7 +43,7 @@ public class GeneratedProgram { #> Func<<#= model.GeneratedMethod.Parameters.Any() ? string.Join(", ", model.GeneratedMethod.Parameters.Select(p => $"{p.Type.FullName}")) : "Stream" #>, <#= model.GeneratedMethod.ReturnType.FullName #>> <#= model.LambdaMethod.ExecutableAssemblyHandlerName #> = new <#= model.LambdaMethod.ContainingNamespace #>.<#= model.LambdaMethod.ContainingType.Name #>_<#= model.LambdaMethod.Name #>_Generated().<#= model.LambdaMethod.Name #>; - await Amazon.Lambda.RuntimeSupport.LambdaBootstrapBuilder.Create(<#= model.LambdaMethod.ExecutableAssemblyHandlerName #>, new <#= model.Serializer #>()).Build().RunAsync(); + await Amazon.Lambda.RuntimeSupport.LambdaBootstrapBuilder.Create(<#= model.LambdaMethod.ExecutableAssemblyHandlerName #>, new <#= model.SerializerInfo.SerializerName #>()).Build().RunAsync(); break; <# } diff --git a/Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Templates/FieldsAndConstructor.cs b/Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Templates/FieldsAndConstructor.cs index 76f304bf7..c606fb5d0 100644 --- a/Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Templates/FieldsAndConstructor.cs +++ b/Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Templates/FieldsAndConstructor.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------ // // This code was generated by a tool. -// Runtime Version: 16.0.0.0 +// Runtime Version: 17.0.0.0 // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. @@ -19,8 +19,8 @@ namespace Amazon.Lambda.Annotations.SourceGenerator.Templates /// Class to produce the template output /// - #line 1 "C:\Users\jamesuk\source\github\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\FieldsAndConstructor.tt" - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.TextTemplating", "16.0.0.0")] + #line 1 "C:\codebase\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 { #line hidden @@ -30,7 +30,7 @@ public partial class FieldsAndConstructor : FieldsAndConstructorBase public virtual string TransformText() { - #line 7 "C:\Users\jamesuk\source\github\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\FieldsAndConstructor.tt" + #line 7 "C:\codebase\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:\Users\jamesuk\source\github\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\FieldsAndConstructor.tt" + #line 12 "C:\codebase\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\FieldsAndConstructor.tt" } else @@ -51,28 +51,28 @@ public virtual string TransformText() #line hidden this.Write(" private readonly "); - #line 17 "C:\Users\jamesuk\source\github\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\FieldsAndConstructor.tt" + #line 17 "C:\codebase\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:\Users\jamesuk\source\github\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\FieldsAndConstructor.tt" + #line 17 "C:\codebase\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:\Users\jamesuk\source\github\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\FieldsAndConstructor.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(_model.Serializer)); + #line 18 "C:\codebase\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:\Users\jamesuk\source\github\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\FieldsAndConstructor.tt" + #line 19 "C:\codebase\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\FieldsAndConstructor.tt" } @@ -81,14 +81,14 @@ public virtual string TransformText() #line hidden this.Write("\r\n public "); - #line 23 "C:\Users\jamesuk\source\github\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\FieldsAndConstructor.tt" + #line 23 "C:\codebase\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:\Users\jamesuk\source\github\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\FieldsAndConstructor.tt" + #line 26 "C:\codebase\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\FieldsAndConstructor.tt" if (_model.LambdaMethod.UsingDependencyInjection) { @@ -96,30 +96,35 @@ public virtual string TransformText() #line default #line hidden - this.Write(" var services = new ServiceCollection();\r\n\r\n // By default, Lambda function class is added to the service container using the singleton lifetime\r\n // To use a different lifetime, specify the lifetime in Startup.ConfigureServices(IServiceCollection) method.\r\n services.AddSingleton<"); + this.Write(@" var services = new ServiceCollection(); + + // By default, Lambda function class is added to the service container using the singleton lifetime + // To use a different lifetime, specify the lifetime in Startup.ConfigureServices(IServiceCollection) method. + services.AddSingleton<"); - #line 34 "C:\Users\jamesuk\source\github\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\FieldsAndConstructor.tt" + #line 34 "C:\codebase\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:\Users\jamesuk\source\github\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\FieldsAndConstructor.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(_model.Serializer)); + #line 35 "C:\codebase\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:\Users\jamesuk\source\github\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\FieldsAndConstructor.tt" + #line 37 "C:\codebase\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\FieldsAndConstructor.tt" this.Write(this.ToStringHelper.ToStringWithCulture(_model.StartupType.FullName)); #line default #line hidden - this.Write("();\r\n startup.ConfigureServices(services);\r\n serviceProvider = services.BuildServiceProvider();\r\n"); + this.Write("();\r\n startup.ConfigureServices(services);\r\n serviceProvide" + + "r = services.BuildServiceProvider();\r\n"); - #line 40 "C:\Users\jamesuk\source\github\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\FieldsAndConstructor.tt" + #line 40 "C:\codebase\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\FieldsAndConstructor.tt" } else @@ -130,28 +135,28 @@ public virtual string TransformText() #line hidden this.Write(" "); - #line 45 "C:\Users\jamesuk\source\github\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\FieldsAndConstructor.tt" + #line 45 "C:\codebase\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:\Users\jamesuk\source\github\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\FieldsAndConstructor.tt" + #line 45 "C:\codebase\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:\Users\jamesuk\source\github\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\FieldsAndConstructor.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(_model.Serializer)); + #line 46 "C:\codebase\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:\Users\jamesuk\source\github\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\FieldsAndConstructor.tt" + #line 47 "C:\codebase\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\FieldsAndConstructor.tt" } @@ -169,7 +174,7 @@ public virtual string TransformText() /// /// Base class for this transformation /// - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.TextTemplating", "16.0.0.0")] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.TextTemplating", "17.0.0.0")] public class FieldsAndConstructorBase { #region Fields @@ -184,7 +189,7 @@ public class FieldsAndConstructorBase /// /// The string builder that generation-time code is using to assemble generated output /// - protected System.Text.StringBuilder GenerationEnvironment + public System.Text.StringBuilder GenerationEnvironment { get { diff --git a/Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Templates/FieldsAndConstructor.tt b/Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Templates/FieldsAndConstructor.tt index 5b9f6b7a5..8434ff348 100644 --- a/Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Templates/FieldsAndConstructor.tt +++ b/Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Templates/FieldsAndConstructor.tt @@ -15,7 +15,7 @@ { #> private readonly <#= _model.LambdaMethod.ContainingType.Name #> <#= _model.LambdaMethod.ContainingType.Name.ToCamelCase() #>; - private readonly <#= _model.Serializer #> serializer; + private readonly <#= _model.SerializerInfo.SerializerName #> serializer; <# } #> @@ -32,7 +32,7 @@ // By default, Lambda function class is added to the service container using the singleton lifetime // To use a different lifetime, specify the lifetime in Startup.ConfigureServices(IServiceCollection) method. services.AddSingleton<<#= _model.LambdaMethod.ContainingType.Name #>>(); - services.AddSingleton<<#= _model.Serializer #>>(); + services.AddSingleton<<#= _model.SerializerInfo.SerializerName #>>(); var startup = new <#= _model.StartupType.FullName #>(); startup.ConfigureServices(services); @@ -43,7 +43,7 @@ { #> <#= _model.LambdaMethod.ContainingType.Name.ToCamelCase() #> = new <#= _model.LambdaMethod.ContainingType.Name #>(); - serializer = new <#= _model.Serializer #>(); + serializer = new <#= _model.SerializerInfo.SerializerName #>(); <# } #> diff --git a/Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Templates/LambdaFunctionTemplate.cs b/Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Templates/LambdaFunctionTemplate.cs index 54c369bb3..2652a73be 100644 --- a/Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Templates/LambdaFunctionTemplate.cs +++ b/Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Templates/LambdaFunctionTemplate.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------ // // This code was generated by a tool. -// Runtime Version: 16.0.0.0 +// Runtime Version: 17.0.0.0 // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. @@ -24,8 +24,8 @@ namespace Amazon.Lambda.Annotations.SourceGenerator.Templates /// Class to produce the template output /// - #line 1 "C:\Users\jamesuk\source\github\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\LambdaFunctionTemplate.tt" - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.TextTemplating", "16.0.0.0")] + #line 1 "C:\codebase\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\LambdaFunctionTemplate.tt" + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.TextTemplating", "17.0.0.0")] public partial class LambdaFunctionTemplate : LambdaFunctionTemplateBase { #line hidden @@ -35,7 +35,7 @@ public partial class LambdaFunctionTemplate : LambdaFunctionTemplateBase public virtual string TransformText() { - #line 12 "C:\Users\jamesuk\source\github\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\LambdaFunctionTemplate.tt" + #line 12 "C:\codebase\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\LambdaFunctionTemplate.tt" foreach (var ns in _model.GeneratedMethod.Usings) { @@ -45,14 +45,14 @@ public virtual string TransformText() #line hidden this.Write("using "); - #line 16 "C:\Users\jamesuk\source\github\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\LambdaFunctionTemplate.tt" + #line 16 "C:\codebase\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:\Users\jamesuk\source\github\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\LambdaFunctionTemplate.tt" + #line 17 "C:\codebase\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\LambdaFunctionTemplate.tt" } @@ -61,21 +61,21 @@ public virtual string TransformText() #line hidden this.Write("\r\nnamespace "); - #line 21 "C:\Users\jamesuk\source\github\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\LambdaFunctionTemplate.tt" + #line 21 "C:\codebase\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:\Users\jamesuk\source\github\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\LambdaFunctionTemplate.tt" + #line 23 "C:\codebase\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:\Users\jamesuk\source\github\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\LambdaFunctionTemplate.tt" + #line 25 "C:\codebase\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\LambdaFunctionTemplate.tt" this.Write(new FieldsAndConstructor(_model).TransformText()); @@ -84,34 +84,34 @@ public virtual string TransformText() #line hidden this.Write("\r\n\r\n public "); - #line 30 "C:\Users\jamesuk\source\github\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\LambdaFunctionTemplate.tt" + #line 30 "C:\codebase\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:\Users\jamesuk\source\github\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\LambdaFunctionTemplate.tt" + #line 30 "C:\codebase\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:\Users\jamesuk\source\github\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\LambdaFunctionTemplate.tt" + #line 30 "C:\codebase\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:\Users\jamesuk\source\github\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\LambdaFunctionTemplate.tt" + #line 30 "C:\codebase\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:\Users\jamesuk\source\github\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\LambdaFunctionTemplate.tt" + #line 32 "C:\codebase\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\LambdaFunctionTemplate.tt" if (_model.LambdaMethod.UsingDependencyInjection) { @@ -119,30 +119,32 @@ public virtual string TransformText() #line default #line hidden - this.Write(" // Create a scope for every request,\r\n // this allows creating scoped dependencies without creating a scope manually.\r\n using var scope = serviceProvider.CreateScope();\r\n var "); + this.Write(" // Create a scope for every request,\r\n // this allows crea" + + "ting scoped dependencies without creating a scope manually.\r\n using v" + + "ar scope = serviceProvider.CreateScope();\r\n var "); - #line 39 "C:\Users\jamesuk\source\github\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\LambdaFunctionTemplate.tt" + #line 39 "C:\codebase\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:\Users\jamesuk\source\github\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\LambdaFunctionTemplate.tt" + #line 40 "C:\codebase\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:\Users\jamesuk\source\github\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\LambdaFunctionTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(_model.Serializer)); + #line 41 "C:\codebase\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:\Users\jamesuk\source\github\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\LambdaFunctionTemplate.tt" + #line 43 "C:\codebase\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\LambdaFunctionTemplate.tt" } @@ -160,14 +162,29 @@ public virtual string TransformText() #line default #line hidden - this.Write(" }\r\n\r\n private static void SetExecutionEnvironment()\r\n {\r\n const string envName = \"AWS_EXECUTION_ENV\";\r\n\r\n var envValue = new StringBuilder();\r\n\r\n // If there is an existing execution environment variable add the annotations package as a suffix.\r\n if(!string.IsNullOrEmpty(Environment.GetEnvironmentVariable(envName)))\r\n {\r\n envValue.Append($\"{Environment.GetEnvironmentVariable(envName)}_\");\r\n }\r\n\r\n envValue.Append(\"amazon-lambda-annotations_"); + this.Write(@" } + + 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(""amazon-lambda-annotations_"); - #line 71 "C:\Users\jamesuk\source\github\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\LambdaFunctionTemplate.tt" + #line 71 "C:\codebase\aws-lambda-dotnet\Libraries\src\Amazon.Lambda.Annotations.SourceGenerator\Templates\LambdaFunctionTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(_model.SourceGeneratorVersion)); #line default #line hidden - this.Write("\");\r\n\r\n Environment.SetEnvironmentVariable(envName, envValue.ToString());\r\n }\r\n }\r\n}"); + this.Write("\");\r\n\r\n Environment.SetEnvironmentVariable(envName, envValue.ToString(" + + "));\r\n }\r\n }\r\n}"); return this.GenerationEnvironment.ToString(); } } @@ -178,7 +195,7 @@ public virtual string TransformText() /// /// Base class for this transformation /// - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.TextTemplating", "16.0.0.0")] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.TextTemplating", "17.0.0.0")] public class LambdaFunctionTemplateBase { #region Fields @@ -193,7 +210,7 @@ public class LambdaFunctionTemplateBase /// /// The string builder that generation-time code is using to assemble generated output /// - protected System.Text.StringBuilder GenerationEnvironment + public System.Text.StringBuilder GenerationEnvironment { get { diff --git a/Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Templates/LambdaFunctionTemplate.tt b/Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Templates/LambdaFunctionTemplate.tt index 050364e79..b9c555743 100644 --- a/Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Templates/LambdaFunctionTemplate.tt +++ b/Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Templates/LambdaFunctionTemplate.tt @@ -38,7 +38,7 @@ this.Write(new FieldsAndConstructor(_model).TransformText()); using var scope = serviceProvider.CreateScope(); var <#= _model.LambdaMethod.ContainingType.Name.ToCamelCase() #> = scope.ServiceProvider.GetRequiredService<<#= _model.LambdaMethod.ContainingType.Name #>>(); - var serializer = scope.ServiceProvider.GetRequiredService<<#= _model.Serializer #>>(); + var serializer = scope.ServiceProvider.GetRequiredService<<#= _model.SerializerInfo.SerializerName #>>(); <# } diff --git a/Libraries/src/Amazon.Lambda.Annotations/APIGateway/HttpResults.cs b/Libraries/src/Amazon.Lambda.Annotations/APIGateway/HttpResults.cs index 9662da61d..f2c713ece 100644 --- a/Libraries/src/Amazon.Lambda.Annotations/APIGateway/HttpResults.cs +++ b/Libraries/src/Amazon.Lambda.Annotations/APIGateway/HttpResults.cs @@ -3,6 +3,7 @@ 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; @@ -65,6 +66,17 @@ public enum ProtocolVersion { /// V2 -> HttpApi either implicit or explicit set to V2 /// 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. + /// + public JsonSerializerContext JsonContext { get; set; } +#endif } /// @@ -131,16 +143,13 @@ public class HttpResults : IHttpResult private const string CONTENT_TYPE_TEXT_PLAIN = "text/plain"; private const string CONTENT_TYPE_APPLICATION_OCTET_STREAM = "application/octet-stream"; - private string _body; + private object _rawBody; private IDictionary> _headers; - private bool _isBase64Encoded; - private string _defaultContentType; private HttpResults(HttpStatusCode statusCode, object body = null) { StatusCode = statusCode; - - FormatBody(body); + _rawBody = body; } /// @@ -172,7 +181,7 @@ public static IHttpResult Accepted(object body = null) { return new HttpResults(HttpStatusCode.Accepted, body); } - + /// /// Creates an IHttpResult for a Bad Gateway (502) status code. /// @@ -228,7 +237,7 @@ public static IHttpResult Forbid(object body = null) { return new HttpResults(HttpStatusCode.Forbidden, body); } - + /// /// Creates an IHttpResult for an Internal Server Error (500) status code. /// @@ -299,7 +308,7 @@ public static IHttpResult Redirect(string uri, bool permanent = false, bool pres return result; } - + /// /// Creates an IHttpResult for a Service Unavailable (503) status code. /// @@ -312,7 +321,7 @@ public static IHttpResult ServiceUnavailable(int? delaySeconds = null) { result.AddHeader("Retry-After", delaySeconds.ToString()); } - + return result; } @@ -337,34 +346,34 @@ public static IHttpResult NewResult(HttpStatusCode statusCode, object body = nul } - #region Serialization + #region Serialization + +#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. - private void FormatBody(object body) + [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) { - // See comment at the top about .NET Standard 2.0 -#if NETSTANDARD2_0 - throw new NotImplementedException(); -#else - if (body == null) - return; + return new (null, null, false); if (body is string str) { - _defaultContentType = CONTENT_TYPE_TEXT_PLAIN; - _body = str; + return new (str, CONTENT_TYPE_TEXT_PLAIN, false); } else if (body is Stream stream) { - _defaultContentType = CONTENT_TYPE_APPLICATION_OCTET_STREAM; - _isBase64Encoded = true; var buffer = ArrayPool.Shared.Rent((int)stream.Length); try { var readLength = stream.Read(buffer, 0, buffer.Length); - _body = Convert.ToBase64String(buffer, 0, readLength); + var serializedBody = Convert.ToBase64String(buffer, 0, readLength); + + return new(serializedBody, CONTENT_TYPE_APPLICATION_OCTET_STREAM, true); } finally { @@ -373,23 +382,30 @@ private void FormatBody(object body) } else if (body is byte[] binaryData) { - _defaultContentType = CONTENT_TYPE_APPLICATION_OCTET_STREAM; - _isBase64Encoded = true; - _body = Convert.ToBase64String(binaryData, 0, binaryData.Length); + var serializedBody = Convert.ToBase64String(binaryData, 0, binaryData.Length); + return new(serializedBody, CONTENT_TYPE_APPLICATION_OCTET_STREAM, true); } else if (body is IList listBinaryData) { - _defaultContentType = CONTENT_TYPE_APPLICATION_OCTET_STREAM; - _isBase64Encoded = true; - _body = Convert.ToBase64String(listBinaryData.ToArray(), 0, listBinaryData.Count); + var serializedBody = Convert.ToBase64String(listBinaryData.ToArray(), 0, listBinaryData.Count); + return new(serializedBody, CONTENT_TYPE_APPLICATION_OCTET_STREAM, true); } else { - _defaultContentType = CONTENT_TYPE_APPLICATION_JSON; - _body = JsonSerializer.Serialize(body); + string serializedBody; + if (context != null) + { + serializedBody = JsonSerializer.Serialize(body, body.GetType(), context); + } + else + { + serializedBody = JsonSerializer.Serialize(body); + } + + return new(serializedBody, CONTENT_TYPE_APPLICATION_JSON, false); } -#endif } +#endif /// public HttpStatusCode StatusCode { get; } @@ -401,43 +417,49 @@ private void FormatBody(object body) /// public Stream Serialize(HttpResultSerializationOptions options) { - // See comment at the top about .NET Standard 2.0 #if NETSTANDARD2_0 throw new NotImplementedException(); #else + + var (serializedBody, defaultContentType, isBase64Encoded) = FormatBody(_rawBody, options.JsonContext); + // If the user didn't explicit set the content type then default to application/json - if(!string.IsNullOrEmpty(_body) && (_headers == null || !_headers.ContainsKey(HEADER_NAME_CONTENT_TYPE))) + if (!string.IsNullOrEmpty(serializedBody) && (_headers == null || !_headers.ContainsKey(HEADER_NAME_CONTENT_TYPE))) { - AddHeader(HEADER_NAME_CONTENT_TYPE, _defaultContentType); + AddHeader(HEADER_NAME_CONTENT_TYPE, defaultContentType); } var stream = new MemoryStream(); + object response; + Type responseType; if (options.Format == HttpResultSerializationOptions.ProtocolFormat.RestApi || (options.Format == HttpResultSerializationOptions.ProtocolFormat.HttpApi && options.Version == HttpResultSerializationOptions.ProtocolVersion.V1)) { - var response = new APIGatewayV1Response + response = new APIGatewayV1Response { StatusCode = (int)StatusCode, - Body = _body, + Body = serializedBody, MultiValueHeaders = _headers, - IsBase64Encoded = _isBase64Encoded + IsBase64Encoded = isBase64Encoded }; - JsonSerializer.Serialize(stream, response); + responseType = typeof(APIGatewayV1Response); } else { - var response = new APIGatewayV2Response + response = new APIGatewayV2Response { StatusCode = (int)StatusCode, - Body = _body, + Body = serializedBody, Headers = ConvertToV2MultiValueHeaders(_headers), - IsBase64Encoded = _isBase64Encoded + IsBase64Encoded = isBase64Encoded }; - JsonSerializer.Serialize(stream, response); + responseType = typeof(APIGatewayV2Response); } + JsonSerializer.Serialize(stream, response, responseType, AnnotationsResponseJsonSerializerContext.Default); + stream.Position = 0; return stream; #endif @@ -468,7 +490,7 @@ private static IDictionary ConvertToV2MultiValueHeaders(IDiction #if !NETSTANDARD2_0 // Class representing the V1 API Gateway response. Very similiar to Amazon.Lambda.APIGatewayEvents.APIGatewayProxyResponse but this library can // not take a dependency on Amazon.Lambda.APIGatewayEvents so it has to have its own version. - private class APIGatewayV1Response + internal class APIGatewayV1Response { [JsonPropertyName("statusCode")] public int StatusCode { get; set; } @@ -485,7 +507,7 @@ private class APIGatewayV1Response // Class representing the V2 API Gateway response. Very similiar to Amazon.Lambda.APIGatewayEvents.APIGatewayHttpApiV2ProxyResponse but this library can // not take a dependency on Amazon.Lambda.APIGatewayEvents so it has to have its own version. - private class APIGatewayV2Response + internal class APIGatewayV2Response { [JsonPropertyName("statusCode")] public int StatusCode { get; set; } @@ -502,6 +524,15 @@ private class APIGatewayV2Response public bool IsBase64Encoded { get; set; } } #endif -#endregion + #endregion } + +#if !NETSTANDARD2_0 + [JsonSerializable(typeof(HttpResults.APIGatewayV1Response))] + [JsonSerializable(typeof(HttpResults.APIGatewayV2Response))] + internal partial class AnnotationsResponseJsonSerializerContext : JsonSerializerContext + { + } + +#endif } diff --git a/Libraries/src/Amazon.Lambda.Annotations/Amazon.Lambda.Annotations.csproj b/Libraries/src/Amazon.Lambda.Annotations/Amazon.Lambda.Annotations.csproj index 415f7e701..d9a3cafdc 100644 --- a/Libraries/src/Amazon.Lambda.Annotations/Amazon.Lambda.Annotations.csproj +++ b/Libraries/src/Amazon.Lambda.Annotations/Amazon.Lambda.Annotations.csproj @@ -2,7 +2,17 @@ 1.1.0 - netstandard2.0;net6.0 + netstandard2.0;net6.0;net8.0 true + + + IL2026,IL2067,IL2075,IL3050 + true + true + + + + + \ No newline at end of file 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 884b6c857..f72142181 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 @@ -138,9 +138,10 @@ + - + Always diff --git a/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/HttpResultsTest.cs b/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/HttpResultsTest.cs index 82296228b..04e72cdd7 100644 --- a/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/HttpResultsTest.cs +++ b/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/HttpResultsTest.cs @@ -14,9 +14,9 @@ public class HttpResultsTest [Fact] public void OkNoBody() { - var result = HttpResults.Ok(); + var result = () => HttpResults.Ok(); - Assert.Equal(HttpStatusCode.OK, result.StatusCode); + Assert.Equal(HttpStatusCode.OK, result().StatusCode); ValidateResult(result, HttpStatusCode.OK); } @@ -25,9 +25,9 @@ public void OkNoBody() public void OkStringBody() { var body = "Hello World"; - var result = HttpResults.Ok(body); + var result = () => HttpResults.Ok(body); - Assert.Equal(HttpStatusCode.OK, result.StatusCode); + Assert.Equal(HttpStatusCode.OK, result().StatusCode); ValidateResult(result, HttpStatusCode.OK, body, headers: new Dictionary> { @@ -40,9 +40,9 @@ public void OkStringBody() public void OverrideContentType() { var body = "Hello World"; - var result = HttpResults.Ok(body).AddHeader("content-type", "custom/foo"); + var result = () => HttpResults.Ok(body).AddHeader("content-type", "custom/foo"); - Assert.Equal(HttpStatusCode.OK, result.StatusCode); + Assert.Equal(HttpStatusCode.OK, result().StatusCode); ValidateResult(result, HttpStatusCode.OK, body, headers: new Dictionary> { @@ -56,9 +56,9 @@ public void OkByteArrayBody() { var body = new byte[] { 0x01, 0x02 }; - var result = HttpResults.Ok(body); + var result = () => HttpResults.Ok(body); - Assert.Equal(HttpStatusCode.OK, result.StatusCode); + Assert.Equal(HttpStatusCode.OK, result().StatusCode); ValidateResult(result, HttpStatusCode.OK, Convert.ToBase64String(body), isBase64Encoded: true, headers: new Dictionary> { @@ -71,9 +71,9 @@ public void OkByteArrayBody() public void OkStreamBody() { var body = new byte[] { 0x01, 0x02 }; - var result = HttpResults.Ok(new MemoryStream(body)); + var result = () => HttpResults.Ok(new MemoryStream(body)); - Assert.Equal(HttpStatusCode.OK, result.StatusCode); + Assert.Equal(HttpStatusCode.OK, result().StatusCode); ValidateResult(result, HttpStatusCode.OK, Convert.ToBase64String(body), isBase64Encoded: true, headers: new Dictionary> { @@ -86,9 +86,9 @@ public void OkStreamBody() public void OkListOfBytesBody() { var body = new byte[] { 0x01, 0x02 }; - var result = HttpResults.Ok(new List(body)); + var result = () => HttpResults.Ok(new List(body)); - Assert.Equal(HttpStatusCode.OK, result.StatusCode); + Assert.Equal(HttpStatusCode.OK, result().StatusCode); ValidateResult(result, HttpStatusCode.OK, Convert.ToBase64String(body), isBase64Encoded: true, headers: new Dictionary> { @@ -101,9 +101,9 @@ public void OkListOfBytesBody() public void OkWithTypeBody() { var body = new FakeBody(); - var result = HttpResults.Ok(body); + var result = () => HttpResults.Ok(body); - Assert.Equal(HttpStatusCode.OK, result.StatusCode); + Assert.Equal(HttpStatusCode.OK, result().StatusCode); ValidateResult(result, HttpStatusCode.OK, "{\"Id\":1}", isBase64Encoded: false, headers: new Dictionary> { @@ -115,11 +115,11 @@ public void OkWithTypeBody() [Fact] public void OkWithSingleValueHeader() { - var result = HttpResults.Ok() + var result = () => HttpResults.Ok() .AddHeader("header1", "value1") .AddHeader("header2", "value2"); - Assert.Equal(HttpStatusCode.OK, result.StatusCode); + Assert.Equal(HttpStatusCode.OK, result().StatusCode); ValidateResult(result, HttpStatusCode.OK, headers: new Dictionary> @@ -133,13 +133,13 @@ public void OkWithSingleValueHeader() [Fact] public void OkWithMultiValueHeader() { - var result = HttpResults.Ok() + var result = () => HttpResults.Ok() .AddHeader("header1", "foo1") .AddHeader("header1", "foo2") .AddHeader("header2", "bar1") .AddHeader("header2", "bar2"); - Assert.Equal(HttpStatusCode.OK, result.StatusCode); + Assert.Equal(HttpStatusCode.OK, result().StatusCode); ValidateResult(result, HttpStatusCode.OK, headers: new Dictionary> @@ -153,9 +153,9 @@ public void OkWithMultiValueHeader() [Fact] public void Accepted() { - var result = HttpResults.Accepted(); + var result = () => HttpResults.Accepted(); - Assert.Equal(HttpStatusCode.Accepted, result.StatusCode); + Assert.Equal(HttpStatusCode.Accepted, result().StatusCode); ValidateResult(result, HttpStatusCode.Accepted); } @@ -163,9 +163,9 @@ public void Accepted() [Fact] public void BadRequest() { - var result = HttpResults.BadRequest(); + var result = () => HttpResults.BadRequest(); - Assert.Equal(HttpStatusCode.BadRequest, result.StatusCode); + Assert.Equal(HttpStatusCode.BadRequest, result().StatusCode); ValidateResult(result, HttpStatusCode.BadRequest); } @@ -173,9 +173,9 @@ public void BadRequest() [Fact] public void Conflict() { - var result = HttpResults.Conflict(); + var result = () => HttpResults.Conflict(); - Assert.Equal(HttpStatusCode.Conflict, result.StatusCode); + Assert.Equal(HttpStatusCode.Conflict, result().StatusCode); ValidateResult(result, HttpStatusCode.Conflict); } @@ -183,9 +183,9 @@ public void Conflict() [Fact] public void Created() { - var result = HttpResults.Created(); + var result = () => HttpResults.Created(); - Assert.Equal(HttpStatusCode.Created, result.StatusCode); + Assert.Equal(HttpStatusCode.Created, result().StatusCode); ValidateResult(result, HttpStatusCode.Created); } @@ -193,9 +193,9 @@ public void Created() [Fact] public void CreatedWithUriAndBody() { - var result = HttpResults.Created("http://localhost/foo", "Resource Created"); + var result = () => HttpResults.Created("http://localhost/foo", "Resource Created"); - Assert.Equal(HttpStatusCode.Created, result.StatusCode); + Assert.Equal(HttpStatusCode.Created, result().StatusCode); ValidateResult(result, HttpStatusCode.Created, "Resource Created", headers: new Dictionary> @@ -209,9 +209,9 @@ public void CreatedWithUriAndBody() [Fact] public void Forbid() { - var result = HttpResults.Forbid(); + var result = () => HttpResults.Forbid(); - Assert.Equal(HttpStatusCode.Forbidden, result.StatusCode); + Assert.Equal(HttpStatusCode.Forbidden, result().StatusCode); ValidateResult(result, HttpStatusCode.Forbidden); } @@ -219,9 +219,9 @@ public void Forbid() [Fact] public void Redirect_PermanentRedirect() { - var result = HttpResults.Redirect("http://localhost/foo", permanent: true, preserveMethod: true); + var result = () => HttpResults.Redirect("http://localhost/foo", permanent: true, preserveMethod: true); - Assert.Equal(HttpStatusCode.PermanentRedirect, result.StatusCode); + Assert.Equal(HttpStatusCode.PermanentRedirect, result().StatusCode); ValidateResult(result, HttpStatusCode.PermanentRedirect, headers: new Dictionary> @@ -234,9 +234,9 @@ public void Redirect_PermanentRedirect() [Fact] public void Redirect_MovedPermanently() { - var result = HttpResults.Redirect("http://localhost/foo", permanent: true, preserveMethod: false); + var result = () => HttpResults.Redirect("http://localhost/foo", permanent: true, preserveMethod: false); - Assert.Equal(HttpStatusCode.MovedPermanently, result.StatusCode); + Assert.Equal(HttpStatusCode.MovedPermanently, result().StatusCode); ValidateResult(result, HttpStatusCode.MovedPermanently, headers: new Dictionary> @@ -249,9 +249,9 @@ public void Redirect_MovedPermanently() [Fact] public void Redirect_TemporaryRedirect() { - var result = HttpResults.Redirect("http://localhost/foo", permanent: false, preserveMethod: true); + var result = () => HttpResults.Redirect("http://localhost/foo", permanent: false, preserveMethod: true); - Assert.Equal(HttpStatusCode.TemporaryRedirect, result.StatusCode); + Assert.Equal(HttpStatusCode.TemporaryRedirect, result().StatusCode); ValidateResult(result, HttpStatusCode.TemporaryRedirect, headers: new Dictionary> @@ -264,9 +264,9 @@ public void Redirect_TemporaryRedirect() [Fact] public void Redirect_Redirect() { - var result = HttpResults.Redirect("http://localhost/foo", permanent: false, preserveMethod: false); + var result = () => HttpResults.Redirect("http://localhost/foo", permanent: false, preserveMethod: false); - Assert.Equal(HttpStatusCode.Redirect, result.StatusCode); + Assert.Equal(HttpStatusCode.Redirect, result().StatusCode); ValidateResult(result, HttpStatusCode.Redirect, headers: new Dictionary> @@ -279,9 +279,9 @@ public void Redirect_Redirect() [Fact] public void NotFound() { - var result = HttpResults.NotFound(); + var result = () => HttpResults.NotFound(); - Assert.Equal(HttpStatusCode.NotFound, result.StatusCode); + Assert.Equal(HttpStatusCode.NotFound, result().StatusCode); ValidateResult(result, HttpStatusCode.NotFound); } @@ -289,9 +289,9 @@ public void NotFound() [Fact] public void Unauthorized() { - var result = HttpResults.Unauthorized(); + var result = () => HttpResults.Unauthorized(); - Assert.Equal(HttpStatusCode.Unauthorized, result.StatusCode); + Assert.Equal(HttpStatusCode.Unauthorized, result().StatusCode); ValidateResult(result, HttpStatusCode.Unauthorized); } @@ -299,12 +299,12 @@ public void Unauthorized() [Fact] public void MixCaseHeaders() { - var result = HttpResults.Ok() + var result = () => HttpResults.Ok() .AddHeader("key", "value1") .AddHeader("key", "value2") .AddHeader("KEY", "VALUE3"); - Assert.Equal(HttpStatusCode.OK, result.StatusCode); + Assert.Equal(HttpStatusCode.OK, result().StatusCode); ValidateResult(result, HttpStatusCode.OK, headers: new Dictionary> { @@ -315,9 +315,9 @@ public void MixCaseHeaders() [Fact] public void InternalServerError() { - var result = HttpResults.InternalServerError(); + var result = () => HttpResults.InternalServerError(); - Assert.Equal(HttpStatusCode.InternalServerError, result.StatusCode); + Assert.Equal(HttpStatusCode.InternalServerError, result().StatusCode); ValidateResult(result, HttpStatusCode.InternalServerError); } @@ -325,9 +325,9 @@ public void InternalServerError() [Fact] public void BadGateway() { - var result = HttpResults.BadGateway(); + var result = () => HttpResults.BadGateway(); - Assert.Equal(HttpStatusCode.BadGateway, result.StatusCode); + Assert.Equal(HttpStatusCode.BadGateway, result().StatusCode); ValidateResult(result, HttpStatusCode.BadGateway); } @@ -337,9 +337,9 @@ public void BadGateway() [InlineData(0)] public void ServiceUnavailable_WithoutRetryAfter(int? delay) { - var result = HttpResults.ServiceUnavailable(delay); + var result = () => HttpResults.ServiceUnavailable(delay); - Assert.Equal(HttpStatusCode.ServiceUnavailable, result.StatusCode); + Assert.Equal(HttpStatusCode.ServiceUnavailable, result().StatusCode); ValidateResult(result, HttpStatusCode.ServiceUnavailable); } @@ -347,9 +347,9 @@ public void ServiceUnavailable_WithoutRetryAfter(int? delay) [Fact] public void ServiceUnavailable_WithRetryAfter() { - var result = HttpResults.ServiceUnavailable(100); + var result = () => HttpResults.ServiceUnavailable(100); - Assert.Equal(HttpStatusCode.ServiceUnavailable, result.StatusCode); + Assert.Equal(HttpStatusCode.ServiceUnavailable, result().StatusCode); ValidateResult(result, HttpStatusCode.ServiceUnavailable, headers: new Dictionary> { @@ -358,7 +358,7 @@ public void ServiceUnavailable_WithRetryAfter() } - private void ValidateResult(IHttpResult result, HttpStatusCode statusCode, string body = null, bool isBase64Encoded = false, IDictionary> headers = null) + private void ValidateResult(Func resultCreator, HttpStatusCode statusCode, string body = null, bool isBase64Encoded = false, IDictionary> headers = null) { var testScenarios = new List> { @@ -369,6 +369,8 @@ private void ValidateResult(IHttpResult result, HttpStatusCode statusCode, strin foreach(var (format, version) in testScenarios) { + IHttpResult result = resultCreator(); + var stream = result.Serialize(new HttpResultSerializationOptions { Format = format, Version = version }); var jsonDoc = JsonDocument.Parse(stream); if (format == HttpResultSerializationOptions.ProtocolFormat.RestApi || (format == HttpResultSerializationOptions.ProtocolFormat.HttpApi && version == HttpResultSerializationOptions.ProtocolVersion.V1)) 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 86a9b96b4..21bfdb9fa 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 @@ -59,7 +59,8 @@ public CustomizeResponseExamples_NotFoundResponseWithHeaderV1Async_Generated() var httpResults = await customizeResponseExamples.NotFoundResponseWithHeaderV1Async(x, __context__); HttpResultSerializationOptions.ProtocolFormat serializationFormat = HttpResultSerializationOptions.ProtocolFormat.HttpApi; HttpResultSerializationOptions.ProtocolVersion serializationVersion = HttpResultSerializationOptions.ProtocolVersion.V1; - var serializationOptions = new HttpResultSerializationOptions { Format = serializationFormat, Version = serializationVersion }; + System.Text.Json.Serialization.JsonSerializerContext jsonContext = null; + var serializationOptions = new HttpResultSerializationOptions { Format = serializationFormat, Version = serializationVersion, JsonContext = jsonContext }; 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 f30a9d19f..76e3e99eb 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 @@ -59,7 +59,8 @@ 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; - var serializationOptions = new HttpResultSerializationOptions { Format = serializationFormat, Version = serializationVersion }; + System.Text.Json.Serialization.JsonSerializerContext jsonContext = null; + var serializationOptions = new HttpResultSerializationOptions { Format = serializationFormat, Version = serializationVersion, JsonContext = jsonContext }; 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 b33f9d2b9..568d0a380 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 @@ -59,7 +59,8 @@ public CustomizeResponseExamples_NotFoundResponseWithHeaderV2Async_Generated() var httpResults = await customizeResponseExamples.NotFoundResponseWithHeaderV2Async(x, __context__); HttpResultSerializationOptions.ProtocolFormat serializationFormat = HttpResultSerializationOptions.ProtocolFormat.HttpApi; HttpResultSerializationOptions.ProtocolVersion serializationVersion = HttpResultSerializationOptions.ProtocolVersion.V2; - var serializationOptions = new HttpResultSerializationOptions { Format = serializationFormat, Version = serializationVersion }; + System.Text.Json.Serialization.JsonSerializerContext jsonContext = null; + var serializationOptions = new HttpResultSerializationOptions { Format = serializationFormat, Version = serializationVersion, JsonContext = jsonContext }; 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 b71e5f70c..058e062e0 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 @@ -59,7 +59,8 @@ 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; - var serializationOptions = new HttpResultSerializationOptions { Format = serializationFormat, Version = serializationVersion }; + System.Text.Json.Serialization.JsonSerializerContext jsonContext = null; + var serializationOptions = new HttpResultSerializationOptions { Format = serializationFormat, Version = serializationVersion, JsonContext = jsonContext }; var response = httpResults.Serialize(serializationOptions); return response; } 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 efaee804d..833d412d3 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 @@ -59,7 +59,8 @@ public CustomizeResponseExamples_OkResponseWithHeaderAsync_Generated() var httpResults = await customizeResponseExamples.OkResponseWithHeaderAsync(x, __context__); HttpResultSerializationOptions.ProtocolFormat serializationFormat = HttpResultSerializationOptions.ProtocolFormat.RestApi; HttpResultSerializationOptions.ProtocolVersion serializationVersion = HttpResultSerializationOptions.ProtocolVersion.V1; - var serializationOptions = new HttpResultSerializationOptions { Format = serializationFormat, Version = serializationVersion }; + System.Text.Json.Serialization.JsonSerializerContext jsonContext = null; + var serializationOptions = new HttpResultSerializationOptions { Format = serializationFormat, Version = serializationVersion, JsonContext = jsonContext }; 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 4b47c09b3..44c68a849 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 @@ -59,7 +59,8 @@ 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; - var serializationOptions = new HttpResultSerializationOptions { Format = serializationFormat, Version = serializationVersion }; + System.Text.Json.Serialization.JsonSerializerContext jsonContext = null; + var serializationOptions = new HttpResultSerializationOptions { Format = serializationFormat, Version = serializationVersion, JsonContext = jsonContext }; var response = httpResults.Serialize(serializationOptions); return response; } 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 new file mode 100644 index 000000000..850761100 --- /dev/null +++ b/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/ProgramSourceGeneratorSerializationExample.g.cs @@ -0,0 +1,25 @@ +using System; +using System.Linq; +using System.Collections.Generic; +using System.Text; +using System.Threading.Tasks; +using System.IO; +using Amazon.Lambda.Core; + +namespace TestExecutableServerlessApp; + +public class GeneratedProgram +{ + public static async Task Main(string[] args) + { + + switch (Environment.GetEnvironmentVariable("ANNOTATIONS_HANDLER")) + { + case "GetPerson": + Func getperson_handler = new TestExecutableServerlessApp.SourceGenerationSerializationExample_GetPerson_Generated().GetPerson; + await Amazon.Lambda.RuntimeSupport.LambdaBootstrapBuilder.Create(getperson_handler, new Amazon.Lambda.Serialization.SystemTextJson.SourceGeneratorLambdaJsonSerializer()).Build().RunAsync(); + break; + + } + } +} \ No newline at end of file diff --git a/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/ServerlessTemplates/sourcegeneratorserializationexample.template b/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/ServerlessTemplates/sourcegeneratorserializationexample.template new file mode 100644 index 000000000..0fc6d40ff --- /dev/null +++ b/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/ServerlessTemplates/sourcegeneratorserializationexample.template @@ -0,0 +1,44 @@ +{ + "AWSTemplateFormatVersion": "2010-09-09", + "Transform": "AWS::Serverless-2016-10-31", + "Description": "This template is partially managed by Amazon.Lambda.Annotations (v1.0.0.0).", + "Resources": { + "TestExecutableServerlessAppSourceGenerationSerializationExampleGetPersonGenerated": { + "Type": "AWS::Serverless::Function", + "Metadata": { + "Tool": "Amazon.Lambda.Annotations", + "SyncedEvents": [ + "RootGet" + ] + }, + "Properties": { + "MemorySize": 256, + "Timeout": 30, + "Policies": [ + "AWSLambdaBasicExecutionRole" + ], + "PackageType": "Image", + "ImageUri": ".", + "ImageConfig": { + "Command": [ + "TestProject" + ] + }, + "Environment": { + "Variables": { + "ANNOTATIONS_HANDLER": "GetPerson" + } + }, + "Events": { + "RootGet": { + "Type": "Api", + "Properties": { + "Path": "/", + "Method": "GET" + } + } + } + } + } + } +} \ No newline at end of file diff --git a/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/ServerlessTemplates/voidexample - Copy.template b/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/ServerlessTemplates/voidexample - Copy.template new file mode 100644 index 000000000..d2c49490f --- /dev/null +++ b/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/ServerlessTemplates/voidexample - Copy.template @@ -0,0 +1,27 @@ +{ + "AWSTemplateFormatVersion": "2010-09-09", + "Transform": "AWS::Serverless-2016-10-31", + "Description": "This template is partially managed by Amazon.Lambda.Annotations (v1.0.0.0).", + "Resources": { + "TestServerlessAppVoidExampleVoidReturnGenerated": { + "Type": "AWS::Serverless::Function", + "Metadata": { + "Tool": "Amazon.Lambda.Annotations" + }, + "Properties": { + "MemorySize": 256, + "Timeout": 30, + "Policies": [ + "AWSLambdaBasicExecutionRole" + ], + "PackageType": "Image", + "ImageUri": ".", + "ImageConfig": { + "Command": [ + "TestProject::TestServerlessApp.VoidExample_VoidReturn_Generated::VoidReturn" + ] + } + } + } + } +} \ No newline at end of file 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 new file mode 100644 index 000000000..5bffcd3ad --- /dev/null +++ b/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/SourceGenerationSerializationExample_GetPerson_Generated.g.cs @@ -0,0 +1,52 @@ +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 TestExecutableServerlessApp +{ + public class SourceGenerationSerializationExample_GetPerson_Generated + { + private readonly SourceGenerationSerializationExample sourceGenerationSerializationExample; + private readonly Amazon.Lambda.Serialization.SystemTextJson.SourceGeneratorLambdaJsonSerializer serializer; + + public SourceGenerationSerializationExample_GetPerson_Generated() + { + SetExecutionEnvironment(); + sourceGenerationSerializationExample = new SourceGenerationSerializationExample(); + serializer = new Amazon.Lambda.Serialization.SystemTextJson.SourceGeneratorLambdaJsonSerializer(); + } + + 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 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("amazon-lambda-annotations_1.1.0.0"); + + Environment.SetEnvironmentVariable(envName, envValue.ToString()); + } + } +} \ No newline at end of file diff --git a/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/SourceGeneratorTests.cs b/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/SourceGeneratorTests.cs index c6f2e2b56..b80b324d4 100644 --- a/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/SourceGeneratorTests.cs +++ b/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/SourceGeneratorTests.cs @@ -77,7 +77,7 @@ public async Task TestExecutableOutputWithNoAnnotations() ExpectedDiagnostics = { DiagnosticResult.CompilerError("AWSLambda0113") - .WithMessage("Your project is configured to output an executable and generate a static Main method, but you have not configured any methods with the 'LambdaFunction' attribute."), + .WithMessage("Your project is configured to output an executable and generate a static Main method, but you have not configured any methods with the 'LambdaFunction' attribute"), DiagnosticResult.CompilerError("CS5001") .WithMessage("Program does not contain a static 'Main' method suitable for an entry point"), }, @@ -664,6 +664,71 @@ public async Task VerifyExecutableAssemblyWithMultipleHandler() await test.RunAsync(); } + [Fact] + public async Task VerifySourceGeneratorSerializerWithHttpResultsBody() + { + var expectedTemplateContent = (await File.ReadAllTextAsync(Path.Combine("Snapshots", "ServerlessTemplates", "sourcegeneratorserializationexample.template"))).ToEnvironmentLineEndings(); + var expectedFunctionContent = (await File.ReadAllTextAsync(Path.Combine("Snapshots", "SourceGenerationSerializationExample_GetPerson_Generated.g.cs"))).ToEnvironmentLineEndings(); + var expectedProgramGenerated = (await File.ReadAllTextAsync(Path.Combine("Snapshots", "ProgramSourceGeneratorSerializationExample.g.cs"))).ToEnvironmentLineEndings(); + + var test = new VerifyCS.Test + { + TestState = + { + OutputKind = OutputKind.ConsoleApplication, + Sources = + { + (Path.Combine("TestExecutableServerlessApp", "SourceGenerationSerializationExample.cs"), await File.ReadAllTextAsync(Path.Combine("TestExecutableServerlessApp", "SourceGenerationSerializationExample.cs"))), + (Path.Combine("Amazon.Lambda.Annotations", "LambdaFunctionAttribute.cs"), await File.ReadAllTextAsync(Path.Combine("Amazon.Lambda.Annotations", "LambdaFunctionAttribute.cs"))), + (Path.Combine("Amazon.Lambda.Annotations", "LambdaStartupAttribute.cs"), await File.ReadAllTextAsync(Path.Combine("Amazon.Lambda.Annotations", "LambdaStartupAttribute.cs"))), + (Path.Combine("Amazon.Lambda.Annotations", "LambdaGlobalPropertiesAttribute.cs"), await File.ReadAllTextAsync(Path.Combine("Amazon.Lambda.Annotations", "LambdaGlobalPropertiesAttribute.cs"))), + (Path.Combine("TestExecutableServerlessApp", "AssemblyAttributes.cs"), await File.ReadAllTextAsync(Path.Combine("TestExecutableServerlessApp", "AssemblyAttributes.cs"))), + }, + GeneratedSources = + { + ( + typeof(SourceGenerator.Generator), + "SourceGenerationSerializationExample_GetPerson_Generated.g.cs", + SourceText.From(expectedFunctionContent, Encoding.UTF8, SourceHashAlgorithm.Sha256) + ), + ( + typeof(SourceGenerator.Generator), + "Program.g.cs", + SourceText.From(expectedProgramGenerated, Encoding.UTF8, SourceHashAlgorithm.Sha256) + ) + }, + ExpectedDiagnostics = + { + new DiagnosticResult("AWSLambda0103", DiagnosticSeverity.Info).WithArguments("SourceGenerationSerializationExample_GetPerson_Generated.g.cs", expectedFunctionContent), + new DiagnosticResult("AWSLambda0103", DiagnosticSeverity.Info).WithArguments($"TestExecutableServerlessApp{Path.DirectorySeparatorChar}serverless.template", expectedTemplateContent), + + // 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\Amazon.Lambda.Annotations.SourceGenerator.Generator\SourceGenerationSerializationExample_GetPerson_Generated.g.cs", 29, 137, 29, 144).WithArguments("TestExecutableServerlessApp.HttpApiJsonSerializerContext", "Default"), + DiagnosticResult.CompilerError("CS0534").WithSpan(@"TestExecutableServerlessApp\SourceGenerationSerializationExample.cs", 28, 26, 28, 54).WithArguments("TestExecutableServerlessApp.HttpApiJsonSerializerContext", "System.Text.Json.Serialization.JsonSerializerContext.GeneratedSerializerOptions.get"), + DiagnosticResult.CompilerError("CS0534").WithSpan(@"TestExecutableServerlessApp\SourceGenerationSerializationExample.cs", 28, 26, 28, 54).WithArguments("TestExecutableServerlessApp.HttpApiJsonSerializerContext", "System.Text.Json.Serialization.JsonSerializerContext.GetTypeInfo(System.Type)"), + DiagnosticResult.CompilerError("CS7036").WithSpan(@"TestExecutableServerlessApp\SourceGenerationSerializationExample.cs", 28, 26, 28, 54).WithArguments("options", "System.Text.Json.Serialization.JsonSerializerContext.JsonSerializerContext(System.Text.Json.JsonSerializerOptions?)"), + }, + ReferenceAssemblies = ReferenceAssemblies.Net.Net60 + } + }; + + foreach (var file in Directory.GetFiles( + Path.Combine("Amazon.Lambda.RuntimeSupport"), + "*.cs", SearchOption.AllDirectories)) + { + var content = await File.ReadAllTextAsync(file); + + // Don't include RuntimeSupport's entry point. + if (file.EndsWith("Program.cs") && content.Contains("Task Main(string[] args)")) + continue; + + test.TestState.Sources.Add((file, await File.ReadAllTextAsync(file))); + } + + await test.RunAsync(); + } + [Fact] public async Task VerifyFunctionReturnVoid() { diff --git a/Libraries/test/TestExecutableServerlessApp/SourceGenerationSerializationExample.cs b/Libraries/test/TestExecutableServerlessApp/SourceGenerationSerializationExample.cs new file mode 100644 index 000000000..32362c0b8 --- /dev/null +++ b/Libraries/test/TestExecutableServerlessApp/SourceGenerationSerializationExample.cs @@ -0,0 +1,37 @@ +using Amazon.Lambda.Annotations; +using Amazon.Lambda.Annotations.APIGateway; +using Amazon.Lambda.APIGatewayEvents; +using Amazon.Lambda.Core; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Text.Json.Serialization; +using System.Threading.Tasks; + +namespace TestExecutableServerlessApp +{ + public class SourceGenerationSerializationExample + { + [LambdaFunction(PackageType = LambdaPackageType.Image)] + [RestApi(LambdaHttpMethod.Get, "/")] + [LambdaSerializer(typeof(Amazon.Lambda.Serialization.SystemTextJson.SourceGeneratorLambdaJsonSerializer))] + public IHttpResult GetPerson(ILambdaContext context) + { + return HttpResults.Ok(new Person { Name = "Foobar" }); + } + } + + [JsonSerializable(typeof(APIGatewayHttpApiV2ProxyRequest))] + [JsonSerializable(typeof(APIGatewayHttpApiV2ProxyResponse))] + [JsonSerializable(typeof(Person))] + public partial class HttpApiJsonSerializerContext : JsonSerializerContext + { + + } + + public class Person + { + public string Name { get; set; } + } +} diff --git a/Libraries/test/TestExecutableServerlessApp/serverless.template b/Libraries/test/TestExecutableServerlessApp/serverless.template index 9584ef590..76159b8c0 100644 --- a/Libraries/test/TestExecutableServerlessApp/serverless.template +++ b/Libraries/test/TestExecutableServerlessApp/serverless.template @@ -22,13 +22,16 @@ } }, "Resources": { - "TestServerlessAppDynamicExampleDynamicReturnGenerated": { + "GreeterSayHello": { "Type": "AWS::Serverless::Function", "Metadata": { - "Tool": "Amazon.Lambda.Annotations" + "Tool": "Amazon.Lambda.Annotations", + "SyncedEvents": [ + "RootGet" + ] }, "Properties": { - "MemorySize": 256, + "MemorySize": 1024, "Timeout": 30, "Policies": [ "AWSLambdaBasicExecutionRole" @@ -42,19 +45,32 @@ }, "Environment": { "Variables": { - "ANNOTATIONS_HANDLER": "DynamicReturn" + "ANNOTATIONS_HANDLER": "SayHello" + } + }, + "Events": { + "RootGet": { + "Type": "HttpApi", + "Properties": { + "Path": "/Greeter/SayHello", + "Method": "GET", + "PayloadFormatVersion": "1.0" + } } } } }, - "TestServerlessAppDynamicExampleDynamicInputGenerated": { + "GreeterSayHelloAsync": { "Type": "AWS::Serverless::Function", "Metadata": { - "Tool": "Amazon.Lambda.Annotations" + "Tool": "Amazon.Lambda.Annotations", + "SyncedEvents": [ + "RootGet" + ] }, "Properties": { "MemorySize": 256, - "Timeout": 30, + "Timeout": 50, "Policies": [ "AWSLambdaBasicExecutionRole" ], @@ -67,12 +83,22 @@ }, "Environment": { "Variables": { - "ANNOTATIONS_HANDLER": "DynamicInput" + "ANNOTATIONS_HANDLER": "SayHelloAsync" + } + }, + "Events": { + "RootGet": { + "Type": "HttpApi", + "Properties": { + "Path": "/Greeter/SayHelloAsync", + "Method": "GET", + "PayloadFormatVersion": "1.0" + } } } } }, - "TestServerlessAppTaskExampleTaskReturnGenerated": { + "TestServerlessAppVoidExampleVoidReturnGenerated": { "Type": "AWS::Serverless::Function", "Metadata": { "Tool": "Amazon.Lambda.Annotations" @@ -92,12 +118,12 @@ }, "Environment": { "Variables": { - "ANNOTATIONS_HANDLER": "TaskReturn" + "ANNOTATIONS_HANDLER": "VoidReturn" } } } }, - "TestServerlessAppVoidExampleVoidReturnGenerated": { + "ToUpper": { "Type": "AWS::Serverless::Function", "Metadata": { "Tool": "Amazon.Lambda.Annotations" @@ -117,12 +143,12 @@ }, "Environment": { "Variables": { - "ANNOTATIONS_HANDLER": "VoidReturn" + "ANNOTATIONS_HANDLER": "ToUpper" } } } }, - "TestServerlessAppCustomizeResponseExamplesOkResponseWithHeaderGenerated": { + "TestServerlessAppNullableReferenceTypeExampleNullableHeaderHttpApiGenerated": { "Type": "AWS::Serverless::Function", "Metadata": { "Tool": "Amazon.Lambda.Annotations", @@ -143,23 +169,45 @@ "TestExecutableServerlessApp" ] }, + "Environment": { + "Variables": { + "ANNOTATIONS_HANDLER": "NullableHeaderHttpApi" + } + }, "Events": { "RootGet": { - "Type": "Api", + "Type": "HttpApi", "Properties": { - "Path": "/okresponsewithheader/{x}", + "Path": "/nullableheaderhttpapi", "Method": "GET" } } - }, + } + } + }, + "TestServerlessAppParameterlessMethodWithResponseNoParameterWithResponseGenerated": { + "Type": "AWS::Serverless::Function", + "Metadata": { + "Tool": "Amazon.Lambda.Annotations" + }, + "Properties": { + "Runtime": "provided.al2", + "CodeUri": ".", + "MemorySize": 256, + "Timeout": 30, + "Policies": [ + "AWSLambdaBasicExecutionRole" + ], + "PackageType": "Zip", + "Handler": "TestExecutableServerlessApp", "Environment": { "Variables": { - "ANNOTATIONS_HANDLER": "OkResponseWithHeader" + "ANNOTATIONS_HANDLER": "NoParameterWithResponse" } } } }, - "TestServerlessAppCustomizeResponseExamplesOkResponseWithHeaderAsyncGenerated": { + "TestServerlessAppCustomizeResponseExamplesOkResponseWithHeaderGenerated": { "Type": "AWS::Serverless::Function", "Metadata": { "Tool": "Amazon.Lambda.Annotations", @@ -180,23 +228,23 @@ "TestExecutableServerlessApp" ] }, + "Environment": { + "Variables": { + "ANNOTATIONS_HANDLER": "OkResponseWithHeader" + } + }, "Events": { "RootGet": { "Type": "Api", "Properties": { - "Path": "/okresponsewithheaderasync/{x}", + "Path": "/okresponsewithheader/{x}", "Method": "GET" } } - }, - "Environment": { - "Variables": { - "ANNOTATIONS_HANDLER": "OkResponseWithHeaderAsync" - } } } }, - "TestServerlessAppCustomizeResponseExamplesNotFoundResponseWithHeaderV2Generated": { + "TestServerlessAppCustomizeResponseExamplesOkResponseWithHeaderAsyncGenerated": { "Type": "AWS::Serverless::Function", "Metadata": { "Tool": "Amazon.Lambda.Annotations", @@ -217,23 +265,23 @@ "TestExecutableServerlessApp" ] }, + "Environment": { + "Variables": { + "ANNOTATIONS_HANDLER": "OkResponseWithHeaderAsync" + } + }, "Events": { "RootGet": { - "Type": "HttpApi", + "Type": "Api", "Properties": { - "Path": "/notfoundwithheaderv2/{x}", + "Path": "/okresponsewithheaderasync/{x}", "Method": "GET" } } - }, - "Environment": { - "Variables": { - "ANNOTATIONS_HANDLER": "NotFoundResponseWithHeaderV2" - } } } }, - "TestServerlessAppCustomizeResponseExamplesNotFoundResponseWithHeaderV2AsyncGenerated": { + "TestServerlessAppCustomizeResponseExamplesNotFoundResponseWithHeaderV2Generated": { "Type": "AWS::Serverless::Function", "Metadata": { "Tool": "Amazon.Lambda.Annotations", @@ -254,23 +302,23 @@ "TestExecutableServerlessApp" ] }, + "Environment": { + "Variables": { + "ANNOTATIONS_HANDLER": "NotFoundResponseWithHeaderV2" + } + }, "Events": { "RootGet": { "Type": "HttpApi", "Properties": { - "Path": "/notfoundwithheaderv2async/{x}", + "Path": "/notfoundwithheaderv2/{x}", "Method": "GET" } } - }, - "Environment": { - "Variables": { - "ANNOTATIONS_HANDLER": "NotFoundResponseWithHeaderV2Async" - } } } }, - "TestServerlessAppCustomizeResponseExamplesNotFoundResponseWithHeaderV1Generated": { + "TestServerlessAppCustomizeResponseExamplesNotFoundResponseWithHeaderV2AsyncGenerated": { "Type": "AWS::Serverless::Function", "Metadata": { "Tool": "Amazon.Lambda.Annotations", @@ -291,24 +339,23 @@ "TestExecutableServerlessApp" ] }, + "Environment": { + "Variables": { + "ANNOTATIONS_HANDLER": "NotFoundResponseWithHeaderV2Async" + } + }, "Events": { "RootGet": { "Type": "HttpApi", "Properties": { - "Path": "/notfoundwithheaderv1/{x}", - "Method": "GET", - "PayloadFormatVersion": "1.0" + "Path": "/notfoundwithheaderv2async/{x}", + "Method": "GET" } } - }, - "Environment": { - "Variables": { - "ANNOTATIONS_HANDLER": "NotFoundResponseWithHeaderV1" - } } } }, - "TestServerlessAppCustomizeResponseExamplesNotFoundResponseWithHeaderV1AsyncGenerated": { + "TestServerlessAppCustomizeResponseExamplesNotFoundResponseWithHeaderV1Generated": { "Type": "AWS::Serverless::Function", "Metadata": { "Tool": "Amazon.Lambda.Annotations", @@ -329,24 +376,24 @@ "TestExecutableServerlessApp" ] }, + "Environment": { + "Variables": { + "ANNOTATIONS_HANDLER": "NotFoundResponseWithHeaderV1" + } + }, "Events": { "RootGet": { "Type": "HttpApi", "Properties": { - "Path": "/notfoundwithheaderv1async/{x}", + "Path": "/notfoundwithheaderv1/{x}", "Method": "GET", "PayloadFormatVersion": "1.0" } } - }, - "Environment": { - "Variables": { - "ANNOTATIONS_HANDLER": "NotFoundResponseWithHeaderV1Async" - } } } }, - "GreeterSayHello": { + "TestServerlessAppCustomizeResponseExamplesNotFoundResponseWithHeaderV1AsyncGenerated": { "Type": "AWS::Serverless::Function", "Metadata": { "Tool": "Amazon.Lambda.Annotations", @@ -355,7 +402,7 @@ ] }, "Properties": { - "MemorySize": 1024, + "MemorySize": 256, "Timeout": 30, "Policies": [ "AWSLambdaBasicExecutionRole" @@ -367,34 +414,31 @@ "TestExecutableServerlessApp" ] }, + "Environment": { + "Variables": { + "ANNOTATIONS_HANDLER": "NotFoundResponseWithHeaderV1Async" + } + }, "Events": { "RootGet": { "Type": "HttpApi", "Properties": { - "Path": "/Greeter/SayHello", + "Path": "/notfoundwithheaderv1async/{x}", "Method": "GET", "PayloadFormatVersion": "1.0" } } - }, - "Environment": { - "Variables": { - "ANNOTATIONS_HANDLER": "SayHello" - } } } }, - "GreeterSayHelloAsync": { + "TestServerlessAppTaskExampleTaskReturnGenerated": { "Type": "AWS::Serverless::Function", "Metadata": { - "Tool": "Amazon.Lambda.Annotations", - "SyncedEvents": [ - "RootGet" - ] + "Tool": "Amazon.Lambda.Annotations" }, "Properties": { "MemorySize": 256, - "Timeout": 50, + "Timeout": 30, "Policies": [ "AWSLambdaBasicExecutionRole" ], @@ -405,81 +449,53 @@ "TestExecutableServerlessApp" ] }, - "Events": { - "RootGet": { - "Type": "HttpApi", - "Properties": { - "Path": "/Greeter/SayHelloAsync", - "Method": "GET", - "PayloadFormatVersion": "1.0" - } - } - }, "Environment": { "Variables": { - "ANNOTATIONS_HANDLER": "SayHelloAsync" + "ANNOTATIONS_HANDLER": "TaskReturn" } } } }, - "ToUpper": { + "ToLower": { "Type": "AWS::Serverless::Function", "Metadata": { "Tool": "Amazon.Lambda.Annotations" }, "Properties": { + "Runtime": "provided.al2", + "CodeUri": ".", "MemorySize": 256, "Timeout": 30, "Policies": [ "AWSLambdaBasicExecutionRole" ], - "PackageType": "Image", - "ImageUri": ".", - "ImageConfig": { - "Command": [ - "TestExecutableServerlessApp" - ] - }, + "PackageType": "Zip", + "Handler": "TestExecutableServerlessApp", "Environment": { "Variables": { - "ANNOTATIONS_HANDLER": "ToUpper" + "ANNOTATIONS_HANDLER": "ToLower" } } } }, - "TestServerlessAppNullableReferenceTypeExampleNullableHeaderHttpApiGenerated": { + "TestServerlessAppParameterlessMethodsNoParameterGenerated": { "Type": "AWS::Serverless::Function", "Metadata": { - "Tool": "Amazon.Lambda.Annotations", - "SyncedEvents": [ - "RootGet" - ] + "Tool": "Amazon.Lambda.Annotations" }, "Properties": { + "Runtime": "provided.al2", + "CodeUri": ".", "MemorySize": 256, "Timeout": 30, "Policies": [ "AWSLambdaBasicExecutionRole" ], - "PackageType": "Image", - "ImageUri": ".", - "ImageConfig": { - "Command": [ - "TestExecutableServerlessApp" - ] - }, - "Events": { - "RootGet": { - "Type": "HttpApi", - "Properties": { - "Path": "/nullableheaderhttpapi", - "Method": "GET" - } - } - }, + "PackageType": "Zip", + "Handler": "TestExecutableServerlessApp", "Environment": { "Variables": { - "ANNOTATIONS_HANDLER": "NullableHeaderHttpApi" + "ANNOTATIONS_HANDLER": "NoParameter" } } } @@ -509,7 +525,7 @@ } } }, - "ToLower": { + "TestServerlessAppDynamicExampleDynamicReturnGenerated": { "Type": "AWS::Serverless::Function", "Metadata": { "Tool": "Amazon.Lambda.Annotations" @@ -520,57 +536,78 @@ "Policies": [ "AWSLambdaBasicExecutionRole" ], - "PackageType": "Zip", - "CodeUri": ".", - "Handler": "TestExecutableServerlessApp", + "PackageType": "Image", + "ImageUri": ".", + "ImageConfig": { + "Command": [ + "TestExecutableServerlessApp" + ] + }, "Environment": { "Variables": { - "ANNOTATIONS_HANDLER": "ToLower" + "ANNOTATIONS_HANDLER": "DynamicReturn" } - }, - "Runtime": "provided.al2" + } } }, - "TestServerlessAppParameterlessMethodsNoParameterGenerated": { + "TestServerlessAppDynamicExampleDynamicInputGenerated": { "Type": "AWS::Serverless::Function", "Metadata": { "Tool": "Amazon.Lambda.Annotations" }, "Properties": { - "Runtime": "provided.al2", - "CodeUri": ".", "MemorySize": 256, "Timeout": 30, "Policies": [ "AWSLambdaBasicExecutionRole" ], - "PackageType": "Zip", - "Handler": "TestExecutableServerlessApp", + "PackageType": "Image", + "ImageUri": ".", + "ImageConfig": { + "Command": [ + "TestExecutableServerlessApp" + ] + }, "Environment": { "Variables": { - "ANNOTATIONS_HANDLER": "NoParameter" + "ANNOTATIONS_HANDLER": "DynamicInput" } } } }, - "TestServerlessAppParameterlessMethodWithResponseNoParameterWithResponseGenerated": { + "TestExecutableServerlessAppSourceGenerationSerializationExampleGetPersonGenerated": { "Type": "AWS::Serverless::Function", "Metadata": { - "Tool": "Amazon.Lambda.Annotations" + "Tool": "Amazon.Lambda.Annotations", + "SyncedEvents": [ + "RootGet" + ] }, "Properties": { - "Runtime": "provided.al2", - "CodeUri": ".", "MemorySize": 256, "Timeout": 30, "Policies": [ "AWSLambdaBasicExecutionRole" ], - "PackageType": "Zip", - "Handler": "TestExecutableServerlessApp", + "PackageType": "Image", + "ImageUri": ".", + "ImageConfig": { + "Command": [ + "TestExecutableServerlessApp" + ] + }, "Environment": { "Variables": { - "ANNOTATIONS_HANDLER": "NoParameterWithResponse" + "ANNOTATIONS_HANDLER": "GetPerson" + } + }, + "Events": { + "RootGet": { + "Type": "Api", + "Properties": { + "Path": "/", + "Method": "GET" + } } } } diff --git a/Libraries/test/TestServerlessApp/serverless.template b/Libraries/test/TestServerlessApp/serverless.template index bfbf1a50a..bfc42b834 100644 --- a/Libraries/test/TestServerlessApp/serverless.template +++ b/Libraries/test/TestServerlessApp/serverless.template @@ -22,70 +22,6 @@ } }, "Resources": { - "TestServerlessAppComplexCalculatorAddGenerated": { - "Type": "AWS::Serverless::Function", - "Metadata": { - "Tool": "Amazon.Lambda.Annotations", - "SyncedEvents": [ - "RootPost" - ] - }, - "Properties": { - "MemorySize": 256, - "Timeout": 30, - "Policies": [ - "AWSLambdaBasicExecutionRole" - ], - "PackageType": "Image", - "ImageUri": ".", - "ImageConfig": { - "Command": [ - "TestServerlessApp::TestServerlessApp.ComplexCalculator_Add_Generated::Add" - ] - }, - "Events": { - "RootPost": { - "Type": "HttpApi", - "Properties": { - "Path": "/ComplexCalculator/Add", - "Method": "POST" - } - } - } - } - }, - "TestServerlessAppComplexCalculatorSubtractGenerated": { - "Type": "AWS::Serverless::Function", - "Metadata": { - "Tool": "Amazon.Lambda.Annotations", - "SyncedEvents": [ - "RootPost" - ] - }, - "Properties": { - "MemorySize": 256, - "Timeout": 30, - "Policies": [ - "AWSLambdaBasicExecutionRole" - ], - "PackageType": "Image", - "ImageUri": ".", - "ImageConfig": { - "Command": [ - "TestServerlessApp::TestServerlessApp.ComplexCalculator_Subtract_Generated::Subtract" - ] - }, - "Events": { - "RootPost": { - "Type": "HttpApi", - "Properties": { - "Path": "/ComplexCalculator/Subtract", - "Method": "POST" - } - } - } - } - }, "TestServerlessAppDynamicExampleDynamicReturnGenerated": { "Type": "AWS::Serverless::Function", "Metadata": { @@ -126,7 +62,7 @@ } } }, - "TestServerlessAppTaskExampleTaskReturnGenerated": { + "ToUpper": { "Type": "AWS::Serverless::Function", "Metadata": { "Tool": "Amazon.Lambda.Annotations" @@ -141,12 +77,12 @@ "ImageUri": ".", "ImageConfig": { "Command": [ - "TestServerlessApp::TestServerlessApp.TaskExample_TaskReturn_Generated::TaskReturn" + "TestServerlessApp::TestServerlessApp.Sub1.Functions_ToUpper_Generated::ToUpper" ] } } }, - "TestServerlessAppVoidExampleVoidReturnGenerated": { + "TestServerlessAppFromScratchNoSerializerAttributeReferenceToUpperGenerated": { "Type": "AWS::Serverless::Function", "Metadata": { "Tool": "Amazon.Lambda.Annotations" @@ -161,7 +97,7 @@ "ImageUri": ".", "ImageConfig": { "Command": [ - "TestServerlessApp::TestServerlessApp.VoidExample_VoidReturn_Generated::VoidReturn" + "TestServerlessApp::TestServerlessApp.FromScratch.NoSerializerAttributeReference_ToUpper_Generated::ToUpper" ] } } @@ -360,6 +296,26 @@ } } }, + "TestServerlessAppVoidExampleVoidReturnGenerated": { + "Type": "AWS::Serverless::Function", + "Metadata": { + "Tool": "Amazon.Lambda.Annotations" + }, + "Properties": { + "MemorySize": 256, + "Timeout": 30, + "Policies": [ + "AWSLambdaBasicExecutionRole" + ], + "PackageType": "Image", + "ImageUri": ".", + "ImageConfig": { + "Command": [ + "TestServerlessApp::TestServerlessApp.VoidExample_VoidReturn_Generated::VoidReturn" + ] + } + } + }, "GreeterSayHello": { "Type": "AWS::Serverless::Function", "Metadata": { @@ -426,12 +382,12 @@ } } }, - "SimpleCalculatorAdd": { + "TestServerlessAppComplexCalculatorAddGenerated": { "Type": "AWS::Serverless::Function", "Metadata": { "Tool": "Amazon.Lambda.Annotations", "SyncedEvents": [ - "RootGet" + "RootPost" ] }, "Properties": { @@ -444,21 +400,53 @@ "ImageUri": ".", "ImageConfig": { "Command": [ - "TestServerlessApp::TestServerlessApp.SimpleCalculator_Add_Generated::Add" + "TestServerlessApp::TestServerlessApp.ComplexCalculator_Add_Generated::Add" ] }, "Events": { - "RootGet": { - "Type": "Api", + "RootPost": { + "Type": "HttpApi", "Properties": { - "Path": "/SimpleCalculator/Add", - "Method": "GET" + "Path": "/ComplexCalculator/Add", + "Method": "POST" } } } } }, - "SimpleCalculatorSubtract": { + "TestServerlessAppComplexCalculatorSubtractGenerated": { + "Type": "AWS::Serverless::Function", + "Metadata": { + "Tool": "Amazon.Lambda.Annotations", + "SyncedEvents": [ + "RootPost" + ] + }, + "Properties": { + "MemorySize": 256, + "Timeout": 30, + "Policies": [ + "AWSLambdaBasicExecutionRole" + ], + "PackageType": "Image", + "ImageUri": ".", + "ImageConfig": { + "Command": [ + "TestServerlessApp::TestServerlessApp.ComplexCalculator_Subtract_Generated::Subtract" + ] + }, + "Events": { + "RootPost": { + "Type": "HttpApi", + "Properties": { + "Path": "/ComplexCalculator/Subtract", + "Method": "POST" + } + } + } + } + }, + "TestServerlessAppNullableReferenceTypeExampleNullableHeaderHttpApiGenerated": { "Type": "AWS::Serverless::Function", "Metadata": { "Tool": "Amazon.Lambda.Annotations", @@ -476,21 +464,21 @@ "ImageUri": ".", "ImageConfig": { "Command": [ - "TestServerlessApp::TestServerlessApp.SimpleCalculator_Subtract_Generated::Subtract" + "TestServerlessApp::TestServerlessApp.NullableReferenceTypeExample_NullableHeaderHttpApi_Generated::NullableHeaderHttpApi" ] }, "Events": { "RootGet": { - "Type": "Api", + "Type": "HttpApi", "Properties": { - "Path": "/SimpleCalculator/Subtract", + "Path": "/nullableheaderhttpapi", "Method": "GET" } } } } }, - "SimpleCalculatorMultiply": { + "SimpleCalculatorAdd": { "Type": "AWS::Serverless::Function", "Metadata": { "Tool": "Amazon.Lambda.Annotations", @@ -508,21 +496,21 @@ "ImageUri": ".", "ImageConfig": { "Command": [ - "TestServerlessApp::TestServerlessApp.SimpleCalculator_Multiply_Generated::Multiply" + "TestServerlessApp::TestServerlessApp.SimpleCalculator_Add_Generated::Add" ] }, "Events": { "RootGet": { "Type": "Api", "Properties": { - "Path": "/SimpleCalculator/Multiply/{x}/{y}", + "Path": "/SimpleCalculator/Add", "Method": "GET" } } } } }, - "SimpleCalculatorDivideAsync": { + "SimpleCalculatorSubtract": { "Type": "AWS::Serverless::Function", "Metadata": { "Tool": "Amazon.Lambda.Annotations", @@ -540,24 +528,27 @@ "ImageUri": ".", "ImageConfig": { "Command": [ - "TestServerlessApp::TestServerlessApp.SimpleCalculator_DivideAsync_Generated::DivideAsync" + "TestServerlessApp::TestServerlessApp.SimpleCalculator_Subtract_Generated::Subtract" ] }, "Events": { "RootGet": { "Type": "Api", "Properties": { - "Path": "/SimpleCalculator/DivideAsync/{x}/{y}", + "Path": "/SimpleCalculator/Subtract", "Method": "GET" } } } } }, - "PI": { + "SimpleCalculatorMultiply": { "Type": "AWS::Serverless::Function", "Metadata": { - "Tool": "Amazon.Lambda.Annotations" + "Tool": "Amazon.Lambda.Annotations", + "SyncedEvents": [ + "RootGet" + ] }, "Properties": { "MemorySize": 256, @@ -569,15 +560,27 @@ "ImageUri": ".", "ImageConfig": { "Command": [ - "TestServerlessApp::TestServerlessApp.SimpleCalculator_Pi_Generated::Pi" + "TestServerlessApp::TestServerlessApp.SimpleCalculator_Multiply_Generated::Multiply" ] + }, + "Events": { + "RootGet": { + "Type": "Api", + "Properties": { + "Path": "/SimpleCalculator/Multiply/{x}/{y}", + "Method": "GET" + } + } } } }, - "Random": { + "SimpleCalculatorDivideAsync": { "Type": "AWS::Serverless::Function", "Metadata": { - "Tool": "Amazon.Lambda.Annotations" + "Tool": "Amazon.Lambda.Annotations", + "SyncedEvents": [ + "RootGet" + ] }, "Properties": { "MemorySize": 256, @@ -589,12 +592,21 @@ "ImageUri": ".", "ImageConfig": { "Command": [ - "TestServerlessApp::TestServerlessApp.SimpleCalculator_Random_Generated::Random" + "TestServerlessApp::TestServerlessApp.SimpleCalculator_DivideAsync_Generated::DivideAsync" ] + }, + "Events": { + "RootGet": { + "Type": "Api", + "Properties": { + "Path": "/SimpleCalculator/DivideAsync/{x}/{y}", + "Method": "GET" + } + } } } }, - "Randoms": { + "PI": { "Type": "AWS::Serverless::Function", "Metadata": { "Tool": "Amazon.Lambda.Annotations" @@ -609,18 +621,15 @@ "ImageUri": ".", "ImageConfig": { "Command": [ - "TestServerlessApp::TestServerlessApp.SimpleCalculator_Randoms_Generated::Randoms" + "TestServerlessApp::TestServerlessApp.SimpleCalculator_Pi_Generated::Pi" ] } } }, - "TestServerlessAppNullableReferenceTypeExampleNullableHeaderHttpApiGenerated": { + "Random": { "Type": "AWS::Serverless::Function", "Metadata": { - "Tool": "Amazon.Lambda.Annotations", - "SyncedEvents": [ - "RootGet" - ] + "Tool": "Amazon.Lambda.Annotations" }, "Properties": { "MemorySize": 256, @@ -632,27 +641,15 @@ "ImageUri": ".", "ImageConfig": { "Command": [ - "TestServerlessApp::TestServerlessApp.NullableReferenceTypeExample_NullableHeaderHttpApi_Generated::NullableHeaderHttpApi" + "TestServerlessApp::TestServerlessApp.SimpleCalculator_Random_Generated::Random" ] - }, - "Events": { - "RootGet": { - "Type": "HttpApi", - "Properties": { - "Path": "/nullableheaderhttpapi", - "Method": "GET" - } - } } } }, - "TestServerlessAppFromScratchNoApiGatewayEventsReferenceToUpperGenerated": { + "Randoms": { "Type": "AWS::Serverless::Function", "Metadata": { - "Tool": "Amazon.Lambda.Annotations", - "SyncedEvents": [ - "RootGet" - ] + "Tool": "Amazon.Lambda.Annotations" }, "Properties": { "MemorySize": 256, @@ -661,24 +658,15 @@ "AWSLambdaBasicExecutionRole" ], "PackageType": "Image", - "Events": { - "RootGet": { - "Type": "HttpApi", - "Properties": { - "Path": "/{text}", - "Method": "GET" - } - } - }, "ImageUri": ".", "ImageConfig": { "Command": [ - "TestServerlessApp::TestServerlessApp.FromScratch.NoApiGatewayEventsReference_ToUpper_Generated::ToUpper" + "TestServerlessApp::TestServerlessApp.SimpleCalculator_Randoms_Generated::Randoms" ] } } }, - "TestServerlessAppFromScratchNoSerializerAttributeReferenceToUpperGenerated": { + "TestServerlessAppIntrinsicExampleHasIntrinsicGenerated": { "Type": "AWS::Serverless::Function", "Metadata": { "Tool": "Amazon.Lambda.Annotations" @@ -690,19 +678,21 @@ "AWSLambdaBasicExecutionRole" ], "PackageType": "Image", - "Events": {}, "ImageUri": ".", "ImageConfig": { "Command": [ - "TestServerlessApp::TestServerlessApp.FromScratch.NoSerializerAttributeReference_ToUpper_Generated::ToUpper" + "TestServerlessApp::TestServerlessApp.IntrinsicExample_HasIntrinsic_Generated::HasIntrinsic" ] } } }, - "TestServerlessAppIntrinsicExampleHasIntrinsicGenerated": { + "TestServerlessAppFromScratchNoApiGatewayEventsReferenceToUpperGenerated": { "Type": "AWS::Serverless::Function", "Metadata": { - "Tool": "Amazon.Lambda.Annotations" + "Tool": "Amazon.Lambda.Annotations", + "SyncedEvents": [ + "RootGet" + ] }, "Properties": { "MemorySize": 256, @@ -714,12 +704,21 @@ "ImageUri": ".", "ImageConfig": { "Command": [ - "TestServerlessApp::TestServerlessApp.IntrinsicExample_HasIntrinsic_Generated::HasIntrinsic" + "TestServerlessApp::TestServerlessApp.FromScratch.NoApiGatewayEventsReference_ToUpper_Generated::ToUpper" ] + }, + "Events": { + "RootGet": { + "Type": "HttpApi", + "Properties": { + "Path": "/{text}", + "Method": "GET" + } + } } } }, - "ToUpper": { + "TestServerlessAppTaskExampleTaskReturnGenerated": { "Type": "AWS::Serverless::Function", "Metadata": { "Tool": "Amazon.Lambda.Annotations" @@ -734,7 +733,7 @@ "ImageUri": ".", "ImageConfig": { "Command": [ - "TestServerlessApp::TestServerlessApp.Sub1.Functions_ToUpper_Generated::ToUpper" + "TestServerlessApp::TestServerlessApp.TaskExample_TaskReturn_Generated::TaskReturn" ] } }