diff options
author | Jhon Honce <jhonce@redhat.com> | 2020-02-03 16:47:52 -0700 |
---|---|---|
committer | Jhon Honce <jhonce@redhat.com> | 2020-02-04 16:39:54 -0700 |
commit | 4bb55161e95d9c28928210b92b9cd2bacaa7768b (patch) | |
tree | 9aa599ce853d3265243f5c7111985d70f2092dfd /pkg/api/server/register_swagger.go | |
parent | 5092c078ec635c9f1598989b27ccf53369b3cf2b (diff) | |
download | podman-4bb55161e95d9c28928210b92b9cd2bacaa7768b.tar.gz podman-4bb55161e95d9c28928210b92b9cd2bacaa7768b.tar.bz2 podman-4bb55161e95d9c28928210b92b9cd2bacaa7768b.zip |
Add /swagger/ endpoint to serve swagger yaml to clients
The provided yaml file will describe the current Podman REST API.
Signed-off-by: Jhon Honce <jhonce@redhat.com>
Diffstat (limited to 'pkg/api/server/register_swagger.go')
-rw-r--r-- | pkg/api/server/register_swagger.go | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/pkg/api/server/register_swagger.go b/pkg/api/server/register_swagger.go new file mode 100644 index 000000000..5564ec096 --- /dev/null +++ b/pkg/api/server/register_swagger.go @@ -0,0 +1,26 @@ +package server + +import ( + "net/http" + "os" + + "github.com/gorilla/mux" +) + +// DefaultPodmanSwaggerSpec provides the default path to the podman swagger spec file +const DefaultPodmanSwaggerSpec = "/usr/share/containers/podman/swagger.yaml" + +// RegisterSwaggerHandlers maps the swagger endpoint for the server +func (s *APIServer) RegisterSwaggerHandlers(r *mux.Router) error { + // This handler does _*NOT*_ provide an UI rather just a swagger spec that an UI could render + r.PathPrefix("/swagger/").HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + path := DefaultPodmanSwaggerSpec + if p, found := os.LookupEnv("PODMAN_SWAGGER_SPEC"); found { + path = p + } + w.Header().Set("Content-Type", "text/yaml") + + http.ServeFile(w, r, path) + }) + return nil +} |