0

I'm attempting to document my API using Swagger by writing the documentation in the Swagger editor and then loading it into the Swagger UI. I used the editor and downloaded my JSON file and then changed the /dist/index.html file within the UI to point to my local file using:

var spec = "file:///Users/user1/Desktop/swagger.json";

  if (url && url.length > 1) {
    url = decodeURIComponent(url[1]);
  } else {
    url = "http://petstore.swagger.io/v2/swagger.json";
  }

  // Pre load translate...
  if(window.SwaggerTranslator) {
    window.SwaggerTranslator.translate();
  }
  window.swaggerUi = new SwaggerUi({
    url: url,
    spec: spec,

The only thing I changed within the file is the use of the spec var to point to my JSON file, however when I open the UI, it displays a blank UI page with the message "Finished Loading Resource Information. Rendering Swagger UI..." I would just like to display the documentation I created in the editor in the UI without having to host the specs, is there something I'm missing?

2
  • I've also tried simply cloning the swagger UI repo and attempting to access my file trough the UI in a browser, however it only gives the message "Please specify the protocol for file://..." Does this mean that my JSON file downloaded from the editor is incorrectly formatted? Commented Aug 6, 2015 at 20:11
  • Possible duplicate of How to open local files in Swagger-UI Commented Mar 16, 2017 at 8:19

1 Answer 1

0

Accordign to the Documentation, spec value must be an JSON Object, so you have to do something like:

window.swaggerUi = new SwaggerUi({
  spec: JSON.parse('{ "swagger": "2.0", ...')

where

{ "swagger": "2.0", ...

is the content for your file:///Users/user1/Desktop/swagger.json file

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.