惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

SecWiki News
SecWiki News
量子位
The Cloudflare Blog
美团技术团队
T
The Exploit Database - CXSecurity.com
博客园 - 【当耐特】
Spread Privacy
Spread Privacy
P
Proofpoint News Feed
C
CXSECURITY Database RSS Feed - CXSecurity.com
博客园 - 三生石上(FineUI控件)
T
Tor Project blog
博客园 - 司徒正美
宝玉的分享
宝玉的分享
T
Threatpost
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
S
Secure Thoughts
T
Threat Research - Cisco Blogs
Hacker News: Ask HN
Hacker News: Ask HN
Jina AI
Jina AI
博客园 - 聂微东
A
Arctic Wolf
I
Intezer
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Know Your Adversary
Know Your Adversary
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
爱范儿
爱范儿
Hugging Face - Blog
Hugging Face - Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
小众软件
小众软件
T
Tailwind CSS Blog
The Hacker News
The Hacker News
L
LINUX DO - 最新话题
Hacker News - Newest:
Hacker News - Newest: "LLM"
WordPress大学
WordPress大学
S
SegmentFault 最新的问题
TaoSecurity Blog
TaoSecurity Blog
Project Zero
Project Zero
博客园 - 叶小钗
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Cloudbric
Cloudbric
雷峰网
雷峰网
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
大猫的无限游戏
大猫的无限游戏
D
Darknet – Hacking Tools, Hacker News & Cyber Security
T
Troy Hunt's Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
V2EX - 技术
V2EX - 技术
The GitHub Blog
The GitHub Blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
P
Privacy & Cybersecurity Law Blog

博客园 - Ant

ASP.NET Core 项目简单实现身份验证及鉴权 使用iconfont图标 IIS调试ASP.NET Core项目 配置GitHub的SSH key Visual Studio连接Oracle数据库 Visual Studio Code 如何将新项目发布到GIT服务器 Xamarin踩坑经历 Abp项目中的领域模型实体类访问仓储的方法 发布以NLog作为日记工具的ASP.NET站点到IIS注意事项 Android Studio 简介及导入 jar 包和第三方开源库方[转] 解决jquery-ui-autocomplete选择列表被Bootstrap模态窗遮挡的问题 ORACLE存储过程创建失败,如何查看其原因 EF6配合MySQL或MSSQL(CodeFirst模式)配置指引 火狐通行证升级为Firefox Sync后,如何在多设备间同步书签等信息 (原创)通用查询实现方案(可用于DDD)[附源码] -- 设计思路 (原创)通用查询实现方案(可用于DDD)[附源码] -- 简介 利用Lambda获取属性名称 Entity Framework 6.0 源码解读笔记(一) [转]Sql server2005中如何格式化时间日期
在Abp中集成Swagger UI功能
Ant · 2016-05-19 · via 博客园 - Ant

在Abp中集成Swagger UI功能

1.安装Swashbuckle.Core包

通过NuGet将Swashbuckle.Core包安装到WebApi项目(或Web项目)中。

2.为WebApi方法添加注释,并生成xml

3.在xxx.WebApi项目中配置Swagger

修改xxxWebApiModule类,添加ConfigureSwaggerUi()方法,并在Initialize()方法的最后调用它。
注意:要添加对Abp.Configuration.Startup、Swashbuckle.Application命名空间的引用。
另外,不调用ResolveConflictingActions()方法来提供冲突解决办法将有可能遇到500错误。

using System.Linq;
using Abp.Configuration.Startup;
using Swashbuckle.Application;

    [DependsOn(typeof(AbpWebApiModule), typeof(OrganizationApplicationModule))]
    public class OrganizationWebApiModule : AbpModule
    {
        public override void Initialize()
        {
            IocManager.RegisterAssemblyByConvention(Assembly.GetExecutingAssembly());

            DynamicApiControllerBuilder
                .ForAll<IApplicationService>(typeof(OrganizationApplicationModule).Assembly, "csci")
                .Build();

            //配置跨域
            GlobalConfiguration.Configuration.EnableCors(new System.Web.Http.Cors.EnableCorsAttribute("*", "*", "*"));
            //配置输出json时不使用骆驼式命名法,按对象属性原名输出
            GlobalConfiguration.Configuration.Formatters.JsonFormatter.SerializerSettings.ContractResolver = new Newtonsoft.Json.Serialization.DefaultContractResolver();
            //集成Swagger UI
            ConfigureSwaggerUi();
        }

        private void ConfigureSwaggerUi()
        {
            var xmlFile = string.Format("{0}/bin/{1}.Application.xml", System.AppDomain.CurrentDomain.BaseDirectory, this.GetType().Namespace);
            Configuration.Modules.AbpWebApi().HttpConfiguration
                .EnableSwagger(c =>
       ![](http://images2015.cnblogs.com/blog/19184/201706/19184-20170613111141275-1740289580.png)

         {
                    c.SingleApiVersion("v1", this.GetType().Namespace);
                    c.ResolveConflictingActions(apiDescriptions => apiDescriptions.First());
                    if (System.IO.File.Exists(xmlFile)) { c.IncludeXmlComments(xmlFile); }
                })
                .EnableSwaggerUi();
        }

    }

4.测试

运行WEB项目,在浏览器中访问{项目网址}/swagger,即可见到动态生成的WebApi接口,并可以直接调试。

注:如果见不到[Try it out!]按钮,点一下"Expand Operations"链接即可。

参考:
ABP理论学习之Swagger UI集成
.net WebApi中使用swagger