// By default, swagger-ui will validate specs against swagger.io's online validator and display the result
// in a badge at the bottom of the page. Use these options to set a different validator URL or to disable the
// feature entirely.
//c.SetValidatorUrl("http://localhost/validator");
c.DisableValidator();
6 回答
我猜“http://MYIP/swagger/docs/v1”不公开 .
默认情况下,swagger ui使用在线验证器:online.swagger.io . 如果它无法访问您的swagger网址,那么您将看到该错误消息 .
可能的解决方案:
config.EnableSwagger().EnableSwaggerUi(c => c.DisableValidator());
使您的网站可公开访问
在本地托管验证器:
您可以从以下位置获取验证码:https://github.com/swagger-api/validator-badge#running-locally
您还需要告诉swaggerui验证器的位置
config.EnableSwagger().EnableSwaggerUi(c => c.SetValidatorUrl(<validator_url>));
为了补充已接受的答案......我只是在SwaggerConfig.cs中取消注释了一行 . 我只想通过禁用验证器来摆脱主要招摇页面上的红色错误 .
如果您使用的是swagger-ui github repo中的文件,则可以通过将
validatorUrl
设置为null
来禁用index.html
文件中的架构验证:在
dist/swagger-ui.js
中设置this.model.validatorUrl = null;
为我工作..如果您使用PHP Laravel framework与L5-Swagger只是取消注释
来自配置文件
/config/l5-swagger.php
To anynoe having similar issue when using Swashbuckle.OData:
我有问题将Swagger与我们的OData endpoints 集成(使用ODataController for API和Swashbuckle.OData NuGet包) . 我必须为它编写自己的文档过滤器并添加它:
显然,为了避免验证错误,我必须注释掉设置ODataSwaggerProvider的行以及如上面帖子中提到的关闭验证器 . 这使得Swashbuckle.OData的用处有问题,但我没有测试它与vanilla Swashbuckle有什么用 .
注意:我使用GitHub页面上描述的Swashbuckle.OData方法,但它没有工作:根本没有显示可能的 endpoints . 也许有人知道更好的解决方案 .