We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
What is the feature you want to add? 我们protobuf结构生成的struct如下,json tag默认带着omitempty,忽略空值的。
type ClientWatchConfigFileRequest struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields ClientIp *wrappers.StringValue `protobuf:"bytes,1,opt,name=client_ip,json=clientIp,proto3" json:"client_ip,omitempty"` ServiceName *wrappers.StringValue `protobuf:"bytes,2,opt,name=service_name,json=serviceName,proto3" json:"service_name,omitempty"` WatchFiles []*ClientConfigFileInfo `protobuf:"bytes,3,rep,name=watch_files,json=watchFiles,proto3" json:"watch_files,omitempty"` }
这在用go-restful-openapi 处理生成swagger的model的时候,遇到以下几个问题。
func (b definitionBuilder) isPropertyRequired(field reflect.StructField) bool { required := true if optionalTag := field.Tag.Get("optional"); optionalTag == "true" { return false } if jsonTag := field.Tag.Get("json"); jsonTag != "" { s := strings.Split(jsonTag, ",") if len(s) > 1 && s[1] == "omitempty" { return false } } return required } --- for i := 0; i < st.NumField(); i++ { field := st.Field(i) jsonName, modelDescription, prop := b.buildProperty(field, &sm, modelName) if len(modelDescription) > 0 { modelDescriptions = append(modelDescriptions, modelDescription) } // add if not omitted if len(jsonName) != 0 { // update description if fieldDoc, ok := fullDoc[jsonName]; ok { prop.Description = fieldDoc } // update Required if b.isPropertyRequired(field) { sm.Required = append(sm.Required, jsonName) } sm.Properties[jsonName] = prop } }
生成后的字段只有
state protoimpl.MessageState sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields
而这个是是我们不需要的。因此我们需要支持自定义protobuf生成的json tag。比如新增 default和description字段,和删除omitempty字段。 支持删除或者屏蔽掉state、sizeCache和unknownFields字段
protobuf的类型字段是一个结构·wrappers.StringValue· 它会被认为是嵌套的结构类型,也会被解析为结构,而我们不希望它被解析。
@chuntaojun
Why do you want to add this feature?
How to implement this feature?
Additional context Add any other context or screenshots about the feature request here.
The text was updated successfully, but these errors were encountered:
这个我来处理吧
Sorry, something went wrong.
No branches or pull requests
What is the feature you want to add?
我们protobuf结构生成的struct如下,json tag默认带着omitempty,忽略空值的。
这在用go-restful-openapi 处理生成swagger的model的时候,遇到以下几个问题。
这是它处理逻辑
生成后的字段只有
而这个是是我们不需要的。因此我们需要支持自定义protobuf生成的json tag。比如新增 default和description字段,和删除omitempty字段。
支持删除或者屏蔽掉state、sizeCache和unknownFields字段
protobuf的类型字段是一个结构·wrappers.StringValue· 它会被认为是嵌套的结构类型,也会被解析为结构,而我们不希望它被解析。
@chuntaojun
Why do you want to add this feature?
How to implement this feature?
Additional context
Add any other context or screenshots about the feature request here.
The text was updated successfully, but these errors were encountered: