Skip to content

Commit

Permalink
refactor: Add json tags
Browse files Browse the repository at this point in the history
  • Loading branch information
clockworkgr committed Jul 4, 2023
1 parent eb09d19 commit 70bb246
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 56 deletions.
38 changes: 18 additions & 20 deletions ignite/pkg/cosmosanalysis/module/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,57 +22,55 @@ type Msgs map[string][]string
// Module keeps metadata about a Cosmos SDK module.
type Module struct {
// Name of the module.
Name string
Name string `json:"name,omitempty"`

// GoModulePath of the app where the module is defined.
GoModulePath string
GoModulePath string `json:"go_module_path,omitempty"`

// Pkg holds the proto package info.
Pkg protoanalysis.Package
Pkg protoanalysis.Package `json:"package,omitempty"`

// Msg is a list of sdk.Msg implementation of the module.
Msgs []Msg
Msgs []Msg `json:"messages,omitempty"`

// HTTPQueries is a list of module queries.
HTTPQueries []HTTPQuery
HTTPQueries []HTTPQuery `json:"http_queries,omitempty"`

// Types is a list of proto types that might be used by module.
Types []Type
Types []Type `json:"types,omitempty"`
}

// Msg keeps metadata about an sdk.Msg implementation.
type Msg struct {
// Name of the type.
Name string

Name string `json:"name,omitempty"`
// URI of the type.
URI string

// FilePath is the path of the .proto file where message is defined at.
FilePath string
URI string `json:"uri,omitempty"`
// File path is the path of the proto file where message is defined.
FilePath string `json:"file_path,omitempty"`
}

// HTTPQuery is an sdk Query.
type HTTPQuery struct {
// Name of the RPC func.
Name string
Name string `json:"name,omitempty"`

// FullName of the query with service name and rpc func name.
FullName string
FullName string `json:"full_name,omitempty"`

// HTTPAnnotations keeps info about http annotations of query.
Rules []protoanalysis.HTTPRule
Rules []protoanalysis.HTTPRule `json:"rules,omitempty"`

// Paginated indicates that the query is using pagination.
Paginated bool
Paginated bool `json:"paginated,omitempty"`
}

// Type is a proto type that might be used by module.
type Type struct {
Name string

// FilePath is the path of the .proto file where message is defined at.
FilePath string
// Name pf the type.
Name string `json:"name,omitempty"`
// File path is the path of the .proto file where message is defined at.
FilePath string `json:"file_path,omitempty"`
}

type moduleDiscoverer struct {
Expand Down
66 changes: 30 additions & 36 deletions ignite/pkg/protoanalysis/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,32 +19,31 @@ func (p Packages) Files() Files {
// Package represents a proto pkg.
type Package struct {
// Name of the proto pkg.
Name string
Name string `json:"name,omitempty"`

// Path of the package in the fs.
Path string
Path string `json:"path,omitempty"`

// Files is a list of .proto files in the package.
Files Files
Files Files `json:"files,omitempty"`

// GoImportName is the go package name of proto package.
GoImportName string
GoImportName string `json:"go_import_name,omitempty"`

// Messages is a list of proto messages defined in the package.
Messages []Message
Messages []Message `json:"messages,omitempty"`

// Services is a list of RPC services.
Services []Service
Services []Service `json:"services,omitempty"`
}

type Files []File

type File struct {
// Path of the file.
Path string

// Dependencies is a list of imported .proto files in this package.
Dependencies []string
Path string `json:"path,omitempty"`
// Dependencies is a list of imported proto packages.
Dependencies []string `json:"dependencies,omitempty"`
}

func (f Files) Paths() []string {
Expand Down Expand Up @@ -73,56 +72,51 @@ func (p Package) GoImportPath() string {
// Message represents a proto message.
type Message struct {
// Name of the message.
Name string

// Path of the file where message is defined at.
Path string

// HighestFieldNumber is the highest field number among fields of the message
// This allows to determine new field number when writing to proto message
HighestFieldNumber int

// Fields contains message's field names and types
Fields map[string]string
Name string `json:"name,omitempty"`
// Path of the proto file where the message is defined.
Path string `json:"path,omitempty"`
// Highest field name is the highest field number among fields of the message.
// This allows to determine new field number when writing to proto message.
HighestFieldNumber int `json:"highest_field_number,omitempty"`
// Fields contains message's field names and types.
Fields map[string]string `json:"fields,omitempty"`
}

// Service is an RPC service.
type Service struct {
// Name of the services.
Name string
Name string `json:"name,omitempty"`

// RPC is a list of RPC funcs of the service.
RPCFuncs []RPCFunc
RPCFuncs []RPCFunc `json:"functions,omitempty"`
}

// RPCFunc is an RPC func.
type RPCFunc struct {
// Name of the RPC func.
Name string
Name string `json:"name,omitempty"`

// RequestType is the request type of RPC func.
RequestType string
RequestType string `json:"request_type,omitempty"`

// ReturnsType is the response type of RPC func.
ReturnsType string
ReturnsType string `json:"return_type,omitempty"`

// HTTPRules keeps info about http rules of an RPC func.
// spec:
// https://github.com/googleapis/googleapis/blob/master/google/api/http.proto.
HTTPRules []HTTPRule
HTTPRules []HTTPRule `json:"http_rules,omitempty"`

// Paginated indicates that the RPC function is using pagination.
Paginated bool
Paginated bool `json:"paginated,omitempty"`
}

// HTTPRule keeps info about a configured http rule of an RPC func.
type HTTPRule struct {
// Params is a list of parameters defined in the http endpoint itself.
Params []string

// HasQuery indicates if there is a request query.
HasQuery bool

// HasBody indicates if there is a request payload.
HasBody bool
// Params is a list of parameters defined in the HTTP endpoint itself.
Params []string `json:"params,omitempty"`
// Has query indicates if there is a request query.
HasQuery bool `json:"has_query,omitempty"`
// Has body indicates if there is a request payload.
HasBody bool `json:"has_body,omitempty"`
}

0 comments on commit 70bb246

Please sign in to comment.