启动 swagger 编辑器时删除 petstore 规范
Remove petstore spec when starting swagger editor
我在我的机器上本地使用 Swagger 编辑器。
当我启动 Swagger Editor 时,它在启动时默认显示 petstore 的规范。
我想删除它并显示空白编辑器。有没有办法在启动时做到这一点。
一个简单的解决方法是 运行 带有 ?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 like swagger-ui's it.
详情
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.
使用以下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 图片(docker 拉取 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是机器IP,swagger编辑器镜像是运行ning,将9800替换成你想访问的任何端口
从下一个版本 v1.4.1 开始,将添加以下 属性 以禁用 swagger-ui 默认宠物商店 url:
springdoc.swagger-ui.disable-swagger-default-url=true
复制自
https://github.com/springdoc/springdoc-openapi/issues/714#issuecomment-640215759
我在我的机器上本地使用 Swagger 编辑器。
当我启动 Swagger Editor 时,它在启动时默认显示 petstore 的规范。
我想删除它并显示空白编辑器。有没有办法在启动时做到这一点。
一个简单的解决方法是 运行 带有 ?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 like swagger-ui's it.
详情
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.
使用以下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 图片(docker 拉取 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是机器IP,swagger编辑器镜像是运行ning,将9800替换成你想访问的任何端口
从下一个版本 v1.4.1 开始,将添加以下 属性 以禁用 swagger-ui 默认宠物商店 url:
springdoc.swagger-ui.disable-swagger-default-url=true
复制自 https://github.com/springdoc/springdoc-openapi/issues/714#issuecomment-640215759