Search code examples
fileswaggerswagger-uiswagger-2.0

How to open local files in Swagger-UI


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:

File in windows explorer Enter path to file in bar Will be prefixed by current url and cannot find the file

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

Solution

  • 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: