对外提供的接口在实际生成过程中,可能是需要一个接口版本的,比如说v1,manage。效果如下:
Abp中SwaggerUI的多个接口文档配置说明
 
Abp中SwaggerUI的多个接口文档配置说明
 
在swagger中怎么实现呢?
1. 添加SwaggerVersionHelper.cs
 public class SwaggerVersionHelper
    {
        public static bool ResolveVersionSupportByRouteConstraint(ApiDescription apiDesc, string targetApiVersion)
        {

            var attr = apiDesc.ActionDescriptor.ControllerDescriptor.GetCustomAttributes<VersionedRoute>().FirstOrDefault();
            if (attr == null)
            {
                if (targetApiVersion == "manage")
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }


            
                int targetVersion;
                targetApiVersion = targetApiVersion.TrimStart('v');

                if (attr.Version != 0 && int.TryParse(targetApiVersion, out targetVersion))
                {
                    return attr.Version == targetVersion;
                };

                return false;
         }
    }    
View Code

相关文章:

  • 2022-12-23
  • 2021-07-05
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-10
  • 2021-12-14
  • 2021-11-08
猜你喜欢
  • 2021-09-03
  • 2021-09-13
  • 2022-12-23
  • 2021-07-12
  • 2022-12-23
  • 2021-05-20
  • 2022-12-23
相关资源
相似解决方案