Skip to content
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

[Kotlin] google.api.field_behavior from proto file generates unresolved reference and results in compile error #3198

Open
karthi2007 opened this issue Dec 3, 2024 · 2 comments

Comments

@karthi2007
Copy link

karthi2007 commented Dec 3, 2024

Issue: Compile error on generated kotlin code

Proto file
I have a proto file with field_behavior attribute for a parameter.

import "buf/validate/validate.proto";
import "google/api/field_behavior.proto";

message GetABCRequest {
  string item_id = 1 [
    (buf.validate.field).string = {min_len: 1},
    (google.api.field_behavior) = REQUIRED
  ];
}

Generated code:

import com.google.api.FieldBehavior
import com.google.api.FieldBehaviorOption

public class GetABCRequest(
  @FieldBehaviorOption(value = [
    FieldBehavior.REQUIRED
  ])
  @field:WireField(
    tag = 1,
    adapter = "com.squareup.wire.ProtoAdapter#STRING",
    label = WireField.Label.OMIT_IDENTITY,
    jsonName = "itemId",
    schemaIndex = 0,
  )
  public val item_id: String = "",
  unknownFields: ByteString = ByteString.EMPTY,
) : Message<GetABCRequest, Nothing>(ADAPTER, unknownFields) {

"Config":

wire {
...
protoPath {
        srcJar("com.google.api.grpc:proto-google-common-protos:2.45.1")
        srcJar("build.buf:protovalidate:0.4.2")
    }
...
}

dependencies {
   ...
   implementation("com.google.api.grpc:proto-google-common-protos:2.45.1")
   ...
}

Issue:
Unresolved reference 'FieldBehaviorOption'.

import com.google.api.FieldBehaviorOption

There is no FieldBehaviorOption in google library to refer.

@karthi2007 karthi2007 changed the title [Kotlin] google.api.field_behavior from proto file generates unavailable reference and results in compile error [Kotlin] google.api.field_behavior from proto file generates unresolved reference and results in compile error Dec 3, 2024
@karthi2007
Copy link
Author

Build gradle details

wire {
...
protoPath {
        srcJar("com.google.api.grpc:proto-google-common-protos:2.45.1")
        srcJar("build.buf:protovalidate:0.4.2")
    }
...
}

dependencies {
   ...
   implementation("com.google.api.grpc:proto-google-common-protos:2.45.1")
   ...
}

@oldergod
Copy link
Member

In the kotlin {} block, you can use those two options

    // True to emit types for options declared on messages, fields, etc.
    emitDeclaredOptions = true

    // True to emit annotations for options applied on messages, fields, etc.
    emitAppliedOptions = true

If you need the annotations, set them to true, or both to false if you don't.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants