Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

## Changes

- [#4855](https://github.com/ignite/cli/pull/4855) Implement openapi excludes.
- [#4850](https://github.com/ignite/cli/pull/4850) Add default GitHub Actions for linting and testing.
- [#4849](https://github.com/ignite/cli/pull/4849) Bump `cosmos-sdk` version to `v0.53.5` and minimum Go version to `1.25`.

Expand Down
7 changes: 6 additions & 1 deletion ignite/cmd/generate_openapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"github.com/ignite/cli/v29/ignite/services/chain"
)

var excludeFlag = "exclude"

func NewGenerateOpenAPI() *cobra.Command {
c := &cobra.Command{
Use: "openapi",
Expand All @@ -16,6 +18,7 @@ func NewGenerateOpenAPI() *cobra.Command {
}

c.Flags().AddFlagSet(flagSetYes())
c.Flags().StringSlice(excludeFlag, []string{}, "List of proto files or directories to exclude from the OpenAPI spec generation")

return c
}
Expand Down Expand Up @@ -47,7 +50,9 @@ func generateOpenAPIHandler(cmd *cobra.Command, _ []string) error {
opts = append(opts, chain.GenerateProtoVendor())
}

err = c.Generate(cmd.Context(), cacheStorage, chain.GenerateOpenAPI(), opts...)
excludeList, _ := cmd.Flags().GetStringArray(excludeFlag)

err = c.Generate(cmd.Context(), cacheStorage, chain.GenerateOpenAPI(excludeList), opts...)
if err != nil {
return err
}
Expand Down
3 changes: 2 additions & 1 deletion ignite/config/chain/base/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ type Composables struct {

// OpenAPI configures OpenAPI spec generation for API.
type OpenAPI struct {
Path string `yaml:"path" doc:"Relative path where the application's OpenAPI files are located."`
Path string `yaml:"path" doc:"Relative path where the application's OpenAPI files are located."`
ExcludeList []string `yaml:"exclude_list" doc:"List of proto paths to exclude OpenAPI from generation (supports wildcards)."`
}

// Faucet configuration.
Expand Down
6 changes: 6 additions & 0 deletions ignite/config/chain/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ client:
path: override-1
openapi:
path: docs/static/include1.yml
exclude_list: []
validators:
- name: alice
bonded: 100000000stake`,
Expand Down Expand Up @@ -200,6 +201,7 @@ client:
path: override-2
openapi:
path: docs/static/include2.yml
exclude_list: []
validators:
- name: alice
bonded: 100000000stake
Expand Down Expand Up @@ -259,6 +261,7 @@ client:
path: override-1
openapi:
path: docs/static/include1.yml
exclude_list: []
validators:
- name: alice
bonded: 100stake`,
Expand Down Expand Up @@ -302,6 +305,7 @@ client:
path: override-2
openapi:
path: docs/static/include2.yml
exclude_list: []
validators:
- name: alice
bonded: 100000000stake
Expand Down Expand Up @@ -368,6 +372,7 @@ client:
path: override-2
openapi:
path: docs/static/include2.yml
exclude_list: []
validators:
- name: alice
bonded: 100stake
Expand Down Expand Up @@ -436,6 +441,7 @@ client:
path: override-2
openapi:
path: docs/static/include2.yml
exclude_list: []
validators:
- name: alice
bonded: 100stake
Expand Down
12 changes: 7 additions & 5 deletions ignite/pkg/cosmosgen/cosmosgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ type generateOptions struct {
composablesOut func(module.Module) string
composablesRootPath string

specOut string
openAPISpecOut string
openAPIExcludeList []string
}

// ModulePathFunc defines a function type that returns a path based on a Cosmos SDK module.
Expand Down Expand Up @@ -63,9 +64,10 @@ func WithGoGeneration() Option {
}

// WithOpenAPIGeneration adds OpenAPI spec generation.
func WithOpenAPIGeneration(out string) Option {
func WithOpenAPIGeneration(out string, excludeList []string) Option {
return func(o *generateOptions) {
o.specOut = out
o.openAPISpecOut = out
o.openAPIExcludeList = excludeList
}
}

Expand Down Expand Up @@ -167,8 +169,8 @@ func Generate(ctx context.Context, cacheStorage cache.Storage, appPath, protoDir
}
}

if g.opts.specOut != "" {
if err := g.generateOpenAPISpec(ctx); err != nil {
if g.opts.openAPISpecOut != "" {
if err := g.generateOpenAPISpec(ctx, g.opts.openAPIExcludeList...); err != nil {
return err
}
}
Expand Down
27 changes: 15 additions & 12 deletions ignite/pkg/cosmosgen/generate_openapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func (g *generator) openAPITemplate() string {
return filepath.Join(g.appPath, g.protoDir, "buf.gen.swagger.yaml")
}

func (g *generator) generateOpenAPISpec(ctx context.Context) error {
func (g *generator) generateOpenAPISpec(ctx context.Context, excludeList ...string) error {
var (
specDirs = make([]string, 0)
conf = swaggercombine.New("HTTP API Console", g.goModPath)
Expand Down Expand Up @@ -98,16 +98,19 @@ func (g *generator) generateOpenAPISpec(ctx context.Context) error {
dir,
g.openAPITemplate(),
cosmosbuf.ExcludeFiles(
"*/osmosis-labs/fee-abstraction/*",
"*/module.proto",
"*/testutil/*",
"*/testdata/*",
"*/cosmos/orm/*",
"*/cosmos/reflection/*",
"*/cosmos/app/v1alpha1/*",
"*/cosmos/tx/config/v1/config.proto",
"*/cosmos/msg/textual/v1/textual.proto",
"*/cosmos/vesting/v1beta1/vesting.proto",
append(excludeList, []string{
"*/strangelove_ventures/poa/*",
"*/osmosis-labs/fee-abstraction/*",
"*/module.proto",
"*/testutil/*",
"*/testdata/*",
"*/cosmos/orm/*",
"*/cosmos/reflection/*",
"*/cosmos/app/v1alpha1/*",
"*/cosmos/tx/config/v1/config.proto",
"*/cosmos/msg/textual/v1/textual.proto",
"*/cosmos/vesting/v1beta1/vesting.proto",
}...)...,
),
cosmosbuf.FileByFile(),
); err != nil {
Expand Down Expand Up @@ -165,7 +168,7 @@ func (g *generator) generateOpenAPISpec(ctx context.Context) error {
}
}

out := g.opts.specOut
out := g.opts.openAPISpecOut

if !hasAnySpecChanged {
// In case the generated output has been changed
Expand Down
2 changes: 1 addition & 1 deletion ignite/pkg/cosmosgen/generate_openapi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func TestGenerateOpenAPI(t *testing.T) {
buf: buf,
appModules: m,
opts: &generateOptions{
specOut: openAPIFile,
openAPISpecOut: openAPIFile,
},
}

Expand Down
8 changes: 5 additions & 3 deletions ignite/services/chain/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type generateOptions struct {
isTSClientEnabled bool
isComposablesEnabled bool
isOpenAPIEnabled bool
openAPIExcludeList []string
tsClientPath string
composablesPath string
}
Expand Down Expand Up @@ -57,9 +58,10 @@ func GenerateComposables(path string) GenerateTarget {
}

// GenerateOpenAPI enables generating OpenAPI spec for your chain.
func GenerateOpenAPI() GenerateTarget {
func GenerateOpenAPI(excludeList []string) GenerateTarget {
return func(o *generateOptions) {
o.isOpenAPIEnabled = true
o.openAPIExcludeList = excludeList
}
}

Expand All @@ -86,7 +88,7 @@ func (c *Chain) generateFromConfig(ctx context.Context, cacheStorage cache.Stora
var targets []GenerateTarget

if conf.Client.OpenAPI.Path != "" {
targets = append(targets, GenerateOpenAPI())
targets = append(targets, GenerateOpenAPI(conf.Client.OpenAPI.ExcludeList))
}

if generateClients {
Expand Down Expand Up @@ -149,7 +151,7 @@ func (c *Chain) Generate(
openAPIPath = filepath.Join(c.app.Path, openAPIPath)
}

options = append(options, cosmosgen.WithOpenAPIGeneration(openAPIPath))
options = append(options, cosmosgen.WithOpenAPIGeneration(openAPIPath, targetOptions.openAPIExcludeList))
}

if targetOptions.isTSClientEnabled {
Expand Down
2 changes: 1 addition & 1 deletion ignite/services/scaffolder/scaffolder.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ func protoc(ctx context.Context, cacheStorage cache.Storage, projectPath, protoD
openAPIPath = filepath.Join(projectPath, openAPIPath)
}

options = append(options, cosmosgen.WithOpenAPIGeneration(openAPIPath))
options = append(options, cosmosgen.WithOpenAPIGeneration(openAPIPath, conf.Client.OpenAPI.ExcludeList))
}

if err := cosmosgen.Generate(
Expand Down