Description
🐛 Bug Report
I wanted to use snake_case on the JSON input and output of my grpc-gateway since this is how my company described the API I am writing.
So since the gateway generated json names automatically in camelCase I tried using the runtime.WithMarshalerOption()
(in golang) to change this behavior like this:
gw := runtime.NewServeMux(
// ... other opts ...
// Configure proxy to output camel_case json and to not omit
// 0 values, such as 0, "" or null
runtime.WithMarshalerOption(
runtime.MIMEWildcard,
&runtime.JSONPb{MarshalOptions: protojson.MarshalOptions{
UseProtoNames: true,
}},
),
)
This worked since the proto names I am using are in snake_case, however, when I open the generated swagger documentation it still describes the input and output JSON as if all attributes used camelCase, and I was unable to find an option for fixing this.
So now it seems I will have to stop using this option in favor of naming the JSON name for each attribute on my proto file.
To Reproduce
In an existing grpc-gateway that automatically generates swagger docs add the option mentioned on the call to NewServeMux.
This will make the API read and respond using the proto names as attributes.
But will not update the swagger docs accordingly.
Expected behavior
I expected the swagger docs to show the responses with the actual values they are being generated by the code, e.g.:
(response JSON)
{
"api_token": "string",
"api_secret": "string",
}
Actual Behavior
Swagger is showing JSON inputs and outputs with attribute names written in camelCase, e.g.:
(response JSON)
{
"apiToken": "string",
"apiSecret": "string",
}
Your Environment
Golang version:
$ go version
go version go1.15.5 linux/amd64
Linux Distro:
$ uname -a
Linux vingarcia 5.8.18-1-MANJARO #1 SMP PREEMPT Sun Nov 1 14:10:04 UTC 2020 x86_64 GNU/Linux
Protoc download link (with version):
grpc-gateway downloaded with:
go get -u \
github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway \
github.com/grpc-ecosystem/grpc-gateway/protoc-gen-openapiv2