Skip to content

Commit

Permalink
First Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
arjun-g committed May 1, 2016
0 parents commit c21369b
Show file tree
Hide file tree
Showing 2,514 changed files with 830,818 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
22 changes: 22 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// A launch configuration that launches the extension inside a new window
{
"version": "0.1.0",
"configurations": [
{
"name": "Launch Extension",
"type": "extensionHost",
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": ["--extensionDevelopmentPath=${workspaceRoot}" ],
"stopOnEntry": false
},
{
"name": "Launch Tests",
"type": "extensionHost",
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": ["--extensionDevelopmentPath=${workspaceRoot}", "--extensionTestsPath=${workspaceRoot}/test" ],
"stopOnEntry": false
}
]
}
6 changes: 6 additions & 0 deletions .vscodeignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.vscode/**
typings/**
test/**
.gitignore
jsconfig.json
vsc-extension-quickstart.md
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Swagger Viewer
## Swagger Viewer lets you preview swagger file as you type Visual Studio Code.

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

Open the swagger file and



* Split the editor (`Cmd+\` on OSX or `Ctrl+\` on Windows and Linux)
* Toggle preview (`Shift+CMD+V` on OSX or `Shift+Ctrl+V` on Windows and Linux)
* Press `Ctrl+Space` (Windows, Linux) or `Cmd+Space` (OSX) to see a list of Markdown snippets

### For more information
* [Visual Studio Code's Markdown Support](http://code.visualstudio.com/docs/languages/markdown)
* [Markdown Syntax Reference](https://help.github.com/articles/markdown-basics/)

**Enjoy!**
110 changes: 110 additions & 0 deletions extension.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
// The module 'vscode' contains the VS Code extensibility API
// Import the module and reference it with the alias vscode in your code below
var vscode = require('vscode');
var shell = require("shelljs");
var path = require('path');

var ports = {}
, servers = {}
, ios = {}
;

// this method is called when your extension is activated
// your extension is activated the very first time the command is executed
function activate(context) {

// Use the console to output diagnostic information (console.log) and errors (console.error)
// This line of code will only be executed once when your extension is activated

// The command has been defined in the package.json file
// 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 editor = vscode.window.activeTextEditor;
var doc = editor.document;
var fileName = doc.fileName.toLowerCase();
if (!servers[fileName]) {
// Display a message box to the user
//vscode.window.showInformationMessage('Hello World!');
var express = require('express');
var http = require('http');
var app = express();
app.use(express.static(path.join(__dirname, 'static')));
//app.set('port', 3002);
var server = http.createServer(app);
var io = require('socket.io')(server);
function startServer(port) {
app.set('port', port);
try {
server.listen(port, function (err) {
servers[fileName] = server;
ports[fileName] = port;
ios[fileName] = io;
vscode.window.showInformationMessage('Preview "' + fileName.substring((fileName.lastIndexOf("\\") || fileName.lastIndexOf("/")) + 1) + '" in http://localhost:' + port + "/");
//console.log('Example app listening on port 3000!');
ios[fileName].on("connection", function (socket) {
socket.on("GET_UPDATE", function (data, fn) {
fn(doc.getText());
})
})
var previewSwagger = new PreviewSwagger(fileName);
var previewSwaggerController = new PreviewSwaggerController(previewSwagger);
context.subscriptions.push(previewSwagger);
context.subscriptions.push(previewSwaggerController);
previewSwagger.update();
});
server.on("error", function (err) {
startServer(++port);
})
}
catch (ex) {
startServer(++port);
}
}
startServer(9000);
}
else{
vscode.window.showInformationMessage('Preview "' + fileName.substring((fileName.lastIndexOf("\\") || fileName.lastIndexOf("/")) + 1) + '" in http://localhost:' + ports[fileName] + "/");
}
});
context.subscriptions.push(disposable);
}

function PreviewSwagger(fileName) {
var editor = vscode.window.activeTextEditor;
var doc = editor.document;
this.update = function () {
ios[fileName].emit("TEXT_UPDATE", doc.getText());
}
this.close = function () {
servers[fileName].close();
console.log("CLOSED");
}
}

function PreviewSwaggerController(swag) {
var subscriptions = [];
function update() {
var editor = vscode.window.activeTextEditor;
if (!editor) { return; }
var doc = editor.document;
if (doc.languageId === "yaml") {
swag.update();
} else {
swag.close();
}
}
vscode.window.onDidChangeActiveTextEditor(update, this, subscriptions);
vscode.window.onDidChangeTextEditorSelection(update, this, subscriptions);
swag.update();
}

exports.activate = activate;



// this method is called when your extension is deactivated
function deactivate() {
}
exports.deactivate = deactivate;
10 changes: 10 additions & 0 deletions jsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"compilerOptions": {
"module": "commonjs",
"target": "ES5",
"noLib": true
},
"exclude": [
"node_modules"
]
}
Binary file added logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
37 changes: 37 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"name": "swagger-viewer",
"displayName": "Swagger Viewer",
"description": "Preview your swagger files (yaml and json)",
"version": "0.0.1",
"publisher": "ArjunG",
"engines": {
"vscode": "^0.10.10"
},
"categories": [
"Other"
],
"activationEvents": [
"onLanguage:yaml",
"onLanguage:json"
],
"main": "./extension",
"contributes": {
"commands": [
{
"command": "extension.previewSwagger",
"title": "Preview Swagger"
}
]
},
"scripts": {
"postinstall": "node ./node_modules/vscode/bin/install"
},
"devDependencies": {
"vscode": "^0.11.0"
},
"dependencies": {
"express": "^4.13.4",
"shelljs": "^0.6.0",
"socket.io": "^1.4.5"
}
}
157 changes: 157 additions & 0 deletions static/404.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Page Not Found :(</title>
<style>
::-moz-selection {
background: #b3d4fc;
text-shadow: none;
}

::selection {
background: #b3d4fc;
text-shadow: none;
}

html {
padding: 30px 10px;
font-size: 20px;
line-height: 1.4;
color: #737373;
background: #f0f0f0;
-webkit-text-size-adjust: 100%;
-ms-text-size-adjust: 100%;
}

html,
input {
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
}

body {
max-width: 500px;
_width: 500px;
padding: 30px 20px 50px;
border: 1px solid #b3b3b3;
border-radius: 4px;
margin: 0 auto;
box-shadow: 0 1px 10px #a7a7a7, inset 0 1px 0 #fff;
background: #fcfcfc;
}

h1 {
margin: 0 10px;
font-size: 50px;
text-align: center;
}

h1 span {
color: #bbb;
}

h3 {
margin: 1.5em 0 0.5em;
}

p {
margin: 1em 0;
}

ul {
padding: 0 0 0 40px;
margin: 1em 0;
}

.container {
max-width: 380px;
_width: 380px;
margin: 0 auto;
}

/* google search */

