Skip to content

Commit

Permalink
fix(codegen): protoc to keep snake_case for swagger and ts out (ignit…
Browse files Browse the repository at this point in the history
…e#2149)

* fix: protoc to keep snake_case for swagger and ts out

* refactor

* removed SpVuexError

Co-authored-by: İlker G. Öztürk <ilkergoktugozturk@gmail.com>
Co-authored-by: marinhoarthur <arthurtutuca@gmail.com>
  • Loading branch information
3 people committed Mar 16, 2022
1 parent 347261c commit 16aedb5
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 13 deletions.
4 changes: 2 additions & 2 deletions starport/pkg/cosmosgen/generate_javascript.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ var (
}

jsOpenAPIOut = []string{
"--openapiv2_out=logtostderr=true,allow_merge=true,Mgoogle/protobuf/any.proto=github.com/cosmos/cosmos-sdk/codec/types:.",
"--openapiv2_out=logtostderr=true,allow_merge=true,json_names_for_fields=false,Mgoogle/protobuf/any.proto=github.com/cosmos/cosmos-sdk/codec/types:.",
}
)

Expand Down Expand Up @@ -106,7 +106,7 @@ func (g *jsGenerator) generateModule(ctx context.Context, tsprotoPluginPath, app
m.Pkg.Path,
includePaths,
tsOut,
protoc.Plugin(tsprotoPluginPath),
protoc.Plugin(tsprotoPluginPath, "--ts_proto_opt=snakeToCamel=false"),
)
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion starport/pkg/cosmosgen/generate_openapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
)

var openAPIOut = []string{
"--openapiv2_out=logtostderr=true,allow_merge=true,fqn_for_openapi_name=true,simple_operation_ids=true,Mgoogle/protobuf/any.proto=github.com/cosmos/cosmos-sdk/codec/types:.",
"--openapiv2_out=logtostderr=true,allow_merge=true,json_names_for_fields=false,fqn_for_openapi_name=true,simple_operation_ids=true,Mgoogle/protobuf/any.proto=github.com/cosmos/cosmos-sdk/codec/types:.",
}

func generateOpenAPISpec(g *generator) error {
Expand Down
14 changes: 6 additions & 8 deletions starport/pkg/cosmosgen/templates/vuex/store/index.ts.tpl
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { txClient, queryClient, MissingWalletError , registry} from './module'
// @ts-ignore
import { SpVuexError } from '@starport/vuex'

{{ range .Module.Types }}import { {{ .Name }} } from "./module/types/{{ resolveFile .FilePath }}"
{{ end }}
Expand Down Expand Up @@ -110,7 +108,7 @@ export default {
const sub=JSON.parse(subscription)
await dispatch(sub.action, sub.payload)
}catch(e) {
throw new SpVuexError('Subscriptions: ' + e.message)
throw new Error('Subscriptions: ' + e.message)
}
})
},
Expand Down Expand Up @@ -156,7 +154,7 @@ export default {
if (subscribe) commit('SUBSCRIBE', { action: '{{ $FullName }}{{ $n }}', payload: { options: { all }, params: {...key},query }})
return getters['get{{ $Name }}']( { params: {...key}, query}) ?? {}
} catch (e) {
throw new SpVuexError('QueryClient:{{ $FullName }}{{ $n }}', 'API Node Unavailable. Could not perform query: ' + e.message)
throw new Error('QueryClient:{{ $FullName }}{{ $n }} API Node Unavailable. Could not perform query: ' + e.message)
}
},
Expand All @@ -171,9 +169,9 @@ export default {
return result
} catch (e) {
if (e == MissingWalletError) {
throw new SpVuexError('TxClient:{{ .Name }}:Init', 'Could not initialize signing client. Wallet is required.')
throw new Error('TxClient:{{ .Name }}:Init Could not initialize signing client. Wallet is required.')
}else{
throw new SpVuexError('TxClient:{{ .Name }}:Send', 'Could not broadcast Tx: '+ e.message)
throw new Error('TxClient:{{ .Name }}:Send Could not broadcast Tx: '+ e.message)
}
}
},
Expand All @@ -185,9 +183,9 @@ export default {
return msg
} catch (e) {
if (e == MissingWalletError) {
throw new SpVuexError('TxClient:{{ .Name }}:Init', 'Could not initialize signing client. Wallet is required.')
throw new Error('TxClient:{{ .Name }}:Init Could not initialize signing client. Wallet is required.')
}else{
throw new SpVuexError('TxClient:{{ .Name }}:Create', 'Could not create message: ' + e.message)
throw new Error('TxClient:{{ .Name }}:Create Could not create message: ' + e.message)
}
}
Expand Down
7 changes: 5 additions & 2 deletions starport/pkg/protoc/protoc.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@ type Option func(*configs)
type configs struct {
pluginPath string
isGeneratedDepsEnabled bool
pluginOptions []string
}

// Plugin configures a plugin for code generation.
func Plugin(path string) Option {
func Plugin(path string, options ...string) Option {
return func(c *configs) {
c.pluginPath = path
c.pluginOptions = options
}
}

Expand Down Expand Up @@ -73,6 +75,7 @@ func Command() (command Cmd, cleanup func(), err error) {
// Generate generates code into outDir from protoPath and its includePaths by using plugins provided with protocOuts.
func Generate(ctx context.Context, outDir, protoPath string, includePaths, protocOuts []string, options ...Option) error {
c := configs{}

for _, o := range options {
o(&c)
}
Expand All @@ -89,7 +92,6 @@ func Generate(ctx context.Context, outDir, protoPath string, includePaths, proto
if c.pluginPath != "" {
command = append(command, "--plugin", c.pluginPath)
}

var existentIncludePaths []string

// skip if a third party proto source actually doesn't exist on the filesystem.
Expand All @@ -115,6 +117,7 @@ func Generate(ctx context.Context, outDir, protoPath string, includePaths, proto
for _, out := range protocOuts {
command := append(command, out)
command = append(command, files...)
command = append(command, c.pluginOptions...)

if err := exec.Exec(ctx, command,
exec.StepOption(step.Workdir(outDir)),
Expand Down

0 comments on commit 16aedb5

Please sign in to comment.