Skip to content

Commit

Permalink
feat: Fail generation when a service or method is missing a comment
Browse files Browse the repository at this point in the history
Fixes #652.
  • Loading branch information
jskeet committed Jun 27, 2024
1 parent 08ac199 commit e5aff7b
Showing 1 changed file with 2 additions and 7 deletions.
9 changes: 2 additions & 7 deletions Google.Api.Generator/CodeGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,7 @@ private static void ValidateTransports(ApiTransports transports, List<ServiceDet
/// <summary>
/// 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.
Expand All @@ -256,10 +254,7 @@ private static void ValidateComments(IEnumerable<FileDescriptor> 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)
Expand Down

0 comments on commit e5aff7b

Please sign in to comment.