This commit is contained in:
John Guo
2021-10-08 11:40:47 +08:00
parent 51dbd133a4
commit d430f2f52e
2 changed files with 9 additions and 3 deletions

View File

@ -99,6 +99,7 @@ func New() *OpenApiV3 {
// AddInput is the structured parameter for function OpenApiV3.Add.
type AddInput struct {
Path string // Path specifies the custom path if this is not configured in Meta of struct tag.
Prefix string // Prefix specifies the custom route path prefix, which will be added with the path tag in Meta of struct tag.
Method string // Method specifies the custom HTTP method if this is not configured in Meta of struct tag.
Object interface{} // Object can be an instance of struct or a route function.
}

View File

@ -41,9 +41,10 @@ const (
)
type addPathInput struct {
Path string
Method string
Function interface{}
Path string // Precise route path.
Prefix string // Route path prefix.
Method string // Route method.
Function interface{} // Uniformed function.
}
func (oai *OpenApiV3) addPath(in addPathInput) error {
@ -97,6 +98,9 @@ func (oai *OpenApiV3) addPath(in addPathInput) error {
// Path check.
if in.Path == "" {
in.Path = gmeta.Get(inputObject.Interface(), TagNamePath).String()
if in.Prefix != "" {
in.Path = gstr.TrimRight(in.Prefix, "/") + "/" + gstr.TrimLeft(in.Path, "/")
}
}
if in.Path == "" {
return gerror.NewCodef(
@ -105,6 +109,7 @@ func (oai *OpenApiV3) addPath(in addPathInput) error {
TagNamePath, inputStructTypeName,
)
}
// Method check.
if in.Method == "" {
in.Method = gmeta.Get(inputObject.Interface(), TagNameMethod).String()