Skip to content

Commit

Permalink
Merge branch 'main' into feat/auto-migdoc
Browse files Browse the repository at this point in the history
  • Loading branch information
Pantani authored Apr 18, 2024
2 parents 2224a5f + 6de2f33 commit f74c50f
Show file tree
Hide file tree
Showing 8 changed files with 195 additions and 196 deletions.
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
- [#3967](https://github.com/ignite/cli/issues/3967) Add HD wallet parameters `address index` and `account number` to the chain account config
- [#4004](https://github.com/ignite/cli/pull/4004) Remove all import placeholders using the `xast` pkg
- [#3718](https://github.com/ignite/cli/pull/3718) Add `gen-mig-diffs` tool app to compare scaffold output of two versions of ignite
- [#4077](https://github.com/ignite/cli/pull/4077) Merge the swagger files manually instead use nodetime `swagger-combine`

### Changes

Expand Down
2 changes: 1 addition & 1 deletion docs/docs/08-references/01-cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Ignite CLI offers everything you need to scaffold, test, build, and launch your

**Synopsis**

Ignite CLI is a tool for creating sovereign blockchains built with Cosmos SDK, the worlds
Ignite CLI is a tool for creating sovereign blockchains built with Cosmos SDK, the world's
most popular modular blockchain framework. Ignite CLI offers everything you need to scaffold,
test, build, and launch your blockchain.

Expand Down
13 changes: 13 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ require (
github.com/emicklei/proto-contrib v0.15.0
github.com/go-delve/delve v1.21.0
github.com/go-git/go-git/v5 v5.12.0
github.com/go-openapi/analysis v0.23.0
github.com/go-openapi/loads v0.22.0
github.com/go-openapi/spec v0.21.0
github.com/gobuffalo/genny/v2 v2.1.0
github.com/gobuffalo/packd v1.0.2
github.com/gobuffalo/plush/v4 v4.1.19
Expand Down Expand Up @@ -131,6 +134,7 @@ require (
github.com/andrew-d/go-termutil v0.0.0-20150726205930-009166a695a2 // indirect
github.com/antlr4-go/antlr/v4 v4.13.0 // indirect
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 // indirect
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 // indirect
github.com/ashanbrown/forbidigo v1.6.0 // indirect
github.com/ashanbrown/makezero v1.1.1 // indirect
github.com/atotto/clipboard v0.1.2 // indirect
Expand Down Expand Up @@ -231,6 +235,11 @@ require (
github.com/go-logfmt/logfmt v0.6.0 // indirect
github.com/go-logr/logr v1.4.1 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-openapi/errors v0.22.0 // indirect
github.com/go-openapi/jsonpointer v0.21.0 // indirect
github.com/go-openapi/jsonreference v0.21.0 // indirect
github.com/go-openapi/strfmt v0.23.0 // indirect
github.com/go-openapi/swag v0.23.0 // indirect
github.com/go-toolsmith/astcast v1.1.0 // indirect
github.com/go-toolsmith/astcopy v1.1.0 // indirect
github.com/go-toolsmith/astequal v1.2.0 // indirect
Expand Down Expand Up @@ -303,6 +312,7 @@ require (
github.com/jirfag/go-printf-func-name v0.0.0-20200119135958-7558a9eaa5af // indirect
github.com/jjti/go-spancheck v0.5.3 // indirect
github.com/jmhodges/levigo v1.0.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/jpillora/ansi v1.0.3 // indirect
github.com/jpillora/backoff v1.0.0 // indirect
github.com/jpillora/requestlog v1.0.0 // indirect
Expand All @@ -329,6 +339,7 @@ require (
github.com/lufeee/execinquery v1.2.1 // indirect
github.com/macabu/inamedparam v0.1.3 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/maratori/testableexamples v1.0.0 // indirect
github.com/maratori/testpackage v1.1.1 // indirect
github.com/matoous/godox v0.0.0-20230222163458-006bad1f9d26 // indirect
Expand Down Expand Up @@ -363,6 +374,7 @@ require (
github.com/nunnatsa/ginkgolinter v0.16.2 // indirect
github.com/oasisprotocol/curve25519-voi v0.0.0-20230904125328-1f23a7beb09a // indirect
github.com/oklog/run v1.1.0 // indirect
github.com/oklog/ulid v1.3.1 // indirect
github.com/olekukonko/tablewriter v0.0.5 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.1.0 // indirect
Expand Down Expand Up @@ -446,6 +458,7 @@ require (
gitlab.com/bosi/decorder v0.4.1 // indirect
go-simpler.org/musttag v0.9.0 // indirect
go-simpler.org/sloglint v0.5.0 // indirect
go.mongodb.org/mongo-driver v1.14.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0 // indirect
go.opentelemetry.io/otel v1.24.0 // indirect
go.opentelemetry.io/otel/metric v1.24.0 // indirect
Expand Down
23 changes: 23 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@ github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio=
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs=
github.com/aryann/difflib v0.0.0-20170710044230-e206f873d14a/go.mod h1:DAHtR1m6lCRdSC2Tm3DSWRPvIPr6xNKyeHdqDQSQT+A=
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 h1:DklsrG3dyBCFEj5IhUbnKptjxatkF07cF2ak3yi77so=
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2/go.mod h1:WaHUgvxTVq04UNunO+XhnAqY/wQc+bxr74GqbsZ/Jqw=
github.com/ashanbrown/forbidigo v1.6.0 h1:D3aewfM37Yb3pxHujIPSpTf6oQk9sc9WZi8gerOIVIY=
github.com/ashanbrown/forbidigo v1.6.0/go.mod h1:Y8j9jy9ZYAEHXdu723cUlraTqbzjKF1MUyfOKL+AjcU=
github.com/ashanbrown/makezero v1.1.1 h1:iCQ87C0V0vSyO+M9E/FZYbu65auqH0lnsOkf5FcB28s=
Expand Down Expand Up @@ -557,6 +559,22 @@ github.com/go-logr/logr v1.4.1 h1:pKouT5E8xu9zeFC39JXRDukb6JFQPXM5p5I91188VAQ=
github.com/go-logr/logr v1.4.1/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
github.com/go-openapi/analysis v0.23.0 h1:aGday7OWupfMs+LbmLZG4k0MYXIANxcuBTYUC03zFCU=
github.com/go-openapi/analysis v0.23.0/go.mod h1:9mz9ZWaSlV8TvjQHLl2mUW2PbZtemkE8yA5v22ohupo=
github.com/go-openapi/errors v0.22.0 h1:c4xY/OLxUBSTiepAg3j/MHuAv5mJhnf53LLMWFB+u/w=
github.com/go-openapi/errors v0.22.0/go.mod h1:J3DmZScxCDufmIMsdOuDHxJbdOGC0xtUynjIx092vXE=
github.com/go-openapi/jsonpointer v0.21.0 h1:YgdVicSA9vH5RiHs9TZW5oyafXZFc6+2Vc1rr/O9oNQ=
github.com/go-openapi/jsonpointer v0.21.0/go.mod h1:IUyH9l/+uyhIYQ/PXVA41Rexl+kOkAPDdXEYns6fzUY=
github.com/go-openapi/jsonreference v0.21.0 h1:Rs+Y7hSXT83Jacb7kFyjn4ijOuVGSvOdF2+tg1TRrwQ=
github.com/go-openapi/jsonreference v0.21.0/go.mod h1:LmZmgsrTkVg9LG4EaHeY8cBDslNPMo06cago5JNLkm4=
github.com/go-openapi/loads v0.22.0 h1:ECPGd4jX1U6NApCGG1We+uEozOAvXvJSF4nnwHZ8Aco=
github.com/go-openapi/loads v0.22.0/go.mod h1:yLsaTCS92mnSAZX5WWoxszLj0u+Ojl+Zs5Stn1oF+rs=
github.com/go-openapi/spec v0.21.0 h1:LTVzPc3p/RzRnkQqLRndbAzjY0d0BCL72A6j3CdL9ZY=
github.com/go-openapi/spec v0.21.0/go.mod h1:78u6VdPw81XU44qEWGhtr982gJ5BWg2c0I5XwVMotYk=
github.com/go-openapi/strfmt v0.23.0 h1:nlUS6BCqcnAk0pyhi9Y+kdDVZdZMHfEKQiS4HaMgO/c=
github.com/go-openapi/strfmt v0.23.0/go.mod h1:NrtIpfKtWIygRkKVsxh7XQMDQW5HKQl6S5ik2elW+K4=
github.com/go-openapi/swag v0.23.0 h1:vsEVJDUo2hPJ2tu0/Xc+4noaxyEffXNIs3cOULZ+GrE=
github.com/go-openapi/swag v0.23.0/go.mod h1:esZ8ITTYEsH1V2trKHjAN8Ai7xHb8RV+YSZ577vPjgQ=
github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
github.com/go-playground/locales v0.13.0/go.mod h1:taPMhCMXrRLJO55olJkUXHZBHCxTMfnGwq/HNwmWNS8=
github.com/go-playground/locales v0.14.0 h1:u50s323jtVGugKlcYeyzC0etD1HifMjqmJqb8WugfUU=
Expand Down Expand Up @@ -928,6 +946,7 @@ github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHW
github.com/jmhodges/levigo v1.0.0 h1:q5EC36kV79HWeTBWsod3mG11EgStG3qArTKcvlksN1U=
github.com/jmhodges/levigo v1.0.0/go.mod h1:Q6Qx+uH3RAqyK4rFQroq9RL7mdkABMcfhEI+nNuzMJQ=
github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo=
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
github.com/jpillora/ansi v1.0.3 h1:nn4Jzti0EmRfDxm7JtEs5LzCbNwd5sv+0aE+LdS9/ZQ=
github.com/jpillora/ansi v1.0.3/go.mod h1:D2tT+6uzJvN1nBVQILYWkIdq7zG+b5gcFN5WI/VyjMY=
Expand Down Expand Up @@ -1025,6 +1044,7 @@ github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czP
github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY=
github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0=
github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
github.com/manifoldco/promptui v0.9.0 h1:3V4HzJk1TtXW1MTZMP7mdlwbBpIinw3HztaIlYthEiA=
github.com/manifoldco/promptui v0.9.0/go.mod h1:ka04sppxSGFAtxX0qhlYQjISsg9mR4GWtQEhdbn6Pgg=
Expand Down Expand Up @@ -1172,6 +1192,7 @@ github.com/oklog/oklog v0.3.2/go.mod h1:FCV+B7mhrz4o+ueLpx+KqkyXRGMWOYEvfiXtdGtb
github.com/oklog/run v1.0.0/go.mod h1:dlhp/R75TPv97u0XWUtDeV/lRKWPKSdTuV0TZvrmrQA=
github.com/oklog/run v1.1.0 h1:GEenZ1cK0+q0+wsJew9qUg/DyD8k3JzYsZAi5gYi2mA=
github.com/oklog/run v1.1.0/go.mod h1:sVPdnTZT1zYwAJeCMu2Th4T21pA3FPOQRfWjQlk7DVU=
github.com/oklog/ulid v1.3.1 h1:EGfNDEx6MqHz8B3uNV6QAib1UR2Lm97sHi3ocA6ESJ4=
github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U=
github.com/olekukonko/tablewriter v0.0.0-20170122224234-a0225b3f23b5/go.mod h1:vsDQFd/mU46D+Z4whnwzcISnGGzXWMclvtLoiIKAKIo=
github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec=
Expand Down Expand Up @@ -1542,6 +1563,8 @@ go.etcd.io/bbolt v1.3.3/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU=
go.etcd.io/bbolt v1.3.9 h1:8x7aARPEXiXbHmtUwAIv7eV2fQFHrLLavdiJ3uzJXoI=
go.etcd.io/bbolt v1.3.9/go.mod h1:zaO32+Ti0PK1ivdPtgMESzuzL2VPoIG1PCQNvOdo/dE=
go.etcd.io/etcd v0.0.0-20191023171146-3cf2f69b5738/go.mod h1:dnLIgRNXwCJa5e+c6mIZCrds/GIG4ncV9HhK5PX7jPg=
go.mongodb.org/mongo-driver v1.14.0 h1:P98w8egYRjYe3XDjxhYJagTokP/H6HzlsnojRgZRd80=
go.mongodb.org/mongo-driver v1.14.0/go.mod h1:Vzb0Mk/pa7e6cWw85R4F/endUC3u0U9jGcNU603k65c=
go.opencensus.io v0.20.1/go.mod h1:6WKK9ahsWS3RSO+PY9ZHZUfv2irvY6gN279GOPZjmmk=
go.opencensus.io v0.20.2/go.mod h1:6WKK9ahsWS3RSO+PY9ZHZUfv2irvY6gN279GOPZjmmk=
go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU=
Expand Down
19 changes: 13 additions & 6 deletions ignite/internal/tools/gen-cli-docs/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"bufio"
"bytes"
"context"
"flag"
"fmt"
"io"
"log"
Expand All @@ -23,24 +22,25 @@ import (
"github.com/ignite/cli/v29/ignite/services/plugin"
)

const head = `---
const (
head = `---
description: Ignite CLI docs.
---
# CLI commands
Documentation for Ignite CLI.
`
outFlag = "out"
)

func main() {
outPath := flag.String("out", ".", ".md file path to place Ignite CLI docs inside")
flag.Parse()
if err := run(*outPath); err != nil {
if err := run(); err != nil {
log.Fatal(err)
}
}

func run(outPath string) error {
func run() error {
// We want to have documentation for commands that are implemented in plugins.
// To do that, we need to add the related plugins in the config.
// To avoid conflicts with user config, set an alternate config dir in tmp.
Expand Down Expand Up @@ -71,13 +71,20 @@ func run(outPath string) error {
return err
}
defer cleanUp()
cmd.Flags().String(outFlag, ".", ".md file path to place Ignite CLI docs inside")
cmd.Flags().MarkHidden(outFlag)

// Run ExecuteC so cobra adds the completion command.
cmd, err = cmd.ExecuteC()
if err != nil {
return err
}

outPath, err := cmd.Flags().GetString(outFlag)
if err != nil {
return nil
}

return generate(cmd, outPath)
}

Expand Down
105 changes: 23 additions & 82 deletions ignite/pkg/cosmosgen/generate_openapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,14 @@ import (
"fmt"
"os"
"path/filepath"
"sort"

"github.com/iancoleman/strcase"

"github.com/ignite/cli/v29/ignite/pkg/cache"
"github.com/ignite/cli/v29/ignite/pkg/cosmosanalysis/module"
"github.com/ignite/cli/v29/ignite/pkg/dirchange"
"github.com/ignite/cli/v29/ignite/pkg/errors"
"github.com/ignite/cli/v29/ignite/pkg/nodetime"
swaggercombine "github.com/ignite/cli/v29/ignite/pkg/nodetime/programs/swagger-combine"
swaggercombine "github.com/ignite/cli/v29/ignite/pkg/swagger-combine"
"github.com/ignite/cli/v29/ignite/pkg/xos"
)

Expand All @@ -34,18 +32,8 @@ func (g *generator) openAPITemplateForSTA() string {
func (g *generator) generateOpenAPISpec(ctx context.Context) error {
var (
specDirs []string
conf = swaggercombine.Config{
Swagger: "2.0",
Info: swaggercombine.Info{
Title: "HTTP API Console",
},
}
conf = swaggercombine.New("HTTP API Console", g.gomodPath)
)
command, cleanup, err := nodetime.Command(nodetime.CommandSwaggerCombine)
if err != nil {
return err
}
defer cleanup()
defer func() {
for _, dir := range specDirs {
os.RemoveAll(dir)
Expand Down Expand Up @@ -149,100 +137,53 @@ func (g *generator) generateOpenAPISpec(ctx context.Context) error {
}
}

sort.Slice(conf.APIs, func(a, b int) bool { return conf.APIs[a].ID < conf.APIs[b].ID })

// ensure out dir exists.
outDir := filepath.Dir(out)
if err := os.MkdirAll(outDir, 0o766); err != nil {
return err
}

// combine specs into one and save to out.
if err := swaggercombine.Combine(ctx, conf, command, out); err != nil {
if err := conf.Combine(out); err != nil {
return err
}

return dirchange.SaveDirChecksum(specCache, out, g.appPath, out)
}

// generateModuleOpenAPISpec generates a spec for a module where it's source code resides at src.
// and adds needed swaggercombine configure for it.
func (g *generator) generateModuleOpenAPISpec(ctx context.Context, m module.Module, out string) error {
var (
specDirs []string
conf = swaggercombine.Config{
Swagger: "2.0",
Info: swaggercombine.Info{
Title: "HTTP API Console " + m.Pkg.Name,
},
}
title = "HTTP API Console " + m.Pkg.Name
conf = swaggercombine.New(title, g.gomodPath)
)
command, cleanup, err := nodetime.Command(nodetime.CommandSwaggerCombine)
if err != nil {
return err
}
defer cleanup()

defer func() {
for _, dir := range specDirs {
os.RemoveAll(dir)
}
}()

// gen generates a spec for a module where it's source code resides at src.
// and adds needed swaggercombine configure for it.
gen := func(m module.Module) (err error) {
dir, err := os.MkdirTemp("", "gen-openapi-module-spec")
if err != nil {
return err
}

err = g.buf.Generate(ctx, m.Pkg.Path, dir, g.openAPITemplateForSTA(), "module.proto")
if err != nil {
return err
}

specs, err := xos.FindFiles(dir, xos.JSONFile)
if err != nil {
return err
}

for _, spec := range specs {
if err != nil {
return err
}
if err := conf.AddSpec(strcase.ToCamel(m.Pkg.Name), spec, false); err != nil {
return err
}
}
specDirs = append(specDirs, dir)

return nil
}

// generate specs for each module and persist them in the file system
// after add their path and config to swaggercombine.Config so we can combine them
// into a single spec.

add := func(modules []module.Module) error {
for _, m := range modules {
if err := gen(m); err != nil {
return err
}
}
return nil
dir, err := os.MkdirTemp("", "gen-openapi-module-spec")
if err != nil {
return err
}

// protoc openapi generator acts weird on concurrent run, so do not use goroutines here.
if err := add([]module.Module{m}); err != nil {
err = g.buf.Generate(ctx, m.Pkg.Path, dir, g.openAPITemplateForSTA(), "module.proto")
if err != nil {
return err
}

sort.Slice(conf.APIs, func(a, b int) bool { return conf.APIs[a].ID < conf.APIs[b].ID })

// ensure out dir exists.
outDir := filepath.Dir(out)
if err := os.MkdirAll(outDir, 0o766); err != nil {
specs, err := xos.FindFiles(dir, xos.JSONFile)
if err != nil {
return err
}

for _, spec := range specs {
if err := conf.AddSpec(strcase.ToCamel(m.Pkg.Name), spec, false); err != nil {
return err
}
}
specDirs = append(specDirs, dir)

// combine specs into one and save to out.
return swaggercombine.Combine(ctx, conf, command, out)
return conf.Combine(out)
}
Loading

0 comments on commit f74c50f

Please sign in to comment.