Switched api docs from statik to go:embed

This commit is contained in:
Denis Arh
2021-02-24 06:40:23 +01:00
parent 0598f6502b
commit 5e9545e9ab
7 changed files with 570 additions and 380 deletions
-3
View File
@@ -142,9 +142,6 @@ clean.codegen:
provision:
$(MAKE) --directory=provision clean all
docs: $(STATIK)
$(STATIK) -p docs -m -Z -f -src=./docs
#######################################################################################################################
# Quality Assurance
+3 -5
View File
@@ -3,6 +3,7 @@ package app
import (
"context"
composeRest "github.com/cortezaproject/corteza-server/compose/rest"
"github.com/cortezaproject/corteza-server/docs"
federationRest "github.com/cortezaproject/corteza-server/federation/rest"
messagingRest "github.com/cortezaproject/corteza-server/messaging/rest"
"github.com/cortezaproject/corteza-server/pkg/actionlog"
@@ -69,11 +70,8 @@ func (app *CortezaApp) mountHttpRoutes(r chi.Router) {
r.Route("/federation", federationRest.MountRoutes)
}
r.HandleFunc("/docs", func(w http.ResponseWriter, r *http.Request) {
// redirect to endpoint with slash
http.Redirect(w, r, "/"+apiBaseUrl+"/docs/", http.StatusPermanentRedirect)
})
r.HandleFunc("/docs*", server.ServeDocs("/"+apiBaseUrl+"/docs"))
r.Handle("/docs", http.RedirectHandler("/"+apiBaseUrl+"/docs/", http.StatusPermanentRedirect))
r.Handle("/docs*", http.StripPrefix("/"+apiBaseUrl+"/docs", http.FileServer(docs.GetFS())))
})
app.Log.Info(
+1 -4
View File
@@ -2,13 +2,10 @@
WARNING: Work in progress
WARNING: Any changes to these files here require `make docs`
This is the first step in migration towards full OpenAPI standards support.
## Current state (`2021.3.x` and later)
In branch `2020.12.x` we're experimenting with first step toward conversion to OpenAPI 3.0 YAML files for API
We're experimenting with first step toward conversion to OpenAPI 3.0 YAML files for API
definition. There is a converter available in https://github.com/cortezaproject/openapi3-converter[cortezaproject/openapi3-converter]
that takes those custom YAML files and converts them to OpenAPI format.
+14
View File
@@ -0,0 +1,14 @@
package docs
import (
"embed"
"net/http"
)
//go:embed *.yaml
//go:embed *.html
var docs embed.FS
func GetFS() http.FileSystem {
return http.FS(docs)
}
-6
View File
File diff suppressed because one or more lines are too long
+552 -342
View File
File diff suppressed because it is too large Load Diff
-20
View File
@@ -1,20 +0,0 @@
package server
import (
"fmt"
"github.com/cortezaproject/corteza-server/docs"
"github.com/goware/statik/fs"
"net/http"
)
func ServeDocs(base string) func(w http.ResponseWriter, r *http.Request) {
return func(w http.ResponseWriter, r *http.Request) {
root, err := fs.New(docs.Asset)
if err != nil {
http.Error(w, fmt.Sprintf("could not read embeded filesystem: %v", err.Error()), http.StatusInternalServerError)
return
}
http.StripPrefix(base, http.FileServer(root)).ServeHTTP(w, r)
}
}