Skip to content

Commit

Permalink
Include API route minimum role in route response
Browse files Browse the repository at this point in the history
  • Loading branch information
jvyden committed Nov 8, 2023
1 parent 2a3219d commit 90acc4e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
10 changes: 10 additions & 0 deletions Refresh.GameServer/Documentation/RefreshDocumentationGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Bunkum.Core.Endpoints;
using Bunkum.Core.Extensions;
using Refresh.GameServer.Endpoints;
using Refresh.GameServer.Types.Roles;

namespace Refresh.GameServer.Documentation;

Expand All @@ -25,5 +26,14 @@ protected override void DocumentRouteHook(MethodInfo method, Route route)

AuthenticationAttribute? authentication = method.GetCustomAttribute<AuthenticationAttribute>();
route.AuthenticationRequired = authentication == null || authentication.Required;

if (route.AuthenticationRequired)
{
MinimumRoleAttribute? roleAttribute = method.GetCustomAttribute<MinimumRoleAttribute>();
if (roleAttribute != null)
{
route.ExtraProperties["minimumRole"] = roleAttribute.MinimumRole;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using AttribDoc;
using Refresh.GameServer.Types.Roles;

namespace Refresh.GameServer.Endpoints.ApiV3.DataTypes.Response;

Expand All @@ -9,6 +10,7 @@ public class ApiRouteResponse : IApiResponse, IDataConvertableFrom<ApiRouteRespo
public required string RouteUri { get; set; }
public required string Summary { get; set; }
public required bool AuthenticationRequired { get; set; }
public required GameUserRole? MinimumRole { get; set; }
public required IEnumerable<ApiParameterResponse> Parameters { get; set; }
public required IEnumerable<ApiErrorResponse> PotentialErrors { get; set; }

Expand All @@ -24,6 +26,7 @@ public class ApiRouteResponse : IApiResponse, IDataConvertableFrom<ApiRouteRespo
AuthenticationRequired = old.AuthenticationRequired,
Parameters = ApiParameterResponse.FromOldList(old.Parameters),
PotentialErrors = ApiErrorResponse.FromOldList(old.PotentialErrors),
MinimumRole = (GameUserRole?)old.ExtraProperties.GetValueOrDefault("minimumRole"),
};
}

Expand Down

0 comments on commit 90acc4e

Please sign in to comment.