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?

4

1 に答える 1

0

Documentationによると、仕様値は JSON オブジェクトでなければならないため、次のようにする必要があります。

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

どこ

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

file:///Users/user1/Desktop/swagger.jsonファイルのコンテンツです

于 2015-08-11T18:16:35.217 に答える