Skip to content
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

Merged
merged 2 commits into from
Apr 28, 2022
Merged

fix: swagger ignore "-" param. #1789

merged 2 commits into from
Apr 28, 2022

Conversation

mingzaily
Copy link
Member

Fixes #1765

@@ -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
}
Copy link
Member

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

@@ -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(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

在函数末尾统一循环过滤schema.Properties会比在循环中做过滤更好一些。

@codecov-commenter
Copy link

codecov-commenter commented Apr 28, 2022

Codecov Report

Merging #1789 (ce89b44) into master (be77779) will increase coverage by 0.03%.
The diff coverage is 100.00%.

@@            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              
Flag Coverage Δ
go-1.15 71.24% <100.00%> (+<0.01%) ⬆️
go-1.16 71.25% <100.00%> (+0.05%) ⬆️
go-1.17 71.24% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
protocol/goai/goai.go 82.47% <100.00%> (+0.95%) ⬆️
protocol/goai/goai_parameter_ref.go 80.35% <100.00%> (+1.11%) ⬆️
protocol/goai/goai_shema.go 73.01% <100.00%> (+1.58%) ⬆️
protocol/goai/goai_shemas.go 100.00% <100.00%> (ø)
os/gcron/gcron_z_unit_schedule.go 67.52% <0.00%> (+0.42%) ⬆️
protocol/goai/goai_path.go 61.43% <0.00%> (+0.89%) ⬆️
os/gspath/gspath_cache.go 94.73% <0.00%> (+10.52%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update be77779...ce89b44. Read the comment docs.

@gqcn gqcn merged commit a315534 into gogf:master Apr 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

咋解决显示屏蔽的响应字段,实际是不会响应的
3 participants