-
Notifications
You must be signed in to change notification settings - Fork 552
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: remove
pkg/openapiconsole
import in scaffolded chain (#3337)
* fix typo * add nodeservice * add nodeservice * add doc * remove need for openAPI import * no more import * no more import * changelog * gofmt on go.plush files * update changelog * refactor Co-authored-by: Thomas Bruyelle <[email protected]>
- Loading branch information
Showing
5 changed files
with
92 additions
and
22 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
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 |
---|---|---|
@@ -1,6 +1,41 @@ | ||
package docs | ||
|
||
import "embed" | ||
import ( | ||
"embed" | ||
httptemplate "html/template" | ||
"net/http" | ||
|
||
"github.com/gorilla/mux" | ||
) | ||
|
||
const ( | ||
apiFile = "/static/openapi.yml" | ||
indexFile = "template/index.tpl" | ||
) | ||
|
||
|
||
//go:embed static | ||
var Docs embed.FS | ||
var Static embed.FS | ||
|
||
//go:embed template | ||
var template embed.FS | ||
|
||
func RegisterOpenAPIService(appName string, rtr *mux.Router) { | ||
rtr.Handle(apiFile, http.FileServer(http.FS(Static))) | ||
rtr.HandleFunc("/", handler(appName)) | ||
} | ||
|
||
// handler returns an http handler that servers OpenAPI console for an OpenAPI spec at specURL. | ||
func handler(title string) http.HandlerFunc { | ||
t, _ := httptemplate.ParseFS(template, indexFile) | ||
|
||
return func(w http.ResponseWriter, req *http.Request) { | ||
t.Execute(w, struct { | ||
Title string | ||
URL string | ||
}{ | ||
title, | ||
apiFile, | ||
}) | ||
} | ||
} |
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,28 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<title>{{ .Title }}</title> | ||
<link rel="stylesheet" type="text/css" href="//unpkg.com/[email protected]/swagger-ui.css" /> | ||
<link rel="icon" type="image/png" href="//unpkg.com/[email protected]/favicon-16x16.png" /> | ||
</head> | ||
<body> | ||
<div id="swagger-ui"></div> | ||
|
||
<script src="//unpkg.com/[email protected]/swagger-ui-bundle.js"></script> | ||
<script> | ||
// init Swagger for faucet's openapi.yml. | ||
window.onload = function() { | ||
window.ui = SwaggerUIBundle({ | ||
url: {{ .URL }}, | ||
dom_id: "#swagger-ui", | ||
deepLinking: true, | ||
layout: "BaseLayout", | ||
}); | ||
} | ||
</script> | ||
</body> | ||
</html> | ||
Footer | ||
© 2022 GitHub, Inc. | ||
Footer navigation |