-
Notifications
You must be signed in to change notification settings - Fork 3
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
Fix Gen Class Without Any Properties #15
Conversation
@Dogacel please help to take a look at my PR and let me know your thought!! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Happy to have you as the first contributor 🎉
There are some minor fixes we gotta do. I am not sure if the CI/CD pipeline is ready for PRs as well. I will check it tomorrow morning.
Please let me know if you need any help, I can jump in to fix those small nits 😄
app/src/main/kotlin/dogacel/kotlinx/protobuf/gen/CodeGenerator.kt
Outdated
Show resolved
Hide resolved
testProtos/data_class.proto
Outdated
@@ -0,0 +1,14 @@ | |||
syntax = "proto3"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you run ./gradlew build
in your local? I commit all the generated classes under generated-code-tests. Also we should have a test there to verify an empty message without any properties are serialized correctly.
app/src/main/kotlin/dogacel/kotlinx/protobuf/gen/CodeGenerator.kt
Outdated
Show resolved
Hide resolved
@@ -193,7 +212,7 @@ class CodeGenerator { | |||
* @param messageDescriptor [Descriptors.Descriptor] to generate code for. | |||
* @return [TypeSpec.Builder] that contains the generated code. | |||
*/ | |||
private fun generateSingleClass(messageDescriptor: Descriptors.Descriptor): TypeSpec.Builder { | |||
private fun generateDataClass(messageDescriptor: Descriptors.Descriptor): TypeSpec.Builder { | |||
val typeSpec = TypeSpec.classBuilder(messageDescriptor.name) | |||
.addModifiers(KModifier.DATA) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One thing I would suggest to simplify the code and reduce duplication is to add this modifier conditionally based on isHasPropertyField
call. Simply we can hide this logic behind the generateSingleClass
method so users don't have to worry about figuring out which method to call 🙂
app/src/main/kotlin/dogacel/kotlinx/protobuf/gen/CodeGenerator.kt
Outdated
Show resolved
Hide resolved
*/ | ||
private fun isHasPropertyField(fileDescriptor: Descriptors.Descriptor): Boolean { | ||
return fileDescriptor.fields.any { | ||
it.isOptional || it.isRequired || it.isRepeated |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have a question, in proto3 if optional int32 x = 1
is considered optional and in proto2 if required int32 x = 1
is considered required, is this going to return false int32 x = 1
?
I think we should have a couple of unit tests to verify this doesn't break anything.
Welcome to Codecov 🎉Once merged to your default branch, Codecov will compare your coverage reports and display the results in this comment. Thanks for integrating Codecov - We've got you covered ☂️ |
I have added some additional checks to make sure we generate the code. Also updated codecov to show coverage info. I had to merge latest main into your PR to see those. Don't forget to fetch remote 😉 |
Change fix generate class without Any Properties
Result
Fixes #20