Closed faizanahmadsyed closed 1 year ago
Thanks for the bug report. We will look into this.
Still keeping this open.
Hello @faizanahmadsyed!
in v8.1.0
and onward, jsonSkipDefaults
is set to false
by default, and the NewBuilderServer
constructor no longer recognizes the JSONSkipDefaults
value. For reference, here's the note regarding that. We could potentially improve the comments in the options struct regarding deprecation of that value.
Two potential solutions would be:
Use the options as illustrated in the docs:
builderHandler := rpc.NewBuilderServer(d.handlers.builder,
twirp.WithServerJSONSkipDefaults(true),
twirp.WithServiceHooks(defaultHooks()),
twirp.WithServerPathPrefix(pathPrefix))
If still inclined to define reusable defaults, define defaultOptions
and use them in the following way:
defaultOptions := []twirp.ServerOption{
twirp.WithServerJSONSkipDefaults(true),
twirp.WithServiceHooks(defaultHooks()),
}
opts := []twirp.ServerOption{} opts = append(opts, defaultOptions...) opts = append(opts, twirp.WithServerPathPrefix(pathPrefix))
builderHandler := rpc.NewBuilderServer(d.handlers.builder, opts...)
Given the explanation from @fpetelin, I am closing this issue.
Hello, I am fairly new to Twirp so this may be something I am doing wrong. We recently upgraded from
github.com/twitchtv/twirp/protoc-gen-twirp@v8.0.0
togithub.com/twitchtv/twirp/protoc-gen-twirp@v8.1.2
.We have a service called
Builder
which we are instantiating in therouter.go
of our application using:Here is the definition of
tw.DefaultOptions()
:The
NewBuilderServer
Twirp function gets defined as follows in v8.1.2:The issue here is that, as we can see in the definition of
tw.DefaultOptions()
,jsonSkipDefaults
should be set to true. However,_ = serverOpts.ReadOpt("jsonSkipDefaults", &jsonSkipDefaults)
does not change the value ofjsonSkipDefaults
and leaves it asfalse
.For context here is how the
NewBuilderServer
Twirp function gets defined in v8.0.0:This works as expected. These two pieces of code are semantically identical for our purposes. I was wondering if I could get some help in determining what could be causing an issue like this to occur. Any guidance will be greatly appreciated!