Skip to content

Commit

Permalink
Merge pull request #732 from cybercongress/v3-swagger-update
Browse files Browse the repository at this point in the history
Swagger and openapi update
  • Loading branch information
cyborgshead committed Apr 24, 2024
2 parents 2e719ce + c4b0619 commit 2302414
Show file tree
Hide file tree
Showing 25 changed files with 65,232 additions and 144,530 deletions.
7 changes: 3 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,9 @@ proto-format:
--workdir /workspace $(PROTO_FORMATTER_IMAGE) \
find ./ -name *.proto -exec clang-format -i {} \;

# TODO update swagger gen
#proto-swagger-gen:
# @#echo "Generating Protobuf Swagger"
# @./scripts/protoc-swagger-gen.sh
proto-swagger-gen:
@echo "Generating Protobuf Swagger OpenAPI"
@./scripts/protoc_swagger_openapi_gen.sh

proto-lint:
@$(DOCKER_BUF) lint --error-format=json
Expand Down
5 changes: 5 additions & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package app

import (
"fmt"
"github.com/cybercongress/go-cyber/v3/client/docs"
"io"
"os"
"strings"
Expand Down Expand Up @@ -71,6 +72,7 @@ import (

const (
appName = "BostromHub"
Name = "bostrom"
)

// We pull these out so we can set them with LDFLAGS in the Makefile
Expand Down Expand Up @@ -437,6 +439,9 @@ func (app *App) RegisterAPIRoutes(apiSvr *api.Server, apiConfig config.APIConfig
// Register legacy and grpc-gateway routes for all modules.
ModuleBasics.RegisterRESTRoutes(clientCtx, apiSvr.Router)
ModuleBasics.RegisterGRPCGatewayRoutes(clientCtx, apiSvr.GRPCGatewayRouter)

// register app's OpenAPI routes.
docs.RegisterOpenAPIService(Name, apiSvr.Router)
}

// RegisterTxService implements the Application.RegisterTxService method.
Expand Down
73 changes: 0 additions & 73 deletions client/docs/config.json

This file was deleted.

40 changes: 40 additions & 0 deletions client/docs/docs.go
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,
})
}
}
Loading

0 comments on commit 2302414

Please sign in to comment.