@@ -58,6 +58,9 @@ type HTTPQuery struct {
5858 // Name of the RPC func.
5959 Name string `json:"name,omitempty"`
6060
61+ // ResponseType is the type of the response.
62+ ResponseType string `json:"response_type,omitempty"`
63+
6164 // FullName of the query with service name and rpc func name.
6265 FullName string `json:"full_name,omitempty"`
6366
@@ -66,6 +69,9 @@ type HTTPQuery struct {
6669
6770 // Paginated indicates that the query is using pagination.
6871 Paginated bool `json:"paginated,omitempty"`
72+
73+ // FilePath is the path of the .proto file where message is defined at.
74+ FilePath string `json:"file_path,omitempty"`
6975}
7076
7177// Type is a proto type that might be used by module.
@@ -84,9 +90,9 @@ type moduleDiscoverer struct {
8490 registeredModules []string
8591}
8692
87- // IsCosmosSDKModulePkg check if a Go import path is a Cosmos SDK package module .
88- // These type of package have the "cosmossdk.io/x" prefix.
89- func IsCosmosSDKModulePkg (path string ) bool {
93+ // IsCosmosSDKPackage check if a Go import path is a Cosmos SDK package.
94+ // These type of package have the "cosmossdk.io/x" prefix or "github.com/cosmos/cosmos-sdk" prefix .
95+ func IsCosmosSDKPackage (path string ) bool {
9096 return strings .Contains (path , "cosmossdk.io/x/" ) || strings .Contains (path , "github.com/cosmos/cosmos-sdk" )
9197}
9298
@@ -140,7 +146,7 @@ func Discover(ctx context.Context, chainRoot, sourcePath string, options ...Disc
140146 // SDK package because the module packages doesn't contain the proto files. These
141147 // files are only available from the Cosmos SDK package.
142148 var protoPath string
143- if o .sdkDir != "" && IsCosmosSDKModulePkg (sourcePath ) {
149+ if o .sdkDir != "" && IsCosmosSDKPackage (sourcePath ) {
144150 protoPath = switchCosmosSDKPackagePath (sourcePath , o .sdkDir )
145151 } else {
146152 protoPath = filepath .Join (sourcePath , o .protoDir )
@@ -247,17 +253,6 @@ func (d *moduleDiscoverer) discover(pkg protoanalysis.Package) (Module, error) {
247253
248254 // fill types.
249255 for _ , protomsg := range pkg .Messages {
250- // Update pagination for RPC functions when a service response uses pagination
251- if hasPagination (protomsg ) {
252- for _ , s := range pkg .Services {
253- for i , q := range s .RPCFuncs {
254- if q .RequestType == protomsg .Name || q .ReturnsType == protomsg .Name {
255- s .RPCFuncs [i ].Paginated = true
256- }
257- }
258- }
259- }
260-
261256 if ! isType (protomsg ) {
262257 continue
263258 }
@@ -271,32 +266,44 @@ func (d *moduleDiscoverer) discover(pkg protoanalysis.Package) (Module, error) {
271266 // fill queries & messages.
272267 for _ , s := range pkg .Services {
273268 for _ , q := range s .RPCFuncs {
269+ pkgmsg , err := pkg .MessageByName (q .RequestType )
270+ if err != nil {
271+ // no msg found in the proto defs corresponds to discovered sdk message.
272+ // if it cannot be found, nothing to worry about, this means that it is used
273+ // only internally and not open for actual use.
274+ continue
275+ }
276+
274277 switch s .Name {
275278 case "Msg" :
276- pkgmsg , err := pkg .MessageByName (q .RequestType )
277- if err != nil {
278- // no msg found in the proto defs corresponds to discovered sdk message.
279- // if it cannot be found, nothing to worry about, this means that it is used
280- // only internally and not open for actual use.
281- continue
282- }
283279
284280 m .Msgs = append (m .Msgs , Msg {
285281 Name : q .RequestType ,
286282 URI : fmt .Sprintf ("%s.%s" , pkg .Name , q .RequestType ),
287283 FilePath : pkgmsg .Path ,
288284 })
289- case "Query" :
285+ case "Query" , "Service" :
290286 // no http rules means this query is not exposed as a REST endpoint.
291287 if len (q .HTTPRules ) == 0 {
292288 continue
293289 }
294290
291+ // check if the query is paginated.
292+ isPaginated := false
293+ for _ , hr := range q .HTTPRules {
294+ if hr .IsPaginated () {
295+ isPaginated = true
296+ break
297+ }
298+ }
299+
295300 m .HTTPQueries = append (m .HTTPQueries , HTTPQuery {
296- Name : q .Name ,
297- FullName : s .Name + q .Name ,
298- Rules : q .HTTPRules ,
299- Paginated : q .Paginated ,
301+ Name : q .Name ,
302+ FullName : s .Name + q .Name ,
303+ Rules : q .HTTPRules ,
304+ Paginated : isPaginated ,
305+ FilePath : pkgmsg .Path ,
306+ ResponseType : q .ReturnsType ,
300307 })
301308 }
302309 }
@@ -399,19 +406,6 @@ func (d moduleDiscoverer) isPkgFromRegisteredModule(pkg protoanalysis.Package) (
399406 return false , nil
400407}
401408
402- func hasPagination (msg protoanalysis.Message ) bool {
403- for _ , fieldType := range msg .Fields {
404- // Message field type suffix check to match common pagination types:
405- // cosmos.base.query.v1beta1.PageRequest
406- // cosmos.base.query.v1beta1.PageResponse
407- if strings .HasSuffix (fieldType , "PageRequest" ) || strings .HasSuffix (fieldType , "PageResponse" ) {
408- return true
409- }
410- }
411-
412- return false
413- }
414-
415409func switchCosmosSDKPackagePath (srcPath , sdkDir string ) string {
416410 modName := xstrings .StringBetween (srcPath , "/x/" , "@" )
417411 if modName == "" {
0 commit comments