ScalaPB icon indicating copy to clipboard operation
ScalaPB copied to clipboard

Allow customizing visibility of the models generated from third-party protos

Open iRevive opened this issue 10 months ago • 2 comments

The problem

otel4s provides a pure Scala implementation of the OpenTelemetry specification. The protocol models used by otel4s are generated from the third-party protos defined in opentelemetry-proto.

Currently, these models are generated in a public package, making them accessible on the classpath.

This poses a significant problem because opentelemetry-proto may introduce binary-breaking changes. As a result, any updates to the opentelemetry-proto can cause otel4s-sdk-exporter-proto to break binary compatibility.

https://scalapb.github.io/docs/faq/#how-do-i-mark-a-generated-case-class-private doesn't work because proto models are third-party.

The proposition

Perhaps we can extend the package-scoped options to allow customizing modifiers of a package?

import "scalapb/scalapb.proto";

package com.mypackage;

option (scalapb.options) = {
  scope: PACKAGE
  package_modifier: "private[com.mypackage]" // or "private"
};

The workaround

As a workaround, I customized the PB.generate task to override package and visibility afterward: https://github.com/typelevel/otel4s/pull/860.

iRevive avatar Dec 03 '24 17:12 iRevive