This repository has been archived by the owner on Apr 30, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Svetlin Ralchev
committed
Nov 25, 2019
1 parent
c43acdf
commit 82b3c76
Showing
21 changed files
with
345,346 additions
and
264 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package cmd | ||
|
||
import ( | ||
"io" | ||
"net/http" | ||
"os" | ||
|
||
"github.com/go-chi/chi" | ||
"github.com/phogolabs/cli" | ||
"github.com/phogolabs/log" | ||
"github.com/phogolabs/log/handler/console" | ||
"github.com/phogolabs/parcello" | ||
"github.com/phogolabs/rest/middleware" | ||
) | ||
|
||
// OpenAPIEditor provides a subcommands to edit OpenAPI specification in the browser | ||
type OpenAPIEditor struct{} | ||
|
||
// CreateCommand creates a cli.Command that can be used by cli.App. | ||
func (m *OpenAPIEditor) CreateCommand() *cli.Command { | ||
return &cli.Command{ | ||
Name: "edit", | ||
Usage: "Edit an OpenAPI specification in the browser", | ||
Description: "Edit an OpenAPI specification in the browser", | ||
Before: m.before, | ||
Action: m.edit, | ||
Flags: []cli.Flag{ | ||
&cli.StringFlag{ | ||
Name: "listen-addr", | ||
Usage: "address on which the http server is listening on", | ||
Value: "localhost:8080", | ||
}, | ||
&cli.StringFlag{ | ||
Name: "file-path, f", | ||
Usage: "path to the open api specification", | ||
Value: "./swagger.yaml", | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func (m *OpenAPIEditor) before(ctx *cli.Context) error { | ||
log.SetHandler(console.New(ctx.Writer)) | ||
return nil | ||
} | ||
|
||
func (m *OpenAPIEditor) edit(ctx *cli.Context) error { | ||
router := chi.NewRouter() | ||
|
||
router.Use(middleware.StripSlashes) | ||
router.Use(middleware.RealIP) | ||
router.Use(middleware.Recoverer) | ||
router.Use(middleware.NoCache) | ||
router.Use(middleware.Logger) | ||
|
||
router.Mount("/", http.FileServer(parcello.ManagerAt("editor"))) | ||
// router.Mount("/", http.FileServer(http.Dir("./template/editor"))) | ||
router.Mount("/swagger.spec", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
switch r.Method { | ||
case "GET": | ||
http.ServeFile(w, r, ctx.String("file-path")) | ||
case "POST": | ||
SaveFile(w, r, ctx.String("file-path")) | ||
} | ||
})) | ||
|
||
log.Infof("http server is listening on http://%v", ctx.String("listen-addr")) | ||
|
||
return http.ListenAndServe(ctx.String("listen-addr"), router) | ||
} | ||
|
||
// SaveFile saves the file | ||
func SaveFile(w http.ResponseWriter, r *http.Request, path string) { | ||
spec, err := os.Create(path) | ||
if err != nil { | ||
middleware.GetLogger(r).WithError(err).Error("failed to save the spec") | ||
return | ||
} | ||
defer spec.Close() | ||
|
||
if _, err := io.Copy(spec, r.Body); err != nil { | ||
middleware.GetLogger(r).WithError(err).Error("failed to save the spec") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
This module, `swagger-editor-dist`, exposes Swagger-Editor's entire dist folder as a dependency-free npm module. | ||
|
||
Use `swagger-editor` instead, if you'd like to have npm install dependencies for you. |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
<!DOCTYPE html> | ||
<!-- HTML for static distribution bundle build --> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title>Swagger Editor</title> | ||
<link rel="icon" type="image/png" href="./favicon-32x32.png" sizes="32x32" /> | ||
<link rel="icon" type="image/png" href="./favicon-16x16.png" sizes="16x16" /> | ||
<link href="./swagger-editor.css" rel="stylesheet"> | ||
<style> | ||
* { | ||
box-sizing: border-box; | ||
} | ||
|
||
body { | ||
font-family: Roboto, sans-serif; | ||
font-size: 9px; | ||
line-height: 1.42857143; | ||
color: #444; | ||
margin: 0px; | ||
} | ||
|
||
#swagger-editor { | ||
font-size: 1.3em; | ||
} | ||
|
||
.container { | ||
height: 100%; | ||
max-width: 880px; | ||
margin-left: auto; | ||
margin-right: auto; | ||
} | ||
|
||
#editor-wrapper { | ||
height: 100%; | ||
border: 1em solid #000; | ||
border: none; | ||
} | ||
|
||
.Pane2 { | ||
overflow-y: scroll; | ||
} | ||
|
||
#swagger-editor #ace-editor.ace_editor { | ||
height: calc(100vh) !important; | ||
} | ||
|
||
#swagger-editor .SplitPane.vertical { | ||
height: calc(100%) !important; | ||
} | ||
</style> | ||
</head> | ||
|
||
<body> | ||
<div id="swagger-editor"></div> | ||
<script src="./swagger-editor-bundle.js"> </script> | ||
<script src="./swagger-editor-standalone-preset.js"> </script> | ||
<script> | ||
const addr = window.location.protocol + "//" + window.location.hostname + ":" + window.location.port + "/swagger.spec"; | ||
|
||
function post(url = '', data = '') { | ||
return fetch(url, { | ||
method: 'POST', | ||
mode: 'cors', | ||
cache: 'no-cache', | ||
credentials: 'same-origin', | ||
headers: { | ||
'Content-Type': 'application/x-yaml', | ||
}, | ||
redirect: 'follow', | ||
referrer: 'no-referrer', | ||
body: data, | ||
}); | ||
} | ||
|
||
const UpdatePlugin = function(system) { | ||
return { | ||
statePlugins: { | ||
spec: { | ||
wrapActions: { | ||
updateSpec: (oriAction, system) => (str) => { | ||
post(addr, str); | ||
return oriAction(str); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
function liveReload() { | ||
const editor = SwaggerEditorBundle({ | ||
url: addr, | ||
dom_id: '#swagger-editor', | ||
plugins: SwaggerEditorStandalonePreset().slice(4).concat(UpdatePlugin) | ||
}) | ||
|
||
window.editor = editor | ||
} | ||
|
||
window.onload = liveReload; | ||
</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
{ | ||
"_from": "swagger-editor-dist", | ||
"_id": "swagger-editor-dist@3.6.28", | ||
"_inBundle": false, | ||
"_integrity": "sha512-xVqL4ON6Ygw7ceNTplTITVcuociemqBg7ZcNXa02BrGY/yf5cH7lRSNecFUpK1ZBhJ04GzFhEGEvXty9eZnhlw==", | ||
"_location": "/swagger-editor-dist", | ||
"_phantomChildren": {}, | ||
"_requested": { | ||
"type": "tag", | ||
"registry": true, | ||
"raw": "swagger-editor-dist", | ||
"name": "swagger-editor-dist", | ||
"escapedName": "swagger-editor-dist", | ||
"rawSpec": "", | ||
"saveSpec": null, | ||
"fetchSpec": "latest" | ||
}, | ||
"_requiredBy": [ | ||
"#USER", | ||
"/" | ||
], | ||
"_resolved": "https://registry.npmjs.org/swagger-editor-dist/-/swagger-editor-dist-3.6.28.tgz", | ||
"_shasum": "ee0a55a2988a366857c46f27f676c62830d7beef", | ||
"_spec": "swagger-editor-dist", | ||
"_where": "/Users/ralch/go/src/github.com/phogolabs/stride/template", | ||
"bugs": { | ||
"url": "https://github.com/swagger-api/swagger-editor/issues" | ||
}, | ||
"bundleDependencies": false, | ||
"contributors": [ | ||
{ | ||
"url": "in alphabetical order" | ||
}, | ||
{ | ||
"name": "Anna Bodnia", | ||
"email": "anna.bodnia@gmail.com" | ||
}, | ||
{ | ||
"name": "Buu Nguyen", | ||
"email": "buunguyen@gmail.com" | ||
}, | ||
{ | ||
"name": "Josh Ponelat", | ||
"email": "jponelat@gmail.com" | ||
}, | ||
{ | ||
"name": "Kyle Shockey", | ||
"email": "kyleshockey1@gmail.com" | ||
}, | ||
{ | ||
"name": "Robert Barnwell", | ||
"email": "robert@robertismy.name" | ||
}, | ||
{ | ||
"name": "Sahar Jafari", | ||
"email": "shr.jafari@gmail.com" | ||
} | ||
], | ||
"dependencies": {}, | ||
"deprecated": false, | ||
"description": "This module, `swagger-editor-dist`, exposes Swagger-Editor's entire dist folder as a dependency-free npm module.", | ||
"devDependencies": {}, | ||
"homepage": "https://github.com/swagger-api/swagger-editor#readme", | ||
"license": "Apache-2.0", | ||
"main": "swagger-editor.js", | ||
"name": "swagger-editor-dist", | ||
"repository": { | ||
"type": "git", | ||
"url": "git+ssh://git@github.com/swagger-api/swagger-editor.git" | ||
}, | ||
"version": "3.6.28" | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Oops, something went wrong.