init
This commit is contained in:
37
DouyinApi.Api/Filter/CustomRouteAttribute.cs
Normal file
37
DouyinApi.Api/Filter/CustomRouteAttribute.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.ApiExplorer;
|
||||
using System;
|
||||
using static DouyinApi.Extensions.CustomApiVersion;
|
||||
|
||||
namespace DouyinApi.SwaggerHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// 自定义路由 /api/{version}/[controler]/[action]
|
||||
/// </summary>
|
||||
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = true, Inherited = true)]
|
||||
public class CustomRouteAttribute : RouteAttribute, IApiDescriptionGroupNameProvider
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// 分组名称,是来实现接口 IApiDescriptionGroupNameProvider
|
||||
/// </summary>
|
||||
public string GroupName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 自定义路由构造函数,继承基类路由
|
||||
/// </summary>
|
||||
/// <param name="actionName"></param>
|
||||
public CustomRouteAttribute(string actionName = "[action]") : base("/api/{version}/[controller]/" + actionName)
|
||||
{
|
||||
}
|
||||
/// <summary>
|
||||
/// 自定义版本+路由构造函数,继承基类路由
|
||||
/// </summary>
|
||||
/// <param name="actionName"></param>
|
||||
/// <param name="version"></param>
|
||||
public CustomRouteAttribute(ApiVersions version, string actionName = "") : base($"/api/{version.ToString()}/[controller]/{actionName}")
|
||||
{
|
||||
GroupName = version.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user