问题描述
我试图用我的 swagger-ui 打开我自己生成的swagger规范文件my.json
本地计算机.
I'm trying to open my self generated swagger specification file my.json
with swagger-ui on my local computer.
所以我下载了最新标签v2.1.8-M1并提取了邮政编码.然后我进入子文件夹dist
并将文件my.json
复制到其中.现在,我打开了index.html
并想浏览my.json
.问题开始了:
So I downloaded the latest tag v2.1.8-M1 and extracted the zip. Then I went inside the sub folder dist
and copied the file my.json
into it. Now I opened the index.html
and want to explore my.json
. And here the problem begins:
如果输入本地路径,它将始终以包含index.html
的当前URL作为前缀.因此,我无法打开文件.我尝试了以下所有组合,但均未成功:
If I enter a local path, it always will be prefixed by the current url containing the index.html
. And therefor I can't open my file. I tried all following combinations without success:
-
my.json
导致file:///D:/swagger-ui/dist/index.html/my.json
-
file:///D:/swagger-ui/dist/my.json
导致file:///D:/swagger-ui/dist/index.html/file:///D:/swagger-ui/dist/my.json
my.json
leads tofile:///D:/swagger-ui/dist/index.html/my.json
file:///D:/swagger-ui/dist/my.json
leads tofile:///D:/swagger-ui/dist/index.html/file:///D:/swagger-ui/dist/my.json
推荐答案
有效的方法是输入相对路径或没有file://
-protocol的绝对值:
What works, is to enter a relative path or an absolute without the file://
-protocol:
-
../my.json
导致file:///D:/swagger-ui/dist/index.html/../my.json
正常工作 -
/D:/swagger-ui/dist/my.json
导致file:///D:/swagger-ui/dist/my.json
并且有效
../my.json
leads tofile:///D:/swagger-ui/dist/index.html/../my.json
and works/D:/swagger-ui/dist/my.json
leads tofile:///D:/swagger-ui/dist/my.json
and works
提示
此答案适用于Win7上的Firefox.对于Chrome浏览器,请参见以下评论:
This answer works with Firefox on Win7. For Chrome-Browser, see comments below:
这篇关于如何在Swagger-UI中打开本地文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!