-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(net/goai): add enhanced response interface #3896
base: master
Are you sure you want to change the base?
Conversation
@UncleChair Hello, thanks for your contribution, but I have a little suggestion for this implementing
type IEnhanceOperation interface{
EnhanceOperation(operation *goai.Operation, req interface{}, res interface{})
}
|
@gqcn Here are some of my opinions
I have also considered to use interface solution to modify the
Since the |
Yes, it is reseanable. But the |
Got it, then would we remove the Btw, where should the |
@UncleChair Indeed, it would be quite complicated for users if only providing
// ResponseStatusStruct is the structure for certain response status.
type ResponseStatusStruct = any
// IEnhanceResponseStatus is used to enhance the documentation of the response.
// Normal response structure could implement this interface to provide more information.
type IEnhanceResponseStatus interface {
EnhanceResponseStatus() map[StatusCode]ResponseStatusStruct
}
|
@gqcn Changed the interface related name
Actually I am also tring to generate json files for examples during the package v1
import (
"cssgen-api/api"
"github.com/gogf/gf/v2/errors/gcode"
"github.com/gogf/gf/v2/frame/g"
)
// parameters should use uppercase
type LoginReq struct {
g.Meta `path:"/login" tags:"Auth" method:"post" sum:"User Login"`
Username string `json:"username" v:"required-without:Email" des:"User Name" eg:"admin"`
Email string `json:"email" v:"required-without:Username" des:"User Email" eg:"[email protected]"`
Password string `json:"password" v:"required" des:"Password" eg:"adminPassword"`
}
type LoginRes struct {
Token string `json:"token" des:"JWT token"`
Expire int64 `json:"expire" des:"JWT expire time"`
}
type LoginRes401 struct {
g.Meta `status:"401" resEg:"resource/openapi/cssgen-api.api.auth.v1.LoginRes/401.json"`
}
func (r LoginRes) EnhanceResponseStatus() map[int]any {
return map[int]any{
401: LoginRes401{},
}
}
var LoginErrRes = map[int][]gcode.Code{
401: {
gcode.New(1, "No related users", nil),
gcode.New(2, "Wrong username or password", nil),
}
}
func (r LoginRes) GenerateJsonFile() (path string, err error) {
return api.GenerateJsonFile(r, LoginErrRes)
} If I want to generate a static file for the error list, I have to use some mechanism to generate the file first and fill the generated file path |
I see. It is quite complicated for users to handle type EnhancedStatusCode = int
type EnhancedStatusType struct{
Response any
Example any
}
func EnhanceResponseStatus() map[EnhancedStatusCode]EnhancedStatusType Currently, we add |
@gqcn Would we keep the |
Fixes #3889
ok github.com/gogf/gf/v2/net/goai coverage: 80.2% of statements