Skip to content

Modify proto files to improve generated Java code #54

Open
@reify-tanner-stirrat

Description

@reify-tanner-stirrat

Background

(take this explanation with a grain of salt; I would not call myself an expert on protobuf and generated code)

You can see the problem here: https://github.com/authzed/authzed-java/blob/main/examples/v1/App.java#L10-L25

This is apparently related to an old behavior of protoc where you could only have a single top-level proto def in a file because you can only have a single top-level class def in a java file. The solution to this was to have protoc generate a wrapper class to bundle up the various definitions in a proto file, which produces the FooOuterClass definitions in the generated Java code.

This ends up being confusing to a user of the library, because whether you need to use FooService or FooServiceOuterClass is entirely down to how many things are defined in the source proto file, which isn't visible to a user of the library without diving into either the jar definition or the proto files.

Proposed fix

Using java_multiple_files in the proto definition as an option should fix this and make the produced code less janky.

Caveat

This will be a breaking change to authzed-java, because all code that referenced FooServiceOuterClass will need to now reference FooService (or something like that).

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