记录下.net core项目无法生成swagger文档问题的修复方案

itlao6 原创 开发&源码 .NET评论557字数 385阅读1分17秒阅读模式

目前遇到无法生成swagger的问题,总结了两种原因及解决方案

问题一、接口缺少http属性文章源自IT老刘-https://itlao6.com/9700.html

为每个接口增加HttpGet或HttpPost属性即可,参考如下:文章源自IT老刘-https://itlao6.com/9700.html

[Route("A/[action]")]
public class AController : ApiBaseController
{
    private BLL_HealthInstructionInfo bllA;
    public AController(BLL_A _BLL_A)
    {
        bllA = _BLL_A;
    }
    [HttpPost] 根据实际情况每个接口都加上HttpPost或HttpGet
    public Result J()
    {
...........

问题二、命名冲突(在不同命名空间下有相同名字的接口或者实体)文章源自IT老刘-https://itlao6.com/9700.html

在Startup.cs配置swagger时,增加如下配置:文章源自IT老刘-https://itlao6.com/9700.html

options.CustomSchemaIds(x => x.FullName);
文章源自IT老刘-https://itlao6.com/9700.html文章源自IT老刘-https://itlao6.com/9700.html
weinxin
我的微信公众号
微信扫一扫关注公众号,不定时更新
itlao6
  • 本文由 发表于 2022年 11月 25日 19:15:00
  • 转载请务必保留本文链接:https://itlao6.com/9700.html
评论  0  访客  0
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定