Skip to main content
Version: 2.8.x(Latest)

When the completed interface is handed over to the frontend for invocation, it is necessary to prepare interface documentation for them. Fortunately, GoFrame has a built-in feature to automatically generate interface documentation, saving us a lot of time. By carrying some additional tags when writing api, beautiful documentation can be generated.

api/users/v1/users.go

package v1  

import "github.com/gogf/gf/v2/frame/g"

type RegisterReq struct {
g.Meta `path:"users/register" method:"post" sm:"Register" tags:"User"`
Username string `json:"username" v:"required|length:3,12" dc:"Username"`
Password string `json:"password" v:"required|length:6,16" dc:"Password"`
Email string `json:"email" v:"required|email" dc:"Email"`
}

type RegisterRes struct {
}

Open the browser at http://127.0.0.1:8000/swagger: swagger

Another address http://127.0.0.1:8000/api.json provides interface documentation in Json format, which can be imported into various Api tools.

In addition to sm, tags, and dc tags, GoFrame also provides the following tags:

Common OpenAPIv3 TagsDescriptionNote
pathCombines with the prefix registered to form the interface URI pathUsed in g.Meta to identify interface metadata
tagsThe tag to which the interface belongs for interface categorizationUsed in g.Meta to identify interface metadata
methodThe request method of the interface: GET/PUT/POST/DELETE... (case-insensitive)Used in g.Meta to identify interface metadata
deprecatedMarks the interface as deprecatedUsed in g.Meta to identify interface metadata
summarySummary description of the interface/parameterAbbreviated as sm
descriptionDetailed description of the interface/parameterAbbreviated as dc
inMethod of parameter submissionheader/path/query/cookie
defaultDefault value of the parameterAbbreviated as d
mimeMIME type of the interface, such as multipart/form-data, generally set globally, default is application/json.Used in g.Meta to identify interface metadata
typeType of the parameter, generally does not need to be set, specific parameters need to be set manually, such as fileOnly for parameter properties