问题
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
In
src\plugins\local-storage\index.js
, replaceimport PetstoreYaml from "./petstore"
with
const PetstoreYaml = ""
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