Skip to content

Commit 3b6db7f

Browse files
committed
Embed Options inside Registry to remove duplicated defs
1 parent baa6bd6 commit 3b6db7f

File tree

3 files changed

+12
-36
lines changed

3 files changed

+12
-36
lines changed

generator/template_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func TestFieldName(t *testing.T) {
2727
}
2828
for _, tt := range tests {
2929
t.Run(tt.input, func(t *testing.T) {
30-
r := &registry.Registry{UseProtoNames: tt.useProtoNames}
30+
r := &registry.Registry{Options: registry.Options{UseProtoNames: tt.useProtoNames}}
3131
fn := fieldName(r)
3232
if got := fn(tt.input); got != tt.want {
3333
assert.Equal(t, got, tt.want, "fieldName(%s) = %s, want %s", tt.input, got, tt.want)

main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func run() error {
5858
EnableStylingCheck: *enableStylingCheck,
5959
EmitUnpopulated: *emitUnpopulated,
6060
FetchModuleDirectory: *fetchModuleDirectory,
61-
FetchModuleFileName: *fetchModuleFilename,
61+
FetchModuleFilename: *fetchModuleFilename,
6262
TSImportRoots: *tsImportRoots,
6363
TSImportRootAliases: *tsImportRootAliases,
6464
})

registry/registry.go

Lines changed: 10 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ type Options struct {
2323
TSImportRootAliases string
2424
// FetchModuleDirectory is the parameter for directory where fetch module will live
2525
FetchModuleDirectory string
26-
// FetchModuleFileName is the file name for the individual fetch module
27-
FetchModuleFileName string
26+
// FetchModuleFilename is the file name for the individual fetch module
27+
FetchModuleFilename string
2828
// UseProtoNames will generate field names the same as defined in the proto
2929
UseProtoNames bool
3030
// UseStaticClasses will cause the generator to generate a static class in the form ServiceName.MethodName, which is
@@ -41,6 +41,8 @@ type Options struct {
4141
// Registry analyze generation request, spits out the data the the rendering process
4242
// it also holds the information about all the types
4343
type Registry struct {
44+
Options
45+
4446
// Types stores the type information keyed by the fully qualified name of a type
4547
Types map[string]*TypeInformation
4648

@@ -53,27 +55,6 @@ type Registry struct {
5355
// TSImportRootAliases if not empty will substitutes the common import root when writing the import into the js file
5456
TSImportRootAliases []string
5557

56-
// FetchModuleDirectory is the directory to place fetch module file
57-
FetchModuleDirectory string
58-
59-
// FetchModuleFilename is the filename for the fetch module
60-
FetchModuleFilename string
61-
62-
// UseProtoNames will cause the generator to generate field name the same as defined in the proto
63-
UseProtoNames bool
64-
65-
// UseStaticClasses will cause the generator to generate a static class in the form ServiceName.MethodName, which is
66-
// the legacy behavior for this generator. If set to false, the generator will generate a client class with methods
67-
// as well as static methods exported for each service method.
68-
UseStaticClasses bool
69-
70-
// EmitUnpopulated mirrors the grpc gateway protojson configuration of the same name and allows
71-
// clients to differentiate between zero values and optional values that aren't set.
72-
EmitUnpopulated bool
73-
74-
// EnableStylingCheck enables both eslint and tsc check for the generated code
75-
EnableStylingCheck bool
76-
7758
// TSPackages stores the package name keyed by the TS file name
7859
TSPackages map[string]string
7960
}
@@ -88,19 +69,14 @@ func NewRegistry(opts Options) (*Registry, error) {
8869
}
8970

9071
log.Debugf("found fetch module directory %s", opts.FetchModuleDirectory)
91-
log.Debugf("found fetch module name %s", opts.FetchModuleFileName)
72+
log.Debugf("found fetch module name %s", opts.FetchModuleFilename)
9273

9374
return &Registry{
94-
Types: make(map[string]*TypeInformation),
95-
TSImportRoots: tsImportRoots,
96-
TSImportRootAliases: tsImportRootAliases,
97-
FetchModuleDirectory: opts.FetchModuleDirectory,
98-
FetchModuleFilename: opts.FetchModuleFileName,
99-
TSPackages: make(map[string]string),
100-
UseProtoNames: opts.UseProtoNames,
101-
UseStaticClasses: opts.UseStaticClasses,
102-
EmitUnpopulated: opts.EmitUnpopulated,
103-
EnableStylingCheck: opts.EnableStylingCheck,
75+
Options: opts,
76+
Types: make(map[string]*TypeInformation),
77+
TSPackages: make(map[string]string),
78+
TSImportRoots: tsImportRoots,
79+
TSImportRootAliases: tsImportRootAliases,
10480
}, nil
10581
}
10682

0 commit comments

Comments
 (0)