Wrong generated java class name with Buf

69 Views Asked by At

According to buf doc, by default option java_outer_classname converts the weather.proto filename, for example, to WeatherProto. In my case, it converted it to WeatherOuterClass.

I'm not setting the option java_outer_classname in my proto file because I thought it would be handled by default by Buf. Am I missing something?

My buf.gen.yaml looks like:

version: v1

managed:
  enabled: true

plugins:
  - plugin: go
    out: v3/golang/gen
    opt: paths=source_relative

My buf.yaml looks like:

version: v1

breaking:
  use:
    - FILE
lint:
  use:
    - DEFAULT
1

There are 1 best solutions below

0
On

This seems to work as documented for me. I'm starting with this tree:

.
├── acme
│   └── weather
│       └── v1
│           └── weather.proto
└── buf.gen.yaml

My buf.gen.yaml:

version: v1
managed:
  enabled: false
plugins:
  - plugin: buf.build/protocolbuffers/java:v25.1
    out: gen

My acme/weather/v1/weather.proto:

syntax="proto3";

option java_package="com.acme.weather.v1";
option java_multiple_files=true;
option java_outer_classname="WeatherProto";

package acme.weather.v1;

message WeatherMessage {}

buf generate generates a class com.acme.weather.v1.WeatherProto.

Now with managed mode enabled:

version: v1
managed:
  enabled: true
# ...

And the options in acme/weather/v1/weather.proto commented out:

syntax="proto3";

// option java_package="com.acme.weather.v1";
// option java_multiple_files=true;
// option java_outer_classname="WeatherProto";
// ...

buf generate generates the same class com.acme.weather.v1.WeatherProto. Managed mode simply sets the options, but does not make any other modifications.