How to open local files in Swagger-UI

前端 未结 13 1663
粉色の甜心
粉色の甜心 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:52

    After a bit of struggle, I found a better solution.

    1. create a directory with name: swagger

      mkdir C:\swagger
      

    If you are in Linux, try:

        mkdir /opt/swagger
    
    1. get swagger-editor with below command:

      git clone https://github.com/swagger-api/swagger-editor.git
      
    2. go into swagger-editor directory that is created now

      cd swagger-editor
      
    3. now get swagger-ui with below command:

      git clone https://github.com/swagger-api/swagger-ui.git
      
    4. now, copy your swagger file, I copied to below path:

      ./swagger-editor/api/swagger/swagger.json
      
    5. all setup is done, run the swagger-edit with below commands

      npm install
      npm run build
      npm start
      
    6. You will be prompted 2 URLs, one of them might look like:

      http://127.0.0.1:3001/
      

      Above is swagger-editor URL

    7. Now browse to:

      http://127.0.0.1:3001/swagger-ui/dist/
      

      Above is swagger-ui URL

    Thats all.

    You can now browse files from either of swagger-ui or swagger-editor

    It will take time to install/build, but once done, you will see great results.

    It took roughly 2 days of struggle for me, one-time installation took only about 5 minutes.

    Now, on top-right, you can browse to your local file.

    best of luck.

提交回复
热议问题