square / square/wire

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

Open
#3,198 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Kotlin
Stars
4.4k
Forks
627
Avg merge
3d 15m
Merged PRs (30d)
20

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing generation from the provided proto file and Wire configuration, then inspect how google.api.field_behavior is mapped into generated Kotlin annotations. Compare the generated imports with the declarations available in proto-google-common-protos; done means the generated Kotlin compiles without the unresolved FieldBehaviorOption reference.

Written by the indexing model from the issue text.

Assessment

Tech stack
kotlin
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.