#goog-fixurl ul {
list-style: none;
padding: 0;
margin: 0;
}

#goog-fixurl form {
margin: 0;
}

#goog-wm-qt,
#goog-wm-sb {
border: 1px solid #bbb;
font-size: 16px;
line-height: normal;
vertical-align: top;
color: #444;
border-radius: 2px;
}

#goog-wm-qt {
width: 220px;
height: 20px;
padding: 5px;
margin: 5px 10px 0 0;
box-shadow: inset 0 1px 1px #ccc;
}

#goog-wm-sb {
display: inline-block;
height: 32px;
padding: 0 10px;
margin: 5px 0 0;
white-space: nowrap;
cursor: pointer;
background-color: #f5f5f5;
background-image: -webkit-linear-gradient(rgba(255,255,255,0), #f1f1f1);
background-image: -moz-linear-gradient(rgba(255,255,255,0), #f1f1f1);
background-image: -ms-linear-gradient(rgba(255,255,255,0), #f1f1f1);
background-image: -o-linear-gradient(rgba(255,255,255,0), #f1f1f1);
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
*overflow: visible;
*display: inline;
*zoom: 1;
}

#goog-wm-sb:hover,
#goog-wm-sb:focus {
border-color: #aaa;
box-shadow: 0 1px 1px rgba(0, 0, 0, 0.1);
background-color: #f8f8f8;
}

#goog-wm-qt:hover,
#goog-wm-qt:focus {
border-color: #105cb6;
outline: 0;
color: #222;
}

input::-moz-focus-inner {
padding: 0;
border: 0;
}
</style>
</head>
<body>
<div class="container">
<h1>Not found <span>:(</span></h1>
<p>Sorry, but the page you were trying to view does not exist.</p>
<p>It looks like this was the result of either:</p>
<ul>
<li>a mistyped address</li>
<li>an out-of-date link</li>
</ul>
<script>
var GOOG_FIXURL_LANG = (navigator.language || '').slice(0,2),GOOG_FIXURL_SITE = location.host;
</script>
<script src="//linkhelp.clients.google.com/tbproxy/lh/wm/fixurl.js"></script>
</div>
</body>
</html>
1 change: 1 addition & 0 deletions static/CNAME
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
editor.swagger.io
Loading

0 comments on commit c21369b

Please sign in to comment.