Search code examples
swaggerswagger-editor

How to publish swagger editor left window as documentation


I want to publish the right side panel of the swagger editor.

Currently, the team has to share the yaml file and each user has to copy & paste the text into the swagger editor to view the right panel rendering.

Is there a way to publish the content to html so that a page would look like the right panel ?

Example swagger editor windown with formated look on the right: http://azimi.me/presentations/building-swagger-editor/images/swagger-ui.png


Solution

  • AFAIK there is no way to publish it right from the swagger editor but you can use swagger-ui. All you need is to

    1. download swagger-ui
    2. host it on a web server that is accessible for your team
    3. save your swagger documentation code to a new file of any filename and host it on your web server, too.
    4. tell swagger-ui which documentation file it shall load.

    For the last step look for the following piece of code within the swagger-ui's index.html:

    $(function () {
      var url = window.location.search.match(/url=([^&]+)/);
      if (url && url.length > 1) {
        url = decodeURIComponent(url[1]);
      } else {
        url = "http://petstore.swagger.io/v2/swagger.json";
      }
    

    Replace the value of line url = "http://petstore.swagger.io/v2/swagger.json"; to point to the swagger documentation file you uploaded.