Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FieldOptions.wire_name to dodge name collisions on options #3042

Open
swankjesse opened this issue Jul 22, 2024 · 0 comments
Open

FieldOptions.wire_name to dodge name collisions on options #3042

swankjesse opened this issue Jul 22, 2024 · 0 comments

Comments

@swankjesse
Copy link
Collaborator

We’ve got a problem where Wire generates broken code when the same option name is used for different targets in the same package.

extend google.protobuf.MethodOptions {
  optional float objective = 26101;
}

extend google.protobuf.ServiceOptions {
  optional float objective = 26101;
}

This generates two annotations that potentially collide.

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface ObjectiveOption {
  float value();
}

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface ObjectiveOption {
  float value();
}

I really like the name ObjectiveOption here and am reluctant to qualify the name with its target ObjectiveMethodOption because this collision is just so rare. Instead I’d like to introduce a mechanism where developers who introduce such collisions in the .proto can choose disambiguating names.

We’ll create a new extension:

extend google.protobuf.FieldOptions {
  /**
   * Sets the name used for this field in generated code.
   *
   * This may only be applied to extension fields, and only impacts the generated names for option
   * annotations.
   *
   * It is an error to apply this option to regular message fields and oneof fields.
   *
   * This doesn't impact the name used an any encoding or decoding, such as JSON encoding.
   */
  optional string wire_name = 9999; // TODO
}

And users would use it like so:

extend google.protobuf.MethodOptions {
  optional float objective = 26101 [(wire.wire_name) = "rpc_objective"];
}

extend google.protobuf.ServiceOptions {
  optional float objective = 26101 [(wire.wire_name) = "service_objective"];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant