Skip to content

Generator does not respect java_multiple_files option #6

@kohenkatz

Description

@kohenkatz

The java_multiple_files option is described like this in the protobuf documentation:

... For each .proto file input, the compiler creates a wrapper .java file containing a Java class which represents the .proto file itself.

If the .proto file contains a line like the following:

option java_multiple_files = true;

Then the compiler will also create separate .java files for each of the classes/enums which it will generate for each top-level message, enumeration, and service declared in the .proto file.

Otherwise (i.e. when the java_multiple_files option is disabled; which is the default), the aforementioned wrapper class will also be used as an outer class, and the generated classes/enums for each top-level message, enumeration, and service declared in the .proto file will all be nested within the outer wrapper class. Thus the compiler will only generate a single .java file for the entire .proto file.

The grpc-java and grpc-kotlin libraries both honor this option. For the given .proto file, the following outputs are produced by grpc-java:

syntax = "proto3";

package com.example;

option java_package = "com.example";

service EventService {
    rpc Start (StartRequest) returns (StartResponse);
}

message StartRequest { }

message StartResponse { }

With java_multiple_files = false

public suspend fun start(request: com.example.EventsServiceProto.StartRequest, headers: Metadata = Metadata()): com.example.EventsServiceProto.StartResponse = unaryRpc(
  channel,
  EventServiceGrpc.getStartMethod(),
  request,
  callOptions,
  headers
)

With java_multiple_files = true

public suspend fun start(request: com.example.StartRequest, headers: Metadata = Metadata()): com.example.StartResponse = unaryRpc(
  channel,
  EventServiceGrpc.getStartMethod(),
  request,
  callOptions,
  headers
)

However, protoc-gen-connect-kotlin generates identical output irrespective of the value of java_multiple_files:

public override suspend fun start(request: StartRequest, headers: Headers): ResponseMessage<StartResponse> = client.unary(
  request,
  headers,
  MethodSpec(
  "live.v1.EventService/Start",
    com.example.StartRequest::class,
    com.example.StartResponse::class,
  ),
)

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.

Metadata

Metadata

Assignees

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