diff --git a/api/address.proto b/api/address.proto index bb1426bd..7fbb42b1 100644 --- a/api/address.proto +++ b/api/address.proto @@ -20,7 +20,7 @@ message SocketAddress { // [#not-implemented-hide:] UDP = 1; } - Protocol protocol = 1; + Protocol protocol = 1 [(validate.rules).enum.defined_only = true]; // The address for this socket. :ref:`Listeners ` will bind // to the address or outbound connections will be made. An empty address is // not allowed, specify ``0.0.0.0`` or ``::`` to bind any. It's still possible to diff --git a/api/base.proto b/api/base.proto index 9d53b415..e565cc88 100644 --- a/api/base.proto +++ b/api/base.proto @@ -149,7 +149,7 @@ message ApiConfigSource { // gRPC v2 API. GRPC = 2; } - ApiType api_type = 1; + ApiType api_type = 1 [(validate.rules).enum.defined_only = true]; // Multiple cluster names may be provided. If > 1 cluster is defined, clusters // will be cycled through if any kind of failure occurs. repeated string cluster_name = 2 [(validate.rules).repeated .min_items = 1]; diff --git a/api/cds.proto b/api/cds.proto index 9be43ee4..fd649206 100644 --- a/api/cds.proto +++ b/api/cds.proto @@ -422,6 +422,8 @@ message CircuitBreakers { message Thresholds { // The :ref:`RoutingPriority` // the specified CircuitBreaker settings apply to. + // [#comment:TODO(htuch): add (validate.rules).enum.defined_only = true once + // https://github.com/lyft/protoc-gen-validate/issues/42 is resolved.] RoutingPriority priority = 1; // The maximum number of connections that Envoy will make to the upstream diff --git a/api/filter/accesslog/accesslog.proto b/api/filter/accesslog/accesslog.proto index fc842b5c..8d578cd0 100644 --- a/api/filter/accesslog/accesslog.proto +++ b/api/filter/accesslog/accesslog.proto @@ -150,6 +150,8 @@ message TCPAccessLogEntry { // [#not-implemented-hide:] Not configuration. TBD how to doc proto APIs. message HTTPRequestProperties { // The request method (RFC 7231/2616). + // [#comment:TODO(htuch): add (validate.rules).enum.defined_only = true once + // https://github.com/lyft/protoc-gen-validate/issues/42 is resolved.] RequestMethod request_method = 1; // The scheme portion of the incoming request URI. diff --git a/api/rds.proto b/api/rds.proto index 609e39ac..63ba15d0 100644 --- a/api/rds.proto +++ b/api/rds.proto @@ -431,6 +431,8 @@ message RouteAction { RequestMirrorPolicy request_mirror_policy = 10; // Optionally specifies the :ref:`routing priority `. + // [#comment:TODO(htuch): add (validate.rules).enum.defined_only = true once + // https://github.com/lyft/protoc-gen-validate/issues/42 is resolved.] RoutingPriority priority = 11; // Specifies a set of headers that will be added to requests matching this @@ -623,6 +625,8 @@ message VirtualCluster { // Optionally specifies the HTTP method to match on. For example GET, PUT, // etc. + // [#comment:TODO(htuch): add (validate.rules).enum.defined_only = true once + // https://github.com/lyft/protoc-gen-validate/issues/42 is resolved.] RequestMethod method = 3; } diff --git a/tools/protodoc/protodoc.py b/tools/protodoc/protodoc.py index 91f6b907..38511ee7 100755 --- a/tools/protodoc/protodoc.py +++ b/tools/protodoc/protodoc.py @@ -22,7 +22,7 @@ WKT_NAMESPACE_PREFIX = '.google.protobuf.' UNICODE_INVISIBLE_SEPARATOR = u'\u2063' # Key-value annotation regex. -ANNOTATION_REGEX = re.compile('\[#([\w-]+?):(.*?)\]\s?') +ANNOTATION_REGEX = re.compile('\[#([\w-]+?):(.*?)\]\s?', re.DOTALL) # Page/section titles with special prefixes in the proto comments DOC_TITLE_ANNOTATION = 'protodoc-title' @@ -99,18 +99,16 @@ def ExtractAnnotations(s, inherited_annotations=None, type_name='file'): for k, v in (inherited_annotations or {}).items() if k in INHERITED_ANNOTATIONS } - stripped_lines = [] - for line in s.split('\n'): - groups = re.findall(ANNOTATION_REGEX, line) - stripped_line = re.sub(ANNOTATION_REGEX, '', line) - if stripped_line.strip() or not groups: - stripped_lines.append(stripped_line) - for group in groups: - annotation = group[0] - if annotation not in VALID_ANNOTATIONS: - raise ProtodocError('Unknown annotation: %s' % annotation) - annotations[group[0]] = group[1].lstrip() - return FormatCommentWithAnnotations('\n'.join(stripped_lines), annotations, + # Extract annotations. + groups = re.findall(ANNOTATION_REGEX, s) + # Remove annotations. + without_annotations = re.sub(ANNOTATION_REGEX, '', s) + for group in groups: + annotation = group[0] + if annotation not in VALID_ANNOTATIONS: + raise ProtodocError('Unknown annotation: %s' % annotation) + annotations[group[0]] = group[1].lstrip() + return FormatCommentWithAnnotations(without_annotations, annotations, type_name), annotations