启动 swagger 编辑器时删除 petstore 规范

Goo*_*ian 5 swagger-editor

我在我的机器上本地使用 Swagger 编辑器。

当我启动 Swagger Editor 时,它在启动时默认显示 petstore 的规范。

我想删除它并显示一个空白的编辑器。有没有办法在启动时做到这一点。

Hel*_*len 4

一个简单的解决方法是使用参数运行编辑器?url=,其中 URL 指向空页面(无 HTTP 响应正文),例如http://httpbin.org/status/200

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

这将打开一个空白编辑器。


或者,您可以修改编辑器的源代码并构建您自己的版本。您将需要 Node.js 6.x 和 npm 3.x(截至撰写本文时)。

默认编辑器内容似乎在这里设置: https://github.com/swagger-api/swagger-editor/blob/master/src/plugins/local-storage/index.js#L29

  1. src\plugins\local-storage\index.js,替换

    import PetstoreYaml from "./petstore"
    
    Run Code Online (Sandbox Code Playgroud)

    const PetstoreYaml = ""
    
    Run Code Online (Sandbox Code Playgroud)
  2. 重建编辑器:

    npm run build
    
    Run Code Online (Sandbox Code Playgroud)