启动Swagger Editor时移除默认Petstore规格的方法
Absolutely, you can totally configure your local Swagger Editor to start with a blank workspace instead of the default Petstore API specification. Below are tailored methods based on how you're running the editor:
1. For npm-installed Swagger Editor (Local Development Setup)
If you installed Swagger Editor via npm and run it locally, follow these steps:
- Locate the configuration file at
swagger-editor/config/defaults.jsonin your installation directory. - Find the
defaultDefinitionkey in this JSON file. Replace its existing Petstore-linked value with a minimal empty OpenAPI structure:{ "openapi": "3.0.0", "info": { "title": "", "version": "" }, "paths": {} } - Save the file and restart your Swagger Editor instance. It will now launch with this empty, valid OpenAPI skeleton ready for your edits.
2. For Docker-run Swagger Editor
If you're using Docker to run Swagger Editor, pass an environment variable to override the default spec:
- Use this modified
docker runcommand to start the editor with an empty workspace:docker run -p 8080:8080 -e SWAGGER_EDITOR_DEFAULT_DEFINITION='{"openapi":"3.0.0","info":{"title":"","version":""},"paths":{}}' swaggerapi/swagger-editor - The
SWAGGER_EDITOR_DEFAULT_DEFINITIONvariable injects the empty OpenAPI structure directly, so the editor loads it on startup instead of Petstore.
3. For Static Swagger Editor (Local HTML File)
If you downloaded the static Swagger Editor files and open index.html directly in your browser:
- Quick one-time fix: Append
?url=to the end of the file path in your browser's address bar (e.g.,file:///path/to/swagger-editor/index.html?url=). This tells the editor to load no default spec. - Permanent fix: Open the
index.htmlfile in a text editor. Look for the initialization script where Swagger Editor is configured, and modify thedefaultDefinitionoption to use the empty OpenAPI structure mentioned earlier. Save the file, and it will open blank every time.
Note
If you want an entirely empty editor (no base OpenAPI skeleton at all), you can set defaultDefinition to an empty string "" instead of the minimal structure. Just keep in mind that some older Swagger Editor versions might require a valid JSON structure to avoid loading errors, so the minimal empty OpenAPI skeleton is the safer bet.
内容的提问来源于stack exchange,提问作者Good Samartian

