betacraft / yaag Goto Github PK
View Code? Open in Web Editor NEWYet Another ApiDoc Generator (for Golang web apps)
License: MIT License
Yet Another ApiDoc Generator (for Golang web apps)
License: MIT License
go get github.com/betacraft/[email protected]
go: finding github.com v1.0.0
go: finding github.com/betacraft v1.0.0
go get: github.com/betacraft/[email protected] requires
github.com/flosch/[email protected] requires
github.com/go-check/[email protected]: reading https://goproxy.io/github.com/go-check/check/@v/v1.0.0-20180628173108-788fd7840127.mod: 404 Not Found
```shell
cannot use irisyaag.New() (type "github.com/kataras/iris/context".Handler) as type "github.com/kataras/iris/v12/context".Handler in argument to api.APIBuilder.Use
Hi,
I have been using yagg for generating the API documentation. I found API are generating only for success cases. I have found this piece of code. Here you are allowing only for status codes ranges in 2XX.
func IsStatusCodeValid(code int) bool {
if code >= 200 && code < 300 {
return true
} else {
return false
}
}
please rewrite it to allow 3xx and 4xx
I import the versioned gin framework and its causing I think its causing problems. Any ideas on how to fix?
cannot use "github.com/betacraft/yaag/gin".Document() (type "github.com/gin-gonic/gin".HandlerFunc) as type "placeable.com/audit-service/vendor/gopkg.in/gin-gonic/gin.v1".HandlerFunc in argument to r.Use
Can yaag configure to follow Swagger/OpenAPI standard as it can import by Postman and do automated testing?
Can anyone recommend an existing solution?
Can anyone help getting Yaag to work with Negroni and Gorilla Mux? No matter what I try I seem to get nothing or I get mulitple http write errors probably because because I already have routes.
I have tried this and a few other things ...
`
yaag.Init(&yaag.Config{On: true, DocTitle: "Negroni-gorilla", DocPath: "apidoc.html", BaseUrls: map[string]string{"Production": "", "Staging": ""}})
router := mux.NewRouter()
// ... Add a bunch of routes
router.HandleFunc("/", middleware.HandleFunc(handler)) //this does nothing
n := negroni.Classic()
n.Use(c)
//n.UseHandlerFunc(middleware.HandleFunc(handler)) //this gives an error but makes a doc
n.UseHandler(router)
n.Run(":5000")
func handler(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, time.Now().String())
}
`
Update:
I got "n.UseHandlerFunc(middleware.HandleFunc(handler))" to work by removing
"fmt.Fprintf(w, time.Now().String())" from the handler. It looks like once I write a response it finishes.
Not sure if that is really working or not.
I still don't get responses. Just requests.
Another_ question (if the first question can be solved):
All the examples show just returning time. How do you return the actual response?
Maybe this would become more apparent if this was working for me. But it seems like all the handlers just return time. Help my Ignorance. Are the responses generated in the middleware somehow?
I know we could return something else in the handler but I don't see how to return a response.
How much work would it be to add native support for https://github.com/bmizerany/pat (a Sinatra style pattern muxer)? It's built purely on "net/http"
and "net/url"
, so there might be a workaround that leverages the basic net.http package (https://github.com/betacraft/yaag#how-to-use-with-basic-nethttp-package), but I figured I would ask about native support.
By the way, thank you for creating this project! This sort of middleware-based api doc generation is extremely useful for large projects with constantly evolving handlers.
First of all, it is really convenient to generate api documents in this way, there is really no pain. But there are some limitations.
For example, API description, param description cannot be customized.
If you can continue to edit the api description and parameter description in the generated html file, then this tool can be safely used in many project
some idea:
cannot use "github.com/betacraft/yaag/gin".Document() (type "gopkg.in/gin-gonic/gin.v1".HandlerFunc) as type "github.com/gin-gonic/gin".HandlerFunc in argument to router.Use
If you're exposing API docs to third parties, you probably want the ability to have the docs at least somewhat match the look and feel of the rest of your site.
We got cpu, memory and file descriptors spikes when the endpoint returns a large json object. pprof shows most of them are spent on yaag/yaag.GenerateHtml and yaag/yaag.Init. Down the tree it, it calls encoding/json.Mashal (47%) and html/template.htmlReplacer(34%) which calls runtime.slicebytetostring(16%) and bytes.(*Buffer).WriteString.
The memory doesn't get GC-ed quickly.
func Init(conf *Config) {
config = conf
// load the config file
if conf.DocPath == "" {
conf.DocPath = "apidoc.html"
}
filePath, err := filepath.Abs(conf.DocPath + ".json")
dataFile, err := os.Open(filePath)
defer dataFile.Close()
if err == nil {
json.NewDecoder(io.Reader(dataFile)).Decode(spec)
generateHtml()
}
}
when init , filePath does not exist os.Open() will be error
err != nil
generateHtml don‘t work always
how do i generateHtml
thanks
Hello, the middleware is not setting Content-Type when status is 404. Content-Type is set only within this if statement https://github.com/betacraft/yaag/blob/master/middleware/yaagmiddleware.go#L204
Do you accept pull request with fix?
step
no apidoc file create?
Hello all,
It would be great if you could provide a middleware for iris-go framework.
https://github.com/kataras/iris
Thanks,
Sanketh
Is there any way to make it generate the api docs for each endpoint in the routes file? Also instead of having the actual model id number can we set things like :model_id in the endpoint url?
application/x-www-form-urlencoded 参数为空时报错
INFO] 2019/09/08 12:16 200 3.582027ms 127.0.0.1 POST /m/login
12:18:23 app | 2019/09/08 12:18:23 application/x-www-form-urlencoded
12:18:23 app | 2019/09/08 12:18:23 Reading form
12:18:23 app | [WARN] 2019/09/08 12:18 Recovered from a route's Handler('github.com/betacraft/yaag/irisyaag.New.func1')
At Request: 200 /m/login POST 127.0.0.1
Trace: runtime error: index out of range
/usr/local/Cellar/go/1.12.9/libexec/src/runtime/panic.go:522
/usr/local/Cellar/go/1.12.9/libexec/src/runtime/panic.go:44
/Users/xxx/go/src/github.com/betacraft/yaag/middleware/yaagmiddleware.go:139
/Users/xxx/go/src/github.com/betacraft/yaag/middleware/yaagmiddleware.go:83
/Users/xxx/go/src/github.com/betacraft/yaag/irisyaag/middleware.go:23
/Users/xxx/go/src/github.com/betacraft/yaag/middleware/yaagmiddleware.go:139
func ReadPostForm(req *http.Request) map[string]string {
postForm := map[string]string{}
for _, param := range strings.Split(*ReadBody(req), "&") {
value := strings.Split(param, "=")
postForm[value[0]] = value[1]
}
return postForm
}
加粗这一行,很明显没有判断空参数的情况。
require github.com/betacraft/yaag/yaag: version "v0.0.0-20191027021412-565f65e36090" invalid: missing github.com/betacraft/yaag/yaag/go.mod at revision 565f65e
go.mod:
github.com/betacraft/yaag/yaag master
I've initialised the library...
yaag.Init(&yaag.Config{
On: true,
DocTitle: "Gin",
DocPath: "apidoc.html",
BaseUrls: map[string]string{"Production": "http://api.test.com", "Staging": "http://devapi.test.com"},
})
But I'm not getting any output, no apidoc.html file's being recreated etc
Am I missing something?
Cheers!
This is not working with revel. Also where will it store apidoc.html?
Hi, all. Is there any chance that someone could work on a middleware for ECHO framework? Thanks.
Getting an error when I use websockets with yaag middleware.
func echo(w http.ResponseWriter, r *http.Request) {
c, err := upgrader.Upgrade(w, r, nil)
hErr(err, "upgrade err")
defer c.Close()
for {
// c.ReadJSON()
mt, message, err := c.ReadMessage()
hErr(err, "readMessage")
hErr(c.WriteMessage(mt, message), "write err")
}
}
The error happens at the upgrader.Upgrade() call
I would like to add additional information to the template using some annotations over the functions handlers, something like
@Description This endpoint to get all the users in the app
@return json
@...
func getAllUsers(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Hi there, I love %s!", r.URL.Path[1:])
}
And handle the route
r.GET("/api/v1/users/all", getAllUsers)
And generate something like
This endpoint to get all the users in the app
GET: /api/v1/users/all
can I do that?
I have integrated yaag with iris application, when this app is run in production or live server then the Post Request body is considered and included in generated document. But when we run unit tests with httptest then Request Body is ignored in generated documents.
The below pull request is required to test this.
#34
I currently have a moderately sized API that is in ongoing development and I came across your "yaag" project and thought I would give it a whirl. I checked out our martini branch and started implementing as your README.md dictates.
I made sure to import the two yaag libraries: yaag/yaag and yaag/martiniyaag
Added: m.Use(martiniyaag.Document)
I now have so many damn m.Use statements it is getting out of control ;)
That seems to be all that is necessary other than initiating the config option in my main(), which I did as well. Do you know if utilizing route groups with Martini would prevent this from working as expected? Currently I leverage m.Group() for all of our routes.
There is only a placeholder test in the yaag package currently. We need proper test cases.
When I request the server,sometimes yaag add the api info to apidoc.html,but sometines it doesn't work;
My computer environment is windows
Running go vet:
akshay@storm:$ go vet github.com/betacraft/yaag/yaag
../../github.com/betacraft/yaag/yaag/yaag.go:111: unreachable code
../../github.com/betacraft/yaag/yaag/yaag.go:117: unreachable code
exit status 1
There seems to be a 404 when I run go get
using
yaag_gin "github.com/betacraft/yaag/gin"
"github.com/betacraft/yaag/yaag"
Right now yaag has too many dependencies. Most of them are framework specific dependencies. So better approach would be to move framework specific convenience packages to their own repos.
The repo path should be :
"github.com/RainingClouds/yaag/martiniyaag"
"github.com/RainingClouds/yaag/yaag"
But the below path appear in readme file:
Import github.com/gophergala/yaag/yaag
Import github.com/gophergala/yaag/martiniyaag
I have the following errors when I execute go get github.com/betacraft/yaag/..
#github.com/betacraft/yaag/filters
../github.com/betacraft/yaag/filters/filter.go:24:32: cannot use w (type *httptest.ResponseRecorder) as type revel.ServerResponse in argument to revel.NewResponse:
*httptest.ResponseRecorder does not implement revel.ServerResponse (missing Get method)
../github.com/betacraft/yaag/filters/filter.go:30:22: c.Request.Request undefined (type *revel.Request has no field or method Request)
../github.com/betacraft/yaag/filters/filter.go:35:39: c.Request.Request undefined (type *revel.Request has no field or method Request)
../github.com/betacraft/yaag/filters/filter.go:81:14: cannot range over c.Request.Header (type *revel.RevelHeader)
I'm using go version go1.9.2 darwin/amd64
Using web framework gin, using yaag to generate automatically, but no response body
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.