Skip to content

Commit 46d30a2

Browse files
committed
Bit more work on AllAttributes
1 parent e4ceae7 commit 46d30a2

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

GoLive.Generator.ApiClientGenerator/ActionRoute.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ public class ActionRoute(string Name, string FullMethodName, HttpMethod Method,
1818
public List<ParameterMapping> Body { get; init; } = Body;
1919
public string XmlComments { get; init; } = XmlComments;
2020
public string CalculatedURL { get; set; }
21-
public string[] AllAttributes { get; set; }
21+
public string[] AllAttributes { get; set; } = AllAttributes;
22+
2223
public void Deconstruct(out string Name, out string FullMethodName, out HttpMethod Method, out string Route, out bool RouteSetByAttributes, out string? ReturnTypeName, out bool ReturnTypeStruct, out bool hasCustomFormatter, out List<ParameterMapping> Mapping, out List<ParameterMapping> Body, out string XmlComments, out string[] AllAttributes)
2324
{
2425
Name = this.Name;

GoLive.Generator.ApiClientGenerator/Scanner.cs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,27 @@ public static ControllerRoute ConvertToRoute(SemanticModel model, INamedTypeSymb
5353

5454
var xmlComments = classSymbol.GetDocumentationCommentXml();
5555

56-
var allAttributes = classSymbol.GetAttributes().Select(r => r.AttributeClass.ToDisplayString());
56+
var allAttributes = GetAllAttributes(classSymbol);
5757

5858
return new ControllerRoute(name, area, route, actionMethods.ToArray(), xmlComments, allAttributes.ToArray());
5959
}
6060

61+
private static IEnumerable<string> GetAllAttributes(INamedTypeSymbol classSymbol)
62+
{
63+
var attributes = new HashSet<string>();
64+
65+
while (classSymbol != null && !classSymbol.ToDisplayString().StartsWith(ASPNETCORE_NAMESPACE, StringComparison.InvariantCultureIgnoreCase))
66+
{
67+
foreach (var attribute in classSymbol.GetAttributes())
68+
{
69+
attributes.Add(attribute.AttributeClass.ToDisplayString());
70+
}
71+
classSymbol = classSymbol.BaseType;
72+
}
73+
74+
return attributes;
75+
}
76+
6177
private static IEnumerable<ActionRoute> ScanForActionMethods(SemanticModel model, INamedTypeSymbol classSymbol)
6278
{
6379
foreach (var member in classSymbol.GetMembers())
@@ -180,7 +196,7 @@ private static IEnumerable<ActionRoute> ScanForActionMethods(SemanticModel model
180196

181197
var fullMethodName = member.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat.WithGlobalNamespaceStyle(SymbolDisplayGlobalNamespaceStyle.Omitted).WithMemberOptions(SymbolDisplayMemberOptions.IncludeContainingType | SymbolDisplayMemberOptions.IncludeType)).Split(' ')[1];
182198

183-
var allAttributes = methodSymbol.GetAttributes().Select(r=>r.AttributeClass.ToDisplayString()).ToArray();
199+
var allAttributes = methodSymbol.GetAttributes().Select(r=>r.AttributeClass.ToDisplayString()).Distinct().ToArray();
184200

185201
yield return new ActionRoute(name, fullMethodName, method, route, routeSetByAttr,
186202
returnType?.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat), returnType?.IsReferenceType != true,

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,4 +114,5 @@ If you don't want XML comments enabled, set the config variable of "DisableXMLCo
114114
- Version 3.0 - changed the way the API generation works (uses a central route template as opposed to hard coded), changed json settings file (not backwards compatible but not that different)
115115
- 3.0.46 - Small issue where _Url's were getting erroneous querystring parameters that were part of URL.
116116
- 3.0.47 - Remove trailing / from URLs as it will break optional parameters, might need to think about a better way to do this.
117-
- 3.0.49 - Expose AllAttributes property on Classes / Methods for external processing
117+
- 3.0.49 - Expose AllAttributes property on Classes / Methods for external processing
118+
- 3.0.50 - Added a bit of logic to AllAttributes and added missing class processing

0 commit comments

Comments
 (0)