如何在 Swagger-UI 中打开本地文件 [英] How to open local files in Swagger-UI

查看:22
本文介绍了如何在 Swagger-UI 中打开本地文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用

如果我输入一个本地路径,它总是会以包含 index.html 的当前 url 为前缀.因此我无法打开我的文件.我尝试了以下所有组合但均未成功:

  • 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

解决方案

有效的方法是在没有 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 和有效

提示

此答案适用于 Win7 上的 Firefox.对于 Chrome 浏览器,请参阅以下评论:

I'm trying to open my self generated swagger specification file my.json with swagger-ui on my local computer.

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:

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 leads to file:///D:/swagger-ui/dist/index.html/my.json
  • file:///D:/swagger-ui/dist/my.json leads to file:///D:/swagger-ui/dist/index.html/file:///D:/swagger-ui/dist/my.json

解决方案

What works, is to enter a relative path or an absolute without the file://-protocol:

  • ../my.json leads to file:///D:/swagger-ui/dist/index.html/../my.json and works
  • /D:/swagger-ui/dist/my.json leads to file:///D:/swagger-ui/dist/my.json and works

HINT

This answer works with Firefox on Win7. For Chrome-Browser, see comments below:

这篇关于如何在 Swagger-UI 中打开本地文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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