Skip to content

Commit

Permalink
Fix user docs paths (#29)
Browse files Browse the repository at this point in the history
* Fix user docs paths

* Fix user doc prefix

* Fix get open api files helper
  • Loading branch information
crabio authored Sep 1, 2021
1 parent b799df5 commit 0c2533f
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
6 changes: 3 additions & 3 deletions pkg/swagger/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ func (s *Server) createHomePageHandler() (http.Handler, error) {
var swaggerFilePaths []string

// Parse and add pkg's swagger files
pkgSwaggerFilePaths, err := GetOpenAPIFilesPaths(docs.Swagger, "swagger", pkgDocsPrefix)
pkgSwaggerFilePaths, err := GetSwaggerFilesPaths(docs.Swagger, "swagger", pkgDocsPrefix)
if err != nil {
return nil, err
}
swaggerFilePaths = append(swaggerFilePaths, pkgSwaggerFilePaths...)

// Parse and add user's swagger files
if s.config.Docs.DocsFS != nil {
userSwaggerFilePaths, err := GetOpenAPIFilesPaths(*s.config.Docs.DocsFS, s.config.Docs.DocsRootFolder, userDocsPrefix)
userSwaggerFilePaths, err := GetSwaggerFilesPaths(*s.config.Docs.DocsFS, s.config.Docs.DocsRootFolder, userDocsPrefix)
if err != nil {
s.log.WithError(err).Error("No user's swagger files found")
} else {
Expand All @@ -49,7 +49,7 @@ func (s *Server) createHomePageHandler() (http.Handler, error) {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// Open API home page
if err := swaggerHomeTmpl.Execute(w, map[string]interface{}{"filePaths": swaggerFilePaths}); err != nil {
s.log.WithError(err).Error("couldn't execute OpenAPI home template")
s.log.WithError(err).Error("couldn't execute Swagger home template")
}
}), nil
}
2 changes: 1 addition & 1 deletion pkg/swagger/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
// Internal
)

func GetOpenAPIFilesPaths(fileSystem embed.FS, dirName string, prefix string) ([]string, error) {
func GetSwaggerFilesPaths(fileSystem embed.FS, dirName string, prefix string) ([]string, error) {
var filesPaths []string

libRegEx, err := regexp.Compile(`^.+\.(json)$`)
Expand Down
4 changes: 2 additions & 2 deletions pkg/swagger/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import (
"github.com/iakrevetkho/archaeopteryx/pkg/swagger"
)

func TestGetOpenAPIFilesPaths(t *testing.T) {
filePaths, err := swagger.GetOpenAPIFilesPaths(docs.Swagger, "swagger", "/doc/swagger/")
func TestGetSwaggerFilesPaths(t *testing.T) {
filePaths, err := swagger.GetSwaggerFilesPaths(docs.Swagger, "swagger", "/doc/swagger/")
assert.NoError(t, err)
assert.Equal(t, 3, len(filePaths))
assert.Equal(t, "/doc/swagger/google/api/annotations.swagger.json", filePaths[0])
Expand Down
2 changes: 1 addition & 1 deletion pkg/swagger/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
const (
mainPagePath = "/doc/swagger/"
pkgDocsPrefix = "/doc/swagger/"
userDocsPrefix = "/doc"
userDocsPrefix = "/doc/"
)

type Server struct {
Expand Down

0 comments on commit 0c2533f

Please sign in to comment.