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

import DescriptorProto custom option extensions with "import" #3

Open
dvisztempacct opened this issue Jul 11, 2018 · 0 comments
Open

Comments

@dvisztempacct
Copy link
Contributor

When importing a package with import you can access custom options that are defined therein by namespacing the option with the package name of the imported .proto file where said custom options were are defined.

For example, this works:

extend.proto:

syntax = "proto3";
package tin_extend;
/* boilerplate needed for TIN sanitization/validation/normalization */
import "google/protobuf/descriptor.proto";
extend google.protobuf.FileOptions {
  string tin_module_validation = 4000;
}
extend google.protobuf.MessageOptions {
  string tin_message_validation = 4000;
}
extend google.protobuf.FieldOptions {
  string tin_field_validation = 4000;
}

assemblyline.proto:

syntax = "proto3";
package assemblyline;
import "extend.proto";

/* Our proto stuff */

enum WidgetCondition {
  WIDGET_CONDITION_ADEQUATE = 0;
  WIDGET_CONDITION_DEFECTIVE = 1;
}

enum WidgetColor {
  WIDGET_COLOR_UNPAINTED = 0;
  WIDGET_COLOR_RED = 1;
  WIDGET_COLOR_GREEN = 2;
}

message BlankWidget {
  WidgetCondition condition = 1 [
    (tin_extend.tin_field_validation) = "required"
  ];
}

message CutWidget {
  WidgetCondition condition = 1 [
    (tin_extend.tin_field_validation) = "required"
  ];
  int32 numTeeth = 2 [
    (tin_extend.tin_field_validation) = "required |> numberRange(32, 63)"
  ];
}

message PaintedWidget {
  WidgetCondition condition = 1[
    (tin_extend.tin_field_validation) = "required"
  ];
  int32 numTeeth = 2[
    (tin_extend.tin_field_validation) = "required |> numberRange(32, 63)"
  ];
  WidgetColor paintJob = 3[
    (tin_extend.tin_field_validation) = "required"
  ];
}

message BoxOfWidgets {
  repeated PaintedWidget paintedWidgets = 1;
}
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