-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Generator does not respect java_multiple_files
option
#6
Comments
I have not fully tested this, but my quick tests seem to work. I was thinking about opening a Pull Request, but since I copied part of this implementation directly from In for (file in request.protoFileList) {
val packageName = if (file.options.javaPackage.isNullOrBlank()) file.`package` else file.options.javaPackage
val nestedClassName = file.getOuterClassName()
for (messageType in file.messageTypeList) {
compiledTypes.put(messageType.name, packageName+nestedClassName)
}
for (enumType in file.enumTypeList) {
compiledTypes.put(enumType.name, packageName+nestedClassName)
}
} // Based on https://github.com/grpc/grpc-kotlin/blob/ae2d5f7b514b45cf944296d91dd14c22a9a17c51/compiler/src/main/java/io/grpc/kotlin/generator/protoc/DescriptorUtil.kt#L119
private fun DescriptorProtos.FileDescriptorProto.getOuterClassName(): String {
if (options.javaMultipleFiles) {
return ""
}
if (options.hasJavaOuterClassname()) {
return ".${options.javaOuterClassname}"
}
val fileName = name.substringAfterLast('/').removeSuffix(".proto")
val defaultName = fileName.replace("-", "_").underscoresToCamel()
val foundDuplicate = messageTypeList.any { it.name == defaultName } ||
enumTypeList.any { it.name == defaultName } ||
serviceList.any { it.name == defaultName }
return if (foundDuplicate) {
".${defaultName}OuterClass"
} else {
".$defaultName"
}
}
// Copied from https://github.com/grpc/grpc-kotlin/blob/ae2d5f7b514b45cf944296d91dd14c22a9a17c51/compiler/src/main/java/io/grpc/kotlin/generator/protoc/DescriptorUtil.kt#L139
private fun String.underscoresToCamel(): String {
val builder = StringBuilder()
var capNextLetter = true
for ((i, ch) in this.withIndex()) {
if (ch in 'a'..'z') {
builder.append(
if (capNextLetter) ch.uppercaseChar() else ch
)
capNextLetter = false
} else if (ch in 'A'..'Z') {
builder.append(
if (i == 0 && !capNextLetter) ch.uppercaseChar() else ch
)
capNextLetter = false
} else if (ch in '0'..'9') {
builder.append(ch)
capNextLetter = true
} else {
capNextLetter = true
}
}
return builder.toString()
} |
Hmm, it looks like you might already have fixed this in #5 while I was working through my testing in the comment above. |
Hey @kohenkatz our (recent release)[https://github.com/bufbuild/connect-kotlin/releases/tag/v0.1.2] should have a fix for your issue. If you observe any issues, don't be afraid to reach back out :) |
The
java_multiple_files
option is described like this in theprotobuf
documentation:The
grpc-java
andgrpc-kotlin
libraries both honor this option. For the given.proto
file, the following outputs are produced bygrpc-java
:With
java_multiple_files = false
With
java_multiple_files = true
However,
protoc-gen-connect-kotlin
generates identical output irrespective of the value ofjava_multiple_files
:This means that the Request and Response classes are not found when trying to compile the application.
The connect-kotlin generator probably should check this option and generate compatible code.
The text was updated successfully, but these errors were encountered: