Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Use the ILambdaSerializer to serialize the response body when returning an IHttpResult and generate documentation comments for public members #1748

Merged
merged 2 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,6 @@ private bool HasSerializerAttribute(GeneratorExecutionContext context, IMethodSy
private LambdaSerializerInfo GetSerializerInfoAttribute(GeneratorExecutionContext context, IMethodSymbol methodModel)
{
var serializerString = DEFAULT_LAMBDA_SERIALIZER;
string serializerJsonContext = null;

ISymbol symbol = null;

Expand All @@ -377,24 +376,19 @@ private LambdaSerializerInfo GetSerializerInfoAttribute(GeneratorExecutionContex
// Else return the default serializer.
else
{
return new LambdaSerializerInfo(serializerString, serializerJsonContext);
return new LambdaSerializerInfo(serializerString);
}

var attribute = symbol.GetAttributes().FirstOrDefault(attr => attr.AttributeClass.Name == TypeFullNames.LambdaSerializerAttributeWithoutNamespace);

var serializerValue = attribute.ConstructorArguments.FirstOrDefault(kvp => kvp.Type.Name == nameof(Type)).Value;

if(serializerValue is INamedTypeSymbol typeSymbol && typeSymbol.Name.Contains("SourceGeneratorLambdaJsonSerializer") && typeSymbol.TypeArguments.Length == 1)
{
serializerJsonContext = typeSymbol.TypeArguments[0].ToString();
}

if (serializerValue != null)
{
serializerString = serializerValue.ToString();
}

return new LambdaSerializerInfo(serializerString, serializerJsonContext);
return new LambdaSerializerInfo(serializerString);
}

public void Initialize(GeneratorInitializationContext context)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,8 @@ private static IList<ParameterModel> BuildParameters(IMethodSymbol lambdaMethodS
Type = new TypeModel
{
FullName = TypeFullNames.ILambdaContext
}
},
Documentation = "The ILambdaContext that provides methods for logging and describing the Lambda environment."
};

if (lambdaMethodSymbol.HasAttribute(context, TypeFullNames.RestApiAttribute))
Expand All @@ -158,7 +159,8 @@ private static IList<ParameterModel> BuildParameters(IMethodSymbol lambdaMethodS
var requestParameter = new ParameterModel
{
Name = "__request__",
Type = type
Type = type,
Documentation = "The API Gateway request object that will be processed by the Lambda function handler."
};
parameters.Add(requestParameter);
parameters.Add(contextParameter);
Expand Down Expand Up @@ -188,7 +190,8 @@ private static IList<ParameterModel> BuildParameters(IMethodSymbol lambdaMethodS
var requestParameter = new ParameterModel
{
Name = "__request__",
Type = type
Type = type,
Documentation = "The API Gateway request object that will be processed by the Lambda function handler."
};
parameters.Add(requestParameter);
parameters.Add(contextParameter);
Expand All @@ -208,6 +211,11 @@ private static IList<ParameterModel> BuildParameters(IMethodSymbol lambdaMethodS
else if(param.Type.FullName == TypeFullNames.ILambdaContext)
{
param.Name = "__context__";
param.Documentation = "The ILambdaContext that provides methods for logging and describing the Lambda environment.";
}
else
{
param.Documentation = "The request object that will be processed by the Lambda function handler.";
}

parameters.Add(param);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class LambdaFunctionModel : ILambdaFunctionSerializable
/// Gets or sets fully qualified name of the serializer used for serialization or deserialization.
/// </summary>
public LambdaSerializerInfo SerializerInfo { get; set; } =
new LambdaSerializerInfo("Amazon.Lambda.Serialization.SystemTextJson.DefaultLambdaJsonSerializer", null);
new LambdaSerializerInfo("Amazon.Lambda.Serialization.SystemTextJson.DefaultLambdaJsonSerializer");

/// <summary>
/// Gets or sets if the output is an executable.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,14 @@ public class LambdaSerializerInfo
/// </summary>
/// <param name="serializerName"></param>
/// <param name="serializerJsonContextName"></param>
public LambdaSerializerInfo(string serializerName, string serializerJsonContextName)
public LambdaSerializerInfo(string serializerName)
{
SerializerName = serializerName;
SerializerJsonContextName = serializerJsonContextName;
}

/// <summary>
/// The full name of the type registered as the ILambdaSerializer.
/// </summary>
public string SerializerName { get; }

/// <summary>
/// The full name of the type used as the generic parameter of the SourceGeneratorLambdaJsonSerializer.
/// </summary>
public string SerializerJsonContextName { get; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,10 @@ public class ParameterModel
/// an empty list.
/// </summary>
public IList<AttributeModel> Attributes { get; set; } = new List<AttributeModel>();

/// <summary>
/// Gets or sets the documentation of parameter.
/// </summary>
public string Documentation { get; set; }
}
}
Loading
Loading