C# · 12月 20, 2021

Swashbuckle Swagger组件扩展

<div style=”white-space: normal; word-spacing: 0px; text-transform: none; color: #000000; text-align: left; font: 14px/21px 微软雅黑; widows: 1; letter-spacing: normal; background-color: #ffffff; text-indent: 0px; -webkit-text-stroke-width: 0px;”>
<div class=”cnblogs_code” onclick=”cnblogs_code_show(‘18730aab-c218-4d9c-899b-f56124b0abfe’)”> 
用Swagger有一段时间,
<div style=”white-space: normal; word-spacing: 0px; text-transform: none; color: #000000; text-align: left; font: 14px/21px 微软雅黑; widows: 1; letter-spacing: normal; background-color: #ffffff; text-indent: 0px; -webkit-text-stroke-width: 0px;”>我的model层是一个单独的dll 但给Swagger配置的是api层dll的XML。
<div style=”white-space: normal; word-spacing: 0px; text-transform: none; color: #000000; text-align: left; font: 14px/21px 微软雅黑; widows: 1; letter-spacing: normal; background-color: #ffffff; text-indent: 0px; -webkit-text-stroke-width: 0px;”>所以就导致了model字段的注释不能够反应到参数说明。
<div style=”white-space: normal; word-spacing: 0px; text-transform: none; color: #000000; text-align: left; font: 14px/21px 微软雅黑; widows: 1; letter-spacing: normal; background-color: #ffffff; text-indent: 0px; -webkit-text-stroke-width: 0px;”>所以我fork了一份 改了一下源码
<div style=”white-space: normal; word-spacing: 0px; text-transform: none; color: #000000; text-align: left; font: 14px/21px 微软雅黑; widows: 1; letter-spacing: normal; background-color: #ffffff; text-indent: 0px; -webkit-text-stroke-width: 0px;”>改动功能如下:
<div style=”white-space: normal; word-spacing: 0px; text-transform: none; color: #000000; text-align: left; font: 14px/21px 微软雅黑; widows: 1; letter-spacing: normal; background-color: #ffffff; text-indent: 0px; -webkit-text-stroke-width: 0px;”> 
<div style=”white-space: normal; word-spacing: 0px; text-transform: none; color: #000000; text-align: left; font: 14px/21px 微软雅黑; widows: 1; letter-spacing: normal; background-color: #ffffff; text-indent: 0px; -webkit-text-stroke-width: 0px;”><span style=”font-size: 14px; font-family: 微软雅黑; color: #000000; font-style: normal; text-align: left; background-color: #ffffff;”>1 增加每个controller下的action 总数 展示
<div style=”white-space: normal; word-spacing: 0px; text-transform: none; color: #000000; text-align: left; font: 14px/21px 微软雅黑; widows: 1; letter-spacing: normal; background-color: #ffffff; text-indent: 0px; -webkit-text-stroke-width: 0px;”>

<img style=”cursor: default; height: 309px; width: 800px; margin-top: 8px; display: inline-block;” src=”https://www.jb51.cc/res/2019/02-15/23/8a634fa047b49290103ea20d54937602.jpg” alt=”” data-inited=”true” data-media-type=”image”>

<div style=”white-space: normal; word-spacing: 0px; text-transform: none; color: #000000; text-align: left; font: 14px/21px 微软雅黑; widows: 1; letter-spacing: normal; background-color: #ffffff; text-indent: 0px; -webkit-text-stroke-width: 0px;”> 
<div style=”white-space: normal; word-spacing: 0px; text-transform: none; color: #000000; text-align: left; font: 14px/21px 微软雅黑; widows: 1; letter-spacing: normal; background-color: #ffffff; text-indent: 0px; -webkit-text-stroke-width: 0px;”>2 增加action的状态参数展示
<div style=”white-space: normal; word-spacing: 0px; text-transform: none; color: #000000; text-align: left; font: 14px/21px 微软雅黑; widows: 1; letter-spacing: normal; background-color: #ffffff; text-indent: 0px; -webkit-text-stroke-width: 0px;”> 
<div style=”white-space: normal; word-spacing: 0px; text-transform: none; color: #000000; text-align: left; font: 14px/21px 微软雅黑; widows: 1; letter-spacing: normal; background-color: #ffffff; text-indent: 0px; -webkit-text-stroke-width: 0px;”>

<img style=”cursor: default; height: 107px; width: 800px; margin-top: 8px; display: inline-block;” src=”https://www.jb51.cc/res/2019/02-15/23/2ed9e3cf47b5ce663f8a86b2268dc485.jpg” alt=”” data-inited=”true” data-media-type=”image”>

<div style=”white-space: normal; word-spacing: 0px; text-transform: none; color: #000000; text-align: left; font: 14px/21px 微软雅黑; widows: 1; letter-spacing: normal; background-color: #ffffff; text-indent: 0px; -webkit-text-stroke-width: 0px;”> 
<div style=”white-space: normal; word-spacing: 0px; text-transform: none; color: #000000; text-align: left; font: 14px/21px 微软雅黑; widows: 1; letter-spacing: normal; background-color: #ffffff; text-indent: 0px; -webkit-text-stroke-width: 0px;”>3 让swagger的model的说明采用读取Description标签 的方式来显示注释
<div style=”white-space: normal; word-spacing: 0px; text-transform: none; color: #000000; text-align: left; font: 14px/21px 微软雅黑; widows: 1; letter-spacing: normal; background-color: #ffffff; text-indent: 0px; -webkit-text-stroke-width: 0px;”>

<img style=”cursor: default; height: 371px; width: 800px; margin-top: 8px; display: inline-block;” src=”https://www.jb51.cc/res/2019/02-15/23/7415606ffb956cc1c9a688cf988fca3f.jpg” alt=”” data-inited=”true” data-media-type=”image”>

<div style=”white-space: normal; word-spacing: 0px; text-transform: none; color: #000000; text-align: left; font: 14px/21px 微软雅黑; widows: 1; letter-spacing: normal; background-color: #ffffff; text-indent: 0px; -webkit-text-stroke-width: 0px;”> 
<div style=”white-space: normal; word-spacing: 0px; text-transform: none; color: #000000; text-align: left; font: 14px/21px 微软雅黑; widows: 1; letter-spacing: normal; background-color: #ffffff; text-indent: 0px; -webkit-text-stroke-width: 0px;”>4.对入参的schema有校验
<div style=”white-space: normal; word-spacing: 0px; text-transform: none; color: #000000; text-align: left; font: 14px/21px 微软雅黑; widows: 1; letter-spacing: normal; background-color: #ffffff; text-indent: 0px; -webkit-text-stroke-width: 0px;”>
<img style=”cursor: default; max-width: 800px; margin-top: 8px; display: inline-block;” src=”https://www.jb51.cc/res/2019/02-15/23/4dc31aa24eb4bc4d2dcb3325d661fc92.jpg” alt=”” data-inited=”true” data-media-type=”image”> <img style=”cursor: default; max-width: 800px; margin-top: 8px; display: inline-block; line-height: 1.5; background-color: #ffffff;” src=”https://www.jb51.cc/res/2019/02-15/23/806b19b073e780e2042b0c143765fec2.jpg” alt=”” data-inited=”true” data-media-type=”image”>

 5.加入汉化的js脚本

 webapi具体使用范例下载:https://pan.baidu.com/s/1micd0fu