github.com/hanks177/podman/v4@v4.1.3-0.20220613032544-16d90015bc83/pkg/api/handlers/libpod/swagger_spec.go (about) 1 package libpod 2 3 import ( 4 "net/http" 5 "os" 6 7 "github.com/hanks177/podman/v4/pkg/api/handlers/utils" 8 "github.com/pkg/errors" 9 ) 10 11 // DefaultPodmanSwaggerSpec provides the default path to the podman swagger spec file 12 const DefaultPodmanSwaggerSpec = "/usr/share/containers/podman/swagger.yaml" 13 14 func ServeSwagger(w http.ResponseWriter, r *http.Request) { 15 path := DefaultPodmanSwaggerSpec 16 if p, found := os.LookupEnv("PODMAN_SWAGGER_SPEC"); found { 17 path = p 18 } 19 if _, err := os.Stat(path); err != nil { 20 if errors.Is(err, os.ErrNotExist) { 21 utils.InternalServerError(w, errors.Errorf("swagger spec %q does not exist", path)) 22 return 23 } 24 utils.InternalServerError(w, err) 25 return 26 } 27 w.Header().Set("Content-Type", "text/yaml") 28 http.ServeFile(w, r, path) 29 }