Skip to content

'Collection has more than one element' when an RPC option contains a multi-value inlined map #3308

Open
@tejasna

Description

@tejasna

I'm encountering an issue where generateCommonMainProtos fails when an RPC option includes an inlined map with multiple values.

Wire Configuration
I have configured Wire to not generate services and applied the following options:

 kotlin {
    emitDeclaredOptions = false
    emitAppliedOptions = false
    rpcRole = "none"
}

Problematic RPC and Extension Option
This is the RPC and associated extension where generation fails:

  rpc Create(Request) returns (Response) {
    option (protobuf.ratelimit.limit) = {
      limits: {
        key: "key"
        value: {
          unit: "minute"
          requests_per_unit: 20
        }
      }
    };
  }
package protobuf.ratelimit;

extend google.protobuf.MethodOptions {
  MethodOptionsRateLimits limit = 50006;
}

message MethodOptionsRateLimits {
  map<string, RateLimit> limits = 1;
}

message RateLimit {
  string unit = 1;
  int64 requests_per_unit = 2;
}

The execution fails with the following error message:
> Collection has more than one element.

I believe the error occurs in this line, which seems to expect the inlined map value to have a single entry:
Options.kt#L391

Environment
Wire version: 5.3.1
Kotlin version: 2.1.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions