Skip to content

Breaking Change: Move all APIGateway attributes to a their own namespace #1260

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

Merged
merged 1 commit into from
Aug 2, 2022
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
@@ -1,4 +1,5 @@
using System;
using Amazon.Lambda.Annotations.APIGateway;
using Microsoft.CodeAnalysis;

namespace Amazon.Lambda.Annotations.SourceGenerator.Models.Attributes
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Amazon.Lambda.Annotations.APIGateway;
using Microsoft.CodeAnalysis;

namespace Amazon.Lambda.Annotations.SourceGenerator.Models.Attributes
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Amazon.Lambda.Annotations.APIGateway;
using Microsoft.CodeAnalysis;

namespace Amazon.Lambda.Annotations.SourceGenerator.Models.Attributes
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Amazon.Lambda.Annotations.APIGateway;
using Microsoft.CodeAnalysis;

namespace Amazon.Lambda.Annotations.SourceGenerator.Models.Attributes
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Linq;
using Amazon.Lambda.Annotations.APIGateway;
using Microsoft.CodeAnalysis;

namespace Amazon.Lambda.Annotations.SourceGenerator.Models.Attributes
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using Amazon.Lambda.Annotations.APIGateway;
using Microsoft.CodeAnalysis;

namespace Amazon.Lambda.Annotations.SourceGenerator.Models.Attributes
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Amazon.Lambda.Annotations.APIGateway;
using System;
using System.Collections.Generic;
using System.Linq;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Amazon.Lambda.Annotations;
using Amazon.Lambda.Annotations.APIGateway;
using Amazon.Lambda.Annotations.SourceGenerator.Extensions;
using Microsoft.CodeAnalysis;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,8 @@ public virtual string TransformText()

return p.Name;
}));
var restApiAttribute = _model.LambdaMethod.Attributes.FirstOrDefault(att => att.Type.FullName == TypeFullNames.RestApiAttribute) as AttributeModel<RestApiAttribute>;
var httpApiAttribute = _model.LambdaMethod.Attributes.FirstOrDefault(att => att.Type.FullName == TypeFullNames.HttpApiAttribute) as AttributeModel<HttpApiAttribute>;
var restApiAttribute = _model.LambdaMethod.Attributes.FirstOrDefault(att => att.Type.FullName == TypeFullNames.RestApiAttribute) as AttributeModel<Amazon.Lambda.Annotations.APIGateway.RestApiAttribute>;
var httpApiAttribute = _model.LambdaMethod.Attributes.FirstOrDefault(att => att.Type.FullName == TypeFullNames.HttpApiAttribute) as AttributeModel<Amazon.Lambda.Annotations.APIGateway.HttpApiAttribute>;

if (restApiAttribute != null && httpApiAttribute != null)
{
Expand Down Expand Up @@ -326,7 +326,7 @@ public virtual string TransformText()
}
else if (parameter.Attributes.Any(att => att.Type.FullName == TypeFullNames.FromQueryAttribute))
{
var fromQueryAttribute = parameter.Attributes.First(att => att.Type.FullName == TypeFullNames.FromQueryAttribute) as AttributeModel<FromQueryAttribute>;
var fromQueryAttribute = parameter.Attributes.First(att => att.Type.FullName == TypeFullNames.FromQueryAttribute) as AttributeModel<Amazon.Lambda.Annotations.APIGateway.FromQueryAttribute>;

// Use parameter name as key, if Name has not specified explicitly in the attribute definition.
var parameterKey = fromQueryAttribute?.Data?.Name ?? parameter.Name;
Expand Down Expand Up @@ -362,14 +362,14 @@ public virtual string TransformText()
// Therefore, it is required to split the string to convert to an enumerable
// and convert individual item to target data type.
var commaSplit = "";
if (httpApiAttribute?.Data.Version == HttpApiVersion.V2)
if (httpApiAttribute?.Data.Version == Amazon.Lambda.Annotations.APIGateway.HttpApiVersion.V2)
{
commaSplit = @".Split("","")";
}

// HTTP API V1 and Rest API, multiple values for the same parameter are provided
// dedicated dictionary of string key and list value.
if (restApiAttribute != null || httpApiAttribute?.Data.Version == HttpApiVersion.V1)
if (restApiAttribute != null || httpApiAttribute?.Data.Version == Amazon.Lambda.Annotations.APIGateway.HttpApiVersion.V1)
{
queryStringParameters = "MultiValueQueryStringParameters";
}
Expand Down Expand Up @@ -553,7 +553,7 @@ public virtual string TransformText()
{
var fromHeaderAttribute =
parameter.Attributes.First(att => att.Type.FullName == TypeFullNames.FromHeaderAttribute) as
AttributeModel<FromHeaderAttribute>;
AttributeModel<Amazon.Lambda.Annotations.APIGateway.FromHeaderAttribute>;

// Use parameter name as key, if Name has not specified explicitly in the attribute definition.
var headerKey = fromHeaderAttribute?.Data?.Name ?? parameter.Name;
Expand Down Expand Up @@ -589,14 +589,14 @@ public virtual string TransformText()
// Therefore, it is required to split the string to convert to an enumerable
// and convert individual item to target data type.
var commaSplit = "";
if (httpApiAttribute?.Data.Version == HttpApiVersion.V2)
if (httpApiAttribute?.Data.Version == Amazon.Lambda.Annotations.APIGateway.HttpApiVersion.V2)
{
commaSplit = @".Split("","")";
}

// HTTP API V1 and Rest API, multiple values for the same header are provided
// dedicated dictionary of string key and list value.
if (restApiAttribute != null || httpApiAttribute?.Data.Version == HttpApiVersion.V1)
if (restApiAttribute != null || httpApiAttribute?.Data.Version == Amazon.Lambda.Annotations.APIGateway.HttpApiVersion.V1)
{
headers = "MultiValueHeaders";
}
Expand Down Expand Up @@ -847,7 +847,7 @@ public virtual string TransformText()
}
else if (parameter.Attributes.Any(att => att.Type.FullName == TypeFullNames.FromRouteAttribute) || routeParameters.Contains(parameter.Name))
{
var fromRouteAttribute = parameter.Attributes?.FirstOrDefault(att => att.Type.FullName == TypeFullNames.FromRouteAttribute) as AttributeModel<FromRouteAttribute>;
var fromRouteAttribute = parameter.Attributes?.FirstOrDefault(att => att.Type.FullName == TypeFullNames.FromRouteAttribute) as AttributeModel<Amazon.Lambda.Annotations.APIGateway.FromRouteAttribute>;

// Use parameter name as key, if Name has not specified explicitly in the attribute definition.
var routeKey = fromRouteAttribute?.Data?.Name ?? parameter.Name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ namespace <#= _model.LambdaMethod.ContainingNamespace #>

return p.Name;
}));
var restApiAttribute = _model.LambdaMethod.Attributes.FirstOrDefault(att => att.Type.FullName == TypeFullNames.RestApiAttribute) as AttributeModel<RestApiAttribute>;
var httpApiAttribute = _model.LambdaMethod.Attributes.FirstOrDefault(att => att.Type.FullName == TypeFullNames.HttpApiAttribute) as AttributeModel<HttpApiAttribute>;
var restApiAttribute = _model.LambdaMethod.Attributes.FirstOrDefault(att => att.Type.FullName == TypeFullNames.RestApiAttribute) as AttributeModel<Amazon.Lambda.Annotations.APIGateway.RestApiAttribute>;
var httpApiAttribute = _model.LambdaMethod.Attributes.FirstOrDefault(att => att.Type.FullName == TypeFullNames.HttpApiAttribute) as AttributeModel<Amazon.Lambda.Annotations.APIGateway.HttpApiAttribute>;

if (restApiAttribute != null && httpApiAttribute != null)
{
Expand Down Expand Up @@ -136,7 +136,7 @@ namespace <#= _model.LambdaMethod.ContainingNamespace #>
}
else if (parameter.Attributes.Any(att => att.Type.FullName == TypeFullNames.FromQueryAttribute))
{
var fromQueryAttribute = parameter.Attributes.First(att => att.Type.FullName == TypeFullNames.FromQueryAttribute) as AttributeModel<FromQueryAttribute>;
var fromQueryAttribute = parameter.Attributes.First(att => att.Type.FullName == TypeFullNames.FromQueryAttribute) as AttributeModel<Amazon.Lambda.Annotations.APIGateway.FromQueryAttribute>;

// Use parameter name as key, if Name has not specified explicitly in the attribute definition.
var parameterKey = fromQueryAttribute?.Data?.Name ?? parameter.Name;
Expand All @@ -153,14 +153,14 @@ namespace <#= _model.LambdaMethod.ContainingNamespace #>
// Therefore, it is required to split the string to convert to an enumerable
// and convert individual item to target data type.
var commaSplit = "";
if (httpApiAttribute?.Data.Version == HttpApiVersion.V2)
if (httpApiAttribute?.Data.Version == Amazon.Lambda.Annotations.APIGateway.HttpApiVersion.V2)
{
commaSplit = @".Split("","")";
}

// HTTP API V1 and Rest API, multiple values for the same parameter are provided
// dedicated dictionary of string key and list value.
if (restApiAttribute != null || httpApiAttribute?.Data.Version == HttpApiVersion.V1)
if (restApiAttribute != null || httpApiAttribute?.Data.Version == Amazon.Lambda.Annotations.APIGateway.HttpApiVersion.V1)
{
queryStringParameters = "MultiValueQueryStringParameters";
}
Expand Down Expand Up @@ -217,7 +217,7 @@ namespace <#= _model.LambdaMethod.ContainingNamespace #>
{
var fromHeaderAttribute =
parameter.Attributes.First(att => att.Type.FullName == TypeFullNames.FromHeaderAttribute) as
AttributeModel<FromHeaderAttribute>;
AttributeModel<Amazon.Lambda.Annotations.APIGateway.FromHeaderAttribute>;

// Use parameter name as key, if Name has not specified explicitly in the attribute definition.
var headerKey = fromHeaderAttribute?.Data?.Name ?? parameter.Name;
Expand All @@ -234,14 +234,14 @@ namespace <#= _model.LambdaMethod.ContainingNamespace #>
// Therefore, it is required to split the string to convert to an enumerable
// and convert individual item to target data type.
var commaSplit = "";
if (httpApiAttribute?.Data.Version == HttpApiVersion.V2)
if (httpApiAttribute?.Data.Version == Amazon.Lambda.Annotations.APIGateway.HttpApiVersion.V2)
{
commaSplit = @".Split("","")";
}

// HTTP API V1 and Rest API, multiple values for the same header are provided
// dedicated dictionary of string key and list value.
if (restApiAttribute != null || httpApiAttribute?.Data.Version == HttpApiVersion.V1)
if (restApiAttribute != null || httpApiAttribute?.Data.Version == Amazon.Lambda.Annotations.APIGateway.HttpApiVersion.V1)
{
headers = "MultiValueHeaders";
}
Expand Down Expand Up @@ -321,7 +321,7 @@ namespace <#= _model.LambdaMethod.ContainingNamespace #>
}
else if (parameter.Attributes.Any(att => att.Type.FullName == TypeFullNames.FromRouteAttribute) || routeParameters.Contains(parameter.Name))
{
var fromRouteAttribute = parameter.Attributes?.FirstOrDefault(att => att.Type.FullName == TypeFullNames.FromRouteAttribute) as AttributeModel<FromRouteAttribute>;
var fromRouteAttribute = parameter.Attributes?.FirstOrDefault(att => att.Type.FullName == TypeFullNames.FromRouteAttribute) as AttributeModel<Amazon.Lambda.Annotations.APIGateway.FromRouteAttribute>;

// Use parameter name as key, if Name has not specified explicitly in the attribute definition.
var routeKey = fromRouteAttribute?.Data?.Name ?? parameter.Name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,27 @@ namespace Amazon.Lambda.Annotations.SourceGenerator
/// </summary>
public static class TypeFullNames
{
public const string RestApiAttribute = "Amazon.Lambda.Annotations.RestApiAttribute";
public const string HttpApiAttribute = "Amazon.Lambda.Annotations.HttpApiAttribute";
public const string IEnumerable = "System.Collections.IEnumerable";
public const string Task1 = "System.Threading.Tasks.Task`1";
public const string Task = "System.Threading.Tasks.Task";
public const string MemoryStream = "System.IO.MemoryStream";

public const string ILambdaContext = "Amazon.Lambda.Core.ILambdaContext";
public const string APIGatewayProxyRequest = "Amazon.Lambda.APIGatewayEvents.APIGatewayProxyRequest";
public const string APIGatewayProxyResponse = "Amazon.Lambda.APIGatewayEvents.APIGatewayProxyResponse";
public const string APIGatewayHttpApiV2ProxyRequest = "Amazon.Lambda.APIGatewayEvents.APIGatewayHttpApiV2ProxyRequest";
public const string APIGatewayHttpApiV2ProxyResponse = "Amazon.Lambda.APIGatewayEvents.APIGatewayHttpApiV2ProxyResponse";
public const string MemoryStream = "System.IO.MemoryStream";
public const string HttpApiVersion = "Amazon.Lambda.Annotations.HttpApiVersion";

public const string LambdaFunctionAttribute = "Amazon.Lambda.Annotations.LambdaFunctionAttribute";
public const string FromQueryAttribute = "Amazon.Lambda.Annotations.FromQueryAttribute";
public const string FromHeaderAttribute = "Amazon.Lambda.Annotations.FromHeaderAttribute";
public const string FromBodyAttribute = "Amazon.Lambda.Annotations.FromBodyAttribute";
public const string FromRouteAttribute = "Amazon.Lambda.Annotations.FromRouteAttribute";
public const string FromServiceAttribute = "Amazon.Lambda.Annotations.FromServicesAttribute";
public const string ILambdaContext = "Amazon.Lambda.Core.ILambdaContext";
public const string IEnumerable = "System.Collections.IEnumerable";
public const string Task1 = "System.Threading.Tasks.Task`1";
public const string Task = "System.Threading.Tasks.Task";

public const string HttpApiVersion = "Amazon.Lambda.Annotations.APIGateway.HttpApiVersion";
public const string RestApiAttribute = "Amazon.Lambda.Annotations.APIGateway.RestApiAttribute";
public const string HttpApiAttribute = "Amazon.Lambda.Annotations.APIGateway.HttpApiAttribute";
public const string FromQueryAttribute = "Amazon.Lambda.Annotations.APIGateway.FromQueryAttribute";
public const string FromHeaderAttribute = "Amazon.Lambda.Annotations.APIGateway.FromHeaderAttribute";
public const string FromBodyAttribute = "Amazon.Lambda.Annotations.APIGateway.FromBodyAttribute";
public const string FromRouteAttribute = "Amazon.Lambda.Annotations.APIGateway.FromRouteAttribute";

public static HashSet<string> Requests = new HashSet<string>
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Amazon.Lambda.Annotations.APIGateway;
using Amazon.Lambda.Annotations.SourceGenerator.Models;
using Amazon.Lambda.Annotations.SourceGenerator.Models.Attributes;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using Amazon.Lambda.Annotations.APIGateway;
using Amazon.Lambda.Annotations.SourceGenerator.Diagnostics;
using Amazon.Lambda.Annotations.SourceGenerator.FileIO;
using Amazon.Lambda.Annotations.SourceGenerator.Models;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;

namespace Amazon.Lambda.Annotations
namespace Amazon.Lambda.Annotations.APIGateway
{
[AttributeUsage(AttributeTargets.Parameter)]
public class FromBodyAttribute : Attribute
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;

namespace Amazon.Lambda.Annotations
namespace Amazon.Lambda.Annotations.APIGateway
{
[AttributeUsage(AttributeTargets.Parameter)]
public class FromHeaderAttribute : Attribute, INamedAttribute
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;

namespace Amazon.Lambda.Annotations
namespace Amazon.Lambda.Annotations.APIGateway
{
[AttributeUsage(AttributeTargets.Parameter)]
public class FromQueryAttribute : Attribute, INamedAttribute
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;

namespace Amazon.Lambda.Annotations
namespace Amazon.Lambda.Annotations.APIGateway
{
[AttributeUsage(AttributeTargets.Parameter)]
public class FromRouteAttribute : Attribute, INamedAttribute
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
using System;

namespace Amazon.Lambda.Annotations
namespace Amazon.Lambda.Annotations.APIGateway
{
[AttributeUsage(AttributeTargets.Method)]
public class HttpApiAttribute : Attribute
{
public HttpApiVersion Version { get; set; } = HttpApiVersion.V2;
public string Template { get; set; }
public string Template { get; set; }
public LambdaHttpMethod Method { get; set; }

public HttpApiAttribute(LambdaHttpMethod method, string template)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Amazon.Lambda.Annotations
namespace Amazon.Lambda.Annotations.APIGateway
{
public enum HttpApiVersion
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Amazon.Lambda.Annotations
namespace Amazon.Lambda.Annotations.APIGateway
{
public enum LambdaHttpMethod
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using System;

namespace Amazon.Lambda.Annotations
namespace Amazon.Lambda.Annotations.APIGateway
{
[AttributeUsage(AttributeTargets.Method)]
public class RestApiAttribute : Attribute
{
public string Template { get; set; }
public string Template { get; set; }
public LambdaHttpMethod Method { get; set; }

public RestApiAttribute(LambdaHttpMethod method, string template)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Immutable;
using Amazon.Lambda.Annotations.APIGateway;
using Amazon.Lambda.APIGatewayEvents;
using Amazon.Lambda.Core;
using Amazon.Lambda.Serialization.SystemTextJson;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using Amazon.Lambda.Annotations.APIGateway;
using Amazon.Lambda.Annotations.SourceGenerator;
using Amazon.Lambda.Annotations.SourceGenerator.Models;
using Amazon.Lambda.Annotations.SourceGenerator.Models.Attributes;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using Amazon.Lambda.Annotations.APIGateway;
using Amazon.Lambda.Annotations.SourceGenerator.Diagnostics;
using Amazon.Lambda.Annotations.SourceGenerator.FileIO;
using Amazon.Lambda.Annotations.SourceGenerator.Models;
Expand Down
1 change: 1 addition & 0 deletions Libraries/test/TestServerlessApp/ComplexCalculator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Text.Json;
using System.Threading;
using Amazon.Lambda.Annotations;
using Amazon.Lambda.Annotations.APIGateway;
using Amazon.Lambda.APIGatewayEvents;
using Amazon.Lambda.Core;

Expand Down
1 change: 1 addition & 0 deletions Libraries/test/TestServerlessApp/Greeter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Text.Json;
using System.Threading.Tasks;
using Amazon.Lambda.Annotations;
using Amazon.Lambda.Annotations.APIGateway;
using Amazon.Lambda.APIGatewayEvents;
using Amazon.Lambda.Core;

Expand Down
1 change: 1 addition & 0 deletions Libraries/test/TestServerlessApp/SimpleCalculator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Amazon.Lambda.Core;
using Amazon.Lambda.APIGatewayEvents;
using Amazon.Lambda.Annotations;
using Amazon.Lambda.Annotations.APIGateway;
using TestServerlessApp.Services;

// Assembly attribute to enable the Lambda function's JSON input to be converted into a .NET class.
Expand Down