From e5aff7b8e4bee7db57571bac6a67bbba308213c6 Mon Sep 17 00:00:00 2001 From: Jon Skeet Date: Thu, 27 Jun 2024 07:46:20 +0100 Subject: [PATCH] feat: Fail generation when a service or method is missing a comment Fixes #652. --- Google.Api.Generator/CodeGenerator.cs | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/Google.Api.Generator/CodeGenerator.cs b/Google.Api.Generator/CodeGenerator.cs index d2d509c7..120ee717 100644 --- a/Google.Api.Generator/CodeGenerator.cs +++ b/Google.Api.Generator/CodeGenerator.cs @@ -240,9 +240,7 @@ private static void ValidateTransports(ApiTransports transports, List /// Validate that all proto elements have comments (except the file descriptor). /// We only log warnings for most missing elements; for services and methods, we log warnings - /// and then a log a single combined error at the end, as the generated code won't compile. - /// In the future, we will ideally throw an error instead of just logging, to encourage API producers - /// to fix the protos early. + /// and then throw a single combined error at the end, as the generated code won't compile. /// /// This will still allow through uncommented fields used in method signatures: it would be fiddly to detect /// those. @@ -256,10 +254,7 @@ private static void ValidateComments(IEnumerable descriptorProto } if (errors.Any()) { - Logging.LogError("One or more proto elements has no comment. Violations: {errors}", string.Join(", ", errors)); - // At some point it would be good to actually throw. More work is required to find out how many existing APIs that would break - // though. - // throw new InvalidOperationException($"One or more proto elements has no comment. Violations: {string.Join(", ", errors)}"); + throw new InvalidOperationException($"One or more proto elements has no comment. Violations: {string.Join(", ", errors)}"); } void ValidateFile(FileDescriptor proto)