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?

user2892120
  • 11
  • 1
  • 3
  • 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? – user2892120 Aug 06 '15 at 20:11
  • Possible duplicate of [How to open local files in Swagger-UI](http://stackoverflow.com/questions/30400477/how-to-open-local-files-in-swagger-ui) – Helen Mar 16 '17 at 08:19

1 Answers1

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

Community
  • 1
  • 1