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 ...
随机推荐
- java -> final与static 关键字
final的概念 继承的出现提高了代码的复用性,并方便开发.但随之也有问题,有些类在描述完之后,不想被继承,或者有些类中的部分方法功能是固定的,不想让子类重写.可是当子类继承了这些特殊类之后,就可以对 ...
- C# 微信公众平台开发(5)--添加图文素材
微信公众平台开发 --添加素材 关于微信公众号素材管理,我们可以通过接口文档,了解基本详情:http://mp.weixin.qq.com/wiki/10/10ea5a44870f53d79449 ...
- 6.2 Go 匿名字段
6.2 Go 匿名字段 Golang匿名字段:可以像访问字段成员那样,访问匿名字段方法,go编译器自动查找. package main import "fmt" type Stud ...
- 让SpringBoot自动化配置不再神秘
本文若有任何纰漏.错误,还请不吝指出! 注:本文提到的Spring容器或者Bean容器,或者Spring Bean容器,都是指同一个事情,那就是代指BeanFactory.关于BeanFactory, ...
- 27-1 分组-having
group by select * from TblStudent --1.请从学生表中查询出每个班的班级id和班级人数 select tsclassId as 班级id, 班级人数=count(*) ...
- MyBatis——Mapped Statements collection does not contain value for XXX
报错信息: Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql. ...
- Java-LinkedList围圈的人名
import java.util.*; public class Example12_7 { public static void main(String[] args) { int m=5; Lin ...
- pop() 函数用于移除列表中的一个元素(默认最后一个元素),并且返回该元素的值。
pop() 函数用于移除列表中的一个元素(默认最后一个元素),并且返回该元素的值.
- [FlashDevelop] 003.FlashDevelop + LayaFlash + Starling环境配置及实战
1.首先我们需要下载LayaStarling框架地址:http://layabox.com/index.php?m=content&c=index&a=lists&catid= ...
- [安卓基础] 007.管理Activity的生命周期
*:first-child { margin-top: 0 !important; } body > *:last-child { margin-bottom: 0 !important; } ...