-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #732 from cybercongress/v3-swagger-update
Swagger and openapi update
- Loading branch information
Showing
25 changed files
with
65,232 additions
and
144,530 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 was deleted.
Oops, something went wrong.
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,40 @@ | ||
package docs | ||
|
||
import ( | ||
"embed" | ||
httptemplate "html/template" | ||
"net/http" | ||
|
||
"github.com/gorilla/mux" | ||
) | ||
|
||
const ( | ||
apiFile = "/static/openapi.yml" | ||
indexFile = "template/index.tpl" | ||
) | ||
|
||
//go:embed static | ||
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, | ||
}) | ||
} | ||
} |
Oops, something went wrong.