无法从 Swagger UI 中的文件问题读取 [英] Can't read from file issue in Swagger UI

查看:55
本文介绍了无法从 Swagger UI 中的文件问题读取的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在我的应用程序中加入了 swagger-ui.

I have incorporated swagger-ui in my application.

当我尝试查看 swagger-ui 时,我很好地获得了 API 的文档,但一段时间后它在按钮上显示了一些错误图标.

When I try and see the swagger-ui I get the documentation of the API nicely but after some time it shows some error icon at the button.

错误信息如下:

[{"level":"error","message":"无法从文件中读取http://MYIP/swagger/docs/v1"}]

[{"level":"error","message":"Can't read from file http://MYIP/swagger/docs/v1"}]

我不确定是什么原因造成的.如果我刷新它就可以工作并在几秒钟后显示错误.

I am not sure what is causing it. If I refresh it works and shows error after few seconds.

推荐答案

我猜http://MYIP/swagger/docs/v1" 不可公开访问.

I am guessing "http://MYIP/swagger/docs/v1" is not publicly accessible.

默认情况下,swagger ui 使用在线验证器:online.swagger.io.如果它无法访问您的 swagger url,那么您将看到该错误消息.

By default swagger ui uses an online validator: online.swagger.io. If it cannot access your swagger url then you will see that error message.

可能的解决方案:

  1. 禁用验证:

  1. Disable validation:

config.EnableSwagger().EnableSwaggerUi(c => c.DisableValidator());

让您的网站可公开访问

在本地托管验证器:

您可以从以下位置获取验证器:https://github.com/swagger-api/validator-badge#running-locally

You can get the validator from: https://github.com/swagger-api/validator-badge#running-locally

您还需要告诉 swaggerui 验证器的位置

You will also need to tell swaggerui the location of the validator

config.EnableSwagger().EnableSwaggerUi(c => c.SetValidatorUrl());

这篇关于无法从 Swagger UI 中的文件问题读取的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