Skip to content

Commit

Permalink
Added a shortcut Shift+Alt+P, ability to change default port from set…
Browse files Browse the repository at this point in the history
…tings
  • Loading branch information
arjun-g committed Aug 28, 2016
1 parent 0ad67bd commit 095fe0b
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 4 deletions.
21 changes: 19 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,36 @@

It works on swagger files in json and yaml format. Preview happens in real time as you type.

To start
* Open the swagger file and press F1.
* Run the Command `Preview Swagger`.

OR
* Press `Shift + Alt + P`

THEN
* Either:
1. Copy the URL shown in the message box. (Eg. [https://localhost:9000/](https://localhost:9000/))
* Open in any latest browser and see your changes reflecting in real time as you type in the editor.
2. Click on `Open` to open the preview in your default browser.


![Swagger Preview](https://arjunstatic.blob.core.windows.net/public/swagger_preview.gif)
![Swagger Preview](https://arjunstatic.blob.core.windows.net/public/swagger_preview_launch.gif)

## Change Default Port

Default port of the preview url can be changed by changing the `swaggerViewer.defaultPort` value in `User/Workspace Settings`

![Swagger Preview Settings](https://arjunstatic.blob.core.windows.net/public/swagger_preview_settings.gif)

v1.2.0 Changes

* Added `Open` button in message box. (By [@pmentz](https://github.com/pmentz) [https://github.com/arjun-g/vs-swagger-viewer/pull/3](https://github.com/arjun-g/vs-swagger-viewer/pull/3)
* Added shortcut `Shift + Alt + P` to run the command
* Ability to change default port from `User/Workspace Settings`.

### Credits
Swagger Viewer utilizes the following open source projects
* [Sawgger Editor](https://github.com/swagger-api/swagger-editor)
* [Swagger Editor](https://github.com/swagger-api/swagger-editor)
* [Express](https://github.com/expressjs/express)
* [socket.io](https://github.com/socketio/socket.io/)
3 changes: 2 additions & 1 deletion extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ function activate(context) {
// Now provide the implementation of the command with registerCommand
// The commandId parameter must match the command field in package.json
var disposable = vscode.commands.registerCommand('extension.previewSwagger', function () {
var defaultPort = vscode.workspace.getConfiguration('swaggerViewer').defaultPort || 9000;
let handlePreviewResponse = (option) => {
if (typeof option == 'undefined') {
return;
Expand Down Expand Up @@ -75,7 +76,7 @@ function activate(context) {
startServer(++port);
}
}
startServer(9000);
startServer(defaultPort);
}
else{
vscode.window.showInformationMessage('Preview "' + fileName.substring((fileName.lastIndexOf("\\") || fileName.lastIndexOf("/")) + 1) + '" in http://localhost:' + ports[fileName] + "/",
Expand Down
19 changes: 18 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,24 @@
"command": "extension.previewSwagger",
"title": "Preview Swagger"
}
]
],
"configuration": {
"type": "object",
"title": "Swagger Viewer configuration",
"properties": {
"swaggerViewer.defaultPort": {
"type": "integer",
"default": 9000,
"description": "Default port in which the preview should be opened."
}
}
},
"keybindings": [{
"command": "extension.previewSwagger",
"key": "shift+alt+p",
"mac": "shift+alt+p",
"when": "editorTextFocus"
}]
},
"devDependencies": {
"vscode": "^0.11.0"
Expand Down

0 comments on commit 095fe0b

Please sign in to comment.