Skip to content

Commit 5f5a9a5

Browse files
authored
feat(cosmosgen): add openapi excludes (#4855)
* feat(cosmosgen): add openapi excludes * test: fix test * cl
1 parent db39c0f commit 5f5a9a5

9 files changed

Lines changed: 44 additions & 24 deletions

File tree

changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
## Changes
66

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

ignite/cmd/generate_openapi.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import (
88
"github.com/ignite/cli/v29/ignite/services/chain"
99
)
1010

11+
var excludeFlag = "exclude"
12+
1113
func NewGenerateOpenAPI() *cobra.Command {
1214
c := &cobra.Command{
1315
Use: "openapi",
@@ -16,6 +18,7 @@ func NewGenerateOpenAPI() *cobra.Command {
1618
}
1719

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

2023
return c
2124
}
@@ -47,7 +50,9 @@ func generateOpenAPIHandler(cmd *cobra.Command, _ []string) error {
4750
opts = append(opts, chain.GenerateProtoVendor())
4851
}
4952

50-
err = c.Generate(cmd.Context(), cacheStorage, chain.GenerateOpenAPI(), opts...)
53+
excludeList, _ := cmd.Flags().GetStringArray(excludeFlag)
54+
55+
err = c.Generate(cmd.Context(), cacheStorage, chain.GenerateOpenAPI(excludeList), opts...)
5156
if err != nil {
5257
return err
5358
}

ignite/config/chain/base/config.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ type Composables struct {
5959

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

6566
// Faucet configuration.

ignite/config/chain/parse_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ client:
154154
path: override-1
155155
openapi:
156156
path: docs/static/include1.yml
157+
exclude_list: []
157158
validators:
158159
- name: alice
159160
bonded: 100000000stake`,
@@ -200,6 +201,7 @@ client:
200201
path: override-2
201202
openapi:
202203
path: docs/static/include2.yml
204+
exclude_list: []
203205
validators:
204206
- name: alice
205207
bonded: 100000000stake
@@ -259,6 +261,7 @@ client:
259261
path: override-1
260262
openapi:
261263
path: docs/static/include1.yml
264+
exclude_list: []
262265
validators:
263266
- name: alice
264267
bonded: 100stake`,
@@ -302,6 +305,7 @@ client:
302305
path: override-2
303306
openapi:
304307
path: docs/static/include2.yml
308+
exclude_list: []
305309
validators:
306310
- name: alice
307311
bonded: 100000000stake
@@ -368,6 +372,7 @@ client:
368372
path: override-2
369373
openapi:
370374
path: docs/static/include2.yml
375+
exclude_list: []
371376
validators:
372377
- name: alice
373378
bonded: 100stake
@@ -436,6 +441,7 @@ client:
436441
path: override-2
437442
openapi:
438443
path: docs/static/include2.yml
444+
exclude_list: []
439445
validators:
440446
- name: alice
441447
bonded: 100stake

ignite/pkg/cosmosgen/cosmosgen.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ type generateOptions struct {
2929
composablesOut func(module.Module) string
3030
composablesRootPath string
3131

32-
specOut string
32+
openAPISpecOut string
33+
openAPIExcludeList []string
3334
}
3435

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

6566
// WithOpenAPIGeneration adds OpenAPI spec generation.
66-
func WithOpenAPIGeneration(out string) Option {
67+
func WithOpenAPIGeneration(out string, excludeList []string) Option {
6768
return func(o *generateOptions) {
68-
o.specOut = out
69+
o.openAPISpecOut = out
70+
o.openAPIExcludeList = excludeList
6971
}
7072
}
7173

@@ -167,8 +169,8 @@ func Generate(ctx context.Context, cacheStorage cache.Storage, appPath, protoDir
167169
}
168170
}
169171

170-
if g.opts.specOut != "" {
171-
if err := g.generateOpenAPISpec(ctx); err != nil {
172+
if g.opts.openAPISpecOut != "" {
173+
if err := g.generateOpenAPISpec(ctx, g.opts.openAPIExcludeList...); err != nil {
172174
return err
173175
}
174176
}

ignite/pkg/cosmosgen/generate_openapi.go

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func (g *generator) openAPITemplate() string {
2828
return filepath.Join(g.appPath, g.protoDir, "buf.gen.swagger.yaml")
2929
}
3030

31-
func (g *generator) generateOpenAPISpec(ctx context.Context) error {
31+
func (g *generator) generateOpenAPISpec(ctx context.Context, excludeList ...string) error {
3232
var (
3333
specDirs = make([]string, 0)
3434
conf = swaggercombine.New("HTTP API Console", g.goModPath)
@@ -98,16 +98,19 @@ func (g *generator) generateOpenAPISpec(ctx context.Context) error {
9898
dir,
9999
g.openAPITemplate(),
100100
cosmosbuf.ExcludeFiles(
101-
"*/osmosis-labs/fee-abstraction/*",
102-
"*/module.proto",
103-
"*/testutil/*",
104-
"*/testdata/*",
105-
"*/cosmos/orm/*",
106-
"*/cosmos/reflection/*",
107-
"*/cosmos/app/v1alpha1/*",
108-
"*/cosmos/tx/config/v1/config.proto",
109-
"*/cosmos/msg/textual/v1/textual.proto",
110-
"*/cosmos/vesting/v1beta1/vesting.proto",
101+
append(excludeList, []string{
102+
"*/strangelove_ventures/poa/*",
103+
"*/osmosis-labs/fee-abstraction/*",
104+
"*/module.proto",
105+
"*/testutil/*",
106+
"*/testdata/*",
107+
"*/cosmos/orm/*",
108+
"*/cosmos/reflection/*",
109+
"*/cosmos/app/v1alpha1/*",
110+
"*/cosmos/tx/config/v1/config.proto",
111+
"*/cosmos/msg/textual/v1/textual.proto",
112+
"*/cosmos/vesting/v1beta1/vesting.proto",
113+
}...)...,
111114
),
112115
cosmosbuf.FileByFile(),
113116
); err != nil {
@@ -165,7 +168,7 @@ func (g *generator) generateOpenAPISpec(ctx context.Context) error {
165168
}
166169
}
167170

168-
out := g.opts.specOut
171+
out := g.opts.openAPISpecOut
169172

170173
if !hasAnySpecChanged {
171174
// In case the generated output has been changed

ignite/pkg/cosmosgen/generate_openapi_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ func TestGenerateOpenAPI(t *testing.T) {
8989
buf: buf,
9090
appModules: m,
9191
opts: &generateOptions{
92-
specOut: openAPIFile,
92+
openAPISpecOut: openAPIFile,
9393
},
9494
}
9595

ignite/services/chain/generate.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ type generateOptions struct {
2222
isTSClientEnabled bool
2323
isComposablesEnabled bool
2424
isOpenAPIEnabled bool
25+
openAPIExcludeList []string
2526
tsClientPath string
2627
composablesPath string
2728
}
@@ -57,9 +58,10 @@ func GenerateComposables(path string) GenerateTarget {
5758
}
5859

5960
// GenerateOpenAPI enables generating OpenAPI spec for your chain.
60-
func GenerateOpenAPI() GenerateTarget {
61+
func GenerateOpenAPI(excludeList []string) GenerateTarget {
6162
return func(o *generateOptions) {
6263
o.isOpenAPIEnabled = true
64+
o.openAPIExcludeList = excludeList
6365
}
6466
}
6567

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

8890
if conf.Client.OpenAPI.Path != "" {
89-
targets = append(targets, GenerateOpenAPI())
91+
targets = append(targets, GenerateOpenAPI(conf.Client.OpenAPI.ExcludeList))
9092
}
9193

9294
if generateClients {
@@ -149,7 +151,7 @@ func (c *Chain) Generate(
149151
openAPIPath = filepath.Join(c.app.Path, openAPIPath)
150152
}
151153

152-
options = append(options, cosmosgen.WithOpenAPIGeneration(openAPIPath))
154+
options = append(options, cosmosgen.WithOpenAPIGeneration(openAPIPath, targetOptions.openAPIExcludeList))
153155
}
154156

155157
if targetOptions.isTSClientEnabled {

ignite/services/scaffolder/scaffolder.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ func protoc(ctx context.Context, cacheStorage cache.Storage, projectPath, protoD
173173
openAPIPath = filepath.Join(projectPath, openAPIPath)
174174
}
175175

176-
options = append(options, cosmosgen.WithOpenAPIGeneration(openAPIPath))
176+
options = append(options, cosmosgen.WithOpenAPIGeneration(openAPIPath, conf.Client.OpenAPI.ExcludeList))
177177
}
178178

179179
if err := cosmosgen.Generate(

0 commit comments

Comments
 (0)