Skip to content

Commit 36c088a

Browse files
lvan100lianghuan
authored andcommitted
111
1 parent b805202 commit 36c088a

File tree

4 files changed

+14
-8
lines changed

4 files changed

+14
-8
lines changed

lib/tidl/parser.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,9 @@ func (l *ParseTreeListener) ExitRpc_def(ctx *Rpc_defContext) {
504504
if !IsPascal(r.Request.Name) {
505505
panic(errutil.Explain(nil, "RPC request type %s is not PascalCase in line %d", r.Request.Name, r.Position.Start))
506506
}
507+
if !strings.HasSuffix(r.Request.Name, "Req") {
508+
panic(errutil.Explain(nil, "RPC request type %s does not end with \"Req\" in line %d", r.Request.Name, r.Position.Start))
509+
}
507510
l.Document.UsedTypes[r.Request.Name] = struct{}{}
508511

509512
// Response
@@ -518,6 +521,9 @@ func (l *ParseTreeListener) ExitRpc_def(ctx *Rpc_defContext) {
518521
if !IsPascal(r.Response.UserType.Name) {
519522
panic(errutil.Explain(nil, "RPC response type %s is not PascalCase in line %d", r.Response.UserType.Name, r.Position.Start))
520523
}
524+
if !strings.HasSuffix(r.Response.UserType.Name, "Resp") {
525+
panic(errutil.Explain(nil, "RPC response type %s does not end with \"Resp\" in line %d", r.Response.UserType.Name, r.Position.Start))
526+
}
521527
l.Document.UsedTypes[r.Response.UserType.Name] = struct{}{}
522528

523529
// Annotations

lib/tidl/testdata/success/http.formated.idl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,11 @@ type Response<T> {
5757
}
5858

5959
// ---- RPC definitions ----
60-
rpc GetUser(UserReq) UserResponse {
60+
rpc GetUser(UserReq) UserResp {
6161
go.type = "*string"
6262
method = "GET"
6363
path = "/user"
6464
}
6565

6666
// ---- type re-definition ----
67-
type UserResponse Response<list<User?>>
67+
type UserResp Response<list<User?>>

lib/tidl/testdata/success/http.idl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,11 @@ type Response<T> {
5656
}
5757

5858
// ---- RPC definitions ----
59-
rpc GetUser (UserReq) UserResponse {
59+
rpc GetUser (UserReq) UserResp {
6060
go.type="*string"
6161
method="GET"
6262
path="/user"
6363
}
6464

6565
// ---- type re-definition ----
66-
type UserResponse Response<list<User?>>
66+
type UserResp Response<list<User?>>

lib/tidl/testdata/success/http.idl.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,7 @@
574574
}
575575
},
576576
{
577-
"Name": "UserResponse",
577+
"Name": "UserResp",
578578
"OneOf": false,
579579
"Redefined": {
580580
"Name": "Response",
@@ -618,7 +618,7 @@
618618
"Response": {
619619
"Stream": false,
620620
"UserType": {
621-
"Name": "UserResponse",
621+
"Name": "UserResp",
622622
"Optional": false
623623
}
624624
},
@@ -690,13 +690,13 @@
690690
"Response": 4,
691691
"User": 1,
692692
"UserReq": 0,
693-
"UserResponse": 5
693+
"UserResp": 5
694694
},
695695
"UsedTypes": {
696696
"Address": {},
697697
"Payload": {},
698698
"User": {},
699699
"UserReq": {},
700-
"UserResponse": {}
700+
"UserResp": {}
701701
}
702702
}

0 commit comments

Comments
 (0)