Swagger使用的时候报错:Failed to load API definition
NuGet添加Swashbuckle.AspNetCore,在Startup.cs添加和启用中间件Swagger
public void ConfigureServices(IServiceCollection services)
{
#region Swagger
services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new Info
{
Version = "v1.0.0",
Title = "My Web API",
Description = "说明文档",
TermsOfService = "None",
Contact = new Swashbuckle.AspNetCore.Swagger.Contact { Name = "My.Web", Email = "My.Web@xxx.com", Url = "https://www.cnblogs.com/Zev_Fung/" }
});
});
#endregion
} public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
#region Swagger
app.UseSwagger();
app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("/swagger/v1/swagger.json", "My Web API V1");
});
#endregion
}
使用自带的Kestrel web调试,输入地址:http://localhost:<port>/swagger,默认跳转到https://localhost:<port>/swagger/index.html
Swagger提示报错:
Failed to load API definition.
Errors
Fetch errorInternal Server Error /swagger/v1/swagger.json

打开http://localhost:<port>/swagger/v1/swagger.json,提示错误
An unhandled exception occurred while processing the request.
NotSupportedException: Ambiguous HTTP method for action - xxxxx.Controllers.BooksController.Post (xxxxx). Actions require an explicit HttpMethod binding for Swagger 2.0
Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.CreatePathItem(IEnumerable<ApiDescription> apiDescriptions, ISchemaRegistry schemaRegistry) Stack Query Cookies Headers
NotSupportedException: Ambiguous HTTP method for action - xxxxx.Controllers.BooksController.Post (xxxxx). Actions require an explicit HttpMethod binding for Swagger 2.0
Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.CreatePathItem(IEnumerable<ApiDescription> apiDescriptions, ISchemaRegistry schemaRegistry)
System.Linq.Enumerable.ToDictionary<TSource, TKey, TElement>(IEnumerable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, TElement> elementSelector, IEqualityComparer<TKey> comparer)
Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.CreatePathItems(IEnumerable<ApiDescription> apiDescriptions, ISchemaRegistry schemaRegistry)
Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.GetSwagger(string documentName, string host, string basePath, string[] schemes)
Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.Invoke(HttpContext httpContext, ISwaggerProvider swaggerProvider)
Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context) Show raw exception details

或者在控制台查看输出错误

大概意思是:不支持的异常:操作的HTTP方法不明确,方法需要必须指明请求方式
在方法加上 [HttpGet]、[HttpPost] 等,就可以通过 Swagger UI 查看 API

上面只是其中一种引起的Fetch errorInternal Server Error /swagger/v1/swagger.json原因,其他也是通过查看错误信息解决
Swagger使用的时候报错:Failed to load API definition的更多相关文章
- Eclipse启动 报错[Failed to load the JNI shared library jvm.dll
准备要做java服务器,在安装开发环境时,启动Eclipse报错[Failed to load the JNI shared library jvm.dll] 研究了下,造成错误的原因是由于eclip ...
- 使用laravel-admin后台sdk报错Failed to load resource: net::ERR_CERT_AUTHORITY_INVALID、Provisional headers are shown
报错Failed to load resource: net::ERR_CERT_AUTHORITY_INVALID请先确定自己的资源url是否可以确实访问到(地址正确与否.访问权限是否开启等) 若n ...
- junit单元测试报错Failed to load ApplicationContext,但是项目发布到tomcat浏览器访问没问题
junit单元测试报错Failed to load ApplicationContext,但是项目发布到tomcat浏览器访问没问题,说明代码是没问题的,配置也没问题.开始时怀疑是我使用junit版本 ...
- Abp的swagger UI 出现Failed to load API definition.
Abp 出现Failed to load API definition.如下图: 原因:本次出现的原因是Api里面的方法重名了(只是方法的参数不一样)(可能是controller中的auction上面 ...
- 安卓预览报错 Failed to load AppCompat ActionBar with unknown error
报错信息 : Render ProblemFailed to load AppCompat ActionBar with unknown error. Failed to instantiate on ...
- 使用elasticsearch启动项目报错failed to load elasticsearch nodes 。。。。。No type specified for field [name]
failed to load elasticsearch nodes .....No type specified for field [name]翻译: 加载ElasticSearch节点失败... ...
- mesos-master启动失败,报错Failed to load unknown flag 'quorum.rpmsave'
[现象] mesos启动失败,查看mesos状态报错: [root@hps102 ~]# systemctl status mesos-master ● mesos-master.service - ...
- Linux安装U盘启动报错Failed to load ldlinux.c32
报错信息 使用U盘安装linux无法正常启动 Start booting from USB device... SYSLINUX 5.10 EDD 2013-06-04 Copyright (C) 1 ...
- Hive 报错 Failed to load class "org.slf4j.impl.StaticLoggerBinder".
打开hive报错 SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder". SLF4J: Defaultin ...
随机推荐
- windows定时任务schtasks命令详细解
SCHTASKS /Create [/S system [/U username [/P [password]]]] [/RU username [/RP password]] /SC schedul ...
- Flutter不能做什么:局限性
老孟导读:您在网络上一定看过很多Flutter如何优秀的.如何完美的文章,而这篇文章将会告诉你Flutter不能做什么,注意并不是Flutter的缺点,比如第三方插件少.Dart不流行等,在我看来这都 ...
- 在linux下执行git clone、git pull 、git push等操作免密
1. 通过ssh密钥实现 ssh-keygen -t rsa -C "你的邮箱" -f "自己定义的目录" 打开: id_rsa.pub ,将文件内容复制到 g ...
- nginx均衡负载
一直在担心session 问题,结果试了2个web 论坛,discuz 和phpbb ,前面用nginx 均衡负载,后端是apache httpd +php ,mysql 用同一个,修改一下confi ...
- sound of the genuine
“There is something in every one of you that waits and listens for the sound of the genuine in yours ...
- 【Linux】Xshell 配置密钥登陆
设置不需要密码登陆 vim /etc/ssh/sshd_config 在配置文件中参数的意义 PubkeyAuthentication yes #启用公告密钥配对认证方式 AuthorizedKeys ...
- BZOJ1010单调性DP优化
1010: [HNOI2008]玩具装箱toy Time Limit: 1 Sec Memory Limit: 162 MBSubmit: 10707 Solved: 4445[Submit][S ...
- 整理总结数据库常用sql语句,建议收藏,忘记了可以来看一下
第一节课:sql语言介绍(参照PPT)及基本查询sql学习 1.数据库表的介绍 emp表:员工表 dept表:部门表 salgrady:薪资水平表 Balance: 2.基本的查询语句: 知识点: s ...
- 需求:一个页面中需要用到多个字典数据。用于下拉选项,同时,需要将其保存为json格式。以便于key,value的相互转换。记录在实现过程中踩的坑
本文涉及到的知识: Promise,all()的使用 js处理机制 reduce的用法 map的用法 同步异步 需求: 一个页面中需要用到多个字典数据.用于下拉选项,同时,需要将其保存为json格式. ...
- 安卓到底是不是Linux
有人说安卓就是 Linux,也有人说安卓是安卓.Linux 是 Linux,两者没什么关系,还有人说安卓用的是 Linux 的内核,那么它们之间到底是什么关系呢.要想得到这个问题的答案,我们要先弄清楚 ...