Remove petstore spec when starting swagger editor

守給你的承諾、 提交于 2019-12-10 20:07:43

问题


I am using Swagger Editor locally in my machine.

When I start the Swagger Editor, it shows the spec for petstore by default at startup.

I want to remove that and show a blank editor. Is there a way to do that at startup.


回答1:


A simple workaround is to run the editor with the ?url= parameter where the URL points to an empty page (no HTTP response body), such as http://httpbin.org/status/200.

http://editor.swagger.io/?url=http://httpbin.org/status/200

This will open a blank editor.


Alternatively, you can modify the editor's source code and build your own version. You will need Node.js 6.x and npm 3.x (as of time of this writing).

The default editor contents seems to be set here: https://github.com/swagger-api/swagger-editor/blob/master/src/plugins/local-storage/index.js#L29

  1. In src\plugins\local-storage\index.js, replace

    import PetstoreYaml from "./petstore"
    

    with

    const PetstoreYaml = ""
    
  2. Rebuild the editor:

    npm run build
    



回答2:


Insert url property into swagger-editor's index.html like swagger-ui's it.

detail

Open custom yaml spec in swagger editor on startup · Issue #1727 · swagger-api/swagger-editor

You can use Swagger-UI's config options to load in your own definiton: there's url for fetching a remote document, and spec for passing in a JavaScript object directly. Swagger-Editor passes these options directly to its underlying Swagger-UI instance.




回答3:


Use the following js code to remove the default content in swagger editor.

 editor = SwaggerEditorBundle({
        dom_id: "#swagger-editor",
        layout: "StandaloneLayout",
        presets: [SwaggerEditorStandalonePreset]
      });
      window.editor = editor;
      // The line to remove the content in swagger editor
      editor.specActions.updateSpec(' ');


来源:https://stackoverflow.com/questions/49515713/remove-petstore-spec-when-starting-swagger-editor

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!