How to open local files in Swagger-UI

前端 未结 13 1581
粉色の甜心
粉色の甜心 2020-12-23 09:10

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

13条回答
  •  有刺的猬
    2020-12-23 09:50

    LINUX

    I always had issues while trying paths and the spec parameter.

    Therefore I went for the online solution that will update automatically the JSON on Swagger without having to reimport.

    If you use npm to start your swagger editor you should add a symbolic link of your json file.

    cd /path/to/your/swaggerui where index.html is.

    ln -s /path/to/your/generated/swagger.json

    You may encounter cache problems. The quick way to solve this was to add a token at the end of my url...

    window.onload = function() {
    
    var noCache = Math.floor((Math.random() * 1000000) + 1);
    
    // Build a system
    const editor = SwaggerEditorBundle({
    url: "http://localhost:3001/swagger.json?"+noCache,
      dom_id: '#swagger-editor',
      layout: 'StandaloneLayout',
      presets: [
        SwaggerEditorStandalonePreset
      ]
    })
    
    window.editor = editor
    }
    

提交回复
热议问题