mirror of
https://github.com/zhufuyi/sponge.git
synced 2025-10-07 17:51:12 +08:00
match name xxxID in proto file
This commit is contained in:
@@ -191,8 +191,8 @@ func convertUserExample(record *model.UserExample) (*serverNameExampleV1.UserExa
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
// Note: if copier.Copy cannot assign a value to a field, add it here, e.g. CreatedAt, UpdatedAt
|
||||||
value.Id = record.ID
|
value.Id = record.ID
|
||||||
// todo if copier.Copy cannot assign a value to a field, add it here, e.g. CreatedAt, UpdatedAt
|
|
||||||
// todo generate the conversion createdAt and updatedAt code here
|
// todo generate the conversion createdAt and updatedAt code here
|
||||||
// delete the templates code start
|
// delete the templates code start
|
||||||
value.CreatedAt = record.CreatedAt.Format(time.RFC3339)
|
value.CreatedAt = record.CreatedAt.Format(time.RFC3339)
|
||||||
|
@@ -316,8 +316,8 @@ func convertUserExample(record *model.UserExample) (*serverNameExampleV1.UserExa
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
// Note: if copier.Copy cannot assign a value to a field, add it here, e.g. CreatedAt, UpdatedAt
|
||||||
value.Id = record.ID
|
value.Id = record.ID
|
||||||
// todo if copier.Copy cannot assign a value to a field, add it here, e.g. CreatedAt, UpdatedAt
|
|
||||||
// todo generate the conversion createdAt and updatedAt code here
|
// todo generate the conversion createdAt and updatedAt code here
|
||||||
// delete the templates code start
|
// delete the templates code start
|
||||||
value.CreatedAt = record.CreatedAt.Format(time.RFC3339)
|
value.CreatedAt = record.CreatedAt.Format(time.RFC3339)
|
||||||
|
@@ -191,8 +191,8 @@ func convertUserExample(record *model.UserExample) (*serverNameExampleV1.UserExa
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
// Note: if copier.Copy cannot assign a value to a field, add it here, e.g. CreatedAt, UpdatedAt
|
||||||
value.Id = record.ID.Hex()
|
value.Id = record.ID.Hex()
|
||||||
// todo if copier.Copy cannot assign a value to a field, add it here, e.g. CreatedAt, UpdatedAt
|
|
||||||
// todo generate the conversion createdAt and updatedAt code here
|
// todo generate the conversion createdAt and updatedAt code here
|
||||||
// delete the templates code start
|
// delete the templates code start
|
||||||
value.CreatedAt = record.CreatedAt.Format(time.RFC3339)
|
value.CreatedAt = record.CreatedAt.Format(time.RFC3339)
|
||||||
|
@@ -316,8 +316,8 @@ func convertUserExample(record *model.UserExample) (*serverNameExampleV1.UserExa
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
// Note: if copier.Copy cannot assign a value to a field, add it here, e.g. CreatedAt, UpdatedAt
|
||||||
value.Id = record.ID.Hex()
|
value.Id = record.ID.Hex()
|
||||||
// todo if copier.Copy cannot assign a value to a field, add it here, e.g. CreatedAt, UpdatedAt
|
|
||||||
// todo generate the conversion createdAt and updatedAt code here
|
// todo generate the conversion createdAt and updatedAt code here
|
||||||
// delete the templates code start
|
// delete the templates code start
|
||||||
value.CreatedAt = record.CreatedAt.Format(time.RFC3339)
|
value.CreatedAt = record.CreatedAt.Format(time.RFC3339)
|
||||||
|
@@ -1046,7 +1046,7 @@ func goTypeToProto(fields []tmplField) []tmplField {
|
|||||||
field.GoType = "uint64"
|
field.GoType = "uint64"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
field.JSONName = customToCamel(field.ColName)
|
||||||
newFields = append(newFields, field)
|
newFields = append(newFields, field)
|
||||||
}
|
}
|
||||||
return newFields
|
return newFields
|
||||||
@@ -1082,7 +1082,6 @@ func getDefaultValue(expr ast.ExprNode) (value string) {
|
|||||||
var acronym = map[string]struct{}{
|
var acronym = map[string]struct{}{
|
||||||
"ID": {},
|
"ID": {},
|
||||||
"IP": {},
|
"IP": {},
|
||||||
"RPC": {},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func toCamel(s string) string {
|
func toCamel(s string) string {
|
||||||
@@ -1139,3 +1138,10 @@ func firstLetterToLow(str string) string {
|
|||||||
|
|
||||||
return str
|
return str
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func customToCamel(str string) string {
|
||||||
|
if strings.ToLower(str) == "id" {
|
||||||
|
return str
|
||||||
|
}
|
||||||
|
return firstLetterToLow(toCamel(str))
|
||||||
|
}
|
||||||
|
@@ -116,8 +116,15 @@ func TestParseSQLs(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func Test_toCamel(t *testing.T) {
|
func Test_toCamel(t *testing.T) {
|
||||||
str := "user_example"
|
names := []string{"id", "user_id", "productId", "orderId", "user_name", "host_ip", "teacherId"}
|
||||||
t.Log(toCamel(str))
|
var convertNames []string
|
||||||
|
var convertNames2 []string
|
||||||
|
for _, name := range names {
|
||||||
|
convertNames = append(convertNames, toCamel(name))
|
||||||
|
convertNames2 = append(convertNames2, customToCamel(name))
|
||||||
|
}
|
||||||
|
t.Log(convertNames)
|
||||||
|
t.Log(convertNames2)
|
||||||
}
|
}
|
||||||
|
|
||||||
func Test_parseOption(t *testing.T) {
|
func Test_parseOption(t *testing.T) {
|
||||||
|
@@ -320,6 +320,12 @@ service {{.TName}} {
|
|||||||
option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_operation) = {
|
option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_operation) = {
|
||||||
summary: "create {{.TName}}",
|
summary: "create {{.TName}}",
|
||||||
description: "submit information to create {{.TName}}",
|
description: "submit information to create {{.TName}}",
|
||||||
|
//security: {
|
||||||
|
// security_requirement: {
|
||||||
|
// key: "BearerAuth";
|
||||||
|
// value: {}
|
||||||
|
// }
|
||||||
|
//}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -465,17 +471,20 @@ service {{.TName}} {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Some notes on defining fields under message:
|
// Some notes on defining fields under message:
|
||||||
// (1) Fill in the validate rules https://github.com/envoyproxy/protoc-gen-validate#constraint-rules
|
// (1) Fill in the validate rules https://github.com/envoyproxy/protoc-gen-validate#constraint-rules
|
||||||
// (2) When using the protoc-gen-openapiv2 plugin, if the defined fields are snake case,
|
// (2) Suggest using camel hump naming for message field names, and for names ending in 'id',
|
||||||
// you must add annotations for snake case names, such as string foo_bar = 1 [json_name = "foo_bar"],
|
// use xxxID naming format, such as userID, orderID, etc.
|
||||||
|
// (3) When using the protoc-gen-openapiv2 plugin, if the defined fields are snake case,
|
||||||
|
// you must add annotations for snake case names, such as string fieldName = 1 [json_name = "field_name"],
|
||||||
// to ensure that the front end and back end JSON naming is consistent.
|
// to ensure that the front end and back end JSON naming is consistent.
|
||||||
// (3) If the route contains the path parameter, such as /api/v1/userExample/{id}, the defined
|
// (4) If the route contains the path parameter, such as /api/v1/userExample/{id}, the defined
|
||||||
// message must contain the name of the path parameter and the name should be
|
// message must contain the name of the path parameter and the name should be
|
||||||
// added with a new tag, such as int64 id = 1 [(tagger.tags) = "uri:\"id\""];
|
// added with a new tag, such as int64 id = 1 [(tagger.tags) = "uri:\"id\""];
|
||||||
// (4) If the request url is followed by a query parameter, such as /api/v1/getUserExample?name=Tom,
|
// (5) If the request url is followed by a query parameter, such as /api/v1/getUserExample?name=Tom,
|
||||||
// a form tag must be added when defining the query parameter in the message,
|
// a form tag must be added when defining the query parameter in the message,
|
||||||
// such as string name = 1 [(tagger.tags) = "form:\"name\""];
|
// such as string name = 1 [(tagger.tags) = "form:\"name\""].
|
||||||
|
|
||||||
|
|
||||||
// protoMessageCreateCode
|
// protoMessageCreateCode
|
||||||
@@ -602,6 +611,12 @@ service {{.TName}} {
|
|||||||
option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_operation) = {
|
option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_operation) = {
|
||||||
summary: "create {{.TName}}",
|
summary: "create {{.TName}}",
|
||||||
description: "submit information to create {{.TName}}",
|
description: "submit information to create {{.TName}}",
|
||||||
|
//security: {
|
||||||
|
// security_requirement: {
|
||||||
|
// key: "BearerAuth";
|
||||||
|
// value: {}
|
||||||
|
// }
|
||||||
|
//}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -676,17 +691,20 @@ service {{.TName}} {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Some notes on defining fields under message:
|
// Some notes on defining fields under message:
|
||||||
// (1) Fill in the validate rules https://github.com/envoyproxy/protoc-gen-validate#constraint-rules
|
// (1) Fill in the validate rules https://github.com/envoyproxy/protoc-gen-validate#constraint-rules
|
||||||
// (2) When using the protoc-gen-openapiv2 plugin, if the defined fields are snake case,
|
// (2) Suggest using camel hump naming for message field names, and for names ending in 'id',
|
||||||
// you must add annotations for snake case names, such as string foo_bar = 1 [json_name = "foo_bar"],
|
// use xxxID naming format, such as userID, orderID, etc.
|
||||||
|
// (3) When using the protoc-gen-openapiv2 plugin, if the defined fields are snake case,
|
||||||
|
// you must add annotations for snake case names, such as string fieldName = 1 [json_name = "field_name"],
|
||||||
// to ensure that the front end and back end JSON naming is consistent.
|
// to ensure that the front end and back end JSON naming is consistent.
|
||||||
// (3) If the route contains the path parameter, such as /api/v1/userExample/{id}, the defined
|
// (4) If the route contains the path parameter, such as /api/v1/userExample/{id}, the defined
|
||||||
// message must contain the name of the path parameter and the name should be
|
// message must contain the name of the path parameter and the name should be
|
||||||
// added with a new tag, such as int64 id = 1 [(tagger.tags) = "uri:\"id\""];
|
// added with a new tag, such as int64 id = 1 [(tagger.tags) = "uri:\"id\""];
|
||||||
// (4) If the request url is followed by a query parameter, such as /api/v1/getUserExample?name=Tom,
|
// (5) If the request url is followed by a query parameter, such as /api/v1/getUserExample?name=Tom,
|
||||||
// a form tag must be added when defining the query parameter in the message,
|
// a form tag must be added when defining the query parameter in the message,
|
||||||
// such as string name = 1 [(tagger.tags) = "form:\"name\""];
|
// such as string name = 1 [(tagger.tags) = "form:\"name\""].
|
||||||
|
|
||||||
|
|
||||||
// protoMessageCreateCode
|
// protoMessageCreateCode
|
||||||
|
Reference in New Issue
Block a user