mvrilo / go-redoc Goto Github PK
View Code? Open in Web Editor NEWgo-redoc is an embedded OpenAPI/Swagger documentation ui for Go using ReDoc
License: MIT License
go-redoc is an embedded OpenAPI/Swagger documentation ui for Go using ReDoc
License: MIT License
This is my test demo.
package main
import (
"github.com/gin-gonic/gin"
"github.com/mvrilo/go-redoc"
ginredoc "github.com/mvrilo/go-redoc/gin"
)
func main() {
doc := redoc.Redoc{
Title: "Example API",
Description: "Example API Description",
SpecFile: "./openapi.yml",
SpecPath: "/openapi.yml",
DocsPath: "/docs",
}
r := gin.New()
r.Use(ginredoc.New(doc))
println("Documentation served at http://127.0.0.1:8000/docs")
panic(r.Run(":8000"))
}
When I run and visit http://172.28.73.58:8000/docs Page stuck in initialization (172.28.73.58 is my wsl2 ip)
And my gin run window has a warning message
[GIN-debug] [WARNING] Headers were already written. Wanted to override status code 404 with 200
Can you tell me how to solve it? thank
Registering the net/http handler under a mux router causes a 404 error serving de docs
Using the following code:
func RunInternal() error {
internal := mux.NewRouter()
internal.HandleFunc("/health", health.GetHealth().Handler)
doc := redoc.Redoc{
Title: "API Docs",
Description: "API documentation",
SpecFile: "./api/openapi-spec/openapi.yaml",
SpecPath: "/openapi.yaml",
DocsPath: "/docs",
}
internal.HandleFunc("/docs", doc.Handler())
return http.ListenAndServe(":8079", internal)
}
Hi, I really like the project @mvrilo but there's some suggestions that I think could improve the project, between these are:
The echo
example could be updated for something like this:
The problem with use a middleware for just show documentation is that overwrites all other endpoints.
Other things that I'm sure that goes well to the package is the json/yaml tags
for the structs
, more than nothing because normally the HTTP Servers have configuration files and directly set everything in that configuration file sounds good.
Another improvement could be the favicon.ico implementation, in the same way the openapi.yaml
is provided in my case.
I don't know if I can open a merge request to make these changes, ready to hear your opinion, me.
This is example of my code where I try to load the openapi spec in a certain path. Code is not compiled its just
to show how I did it.
Client struct {
Router *mux.Router
}
client := &Client{}
doc := redoc.Redoc{
Title: "",
Description: "",
SpecFile: "./api.yaml",
SpecPath: "/api.yaml",
DocsPath: "/docs",
}
client.Router.HandleFunc("/hello",HelloHandlerFunc).Methods(http.MethodGet)
client.Router.HandleFunc("/openapi",doc.Handler).Methods(http.MethodGet)
I am trying to access the docs through http://localhost:port/openapi/docs without luck. It just return blank white page
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.