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 ...
随机推荐
- js中的小案例(一)
效果图: html代码: <div id="date"> <p> <span id="prev">上一月</span& ...
- EOS基础全家桶(十二)智能合约IDE-VSCode
简介 上一篇我们介绍了EOS的专用IDE工具EOS Studio,该工具的优势是简单,易上手,但是灵活性低,且对系统资源开销大,依赖多,容易出现功能异常.那么我们开发人员最容易使用的,可能还是深度定制 ...
- VMware 安装 CentOS 7
下载并安装 VMware 访问 VMware 官方网站下载 VMware 安装包程序.博主使用的是 12.5.5 版本,下载完之后点击安装包程序进入 VMware 的安装向导,然后点击"下一 ...
- maven开发SSH
虽然开发SSH的基本步骤都差不多,但每次都从头开始做真的会有点儿烦,把maven的SSH框的基本代码放出来,下次就可以复制粘贴哈哈. 1. 配置文件: (1)pom.xml <project x ...
- 【MySQL】深入理解MySQL锁和事务隔离级别
先看个小案例: 话不多说,上案例,先创建一个表 mysql> CREATE TABLE IF NOT EXISTS `account`( `id` INT UNSIGNED AUTO_INCRE ...
- 求平均成绩(hdu2023)
注意:要心细,不要错在小细节上.如int c[6];double agve; c[j]=agve:这是错误的. #include<stdio.h> #include<cmath> ...
- 解决2003 - 2003 - Can't connect to MySQL server on '127.0.0.1'(61 "Connection refused")
1)右击数据库选择编辑连接2) 3)重新输入密码即可
- oracle 多表连接查询 join
转 简介: 多表连接查询通过表之间的关联字段,一次查询多表数据. 下面将依次介绍 多表连接中的如下方法: 1.from a,b 2.inner join 3.left outer join 4.rig ...
- Unity调用Android Studio中的Java方法
1. 新建Unity项目: 2. Android Studio中新建EmptyActivity: 3. 新建安卓项目时记住最小版本号: 4. 将左侧项目文件浏览面板切换到Project项下,在本项根节 ...
- [C# WPF] 关于将文本框竖起来(旋转文字)
xx.xmal.cs 后台代码中动态添加控件到 UI 文字显示在一个 Canvas 中(定位用Canvas.SetLeft() / Canvas.SetTop() ), 为了实现排版效果,可适当在 T ...