【发布时间】:2018-09-06 00:42:24
【问题描述】:
我在我的机器上本地使用 Swagger Editor。
当我启动 Swagger Editor 时,它会在启动时默认显示 petstore 的规范。
我想删除它并显示一个空白编辑器。有没有办法在启动时做到这一点。
【问题讨论】:
标签: swagger-editor
我在我的机器上本地使用 Swagger Editor。
当我启动 Swagger Editor 时,它会在启动时默认显示 petstore 的规范。
我想删除它并显示一个空白编辑器。有没有办法在启动时做到这一点。
【问题讨论】:
标签: swagger-editor
一个简单的解决方法是使用?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
在src\plugins\local-storage\index.js,替换
import PetstoreYaml from "./petstore"
与
const PetstoreYaml = ""
重建编辑器:
npm run build
【讨论】:
将 url 属性插入到 swagger-editor's index.html 中,例如 swagger-ui's it。
Open custom yaml spec in swagger editor on startup · Issue #1727 · swagger-api/swagger-editor
您可以使用 Swagger-UI 的配置选项来加载您自己的定义:有用于获取远程文档的 url,以及用于直接传入 JavaScript 对象的规范。 Swagger-Editor 将这些选项直接传递给其底层 Swagger-UI 实例。
【讨论】:
使用下面的js代码去除swagger编辑器中的默认内容。
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(' ');
【讨论】:
如果您使用 docker image (docker pull swaggerapi/swagger-editor) 在本地运行 swagger 编辑器,请提供您自己的本地 json 或 yaml 文件,如下所示:
$ ls
teapi-openapi.yaml
$sudo docker run -d -p 9800:8080 -v $(pwd):/tmp -e SWAGGER_FILE=/tmp/teapi-openapi.yaml swaggerapi/swagger-editor
访问:
http://<IP>:9800/
其中,ip 是运行 swagger 编辑器映像的机器 IP,将 9800 替换为您要访问的任何端口
【讨论】:
从下一个版本 v1.4.1 开始,将添加以下属性来禁用 swagger-ui 默认 petstore url:
springdoc.swagger-ui.disable-swagger-default-url=true
复制自 https://github.com/springdoc/springdoc-openapi/issues/714#issuecomment-640215759
【讨论】: