Only append "Service" suffix when services are not properly named.

Protobuf services should end in `Service`. This is a [buf lint rule](https://github.com/bufbuild/buf-examples/blob/main/linting/bad/acme/weather/v1/weather.proto#L39), recommended via [the protobuf style guide](https://developers.google.com/protocol-buffers/docs/style#services), and demonstrated in [Twirp Best Practices](https://twitchtv.github.io/twirp/docs/best_practices.html))

Therefore, we only append "Service" to fixup services that are not well named. This avoids generating e.g. "MessagesServiceService".
This commit is contained in:
darronschall 2022-08-22 10:18:52 -04:00
Родитель cd830052b4
Коммит 8d7ad0adf4
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B1F1B87D782DD365
1 изменённых файлов: 7 добавлений и 2 удалений

Просмотреть файл

@ -109,7 +109,12 @@ func (g *generator) generateRubyCode(file *descriptor.FileDescriptorProto, pbFil
for i, service := range file.Service {
svcName := service.GetName()
print(b, "%sclass %sService < ::Twirp::Service", indent, camelCase(svcName))
// Well-named services already end in "Service"; fixup services that don't.
if !strings.HasSuffix(svcName, "Service") {
svcName += "Service"
}
print(b, "%sclass %s < ::Twirp::Service", indent, camelCase(svcName))
if pkgName != "" {
print(b, "%s package '%s'", indent, pkgName)
}
@ -125,7 +130,7 @@ func (g *generator) generateRubyCode(file *descriptor.FileDescriptorProto, pbFil
print(b, "")
print(b, "%sclass %sClient < ::Twirp::Client", indent, camelCase(svcName))
print(b, "%s client_for %sService", indent, camelCase(svcName))
print(b, "%s client_for %s", indent, camelCase(svcName))
print(b, "%send", indent)
if i < len(file.Service)-1 {
print(b, "")