Skip to content

Commit 174e2a5

Browse files
authored
impl(generator): allow service proto definitions without leading comments (#8215)
1 parent 0d1f74b commit 174e2a5

3 files changed

Lines changed: 48 additions & 62 deletions

File tree

generator/integration_tests/golden/golden_kitchen_sink_client.h

Lines changed: 39 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,7 @@ namespace golden {
3535
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
3636

3737
///
38-
/// A service account is a special type of Google account that belongs to your
39-
/// application or a virtual machine (VM), instead of to an individual end user.
40-
/// Your application assumes the identity of the service account to call Google
41-
/// APIs, so that the users aren't directly involved.
42-
///
43-
/// Service account credentials are used to temporarily assume the identity
44-
/// of the service account. Supported credential types include OAuth 2.0 access
45-
/// tokens, OpenID Connect ID tokens, self-signed JSON Web Tokens (JWTs), and
46-
/// more.
38+
/// GoldenKitchenSinkClient
4739
///
4840
/// @par Equality
4941
///
@@ -116,23 +108,23 @@ class GoldenKitchenSinkClient {
116108
/// not specified, the token's lifetime will be set to a default value of one
117109
/// hour.
118110
/// @param options Optional. Operation options.
119-
/// @return @googleapis_link{google::test::admin::database::v1::GenerateAccessTokenResponse,generator/integration_tests/test.proto#L914}
111+
/// @return @googleapis_link{google::test::admin::database::v1::GenerateAccessTokenResponse,generator/integration_tests/test.proto#L905}
120112
///
121-
/// [google.test.admin.database.v1.GenerateAccessTokenRequest]: @googleapis_reference_link{generator/integration_tests/test.proto#L874}
122-
/// [google.test.admin.database.v1.GenerateAccessTokenResponse]: @googleapis_reference_link{generator/integration_tests/test.proto#L914}
113+
/// [google.test.admin.database.v1.GenerateAccessTokenRequest]: @googleapis_reference_link{generator/integration_tests/test.proto#L865}
114+
/// [google.test.admin.database.v1.GenerateAccessTokenResponse]: @googleapis_reference_link{generator/integration_tests/test.proto#L905}
123115
///
124116
StatusOr<google::test::admin::database::v1::GenerateAccessTokenResponse>
125117
GenerateAccessToken(std::string const& name, std::vector<std::string> const& delegates, std::vector<std::string> const& scope, google::protobuf::Duration const& lifetime, Options options = {});
126118

127119
///
128120
/// Generates an OAuth 2.0 access token for a service account.
129121
///
130-
/// @param request @googleapis_link{google::test::admin::database::v1::GenerateAccessTokenRequest,generator/integration_tests/test.proto#L874}
122+
/// @param request @googleapis_link{google::test::admin::database::v1::GenerateAccessTokenRequest,generator/integration_tests/test.proto#L865}
131123
/// @param options Optional. Operation options.
132-
/// @return @googleapis_link{google::test::admin::database::v1::GenerateAccessTokenResponse,generator/integration_tests/test.proto#L914}
124+
/// @return @googleapis_link{google::test::admin::database::v1::GenerateAccessTokenResponse,generator/integration_tests/test.proto#L905}
133125
///
134-
/// [google.test.admin.database.v1.GenerateAccessTokenRequest]: @googleapis_reference_link{generator/integration_tests/test.proto#L874}
135-
/// [google.test.admin.database.v1.GenerateAccessTokenResponse]: @googleapis_reference_link{generator/integration_tests/test.proto#L914}
126+
/// [google.test.admin.database.v1.GenerateAccessTokenRequest]: @googleapis_reference_link{generator/integration_tests/test.proto#L865}
127+
/// [google.test.admin.database.v1.GenerateAccessTokenResponse]: @googleapis_reference_link{generator/integration_tests/test.proto#L905}
136128
///
137129
StatusOr<google::test::admin::database::v1::GenerateAccessTokenResponse>
138130
GenerateAccessToken(google::test::admin::database::v1::GenerateAccessTokenRequest const& request, Options options = {});
@@ -158,23 +150,23 @@ class GoldenKitchenSinkClient {
158150
/// @param include_email Include the service account email in the token. If set to `true`, the
159151
/// token will contain `email` and `email_verified` claims.
160152
/// @param options Optional. Operation options.
161-
/// @return @googleapis_link{google::test::admin::database::v1::GenerateIdTokenResponse,generator/integration_tests/test.proto#L956}
153+
/// @return @googleapis_link{google::test::admin::database::v1::GenerateIdTokenResponse,generator/integration_tests/test.proto#L947}
162154
///
163-
/// [google.test.admin.database.v1.GenerateIdTokenRequest]: @googleapis_reference_link{generator/integration_tests/test.proto#L923}
164-
/// [google.test.admin.database.v1.GenerateIdTokenResponse]: @googleapis_reference_link{generator/integration_tests/test.proto#L956}
155+
/// [google.test.admin.database.v1.GenerateIdTokenRequest]: @googleapis_reference_link{generator/integration_tests/test.proto#L914}
156+
/// [google.test.admin.database.v1.GenerateIdTokenResponse]: @googleapis_reference_link{generator/integration_tests/test.proto#L947}
165157
///
166158
StatusOr<google::test::admin::database::v1::GenerateIdTokenResponse>
167159
GenerateIdToken(std::string const& name, std::vector<std::string> const& delegates, std::string const& audience, bool include_email, Options options = {});
168160

169161
///
170162
/// Generates an OpenID Connect ID token for a service account.
171163
///
172-
/// @param request @googleapis_link{google::test::admin::database::v1::GenerateIdTokenRequest,generator/integration_tests/test.proto#L923}
164+
/// @param request @googleapis_link{google::test::admin::database::v1::GenerateIdTokenRequest,generator/integration_tests/test.proto#L914}
173165
/// @param options Optional. Operation options.
174-
/// @return @googleapis_link{google::test::admin::database::v1::GenerateIdTokenResponse,generator/integration_tests/test.proto#L956}
166+
/// @return @googleapis_link{google::test::admin::database::v1::GenerateIdTokenResponse,generator/integration_tests/test.proto#L947}
175167
///
176-
/// [google.test.admin.database.v1.GenerateIdTokenRequest]: @googleapis_reference_link{generator/integration_tests/test.proto#L923}
177-
/// [google.test.admin.database.v1.GenerateIdTokenResponse]: @googleapis_reference_link{generator/integration_tests/test.proto#L956}
168+
/// [google.test.admin.database.v1.GenerateIdTokenRequest]: @googleapis_reference_link{generator/integration_tests/test.proto#L914}
169+
/// [google.test.admin.database.v1.GenerateIdTokenResponse]: @googleapis_reference_link{generator/integration_tests/test.proto#L947}
178170
///
179171
StatusOr<google::test::admin::database::v1::GenerateIdTokenResponse>
180172
GenerateIdToken(google::test::admin::database::v1::GenerateIdTokenRequest const& request, Options options = {});
@@ -206,10 +198,10 @@ class GoldenKitchenSinkClient {
206198
/// as a label in this parameter, then the log entry's label is not changed.
207199
/// See [LogEntry][google.logging.v2.LogEntry]. Test delimiter$
208200
/// @param options Optional. Operation options.
209-
/// @return @googleapis_link{google::test::admin::database::v1::WriteLogEntriesResponse,generator/integration_tests/test.proto#L995}
201+
/// @return @googleapis_link{google::test::admin::database::v1::WriteLogEntriesResponse,generator/integration_tests/test.proto#L986}
210202
///
211-
/// [google.test.admin.database.v1.WriteLogEntriesRequest]: @googleapis_reference_link{generator/integration_tests/test.proto#L962}
212-
/// [google.test.admin.database.v1.WriteLogEntriesResponse]: @googleapis_reference_link{generator/integration_tests/test.proto#L995}
203+
/// [google.test.admin.database.v1.WriteLogEntriesRequest]: @googleapis_reference_link{generator/integration_tests/test.proto#L953}
204+
/// [google.test.admin.database.v1.WriteLogEntriesResponse]: @googleapis_reference_link{generator/integration_tests/test.proto#L986}
213205
///
214206
StatusOr<google::test::admin::database::v1::WriteLogEntriesResponse>
215207
WriteLogEntries(std::string const& log_name, std::map<std::string, std::string> const& labels, Options options = {});
@@ -223,12 +215,12 @@ class GoldenKitchenSinkClient {
223215
/// different resources (projects, organizations, billing accounts or
224216
/// folders)
225217
///
226-
/// @param request @googleapis_link{google::test::admin::database::v1::WriteLogEntriesRequest,generator/integration_tests/test.proto#L962}
218+
/// @param request @googleapis_link{google::test::admin::database::v1::WriteLogEntriesRequest,generator/integration_tests/test.proto#L953}
227219
/// @param options Optional. Operation options.
228-
/// @return @googleapis_link{google::test::admin::database::v1::WriteLogEntriesResponse,generator/integration_tests/test.proto#L995}
220+
/// @return @googleapis_link{google::test::admin::database::v1::WriteLogEntriesResponse,generator/integration_tests/test.proto#L986}
229221
///
230-
/// [google.test.admin.database.v1.WriteLogEntriesRequest]: @googleapis_reference_link{generator/integration_tests/test.proto#L962}
231-
/// [google.test.admin.database.v1.WriteLogEntriesResponse]: @googleapis_reference_link{generator/integration_tests/test.proto#L995}
222+
/// [google.test.admin.database.v1.WriteLogEntriesRequest]: @googleapis_reference_link{generator/integration_tests/test.proto#L953}
223+
/// [google.test.admin.database.v1.WriteLogEntriesResponse]: @googleapis_reference_link{generator/integration_tests/test.proto#L986}
232224
///
233225
StatusOr<google::test::admin::database::v1::WriteLogEntriesResponse>
234226
WriteLogEntries(google::test::admin::database::v1::WriteLogEntriesRequest const& request, Options options = {});
@@ -245,7 +237,7 @@ class GoldenKitchenSinkClient {
245237
/// @param options Optional. Operation options.
246238
/// @return std::string
247239
///
248-
/// [google.test.admin.database.v1.ListLogsRequest]: @googleapis_reference_link{generator/integration_tests/test.proto#L998}
240+
/// [google.test.admin.database.v1.ListLogsRequest]: @googleapis_reference_link{generator/integration_tests/test.proto#L989}
249241
///
250242
StreamRange<std::string>
251243
ListLogs(std::string const& parent, Options options = {});
@@ -254,11 +246,11 @@ class GoldenKitchenSinkClient {
254246
/// Lists the logs in projects, organizations, folders, or billing accounts.
255247
/// Only logs that have entries are listed.
256248
///
257-
/// @param request @googleapis_link{google::test::admin::database::v1::ListLogsRequest,generator/integration_tests/test.proto#L998}
249+
/// @param request @googleapis_link{google::test::admin::database::v1::ListLogsRequest,generator/integration_tests/test.proto#L989}
258250
/// @param options Optional. Operation options.
259251
/// @return std::string
260252
///
261-
/// [google.test.admin.database.v1.ListLogsRequest]: @googleapis_reference_link{generator/integration_tests/test.proto#L998}
253+
/// [google.test.admin.database.v1.ListLogsRequest]: @googleapis_reference_link{generator/integration_tests/test.proto#L989}
262254
///
263255
StreamRange<std::string>
264256
ListLogs(google::test::admin::database::v1::ListLogsRequest request, Options options = {});
@@ -278,10 +270,10 @@ class GoldenKitchenSinkClient {
278270
/// "billingAccounts/[BILLING_ACCOUNT_ID]/locations/[LOCATION_ID]/buckets/[BUCKET_ID]/views/[VIEW_ID]"
279271
/// "folders/[FOLDER_ID]/locations/[LOCATION_ID]/buckets/[BUCKET_ID]/views/[VIEW_ID]"
280272
/// @param options Optional. Operation options.
281-
/// @return @googleapis_link{google::test::admin::database::v1::TailLogEntriesResponse,generator/integration_tests/test.proto#L1256}
273+
/// @return @googleapis_link{google::test::admin::database::v1::TailLogEntriesResponse,generator/integration_tests/test.proto#L1247}
282274
///
283-
/// [google.test.admin.database.v1.TailLogEntriesRequest]: @googleapis_reference_link{generator/integration_tests/test.proto#L1224}
284-
/// [google.test.admin.database.v1.TailLogEntriesResponse]: @googleapis_reference_link{generator/integration_tests/test.proto#L1256}
275+
/// [google.test.admin.database.v1.TailLogEntriesRequest]: @googleapis_reference_link{generator/integration_tests/test.proto#L1215}
276+
/// [google.test.admin.database.v1.TailLogEntriesResponse]: @googleapis_reference_link{generator/integration_tests/test.proto#L1247}
285277
///
286278
StreamRange<google::test::admin::database::v1::TailLogEntriesResponse>
287279
TailLogEntries(std::vector<std::string> const& resource_names, Options options = {});
@@ -290,12 +282,12 @@ class GoldenKitchenSinkClient {
290282
/// Streaming read of log entries as they are ingested. Until the stream is
291283
/// terminated, it will continue reading logs.
292284
///
293-
/// @param request @googleapis_link{google::test::admin::database::v1::TailLogEntriesRequest,generator/integration_tests/test.proto#L1224}
285+
/// @param request @googleapis_link{google::test::admin::database::v1::TailLogEntriesRequest,generator/integration_tests/test.proto#L1215}
294286
/// @param options Optional. Operation options.
295-
/// @return @googleapis_link{google::test::admin::database::v1::TailLogEntriesResponse,generator/integration_tests/test.proto#L1256}
287+
/// @return @googleapis_link{google::test::admin::database::v1::TailLogEntriesResponse,generator/integration_tests/test.proto#L1247}
296288
///
297-
/// [google.test.admin.database.v1.TailLogEntriesRequest]: @googleapis_reference_link{generator/integration_tests/test.proto#L1224}
298-
/// [google.test.admin.database.v1.TailLogEntriesResponse]: @googleapis_reference_link{generator/integration_tests/test.proto#L1256}
289+
/// [google.test.admin.database.v1.TailLogEntriesRequest]: @googleapis_reference_link{generator/integration_tests/test.proto#L1215}
290+
/// [google.test.admin.database.v1.TailLogEntriesResponse]: @googleapis_reference_link{generator/integration_tests/test.proto#L1247}
299291
///
300292
StreamRange<google::test::admin::database::v1::TailLogEntriesResponse>
301293
TailLogEntries(google::test::admin::database::v1::TailLogEntriesRequest const& request, Options options = {});
@@ -312,23 +304,23 @@ class GoldenKitchenSinkClient {
312304
/// response. Duplicate key types are not allowed. If no key type
313305
/// is provided, all keys are returned.
314306
/// @param options Optional. Operation options.
315-
/// @return @googleapis_link{google::test::admin::database::v1::ListServiceAccountKeysResponse,generator/integration_tests/test.proto#L1328}
307+
/// @return @googleapis_link{google::test::admin::database::v1::ListServiceAccountKeysResponse,generator/integration_tests/test.proto#L1319}
316308
///
317-
/// [google.test.admin.database.v1.ListServiceAccountKeysRequest]: @googleapis_reference_link{generator/integration_tests/test.proto#L1296}
318-
/// [google.test.admin.database.v1.ListServiceAccountKeysResponse]: @googleapis_reference_link{generator/integration_tests/test.proto#L1328}
309+
/// [google.test.admin.database.v1.ListServiceAccountKeysRequest]: @googleapis_reference_link{generator/integration_tests/test.proto#L1287}
310+
/// [google.test.admin.database.v1.ListServiceAccountKeysResponse]: @googleapis_reference_link{generator/integration_tests/test.proto#L1319}
319311
///
320312
StatusOr<google::test::admin::database::v1::ListServiceAccountKeysResponse>
321313
ListServiceAccountKeys(std::string const& name, std::vector<google::test::admin::database::v1::ListServiceAccountKeysRequest::KeyType> const& key_types, Options options = {});
322314

323315
///
324316
/// Lists every [ServiceAccountKey][google.iam.admin.v1.ServiceAccountKey] for a service account.
325317
///
326-
/// @param request @googleapis_link{google::test::admin::database::v1::ListServiceAccountKeysRequest,generator/integration_tests/test.proto#L1296}
318+
/// @param request @googleapis_link{google::test::admin::database::v1::ListServiceAccountKeysRequest,generator/integration_tests/test.proto#L1287}
327319
/// @param options Optional. Operation options.
328-
/// @return @googleapis_link{google::test::admin::database::v1::ListServiceAccountKeysResponse,generator/integration_tests/test.proto#L1328}
320+
/// @return @googleapis_link{google::test::admin::database::v1::ListServiceAccountKeysResponse,generator/integration_tests/test.proto#L1319}
329321
///
330-
/// [google.test.admin.database.v1.ListServiceAccountKeysRequest]: @googleapis_reference_link{generator/integration_tests/test.proto#L1296}
331-
/// [google.test.admin.database.v1.ListServiceAccountKeysResponse]: @googleapis_reference_link{generator/integration_tests/test.proto#L1328}
322+
/// [google.test.admin.database.v1.ListServiceAccountKeysRequest]: @googleapis_reference_link{generator/integration_tests/test.proto#L1287}
323+
/// [google.test.admin.database.v1.ListServiceAccountKeysResponse]: @googleapis_reference_link{generator/integration_tests/test.proto#L1319}
332324
///
333325
StatusOr<google::test::admin::database::v1::ListServiceAccountKeysResponse>
334326
ListServiceAccountKeys(google::test::admin::database::v1::ListServiceAccountKeysRequest const& request, Options options = {});

generator/integration_tests/test.proto

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -737,15 +737,6 @@ enum RestoreSourceType {
737737
BACKUP = 1;
738738
}
739739

740-
// A service account is a special type of Google account that belongs to your
741-
// application or a virtual machine (VM), instead of to an individual end user.
742-
// Your application assumes the identity of the service account to call Google
743-
// APIs, so that the users aren't directly involved.
744-
//
745-
// Service account credentials are used to temporarily assume the identity
746-
// of the service account. Supported credential types include OAuth 2.0 access
747-
// tokens, OpenID Connect ID tokens, self-signed JSON Web Tokens (JWTs), and
748-
// more.
749740
service GoldenKitchenSink {
750741
option (google.api.default_host) = "goldenkitchensink.googleapis.com";
751742
option (google.api.oauth_scopes) = "https://www.googleapis.com/auth/cloud-platform";

generator/internal/descriptor_utils.cc

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -298,16 +298,19 @@ std::string EscapePrinterDelimiter(std::string const& text) {
298298
std::string FormatClassCommentsFromServiceComments(
299299
google::protobuf::ServiceDescriptor const& service) {
300300
google::protobuf::SourceLocation service_source_location;
301+
std::string formatted_comments;
301302
if (!service.GetSourceLocation(&service_source_location) ||
302303
service_source_location.leading_comments.empty()) {
303-
GCP_LOG(FATAL) << __FILE__ << ":" << __LINE__ << ": " << service.full_name()
304-
<< " no leading_comments to format";
304+
GCP_LOG(INFO) << __FILE__ << ":" << __LINE__ << ": " << service.full_name()
305+
<< " no leading_comments to format";
306+
formatted_comments = absl::StrCat(" ", service.name(), "Client");
307+
} else {
308+
formatted_comments = absl::StrReplaceAll(
309+
ChompByValue(service_source_location.leading_comments),
310+
{{"\n\n", "\n///\n/// "}, {"\n", "\n/// "}});
305311
}
306312
std::string doxygen_formatted_comments =
307-
absl::StrCat("///\n///",
308-
absl::StrReplaceAll(
309-
ChompByValue(service_source_location.leading_comments),
310-
{{"\n\n", "\n///\n/// "}, {"\n", "\n/// "}}),
313+
absl::StrCat("///\n///", formatted_comments,
311314
R"""(
312315
///
313316
/// @par Equality

0 commit comments

Comments
 (0)