-
-
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
fix: swagger ignore "-" param. #1789
Conversation
protocol/goai/goai_parameter_ref.go
Outdated
@@ -37,6 +37,9 @@ func (oai *OpenApiV3) newParameterRefWithStructMethod(field gstructs.Field, path | |||
parameter.Name = field.Name() | |||
} | |||
if len(tagMap) > 0 { | |||
if v, ok := tagMap["json"]; ok && v == "-" { | |||
return nil, nil | |||
} | |||
if err := oai.tagMapToParameter(tagMap, parameter); err != nil { | |||
return nil, err | |||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
在函数末尾检查parameter.Name
而不是 json
标签会更好一些,因为后期可能存在xml
标签的支持。
此外,由于有多个地方需要过滤参数名称,建议封装一个函数来做过滤,例如:
func isValidParameterName(name string) bool
protocol/goai/goai_shema.go
Outdated
@@ -169,6 +169,9 @@ func (oai *OpenApiV3) structToSchema(object interface{}) (*Schema, error) { | |||
} | |||
var fieldName = structField.Name() | |||
if jsonName := structField.TagJsonName(); jsonName != "" { | |||
if jsonName == "-" { | |||
continue | |||
} | |||
fieldName = jsonName | |||
} | |||
schemaRef, err := oai.newSchemaRefWithGolangType( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
在函数末尾统一循环过滤schema.Properties
会比在循环中做过滤更好一些。
Codecov Report
@@ Coverage Diff @@
## master #1789 +/- ##
==========================================
+ Coverage 71.24% 71.27% +0.03%
==========================================
Files 457 457
Lines 43475 43493 +18
==========================================
+ Hits 30974 31001 +27
+ Misses 10516 10507 -9
Partials 1985 1985
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
Fixes #1765